openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

add-syscall (1467B)


      1 $Id: //depot/blt/doc/add-syscall#1 $
      2 
      3 Copyright 1999 Sidney Cammeresi.  All rights reserved.
      4 
      5 
      6 How to add a system call to the kernel
      7 --------------------------------------
      8 
      9 Suppose we want to add a new system call named `port_fry' that will find
     10 all threads listening on a given port and cause the DRAM cells in which
     11 their code is stored to explode in a given number of microseconds.
     12 
     13 1.  Reserve a number for the system call in include/blt/syscall_id.h.  At
     14     the end of the list add a line like
     15 
     16         #define BLT_SYS_port_fry     666
     17 
     18     This name must begin with BLT_SYS_ because all of the actual system
     19     call functions are generated by preprocessor macros.
     20 
     21 2.  Add a function prototype to include/blt/syscall.h.
     22 
     23         int port_fry (int port, int when);
     24 
     25 3.  Add an entry for port_fry in lib/libblt/syscalls.S.  At the bottom
     26     of the file and add a line like
     27 
     28         SYSCALL(port_fry)
     29 
     30     This will generate code that traps into the kernel when you call the
     31     C symbol port_fry().
     32 
     33 4.  Implement the system call in the kernel.  In the function syscall()
     34     in kernel/syscall.c, add a clause to the case statement:
     35 
     36         case BLT_SYS_port_fry :
     37             kprintf ("kernel: will fry on %d in %d usecs", p_uint32 (1),
     38                 p_uint32 (2));
     39             /* ... */
     40             break;
     41 
     42     Note that to retrieve the arguments to your system call, you need to
     43     use the macros p_uint32() and friends.  Argument numbers start at 1.
     44