Introduction to System Calls and Exceptions
The exception mechanism is taken care of throughout many parts of Nachos. These are the steps to serve an exception.
- 1. The MIPS simulator detects an exception instruction
- 2. The MIPS simulator raises an exception by calling the machine method RaiseException and passing what type of exception that was detected (e.g. System call)
- 3. The function ExceptionHandler is called by RaiseException.
- 4. ExceptionHandler serves the exception, depending on what exception that was detected.
To implement system calls in Nachos, the ExceptionHandler function should be extended. Nachos is shipped with only the implementation of the system call Halt. Other Nachos system calls that could be implemented are listed below.
- Exit() : Quit the user program making the call
- Exec(char *name) : Run the executable identified by "name"
- Join(SpaceId id) : Wait for "id". Return only when "id" is done
- Create(char *name) : Create a nachos file with name "name"
- Open(char *name) : Open the nachos file with name "name"
- Write(char *buffer, int size, OpenFileId id) : Write "size" bytes from "buffer" to the open file
- Read(char *buffer, int size, OpenFilesId id) : Read "size" bytes from open file into "buffer"
- Close(OpenFileId id) : Close the file
- Fork(void (*func)()) : Fork a thread to run a procedure "func"
The arguments passed along the steps 1-4 above are put in registers. If a system call is to be executed, the type of system call is put into register R2, by convention. System call arguments are put into R4-R7 and return value is put into R2.
Continue to Lab 2 Tutorial
|
Nachos
Tutorials
Roadmap
Source Code
Introduction
Threads
Interrupts
Synchronization
System Calls
Exception Handling
Multiprogramming
File System
Networking
Tutorials
Lab 1 Tutorial
Lab 2 Tutorial
Lab 3 Tutorial
Lab 4 Tutorial
Lab 5 Tutorial
|