[comp.lang.c] Asm glue for UNIX system calls

levy@ttrdc.UUCP (07/09/87)

In article <4788@columbia.UUCP>, francus@cheshire.columbia.edu (Yoseff Francus) writes:
> >The original PDP-11 Unixes had grossly non-C system-call conventions and
> >worked fine despite a C compiler that never supported "asm" at all.
> >Henry Spencer @ U of Toronto Zoology
> 
> Well, if you look at the source code, if you have source, you'll notice
> that most - if not all - of the system call found in Section 2 of the
> manual are written in 'C'. In fact even kernel system calls like namei
> are written in 'C'.

Gee whiz, they're all in asm on this machine (3b20):

$ ls -C /usr/src/lib/libC/u3b/sys
access.s   dup.s      getpid.s   mount.s    read.s     stime.s    umount.s
acct.s     execve.s   getppid.s  msgsys.s   sbrk.s     stty.s     uname.s
alarm.s    exit.s     getuid.s   nice.s     semsys.s   sync.s     unlink.s
chdir.s    fcntl.s    gtty.s     open.s     setgid.s   sys3b.s    ustat.s
chmod.s    fork.s     ioctl.s    pause.s    setpgrp.s  syscall.s  utime.s
chown.s    fstat.s    kill.s     pipe.s     setuid.s   time.s     wait.s
chroot.s   getegid.s  link.s     plock.s    shmsys.s   times.s    write.s
close.s    geteuid.s  lseek.s    profil.s   signal.s   ulimit.s
creat.s    getgid.s   mknod.s    ptrace.s   stat.s     umask.s

and for good reason.  The way you get into the guts of a system call in the
first place is via a special instruction (e.g., "gate" on the 3B2) which is
your magic trap door into the kernel for the system call you are invoking from
your process.  Nothing says that communication between the code on the near
and far sides of that door has to abide by the semantics of an ordinary
procedure call.  It could be through designated machine registers.  How do
the system calls on your machine handle this "trap door" instruction from
C--by asm statements?  That's okay, but you've at least got to have one
such special asm instruction per call.
-- 
|------------dan levy------------|  path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
|         an engihacker @        |		vax135}!ttrdc!ttrda!levy
|    at&t data systems division  |  disclaimer:  i am not a yvel nad
|--------skokie, illinois--------|

ron@topaz.rutgers.edu (Ron Natalie) (07/10/87)

Of course, once again some naive kernel hacker who thinks that all the
world is 4BSD strikes again.  Berkeley, is the first system that I've
ever seen that claims that they do system calls in C.  In actuallity,
it is just assembler masquerading in .c files.

-Ron