9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] How do 9syscalls work?
@ 2008-01-25  9:54 Anant Narayanan
  2008-01-25 11:03 ` Charles Forsyth
  0 siblings, 1 reply; 2+ messages in thread
From: Anant Narayanan @ 2008-01-25  9:54 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hi,

Sorry if this is explained somewhere already. I couldn't find an  
answer, so here we go.

Considering the `print' function of libc, we see that it calls  
`vfprint', which in turn calls `fmtFdFlush', which finally calls  
`write' with 3 parameters.

write(2) says that the source is to be found in /sys/src/libc/ 
9syscall, but the mkfile in there defines `_write' which in turn does  
nothing but push the value 20 on the accumulator and call the  
interrupt 0x64.

a) Where is `write' actually defined? (Or does `write' simply call  
`_write'?)
b) Why do some syscalls have `_' prefixes while others do not?
c) How are the parameters to the libc syscall wrapper passed onto the  
actual kernel-side implementation?

Thank you for your time.

Cheers,
Anant


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9fans] How do 9syscalls work?
  2008-01-25  9:54 [9fans] How do 9syscalls work? Anant Narayanan
@ 2008-01-25 11:03 ` Charles Forsyth
  0 siblings, 0 replies; 2+ messages in thread
From: Charles Forsyth @ 2008-01-25 11:03 UTC (permalink / raw)
  To: 9fans

> a) Where is `write' actually defined? (Or does `write' simply call  
> `_write'?)

/sys/src/libc/9sys/write.c
it calls pwrite.

>b) Why do some syscalls have `_' prefixes while others do not?

_write is there to allow executables to work that pre-date the introduction of pwrite
(it's a similar tale for read).  a few others emulate calls for executables that pre-date
the 4th edition changes (eg, stat, wstat, fwstat and others).  most of those could probably
be removed now.  one implication is that plan 9 actually has even fewer real system calls.

>c) How are the parameters to the libc syscall wrapper passed onto the  
>actual kernel-side implementation?

the sys calls find their parameters in the usual place for
the particular architecture's calling sequence, except that
when the compiler uses a register for the first argument (eg, mips, sparc, power, amd64)
that value is also put on the stack inside the sys call routine in libc,
and replaced by the system call number, before using which ever trap
convention is used on that platform to do the actual system call.
the kernel carefully copies them in from the stack (just in case).
seek has special handling because of the returned vlong.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-01-25 11:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-25  9:54 [9fans] How do 9syscalls work? Anant Narayanan
2008-01-25 11:03 ` Charles Forsyth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).