RetroForum Welcome, Guest. Please login or register.
September 09, 2010, 10:59:15 PM
Home Help Search Calendar Login Register

RetroForth Discussion  |  Older Boards  |  Development  |  Topic: RF/linux/linux.asm syscall revisited « previous next »
Pages: 1 Go Down Print
Author Topic: RF/linux/linux.asm syscall revisited  (Read 2494 times)
krostif
Jr. Member
***

Karma: +0/-0
Offline Offline

Posts: 11

Mi ankaw parolas esperanton.


View Profile WWW
RF/linux/linux.asm syscall revisited
« on: May 23, 2006, 10:17:39 AM »

Please find herewith a simpler and shorter version of syscall in RF/linux/linux.asm:
Code:
code 'syscall', _syscall

       ; syscalls can take a variable number of arguments, from 0 to 6.
       ; The args go in ebx, ecx, edx, esi, edi, ebp, in that order.
       ; (this is from the Linux Assembly HOWTO)

       ; At entry, the Forth stack holds args, argcount, syscall-number

       ; validate argcount, if > 6 return without changing the stack
           mov ecx, [esi]          ; ecx = argcount
           cmp ecx, 6
           ja .ret

           lea edi, [esi+4 +4*ecx] ; compute data stack adjustment
           push edi                ; save it
           push eax                ; save syscall-number
           mov eax, esi            ; esi modified when argcount>3
           neg ecx
           lea ecx, [.0 +4*ecx]    ; i.e. .0-4*argcount
           jmp ecx

.6:        mov ebp, [eax+24]       ; 3-bytes instruction
           nop                     ; 1-byte nop padding
.5:        mov edi, [eax+20]
           nop
.4:        mov esi, [eax+16]
           nop
.3:        mov edx, [eax+12]
           nop
.2:        mov ecx, [eax+8]
           nop
.1:        mov ebx, [eax+4]
           nop
.0:        pop eax                 ; restore syscall-number
           int 80h                 ; eax = syscall result
           pop esi                 ; restore adjusted data stack
.ret:      ret
Logged

Charles Childers
Administrator
Sr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 745


View Profile WWW
Re: RF/linux/linux.asm syscall revisited
« Reply #1 on: May 24, 2006, 02:12:46 AM »

Looks good; I have merged this into my private repository which will eventually become RetroForth 9.2 Smiley
Logged
ron
Contributor
Full Member
****

Karma: +0/-0
Offline Offline

Posts: 88


View Profile WWW
Re: RF/linux/linux.asm syscall revisited
« Reply #2 on: May 24, 2006, 05:22:09 AM »

Me too! Wink
Logged
Helmar
Library Contributor
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 129

TUCK what??? SWAP OVER!!!


View Profile
Re: RF/linux/linux.asm syscall revisited
« Reply #3 on: May 24, 2006, 11:54:03 PM »

Why
Code:
           lea ecx, [.0 +4*ecx]    ; i.e. .0-4*argcount
Huh
It would work perfectly with
Code:
           lea ecx, [.0 +3*ecx]  ; is ECX + ECX * 2
and without the nop padding.

... wrong edit, too late today ...

-Helmar
« Last Edit: May 25, 2006, 01:14:15 AM by Helmar » Logged
krostif
Jr. Member
***

Karma: +0/-0
Offline Offline

Posts: 11

Mi ankaw parolas esperanton.


View Profile WWW
Re: RF/linux/linux.asm syscall revisited
« Reply #4 on: May 29, 2006, 08:57:49 AM »

Quote
It would work perfectly with
Code:
           lea ecx, [.0 +3*ecx]  ; is ECX + ECX * 2
and without the nop padding.
You're perfectly right.
Thanks Helmar.
Logged

tcn
Contributor
Jr. Member
***

Karma: +0/-0
Offline Offline

Posts: 30


View Profile WWW
Re: RF/linux/linux.asm syscall revisited
« Reply #5 on: June 18, 2006, 05:06:49 PM »

The NOP padding must be because some x86 CPUs expect 2- or 4- byte alignment... I think the 486 was the worst, and newer ones might not care at all. It only adds 6 bytes, so I suggest leaving it in for the people running Retro on old computers.
Logged
Helmar
Library Contributor
Full Member
****

Karma: +1/-0
Offline Offline

Posts: 129

TUCK what??? SWAP OVER!!!


View Profile
Re: RF/linux/linux.asm syscall revisited
« Reply #6 on: June 18, 2006, 06:23:59 PM »

Well, but in that case I would think it's also needed to align the starting code. I dont think it's needed to make a alignment of the entry points (the addr is passed to a JMP ECX!). Probably it could give some ticks less time to run (best with a 4k-alignement for some AMD processors) - but together with the overhead of a syscall this "optimization" is about nothing. Especially because modern processors dont care that much about. So for making the code more clear and understandable, I would not use the padding.

-Helmar
Logged
Pages: 1 Go Up Print 
RetroForth Discussion  |  Older Boards  |  Development  |  Topic: RF/linux/linux.asm syscall revisited « previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC2 | SMF © 2001-2005, Lewis Media Valid XHTML 1.0! Valid CSS!