Nachos Operating System Simulator
This document assumes you have read the introduction to
Nachos handout.
Nachos, SmartGDB, and the
support tools are installed only on the cse451 Linux box.
You MUST ssh (or rlogin or telnet) to this machine to use these tools
at the time of this writing.
DO NOT TRY TO USE THEM FROM ANY OTHER MACHINE.
I suggest using the command ssh cse451 to establish
a connection to the cse451 Linux computer. Before doing
this, create a file called .rhosts in your home directory with the
following two lines:
cse.unl.edu login-name
cse451.unl.edu login-name
where login-name is your own login name on cse
(and cse451). This file will let you establish rlogin or
secure shell rlogins. the command ssh cse451 will create a
secure rlogin session and redirect any X (graphic) output to your
terminal.
Code Organization
The Nachos source code contains nine subdirectories. Of these,
you will spend most of your time working with the threads,
userprog, machine, and test subdirectories. The directories are
listed in rough order of importance to your work.
- threads - this directory contains the thread code for
Nachos. These routines create and maintain the individual user
threads which are the processes in the Nachos operating system.
This is one of the most important directories you will need to
work with and understand.
- thread.cc - most of the thread operations
- scheduler.cc - scheduling routines
- list.cc - a list object (for scheduling,
interrupts, etc).
- synchlist.cc - synchronization objects
- main.cc - the startup routines
- userprog - this directory contains most of the
routines that Nachos uses to run user programs. All of the
memory handling routines (address space and memory and swap
management) are here. This is the other important directory you
will need to work with and understand. The only executable that
you will need to run directly, nachos, will be built here.
- addrspace.cc - the address space handling
routines.
- systemcall.cc - the system call routines.
- memmgr.cc - the memory management routines.
- swapmgr.cc - the swap management routines.
- machine - this directory contains the machine
simulator for Nachos. The files in this directory simulate
various parts of a real MIPS machine.
- mipssim.cc - the main part of the machine simulator
- machine.cc - the auxiliary parts of the machine
simulator
- test - this directory contains several example user
programs for nachos. These programs (and those you may write on
your own) will be used to test the Nachos code you provide. The
start.s file contains the stub routines for the system calls as
well as the equivalent of the startup routines (usually found in
crt0.o).
- lib - this directory contains a user library for
Nachos. Several of the standard string handling functions are
provided to make writing user programs easier. You can add
routines to this directory if you wish to add more
functionality.
- bin - this directory contains the coff2noff
converter. coff2noff converts from the output format
gcc uses (coff) to the noff format that Nachos uses. You should
not need to do anything with this directory.
- filesys - this directory contains the file system for
Nachos. Again, you should not need to do anything to this
directory.
- network - this directory contains the network code
for Nachos. None of this code is functional yet, so you will
not need to do anything with it.
- vm - this directory was to contain the virtual memory
subsystem for Nachos.
Running Nachos
Although Nachos has many optional arguments, you will probably
only use two of them on a regular basis.
- nachos -x <userprog>
Where "<userprog>" is one of the user programs provided in
the test directory. You must specify the path to the user program
so that Nachos is able to locate it (if it is not in the current
directory). In other words, you should be in the directory
nachos/test or else you will have to specify the entire
path to the shell (and all other user programs you run). For
example:
- ../userprog/nachos -x shell
will start the nachos shell program running if you are in the
nachos/test directory. This is the recommended way to run Nachos.
If you are in a different directory, you will need to specify the
full path to the user program. For example, if you were in the
top level directory (nachos) you would need to type:
- userprog/nachos -x test/shell
to specify the full path to the shell program. The nachos shell
allows you to then start other programs running. Several user programs have been provided:
- exit-prog - a simple program that Write()'s a message and
then calls the Exit() system call.
- halt - another simple program that calls the Halt()
system call.
- matmult - a matrix multiplication program intended to
stress virtual memory. Several versions of this program are
available. The versions with numbers after matmult indicate
how many copies of the program are forked (for instance,
matmult8 forks 8 copies of the program).
- shell - the nachos shell program.
This program allows you to run other user programs. Simply
typing a program name will start that program running just as in
your normal shell (tcsh for instance). If you are not in the
nachos/test directory, you will have to type the path to the
user programs each time in order for the shell to find them.
You can run programs in the background by appending an
ampersand "&" to the end of the command line without any
space in between the program's name and the &. When you
run a program in the background, the shell does not issue a
Wait() for that program, so it will not completely die until
you issue an explicit "wait" command to the shell (remember
that child processes do not die until their parent Wait()'s
on them, they become ZOMBIE processes--try launching a
program in the background and then check the status of it
after it exits). The only other built-in command in the
shell is "exit", a built-in command to exit the shell.
- sort - a program to bubble sort an array of integers
which is initialized in reverse order. This is another test
of virtual memory ability.
The other main option you may need to specify is
- ../userprog/nachos -S <swap file name>
Where <swap file name> is the name of the file you want
nachos to use as the swapfile (where pages that can't be kept in
memory are temporarily stored--the swap). If you do not use -S,
nachos will create a file called "swapfile" in the current
directory. Obviously, when you are running nachos from a
directory you do not have write access to, you, you will need to
specify a swapfile in your own directory. For example:
- ../userprog/nachos -S ~/swapfile -x shell
will create a file called "swapfile" in your home directory to
use as swap while running the "shell" user program.
In some cases, you will want to run Nachos without preemptive
multitasking. This is accomplished using the -noswitch flag:
- ../userprog/nachos -noswitch
When you exit Nachos, some informational statistics will be
printed including the total number of ticks used broken down into
the number of idle, system, and user ticks. The number of Console
reads and writes, and the paging statistics, including the number
of faults, pageins and pageouts.
Other Links to Nachos Information
These are some other links to Nachos information on the web.
Warning: Extensive changes have been made to our Nachos
release, so some of the information on the standard release may no longer
be applicable.
- A
Road Map Through Nachos
- Nachos
Home Page: Berkeley
- Nachos Introduction
Steve Goddard
Last modified: Fri Sep 18 11:39:28 CDT 1998