Jolix
/joh'liks/ n.,adj. 386BSD

PORTING UNIX TO THE 386: A PRACTICAL APPROACH


William & Lynne Jolitz


How to call the system's kernel from a process, using existing industry standards accross the X86 platform.




System Call Interface
A table of system calls is provided by Berkeley UNIX with the assigned index number that differentiates them. This table specifies, in part, a binary standard for system calls -- in this case, of a POSIX-based system. Of course, because POSIX is considered an "object library" definition (as opposed to the regulation at the system call level desired by ABI and BCS advocates), one might accurately consider this an "academic" standard. In deference to these other standards, however, we chose to accept their suggested format for system calls.

Figure 8 - System Call Code Stub
#include <syscall.h>

     .globl _write, _errno

     # amtwritten =  write(fildes, address, count);

_write:                   # caller places arguments on stack
     lea   SYS_write,%eax # select desired system call
     lcall $0x7,0         # call the system
     jb    1f             # if system returns error, handle
     ret                  # otherwise return

1:   movl  %eax,_errno    # save error in global variable
     movl  $-1,%eax       # indicate error has occured
     ret                  # and return

Figure 8 is a code template for the system call stub used in 386BSD, in this case a write system call. The lcall instruction is an intersegmental call instruction that references a special segment selector, known to be a UNIX system call gate into the kernel. The selector corresponds to the first descriptor in the processes local descriptor table. To designate which system call is to be used, the eax register is loaded with the index from the table. Arguments for each system call are present on the stack, and this stub is called from another procedure. System calls return after the lcall instruction, returning values in the eax and edx registers (just as other C procedures do). System calls report failure by setting the carry bit and recording error notification in eax.



<<BACK NEXT >>



Copyright 1989, 1990, 2006 TeleMuse Partners, William Jolitz and Lynne Jolitz