Page principale | Liste des namespaces | Hiérarchie des classes | Liste des classes | Répertoires | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

syscall.h

Aller à la documentation de ce fichier.
00001 /* syscalls.h 
00002  *      Nachos system call interface.  These are Nachos kernel operations
00003  *      that can be invoked from user programs, by trapping to the kernel
00004  *      via the "syscall" instruction.
00005  *
00006  *      This file is included by user programs and by the Nachos kernel. 
00007  *
00008  * Copyright (c) 1992-1993 The Regents of the University of California.
00009  * All rights reserved.  See copyright.h for copyright notice and limitation 
00010  * of liability and disclaimer of warranty provisions.
00011  */
00012 
00013 #ifndef SYSCALLS_H
00014 #define SYSCALLS_H
00015 
00016 #include "copyright.h"
00017 #include "errno.h"
00018 /* system call codes -- used by the stubs to tell the kernel which system call
00019  * is being asked for
00020  */
00021 #define SC_Halt         0
00022 #define SC_Exit         1
00023 #define SC_ForkExec     2
00024 #define SC_ForkExecV    3
00025 #define SC_Join         4
00026 #define SC_getSpaceID   5
00027 //
00028 #define SC_ThreadFork   6
00029 #define SC_ThreadYield  7
00030 #define SC_ThreadExit   8
00031 #define SC_getThreadID  9
00032 //
00033 #define SC_NewSem       10
00034 #define SC_NewCond      11
00035 #define SC_NewLock      12
00036 #define SC_DeleteSem    13
00037 #define SC_DeleteCond   14
00038 #define SC_DeleteLock   15
00039 #define SC_Acquire      16
00040 #define SC_Release      18
00041 #define SC_Wait         19
00042 #define SC_Signal       20
00043 #define SC_Broadcast    21
00044 //
00045 #define SC_Create       
00046 #define SC_Remove       22
00047 #define SC_Open         23
00048 #define SC_Read         24
00049 #define SC_Write        25
00050 #define SC_Seek         26
00051 #define SC_Close        27
00052 #define SC_Delete       28
00053 //
00054 #define SC_Clock         29
00055 
00056 #define SC_Ipc          30
00057 
00058 #define SC_Add          42
00059 
00060 #ifndef IN_ASM
00061 
00062 /* The system call interface.  These are the operations the Nachos
00063  * kernel needs to support, to be able to run user programs.
00064  *
00065  * Each of these is invoked by a user program by simply calling the 
00066  * procedure; an assembly language stub stuffs the system call code
00067  * into a register, and traps to the kernel.  The kernel procedures
00068  * are then invoked in the Nachos kernel, after appropriate error checking, 
00069  * from the system call entry point in exception.cc.
00070  */
00071 
00072 /* Stop Nachos, and print out performance stats */
00073 void Halt();            
00074  
00075  
00076 /* Address space control operations: Exit, Exec, Execv, and Join */
00077 
00078 /* This user program is done (status = 0 means exited normally). */
00079 void Exit(int status);  
00080 
00081 /* A unique identifier for an executing user program (address space) */
00082 typedef int SpaceId;    
00083 
00084 /* the Bad identifier returned when a system call fails*/
00085 #define BAD_ID -1;
00086 /* Run the specified executable, with no args */
00087 /* This can be implemented as a call to ExecV.
00088  */ 
00089 SpaceId ForkExec(char* exec_name);
00090 
00091 /* Run the executable, stored in the Nachos file "argv[0]", with
00092  * parameters stored in argv[1..argc-1] and return the 
00093  * address space identifier
00094  */
00095 SpaceId ForkExecV(int argc, char* argv[]);
00096  
00097 /* Only return once the user program "id" has finished.  
00098  * Return the exit status.
00099  */
00100 int Join(SpaceId id);   
00101  
00102 /*
00103  * Returns SpaceId of current address space.
00104  */
00105 SpaceId getSpaceID();
00106 
00107 
00108 
00109 /* User-level thread operations: Fork and Yield.  To allow multiple
00110  * threads to run within a user program.  and synchronize them
00111  *
00112  * .
00113  */
00114 
00115 
00116 /* A unique identifier for a thread within a task */
00117 typedef int ThreadId;
00118 
00119 /* Fork a thread to run a procedure ("func") in the *same* address space 
00120  * as the current thread.
00121  * Return a positive ThreadId on success, negative error code on failure
00122  */
00123 ThreadId ThreadFork(void (*func)(void *), void* arg);
00124 
00125 /* Yield the CPU to another runnable thread, whether in this address space 
00126  * or not. 
00127  */
00128 void ThreadYield();     
00129 
00130 
00131 
00132 /*
00133  * Deletes current thread 
00134  */
00135 void ThreadExit();      
00136 
00137 
00138 /*
00139  * Returns ThreadId of current thread. 
00140  */
00141 ThreadId getThreadID();
00142 /*
00143  * Semaphore Id 
00144  */
00145 
00146 typedef int SemId;
00147 /*
00148  * Semaphore create. Returns the semphare ID or BAD_ID if failure
00149  */
00150 SemId SemNew();
00151 /*
00152  * Semaphore P. Returns 0 if OK. -1 if failure
00153  */
00154 int P(SemId);
00155 /*
00156  * Semaphore V. Returns 0 if OK. -1 if failure
00157  */
00158 int V(SemId);
00159 /*
00160  * Semaphore delete. Returns 0 if OK. -1 if failure
00161  */
00162 int SemDelete(SemId);
00163 /*
00164  * Lock Id 
00165  */
00166 typedef int LockId;
00167 /*
00168  * Lock create. Returns the lock ID or BAD_ID if failure
00169  */
00170 LockId LockNew();
00171 /*
00172  * Acquire a lock. Returns 0 if OK. -1 if failure
00173  */
00174 int Acquire(LockId);
00175 /*
00176  * Release a lock. Returns 0 if OK. -1 if failure
00177  */
00178 int Release(LockId);
00179 /*
00180  * Lock delete. Returns 0 if OK. -1 if failure
00181  */
00182 int LockDelete(LockId);
00183 
00184 /*
00185  * Condition Id 
00186  */
00187 typedef int CondId;
00188 /*
00189  * Condition create. Returns the condition ID or BAD_ID if failure
00190  */
00191 CondId CondNew(LockId);
00192 /*
00193  * Wait on condition . Returns 0 if OK. -1 if failure
00194  */
00195 int Wait(CondId);
00196 /*
00197  * Signal a condition . Returns 0 if OK. -1 if failure
00198  */
00199 int Signal(CondId);
00200 /*
00201  * Broadcast a condition . Returns 0 if OK. -1 if failure
00202  */
00203 int Broadcast(CondId);
00204 /*
00205  * Condition delete. Returns 0 if OK. -1 if failure
00206  */
00207 
00208 int CondDelete(CondId);
00209 
00210 
00211 /* File system operations: Create, Remove, Open, Read, Write, Close
00212  * These functions are patterned after UNIX -- files represent
00213  * both files *and* hardware I/O devices.
00214  *
00215  * Note that the Nachos file system has a stub implementation, which
00216  * can be used to support these system calls if the regular Nachos
00217  * file system has not been implemented.
00218  */
00219  
00220 /* A unique identifier for an open Nachos file. */
00221 typedef int OpenFileId; 
00222 
00223 /* when an address space starts up, it has two open files, representing 
00224  * keyboard input and display output (in UNIX terms, stdin and stdout).
00225  * Read and Write can be used directly on these, without first opening
00226  * the console device.
00227  */
00228 
00229 #define ConsoleInput    0  
00230 #define ConsoleOutput   1  
00231  
00232 /* Create a Nachos file, with name "name" */
00233 /* Note: Create does not open the file.   */
00234 /* Return 1 on success, negative error code on failure */
00235 int Create(char *name);
00236 
00237 /* Remove a Nachos file, with name "name" */
00238 int Remove(char *name);
00239 
00240 /* Open the Nachos file "name", and return an "OpenFileId" that can 
00241  * be used to read and write to the file. "mode" gives the requested 
00242  * operation mode for this file.
00243  */
00244 #define RO 1
00245 #define RW 2
00246 #define APPEND 3
00247 OpenFileId Open(char *name, int mode);
00248 
00249 /* Write "size" bytes from "buffer" to the open file. 
00250  * Return the number of bytes actually read on success.
00251  * On failure, a negative error code is returned.
00252  */
00253 int Write(char *buffer, int size, OpenFileId id);
00254 
00255 /* Read "size" bytes from the open file into "buffer".  
00256  * Return the number of bytes actually read -- if the open file isn't
00257  * long enough, or if it is an I/O device, and there aren't enough 
00258  * characters to read, return whatever is available (for I/O devices, 
00259  * you should always wait until you can return at least one character).
00260  */
00261 int Read(char *buffer, int size, OpenFileId id);
00262 
00263 /* Set the seek position of the open file "id"
00264  * to the byte "position".
00265  */
00266 int Seek(int position, OpenFileId id);
00267 
00268 /* Deletes a file with the filename given by "name".
00269  * An error is returned if file does not exist or other wicked things happen.
00270  */
00271 int Delete(char* name);
00272 
00273 /* Close the file, we're done reading and writing to it.
00274  * Return 1 on success, negative error code on failure
00275  */
00276 int Close(OpenFileId id);
00277 
00278 /*
00279  * IPC Inter Process Communication
00280  */
00281 void Ipc(int sendDescriptor, SpaceId r_space, ThreadId r_thread,
00282          int s_msg0, int s_msg1,
00283          int receiveDescriptor, SpaceId * s_space, ThreadId * s_thread,
00284          int * r_msg0, int * r_msg1);
00285 
00286 /*
00287  * returns the current cycle counter.
00288  */
00289 unsigned int Clock();
00290 
00291 
00292 /*
00293  * Add the two operants and return the result
00294  */ 
00295 
00296 int Add(int op1, int op2);
00297 
00298 #endif /* IN_ASM */
00299 
00300 #endif /* SYSCALL_H */
00301 

Généré le Sun Jan 15 00:45:45 2006 pour Système NachOS : par  doxygen 1.4.4