Create your document — readme (doc or pdf) including the disclosure form, screenshot(s) of your output
Due: Nov. 16 (Friday, end of the day)
Late submission: you have total 72 hours throughout the semester.
Follow the Lab1 instruction and create a new fresh Nachos folder.
So far, all the code you have written for Nachos has been part of the operating system kernel (ThreadTest() is compiled and ran within Nachos). In a real operating system, the kernel not only uses its procedures internally, but allows user-level programs to access some of its routines via “system calls”. In this project, you are going to implement several system call routines for user programs and round-robin scheduling.
The user programs are written in C and located under test/ directory. There are several example programs provided, including halt, shell, etc. The command “./nachos -x ../test/programname” will load the program ‘programname’ to Nachos memory (see addrspace.cc and progtest.cc) and run it on Nachos.
For this task, syscall.h, exception.cc, start.s (assembly routine for system calls and under test/ directory), and scheduler.cc must be modified. The userprog/exception.cc implements the handlers for system calls and other user-level exceptions. In the original file, only the Halt() system call is supported.
Hint: you can find a good example from system call Add.
You can find test programs (prog1.c, prog2.c and prog3.c) in the Testing section. For this task testing, you don’t need multitasking with round-robin.
Multitasking (running multiple user-level programs): when the ‘-x’ flag is used, the ‘main’ function of Nachos calls the RunUserProg() function with the string following ‘-x’ as parameter. Remember that every user program should have its own thread structure, but for now there’s only one thread, the ‘main’ thread.
The goal of this task is to make the command
./nachos -x ../test/mprog1 -x ../test/mprog2
work in Nachos. What this means is that when you type this command, Nachos will load multiple user programs into its main memory and start executing them as threads with round-robin scheduling. You need to implement Write system call.
Memory Allocation (Address Space for user programs): The main issue in this implementation is how to create the address spaces of the Nachos processes and put them all in the main memory without overlapping. The allocation of address space is done in userprog/addrspace.cc.
If the total size of the user programs (for example, ./nachos -x ../test/prog1 -x ../test/prog2 …) are smaller than the memory size, you can just use contiguous memory allocation. However, for the command like ./nachos -x ../test/matmult, you need to consider larger memory allocation needed than Nachos physical memory size. matmult is a matrix multiplication program. If you run the program now, you’ll get an assertion failure in userprog/addrspace.cc because there’s not enough memory to load it. So what you need to accomplish is to let Nachos run the program with part of the address space loaded, and load the other part(s) when they are accessed. Because an exception will arise when they are accessed, the loading should be done as an exception handling in userprog/exception.cc.
You’re free to use whatever design you choose.
Round-robin scheduling: Round-robin scheduling gives each process (Nachos thread) a fix time slice (quantum) to run. After the quantum expires, the CPU will be taken from the process and given to the next process in the ready list. The older process is then inserted to the end of the ready list.
We will build and run your Nachos on the VM. TAs will test multitasking with user programs with their quantum size and memory allocation using matmult program.
Place the following programs into test/ directory and update Makefile. The test programs must be compiled before Nachos is built.