jueves, 11 de agosto de 2011

Starting with NachOS

Good Day.

Starting a new semester in the university and as common, we start defining the tools which we are going to use in the course.
In this class we are going to work with NachOS, so we were given the option to choose in which programming language we are going to modify NachOS, and which version of NachOS are we going to use.

First of all: What is NachOS?


[imagen obtenida de: "http://libroderecetas.com/files/recetas/nachos.jpg"]

NachOS is an educative Operating System designed for students of this type of course.
It was developed in the University of California in Berkeley, by Wayne A. Cristopher, Steven J. Procter and Thomas E. Anderson between 1991 and 1992 Spring.

Originally written in C++(altough it can also be found in Java) for MIPS, NachOS is executed as an user process in the host Operating System. A MIPS simulator executes the code for every user's program executing in NachOS.

Making a decision:

As previously mentioned, the first asigned task was to choose the programming language in which we are going to work with. Like you may already know, the options are not many(Java and C++). After extensive discusions and a lot of disagreement, we decided for C++.

Why?
The reason is primary because we have worked a couple of times with Java already, and we all agreed to try something different and, why not?, learn C++.

Compiling NachOS

Our experience compiling and executing NachOS was interesting. At first we didn't have any idea about how to compile NachOS, scratching our head like monkeys about in front of a computer, but thanks to Dr. Elisa who found a post about a Taiwanese student(http://mike820324.blogspot.com)who went through the same situation as us, it was more easy for us to compile and execute NachOS.

Like his guide says, the first thing we did was download NachOS from the terminal using wget as follows:

wget http://neuron.csie.ntust.edu.tw/homework/99/os/materials/nachos-4.0.tar.gz


After this we used tar zxvf to exctract the nachos folder in the home directory.

Then we downloaded a cross compiler (a compiler capable of creating executable code for a different platform other than the one on which compiler is running), thanks to our taiwanese friend, we could also download it with wget:

wget http://neuron.csie.ntust.edu.tw/homework/99/os/materials/mips-decstation.linux-xgcc.gz


Now with the cross compiler downloaded, we just moved it to the root directory and unzipped it with the tar zxvf command.

sudo mv mips-decstation.linux-xgcc.gz /

sudo tar xvzf /mips-decstation.linux-xgcc.gz

WIth that done, we moved to the nachos-4.0/code/ folder in order to build nachOS(supposedly).But it didn't work, as all of you may know, NachOS is old, so it needs an old version of the gcc compiler in order to build it. Our friend MicroMike found a way to fix this, modifying certain files.

Files to modify:

First
The first file to modify is Makefile. In this, we just modified line 5, changing gmake to make.

Wrong
MAKE = gmake

Right
MAKE = make


Second
The second error is in the file sysdep.h, from the nachos-4.0/code/lib directory. Apparently iostream.h cannot be found, to fix this we just changed "iostream.h" to "iostream".

Wrong
#include "copyright.h"

#include "iostream.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
Right
#include "copyright.h"

#include "iostream"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"

using namespace std;

Third
The third problem seems to be the gcc version. The file to modify is Makefile.common, in the nachos-4.0/code directory. To fix this problem we just deleted -fwritable strings from line 28, leaving the rest as it was.

Wrong
CFLAGS = -g -Wall -fwritable strings $(INCPATH) $(DEFINES) $(HOST) -DCHANGED

Right
CFLAGS = -g -Wall $(INCPATH) $(DEFINES) $(HOST) -DCHANGED


Fourth
Now with that done, we proceeded to try again and compile NachOS. Running make again, the terminal showed many errors, all of them fixed adding this-> to the variables or functions found in the corresponding error line.

Example:
Wrong
void

SortedList::Insert(T item)
{
ListElement *element = new ListElement(item);
ListElement *ptr; // keep track

ASSERT(!IsInList(item));
if (IsEmpty()) { // if list is empty, put at front
first = element;
last = element;
} else if (compare(item, first->item) < 0) { // item goes at front element->next = first;
first = element;
} else { // look for first elt in list bigger than item
for (ptr = first; ptr->next != NULL; ptr = ptr->next) {
if (compare(item, ptr->next->item) < 0) { element->next = ptr->next;
ptr->next = element;
numInList++;
return;
}
}
last->next = element; // item goes at end of list
last = element;
}
numInList++;
ASSERT(IsInList(item));
}

Right
void

SortedList::Insert(T item)
{
ListElement *element = new ListElement(item);
ListElement *ptr; // keep track

ASSERT(!IsInList(item));
if (this->IsEmpty()) { // if list is empty, put at front
this->first = element;
this->last = element;
} else if (compare(item, this->first->item) < 0) { // item goes at front element->next = this->first;
this->first = element;
} else { // look for first elt in list bigger than item
for (ptr = this->first; ptr->next != NULL; ptr = ptr->next) {
if (compare(item, ptr->next->item) < 0) { element->next = ptr->next;
ptr->next = element;
this->numInList++;
return;
}
}
this->last->next = element; // item goes at end of list
this->last = element;
}
this->numInList++;
ASSERT(IsInList(item));
}


With all that fixed, we could successfully compile NachOS, and this generated an executable file named nachos in the nachos-4.0/code/userprog directory.

Running nachos with: ./nachos shows the following output:



And running test1 the output was:



And thats it, thats how we managed to compile and run NachOS using MicroMike's guide, thanks for reading, and as always, have a nice day.

References:

No hay comentarios:

Publicar un comentario