What are syscalls for?

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
User avatar
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

What are syscalls for?

Post by d4n1l0d »

What are syscalls for?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Wow, You could of at least searched around a bit.. :wink:

There is an article about it on the Wiki, and countless forum discussions..

http://www.osdev.org/wiki/System_Calls
http://en.wikipedia.org/wiki/System_call

Good luck :roll:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

Post by d4n1l0d »

sorry, I was in a hurry =//
Thank you for the links
User avatar
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Post by deadmutex »

User applications and other non-privileged code use system calls in order to access system services that are controlled by the kernel. User code and Kernel code should be completely separated with the system calls as an interface. This way, the user can't touch the sensitive stuff in the kernel. Without system calls, a userland program wouldn't be able to do much besides calculate stuff...

Some examples of system calls are:

yield(): Give up control of processor
sleep(): Sleep for x msecs
read(): Read a file
write(): Write to a file
sendMsg(): Send a message to another process
sbrk(): Extend end of heap pointer
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Typically your kernel sets up an interrupt (Linux uses 0x80, Windows 0x21) and user space code calls these interrupts, generally with a function number in EAX. My syscall interface uses a switch() statement to choose what to execute.

For instance, my kernel has, on syscall 0x01, "Print String". Instead of rewriting my console i/o code into userland programs, I just call int 0x80 (my kernel's interrupt) with EAX=1 and ESI=addy of string.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

I found this page from the FreeBSD developers handbook informative..

http://www.freebsd.org/doc/en_US.ISO885 ... calls.html
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

Post by d4n1l0d »

thank you very much
so, when the user calls a syscall function the processor goes to ring 0 and execute kernel code??
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Pretty much...
User avatar
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

Post by d4n1l0d »

xD
Post Reply