250 likes | 449 Views
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
E N D
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/
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
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
Designated Platform in This Class • Linux in Workstation Room 217 • Installation guidehttp://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 is2.6.26. • Please contact me to apply a workstation account if you need it.
Setup the System • Refer to the following document:http://mll.csie.ntu.edu.tw/course/os_f08/217.htm • You need: • Nachos source code • MIPS Cross compiler • A patch for Nachos to work on 217 workstations
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
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
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
How to run • “nachos –x userprog –d u” • Nachos binaries is in NachOS-4.0/code/build.linux/nachos • Use –x to run the user programs • Use –d to show debug messagesA full list of options is under NachOS-4.0/code/lib/debug.h • Nachos would startup, load and run the user program, then halt
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 fromhttp://www.gnu.org/software/global/download.html
GLOBAL (Cont.) • How To Start? • http://www.gnu.org/software/global/download.html • Installation % ./configure % make % make install • Two utilities • gtags, htags
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.0http://www.csie.ntu.edu.tw/~artoo/NachOS-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
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
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); };
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); }
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; }
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
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