tac0S
Template Affectional Command Operating System
syscall.h
1 
15 /* syscalls.h
16 
17  */
18 
19 #ifndef SYSCALLS_H
20 #define SYSCALLS_H
21 
22 #include "copyright.h"
23 
24 /* system call codes -- used by the stubs to tell the kernel which system call
25  * is being asked for
26  */
27 #define SC_Halt 0
28 #define SC_Exit 1
29 #define SC_Exec 2
30 #define SC_Join 3
31 #define SC_Create 4
32 #define SC_Open 5
33 #define SC_Read 6
34 #define SC_Write 7
35 #define SC_Close 8
36 #define SC_Fork 9
37 #define SC_Yield 10
38 #define SC_PutChar 11
39 #define SC_PutString 12
40 #define SC_GetChar 13
41 #define SC_GetString 14
42 #define SC_GetInt 15
43 #define SC_PutInt 16
44 #define SC_Feof 17
45 #define SC_Seek 18
46 
47 // ID Reservé pour Olivier et les threads de 20 à 40
48 
49 #define SC_createUserThread 20
50 #define SC_WaitForChildExited 21
51 #define SC_ExitThread 22
52 #define SC_WaitForAllChildExited 23
53 #define SC_makeAllChildSurvive 24
54 #define SC_makeChildSurvive 25
55 #define SC_WakeUpChild 26
56 #define SC_StopChild 27
57 #define SC_ThreadEndedWithoutExit 28
58 #define SC_ThreadId 29
59 
60 #define SC_LockCreate 30
61 #define SC_LockAcquire 31
62 #define SC_LockRelease 32
63 #define SC_LockDelete 33
64 #define SC_SemaphoreCreate 34
65 #define SC_SemaphoreP 35
66 #define SC_SemaphoreV 36
67 #define SC_SemaphoreDelete 37
68 
69 
70 #ifdef IN_USER_MODE
71 
72 // LB: This part is read only on compiling the test/*.c files.
73 // It is *not* read on compiling test/start.S
74 
75 
76 /* The system call interface. These are the operations the Nachos
77  * kernel needs to support, to be able to run user programs.
78  *
79  * Each of these is invoked by a user program by simply calling the
80  * procedure; an assembly language stub stuffs the system call code
81  * into a register, and traps to the kernel. The kernel procedures
82  * are then invoked in the Nachos kernel, after appropriate error checking,
83  * from the system call entry point in exception.cc.
84  */
85 
86 /* Stop Nachos, and print out performance stats */
87 void Halt () __attribute__((noreturn));
88 
89 
90 /* Address space control operations: Exit, Exec, and Join */
91 
92 /* This user program is done (status = 0 means exited normally). */
93 void Exit (int status) __attribute__((noreturn));
94 
95 /* A unique identifier for an executing user program (address space) */
96 typedef int SpaceId;
97 
98 /* Run the executable, stored in the Nachos file "name", and return the
99  * address space identifier
100  */
101 SpaceId Exec (char *name);
102 
103 /* Only return once the the user program "id" has finished.
104  * Return the exit status.
105  */
106 int Join (SpaceId id);
107 
108 
109 /* File system operations: Create, Open, Read, Write, Close
110  * These functions are patterned after UNIX -- files represent
111  * both files *and* hardware I/O devices.
112  *
113  * If this assignment is done before doing the file system assignment,
114  * note that the Nachos file system has a stub implementation, which
115  * will work for the purposes of testing out these routines.
116  */
117 
118 /* A unique identifier for an open Nachos file. */
119 typedef int OpenFileId;
120 
121 /* when an address space starts up, it has two open files, representing
122  * keyboard input and display output (in UNIX terms, stdin and stdout).
123  * Read and Write can be used directly on these, without first opening
124  * the console device.
125  */
126 
127 #define ConsoleInput 0
128 #define ConsoleOutput 1
129 
130 /* Create a Nachos file, with "name" */
131 void Create (char *name);
132 
137 OpenFileId Open (char *name);
138 
140 void Write (char *buffer, int size, OpenFileId id);
141 
149 int Read (char *buffer, int size, OpenFileId id);
150 
154 void Close (OpenFileId id);
155 
156 
157 
167 void Fork (void (*func) ());
168 
173 void Yield ();
174 
175 
176 //
177 // PutChar
178 // Write a char in the current SynchConsole
179 // @param c : the char
180 //
181 
182 void PutChar( char c);
183 
184 
185 //
186 // PutChar
187 // Write a String in the current SynchConsole
188 // Only one syscall is made there
189 // @param s : The string
190 //
191 
192 void PutString(char * string);
193 
194 
195 //
196 // GetChar
197 // Get the char written in the current SynchConsole
198 // @return char
199 //
200 
201 int GetChar();
202 
203 //
204 // GetString
205 // Get the a String written in the current SynchConsole
206 // Only one syscall is made there
207 // @param string : The adresse where the string will be writted
208 // @param taille : The max size of the string.
209 //
210 
211 void GetString(char * string, int taille);
212 
213 //
214 // GetInt
215 // Get the int written in the current SynchConsole
216 // @param *n, the adress where the in will be writted.
217 //
218 
219 void GetInt(int * n);
220 
221 
222 //
223 // PutInt
224 // Write a int in the current SynchConsole
225 // @param n : The int
226 //
227 
228 
229 
230 void PutInt(int n);
231 
232 //
233 // Feof
234 // Know if there is char to be read in the SynchConsole
235 // @return 1 if feof 0 instead
236 //
237 //
238 
239 int Feof();
240 unsigned int createUserThread(void * f,void * arg);
241 void* WaitForChildExited(unsigned int CID);
242 void ExitThread(void * object);
243 // Expert mode
244 void WaitForAllChildExited();
245 int StopChild(int CID);
246 int WakeUpChild(int CID);
247 int makeChildSurvive(int CID);
248 void makeAllChildSurvive();
249 unsigned int ThreadId();
250 
251 int fopen(const char* filename);
252 int fgets(int fileDescriptor, char* into, int numBytes);
253 int fputs(int fileDescriptor, char* from, int numBytes);
254 void fseek(int fileDescriptor, int position);
255 int fclose(int fileDescriptor);
256 int LockCreate();
257 void LockAcquire(unsigned int ID);
258 void LockRelease(unsigned int ID);
259 int LockDelete(unsigned int ID);
260 int SemaphoreCreate(int nbTokens);
261 void SemaphoreP(unsigned int ID);
262 void SemaphoreV(unsigned int ID);
263 int SemaphoreDelete(unsigned int ID);
264 
265 
266 
267 #endif // IN_USER_MODE
268 
269 #endif /* SYSCALL_H */
void Read(int fd, char *buffer, int nBytes)
Read Read characters from an open file. Abort if read fails.
Definition: sysdep.cc:182
void Close(int fd)
Close Close a file. Abort on error.
Definition: sysdep.cc:247
void Exit(int exitCode)
Exit Quit without dropping core.
Definition: sysdep.cc:439