Nachos Overview Slide

advertisement
Nachos Overview
Lecturer: Hao-Hua Chu
TA: Chun-Po Wang (Artoo)
Date: 2008/09/18
Material Provided by
Yuan-Hao Chang, Yung-Feng Lu
Nachos
• Nachos:
– Not Another Completely Heuristic Operating System
• Written by Tom Anderson and his
students at UC Berkeley
http://www.cs.washington.edu/homes/tom/nachos/
2
Nachos 4.0
• An educational OS used to
– teach kernel design and implementation
– do experiments
• Fact:
– Real hardware is difficult to handle.
– May break if handled wrong.
• Approach:
– Use a virtual MIPS machine
– Provide some basic OS elements
3
Nachos 4.0
4
Nachos 4.0
• Simulates MIPS architecture on host system
(Unix /Linux/ Windows / MacOS X )
• User programs need a cross-compiler (target
MIPS)
– Eg. To compile user programs to MIPS on Linux
• Nachos appears as a single threaded process
to the host operating system
5
Designated Platform
in This Class
•
Linux in Workstation Room 217
–
•
Installation guide
http://mll.csie.ntu.edu.tw/course/os_f08/
217.htm
If your project submission can’t
execute on Linux in Workstation
Room 217, we will consider it as fail.
–
–
The Linux kernel in Workstation Room
217 is 2.6.26.
Please contact me to apply a
workstation account if you need it.
6
How does it work?
7
How does it work? (Cont.)
8
How does it work? (Cont..)
9
Setup the System
• Refer to the following document:
http://mll.csie.ntu.edu.tw/course/os_f08/217.h
tm
• You need:
– Nachos source code
– MIPS Cross compiler
– A patch for Nachos to work on 217
workstations
10
Nachos content
11
Setup the System (cont.)
• You can build Nachos on Linux
– Your linux
– Virtual machine
– 217 linux (1~14) (recommended)
• 217 runs 64-bit machines
– Apply the patch before you build
anything
12
Setup the System (cont.)
• MIPS Cross compiler
– Nachos simulates MIPS machine
– The user program built by this compiler
cannot run on Linux
• Please make sure that you follow the
steps in the instruction
– You should extract Nachos and the cross
compiler to the same directory
(NachOS-4.0 and usr)
– Or, user programs could not be built
13
Test files
• There are some test user programs in
NachOS-4.0/code/test/
– Use “make” to build them, the MIPS binary
would be generated in the same directory
• Use these files to test if your Nachos is
properly modified and built
14
How to run
• “nachos –x userprog –d u”
– Nachos binaries is in NachOS4.0/code/build.linux/nachos
– Use –x to run the user programs
– Use –d to show debug messages
A full list of options is under NachOS4.0/code/lib/debug.h
• Nachos would startup, load and run
the user program, then halt
15
GLOBAL
• A source code tag system for you to
trace large source files (Eg. Nachos)
• Useful for hacking a large project
containing many subdirectories, many
#ifdef and many main() functions.
• You can download GLOBAL from
http://www.gnu.org/software/global/do
wnload.html
16
GLOBAL (Cont.)
• How To Start?
– http://www.gnu.org/software/global/download.ht
ml
– Installation
% ./configure
% make
% make install
• Two utilities
– gtags, htags
17
GLOBAL (Cont..)
• gtags – Create Tag Database
% cd NachOS-4.0/
% gtags
• htags – Create Hypertext Files
(under HTML/) for a Web-Based
Interface for Global
% htags –Ff
• The GLOBAL for NachOS-4.0
http://www.csie.ntu.edu.tw/~artoo/NachOS18
4.0/HTML/
How to Start Trace Codes
•
•
•
Read interfaces in the *.h files first.
–
To have overview of the whole system.
Then, read the implementations in the *.cc
files.
–
See how the executable code supports
each interface.
Documentation
–
http://www.cs.duke.edu/~narten/110/nachos/main/
main.html
19
C++
•
•
•
•
Object-Oriented
Looks like JAVA, based on C
C  C++
C++ has lots of features, but
Nachos only uses a few
– So take it easy
20
C++ Class
• Declaration (Usually in header files)
class CoffeCup {
private: // or protected, these members can only be
// accessed by CoffeeCup members
int max_volume, current;
char name[100];
bool checkVolume (void);
public: // these members can be accessed by anyone
CoffeeCup (char * new_name); // constructor
~CoffeeCup (); // destructor
int fill (int vol);
int drink (int vol);
};
21
C++ Class (cont.)
• Definition (Usually in .cc or .cpp files)
CoffeeCup::CoffeeCup (char *new_name) :
max_volume(100), current(0)
{
strcpy(name, new_name);
}
CoffeeCup::~CoffeeCup () {
if(current > 0)
cout << “You left ” << current << “ in the cup ”
<< name << endl;
}
bool CoffeeCup::checkVolume (void) {
return (current <= max_volume);
}
22
C++ Class (cont.)
void CoffeeCup::fill (int vol) {
current += vol;
if(!checkVolume()) {
cout << “Too much!” << endl;
current = max_volume;
}
}
void CoffeeCup::drink (int vol) {
current -= vol;
if(current < 0)
current = 0;
}
23
C++ Class (cont.)
// We demonstrate the difference between an object and
// a pointer to object
CoffeeCup cup1(“Espresso”);
CoffeeCup *cup2 = new CoffeeCup(“Latte”);
cup1.fill(50);
cup2->fill(60);
cup1.drink(30);
(*cup2).drink(30);
// Delete or we’ll have memory leak
delete cup2;
// Now cup1 has 20, cup2 has 30
24
Other features
•
Dynamic allocated array
char *array = new char[100];
array[0] = …
delete [] array;
•
“this”
– A pointer point to the class instance itself
– “checkVolumne()” is equal to “this->checkVolume()”
•
ASSERT(…)
– Check if the condition is meet. Abort if it is not.
– Not really a C++ feature, though
•
ASSERTNOTREACHED( )
– Check if this line is not executed
– Eg. placed after a “return”
•
Feel free to ask me if you have C++ problems
25
Download