Page 1 of 1

Syscall

Posted: Sun Mar 26, 2006 5:13 am
by JMA_SP
Hello. I?d like to know with a simple example how to implement a simple syscall in assembly.
Thanks.

Re:Syscall

Posted: Sun Mar 26, 2006 5:32 am
by paulbarker
I take it you mean for x86.

In kernel mode, set up the IDT with a syscall interrupt (say index 0x80) which can be triggered from user mode. The handler for this interrupt has a syscall table and takes a parameter (in eax) which is the syscall number. It looks up the number in the table and dispatches the request (typically the table is an array of function pointers).

The user program raises a software interrupt ("int 0x80" in this example), with eax set to the syscall number it wants.

Parameter passing is left as an excersize to the reader.

Re:Syscall

Posted: Sun Mar 26, 2006 9:17 am
by hendric
sysenter/sysleave(syscall/sysret) instructions 're the very things you need.

Re:Syscall

Posted: Sun Mar 26, 2006 9:34 am
by paulbarker
sysenter/sysleave and syscall/sysret don't work on all x86 processors if I remember rightly. I'd suggest starting with interrupts and adding those pairs as options depending on what processor you're targeting.

Thats what I'm intending to do with my OS anyways :).

Re:Syscall

Posted: Sun Mar 26, 2006 9:52 am
by hendric
paulbarker wrote: sysenter/sysleave and syscall/sysret don't work on all x86 processors if I remember rightly. I'd suggest starting with interrupts and adding those pairs as options depending on what processor you're targeting.

Thats what I'm intending to do with my OS anyways :).
Yea you 're right. To implement syscalls via interrupts may be the best choice.

Re:Syscall

Posted: Fri Mar 31, 2006 3:23 am
by lode
Does anyone have a simple implementation example for syscall/sysenter based uhm.. syscall?

Re:Syscall

Posted: Fri Mar 31, 2006 3:36 am
by Solar
Erm... the Intel Manuals perhaps?

Re:Syscall

Posted: Fri Mar 31, 2006 4:03 am
by lode
Solar wrote: Erm... the Intel Manuals perhaps?
Yes, I own the Holy Books of Intel, but what I'm looking for would be an actual implementation example, so I could actually see how it fits into an existing system.
I couldn't find a clean example by google, so I thought I might as well ask.

(Actually the Manuals are under my motherboard right now, the board is not in a case and the coolant pipes were too short. Luckily there are the PDF versions ;)

I think I'll try to get my simple sysenter test working and upload it somewhere. Maybe someone else will someday need it. I'm nowhere near implementing them in the core project at this time, I want to handle several bigger performance issues before that. :S