I Like It !

Friday, September 16, 2016

Minix/kernel/system.c

  1 static char rcsid[] = "$Id";
  2 
  3 /* This task handles the interface between file system and kernel as well as
  4  * between memory manager and kernel.  System services are obtained by sending
  5  * sys_task() a message specifying what is needed.  To make life easier for
  6  * MM and FS, a library is provided with routines whose names are of the
  7  * form sys_xxx, e.g. sys_xit sends the SYS_XIT message to sys_task.  The
  8  * message types and parameters are:
  9  *
 10  *   SYS_FORK    informs kernel that a process has forked
 11  *   SYS_NEWMAP  allows MM to set up a process memory map
 12  *   SYS_GETMAP  allows MM to get a process' memory map
 13  *   SYS_EXEC    sets program counter and stack pointer after EXEC
 14  *   SYS_XIT     informs kernel that a process has exited
 15  *   SYS_GETSP   caller wants to read out some process' stack pointer
 16  *   SYS_TIMES   caller wants to get accounting times for a process
 17  *   SYS_ABORT   MM or FS cannot go on; abort MINIX
 18  *   SYS_FRESH   start with a fresh process image during EXEC (68000 & SPARC only)
 19  *   SYS_SENDSIG send a signal to a process (POSIX style)
 20  *   SYS_SIGRETURN complete POSIX-style signalling
 21  *   SYS_KILL    cause a signal to be sent via MM
 22  *   SYS_ENDSIG  finish up after SYS_KILL-type signal
 23  *   SYS_COPY    request a block of data to be copied between processes
 24  *   SYS_VCOPY   request a series of data blocks to be copied between procs
 25  *   SYS_GBOOT   copies the boot parameters to a process
 26  *   SYS_MEM     returns the next free chunk of physical memory
 27  *   SYS_UMAP    compute the physical address for a given virtual address
 28  *   SYS_TRACE   request a trace operation
 29  *
 30  * Message types and parameters:
 31  *
 32  *    m_type       PROC1     PROC2      PID     MEM_PTR
 33  * ------------------------------------------------------
 34  * | SYS_FORK   | parent  |  child  |   pid   |         |
 35  * |------------+---------+---------+---------+---------|
 36  * | SYS_NEWMAP | proc nr |         |         | map ptr |
 37  * |------------+---------+---------+---------+---------|
 38  * | SYS_EXEC   | proc nr | traced  | new sp  |         |
 39  * |------------+---------+---------+---------+---------|
 40  * | SYS_XIT    | parent  | exitee  |         |         |
 41  * |------------+---------+---------+---------+---------|
 42  * | SYS_GETSP  | proc nr |         |         |         |
 43  * |------------+---------+---------+---------+---------|
 44  * | SYS_TIMES  | proc nr |         | buf ptr |         |
 45  * |------------+---------+---------+---------+---------|
 46  * | SYS_ABORT  |         |         |         |         |
 47  * |------------+---------+---------+---------+---------|
 48  * | SYS_FRESH  | proc nr | data_cl |         |         |
 49  * |------------+---------+---------+---------+---------|
 50  * | SYS_GBOOT  | proc nr |         |         | bootptr |
 51  * |------------+---------+---------+---------+---------|
 52  * | SYS_GETMAP | proc nr |         |         | map ptr |
 53  * ------------------------------------------------------
 54  *
 55  *    m_type          m1_i1     m1_i2     m1_i3       m1_p1
 56  * ----------------+---------+---------+---------+--------------
 57  * | SYS_VCOPY     |  src p  |  dst p  | vec siz | vc addr     |
 58  * |---------------+---------+---------+---------+-------------|
 59  * | SYS_SENDSIG   | proc nr |         |         | smp         |
 60  * |---------------+---------+---------+---------+-------------|
 61  * | SYS_SIGRETURN | proc nr |         |         | scp         |
 62  * |---------------+---------+---------+---------+-------------|
 63  * | SYS_ENDSIG    | proc nr |         |         |             |
 64  * -------------------------------------------------------------
 65  *
 66  *    m_type       m2_i1     m2_i2     m2_l1     m2_l2
 67  * ------------------------------------------------------
 68  * | SYS_TRACE  | proc_nr | request |  addr   |  data   |
 69  * ------------------------------------------------------
 70  *
 71  *
 72  *    m_type       m6_i1     m6_i2     m6_i3     m6_f1
 73  * ------------------------------------------------------
 74  * | SYS_KILL   | proc_nr  |  sig    |         |         |
 75  * ------------------------------------------------------
 76  *
 77  *
 78  *    m_type      m5_c1   m5_i1    m5_l1   m5_c2   m5_i2    m5_l2   m5_l3
 79  * --------------------------------------------------------------------------
 80  * | SYS_COPY   |src seg|src proc|src vir|dst seg|dst proc|dst vir| byte ct |
 81  * --------------------------------------------------------------------------
 82  * | SYS_UMAP   |  seg  |proc nr |vir adr|       |        |       | byte ct |
 83  * --------------------------------------------------------------------------
 84  *
 85  *
 86  *    m_type      m1_i1      m1_i2      m1_i3
 87  * |------------+----------+----------+----------
 88  * | SYS_MEM    | mem base | mem size | tot mem |
 89  * ----------------------------------------------
 90  *
 91  * In addition to the main sys_task() entry point, there are 5 other minor
 92  * entry points:
 93  *   cause_sig: take action to cause a signal to occur, sooner or later
 94  *   inform:    tell MM about pending signals
 95  *   numap:     umap D segment starting from process number instead of pointer
 96  *   umap:      compute the physical address for a given virtual address
 97  *   alloc_segments: allocate segments for 8088 or higher processor
 98  */
 99 
100 #include "kernel.h"
101 #include 
102 #include 
103 #include 
104 #include 
105 #include 
106 #include 
107 #include 
108 #include "proc.h"
109 #if (CHIP == INTEL)
110 #include "protect.h"
111 #endif
112 #if (MACHINE == SUN)
113 #include "logging.h"
114 #endif
115 
116 /* PSW masks. */
117 #define IF_MASK 0x00000200
118 #define IOPL_MASK 0x003000
119 
120 PRIVATE message m;
121 #if (MACHINE != SUN)
122 PRIVATE char sig_stuff[SIG_PUSH_BYTES]; /* used to send signals to processes */
123 #endif
124 
125 FORWARD _PROTOTYPE( int do_abort, (message *m_ptr) );
126 FORWARD _PROTOTYPE( int do_copy, (message *m_ptr) );
127 FORWARD _PROTOTYPE( int do_exec, (message *m_ptr) );
128 FORWARD _PROTOTYPE( int do_fork, (message *m_ptr) );
129 FORWARD _PROTOTYPE( int do_gboot, (message *m_ptr) );
130 FORWARD _PROTOTYPE( int do_getsp, (message *m_ptr) );
131 FORWARD _PROTOTYPE( int do_kill, (message *m_ptr) );
132 FORWARD _PROTOTYPE( int do_mem, (message *m_ptr) );
133 FORWARD _PROTOTYPE( int do_newmap, (message *m_ptr) );
134 FORWARD _PROTOTYPE( int do_sendsig, (message *m_ptr) );
135 FORWARD _PROTOTYPE( int do_sigreturn, (message *m_ptr) );
136 FORWARD _PROTOTYPE( int do_endsig, (message *m_ptr) );
137 FORWARD _PROTOTYPE( int do_times, (message *m_ptr) );
138 FORWARD _PROTOTYPE( int do_trace, (message *m_ptr) );
139 FORWARD _PROTOTYPE( int do_umap, (message *m_ptr) );
140 FORWARD _PROTOTYPE( int do_xit, (message *m_ptr) );
141 FORWARD _PROTOTYPE( int do_vcopy, (message *m_ptr) );
142 FORWARD _PROTOTYPE( int do_getmap, (message *m_ptr) );
143 
144 #if (SHADOWING == 1)
145 FORWARD _PROTOTYPE( int do_fresh, (message *m_ptr) );
146 #endif
147 
148