Syscall

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
JMA_SP

Syscall

Post by JMA_SP »

Hello. I?d like to know with a simple example how to implement a simple syscall in assembly.
Thanks.
paulbarker

Re:Syscall

Post 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.
hendric

Re:Syscall

Post by hendric »

sysenter/sysleave(syscall/sysret) instructions 're the very things you need.
paulbarker

Re:Syscall

Post 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 :).
hendric

Re:Syscall

Post 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.
lode

Re:Syscall

Post by lode »

Does anyone have a simple implementation example for syscall/sysenter based uhm.. syscall?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Syscall

Post by Solar »

Erm... the Intel Manuals perhaps?
Every good solution is obvious once you've found it.
lode

Re:Syscall

Post 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
Post Reply