


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Project; Professor: Barnett; Class: OPERATING SYSTEMS; Subject: Computer Science; University: University of Richmond; Term: Spring 2009;
Typology: Study Guides, Projects, Research
1 / 4
This page cannot be seen from the preview
Don't miss anything!
CMSC 321 — Operating Systems Nachos Project 2: Multiprogramming, Part 1 of 2 (Modified copy of Nachos Assignment #2 by Tom Anderson) Due Date: Wednesday, March 4, 2009, 11:59pm
The second phase of Nachos is to support user‐level multiprogramming. This project will be split into two separate parts—this document describes the first of those two. As in the first assignment, you are
given some of the code you need; your job is to complete the system and enhance it.
In order to get the files for this assignment, do the following:
This procedure will overwrite everything in the nachos2/ directory except the threads subdirectory, which will be preserved as you submitted it for Project 1. Some new files will also be placed into the
directory.
Now when you invoke make in your new Nachos top‐level directory, a nachos executable will be created in the userprog subdirectory. This executable will use source files from the threads
directory, including your implementation of locks and condition variables from Project 1.
The first step is to read and understand the part of the system that has been written for you. The code
can run a single user‐level C program at a time. As a test case, you are provided with a trivial user
program (in the test directory) named halt; all halt does is ask the operating system to shut the machine down.
To run the user program in Nachos, execute nachos -x ../test/halt. As before, trace what happens as the user program gets loaded, runs, and invokes a system call. Trace the code down to the
details.
Following are the files for this assignment. Be sure to read each of them carefully. To better understand
what is going on, you may want to read Thomas Narten’s A Road Map Through Nachos , available via link from the course web page.
So far, all the code you have written for Nachos has been part of the operating system kernel. In a real operating system, the kernel not only uses its procedures internally, but also allows user‐level programs
to access some of its routines via system calls.
In this assignment, you are given a simulated CPU. The user programs are run on this simulated CPU
which acts the same as a real MIPS CPU. You cannot just run user programs as regular UNIX processes because you want complete control over how many instructions are executed at a time, how the
address spaces work, and how interrupts and exceptions (including system calls) are handled.
c) Use timer interrupts to force threads to yield after a certain number of ticks. Note that the source code in scheduler.cc already saves and restores user machine state on context switches.
A few brief words on compiling user programs: First, note that all user programs in the test directory
include only syscall.h. This is really the only library header file you can include, since these system calls are the only ones Nachos supports. Second, consider how a Nachos user program is compiled. The
Makefile in the test directory contains instructions for compiling the sample programs in that
directory. For example, the Makefile contains these lines to compile and link shell.c:
shell.o: shell.c $(CC) $(CFLAGS) -c shell.c shell: shell.o start.o $(LD) $(LDFLAGS) start.o shell.o -o shell.coff ../bin/coff2noff shell.coff shell
These lines expand to
/usr/local/gnu/decstation-ultrix/bin/gcc -G 0 -c -I../userprog -I../threads -c shell.c /usr/local/gnu/decstation-ultrix/bin/ld -T script -n start.o shell.o -o shell.coff ../bin/coff2noff shell.coff shell
The gcc and ld in the directory above are the MIPS C cross compiler and linker — they generate MIPS machine language code. Look at the man pages for gcc and ld to explore what all the options do. The
first line compiles a C program into an object file, but does not link it. The second line links the object file with the object file start.o. Notice that every Nachos user program must be linked with start.o. As
mentioned above, it contains the code necessary for a C user program to make a Nachos system call by name. The third line converts a Unix format executable (coff format) to a simpler Nachos format
executable (noff format). The resulting executable shell can be executed by the simulated MIPS processor.