jueves, 25 de agosto de 2011

How to run a user programs in nachOS

Good nigh.

After a few tests with my team partners, we can run a user program in nachOS (for this we used nachOS 4.0 in C++), simple but is the first step in our way to complete one of the principal goals for the first presentation, the implementation of locks.

Here I'm gonna explain how we made it.

First of all, after you have installed nachOS, the cross compiler, and compiled nachOS correctly, you will going to move to the file called 'test' (hosted on the file 'code' of nachos4.0).



After you are on 'test' you have to create a document with .c extension. We will called it 'example.c'


Then, you can start to write the program, for this example we wrote:



syscall.h - make a call to nachOS system. Just let us call nachOS libraries, we can't call other libraries like unix or the library standard of C so we can't use functions as printf, scanf, etc.

We save the document, and return to the terminal.

Next thing you have to do is modify the Makefile for the compiler can create the executable file.

 

You will go to the end of Makefile and you will see the following part of text:



The only thing you have to do is copy one of those two parts and change the name of 'test1' for the name of your document, in this example 'example', and you will get something like this:



After that, save the changes on Makefile and now you are ready to compile and execute your example file.

For compile you just have to write 'make nameofyourfile'



¿No errors?, GOOD! now for execute you have to write:

' ../userprog/nachos -e nameofyourfile '

And we get our precious result (':


 

Hope this guide be useful for some of you which are using the same nachOS version and for those who are using other versions, try it and tell us if it's useful for others versions too :D 

¿Any doubt? Comment! :)

See ya!


References:
http://sopa.dis.ulpgc.es/wiki/index.php/Programas_de_usuario

jueves, 18 de agosto de 2011

Semaphores

Nunca confies en un conductor de autobus desnudo :) ( In construction)

Semaphores

"In computer science, a semaphore is a variable or abstract data type that provides a simple but useful abstraction for controlling access by multiple processes to a common resource in a parallel programming environment."

Searching the semaphore on NachOS

So, our first task was to look for a semaphore code implemented in our Nachos source. This was easy to find because there is a threads directory inside the Nachos-4.0/code directory, so our first impression was "It's probably there".

When searching on the files, we found the implementation on the synch.cc file. The code can be found here:

http://web.ics.purdue.edu/~cs354/Nachos/synch_8cc-source.html

We tried to make an example file using semaphores, but we couldn't find out how to run an user made program in NachOS yet, so we will add it to the post later on.

Example:

...




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:

lunes, 8 de agosto de 2011

Team Presentation

This blog will be used for the class, Operative Systems given by Dr. Elisa Schaeffer, Monday, Wednesday and Fridays, at class room 4104 on M6.


Team members:


Emmanuel Alejandro García Solís
Maximiliano Hernandes Castillo
Adán de Jesús Silva Cuéllar