0%

Using Nachos in Linux

Installation

Make sure the Linux is 32-bit!

Go to https://homes.cs.washington.edu/~tom/nachos/, download nachos-4.0.tar, and download mips-x86.linux-xgcc .

wget http://www.cs.washington.edu/homes/tom/nachos/nachos-4.0.tar
wget https://inst.eecs.berkeley.edu//~cs162/fa13/Nachos/xgcc/mips-x86_64.linux-xgcc.tar.gz

Place it to somewhere.

(Well, that’s the original one. But my Experiment uses 3.4 version modified by my teacher.)

Before anything, make sure you have install GNU/GCC, and csh.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
sudo apt-get install gcc-multilib g++-multilib
sudo apt-get install manpages-dev
sudo apt-get install csh

Unzip it.

tar -xvf nachos-4.0.tar

Use cp -r to copy Code directory to somewhere.

Copy gcc-2.8.1-mips.tar.gz to usr/local directory, and unzip it.

sudo cp gcc-2.8.1-mips.tar.gz /usr/local
cd usr/local
tar -xvf gcc-2.8.1-mips.tar.gz

Add permission by chmod +rwx filename .

Test

Go back to the Code folder. Here is what we have in Code directory.

ass3  bin      lab2  lab5    machine          Makefile.dep  network  threads   vm
ass4 filesys lab3 lab7-8 Makefile.common monitor test userprog

Go to /test/arch/unknown-i386-linux folder, delete files in folders depends and objects (don’t remove the two folders), and in test, delete all files end in .noff.

Test test

Makefile.

make

If failed, remember to add permission to certain files (_the_directory_name_/bin/arch/unknown-i386-linux/bin/coff2noff & coff2flat) suggested. If success, we got some .noff files in test:

arch    halt.flat  Makefile       matmult.c     matmult.noff  shell.c     shell.noff  sort.flat  start.s halt.c  halt.noff  Makefile.orig  matmult.flat  script        shell.flat  sort.c      sort.noff

And something like:

>>> Converting to flat file: arch/unknown-i386-linux/bin/sort.flat <<<
../bin/arch/unknown-i386-linux/bin/coff2flat arch/unknown-i386-linux/objects/sort.coff arch/unknown-i386-linux/bin/sort.flat
Loading 3 sections:
".text", filepos 0xd0, mempos 0x0, size 0x2c0
".data", filepos 0x390, mempos 0x2c0, size 0x0
".bss", filepos 0x0, mempos 0x2c0, size 0x1000
Adding stack of size: 1024

Test threads

Make. Ignore Warnings. Then we get something like this:

>>> Assembling switch-linux.s <<<
/lib/cpp -D HOST_i386 -D HOST_LINUX switch-linux.s > arch/unknown-i386-linux/objects/tmp.s
as -o arch/unknown-i386-linux/objects/switch-linux.o arch/unknown-i386-linux/objects/tmp.s
switch-linux.s: Assembler messages:
switch-linux.s:61: Warning: indirect call without `*'
switch-linux.s:62: Warning: indirect call without `*'
switch-linux.s:63: Warning: indirect call without `*'
rm arch/unknown-i386-linux/objects/tmp.s
>>> Linking arch/unknown-i386-linux/bin/nachos <<<
g++ arch/unknown-i386-linux/objects/main.o arch/unknown-i386-linux/objects/list.o arch/unknown-i386-linux/objects/scheduler.o arch/unknown-i386-linux/objects/synch.o arch/unknown-i386-linux/objects/synchlist.o arch/unknown-i386-linux/objects/system.o arch/unknown-i386-linux/objects/thread.o arch/unknown-i386-linux/objects/utility.o arch/unknown-i386-linux/objects/threadtest.o arch/unknown-i386-linux/objects/synchtest.o arch/unknown-i386-linux/objects/interrupt.o arch/unknown-i386-linux/objects/sysdep.o arch/unknown-i386-linux/objects/stats.o arch/unknown-i386-linux/objects/timer.o arch/unknown-i386-linux/objects/switch-linux.o -o arch/unknown-i386-linux/bin/nachos
ln -sf arch/unknown-i386-linux/bin/nachos nachos

If successful, a link-file named nachos will be generated.

arch         dump     main.cc         nachos        switch.h        synch.cc      synchlist.h   system.h   threadtest.cc
bool.h list.cc Makefile scheduler.cc switch-linux.s synch.h synchtest.cc thread.cc utility.cc
copyright.h list.h Makefile.local scheduler.h switch.s synchlist.cc system.cc thread.h utility.h

Run ./nachos, then got:

*** thread 0 looped 0 times
*** thread 1 looped 0 times
*** thread 0 looped 1 times
*** thread 1 looped 1 times
*** thread 0 looped 2 times
*** thread 1 looped 2 times
*** thread 0 looped 3 times
*** thread 1 looped 3 times
*** thread 0 looped 4 times
*** thread 1 looped 4 times
No threads ready or runnable, and no pending interrupts.
Assuming the program completed.
Machine halting!

Ticks: total 130, idle 0, system 130, user 0
Disk I/O: reads 0, writes 0
Console I/O: reads 0, writes 0
Paging: faults 0
Network I/O: packets received 0, sent 0

Cleaning up...

Test filesys

Make, and got:

>>> Assembling ../threads/switch-linux.s <<<
/lib/cpp -D HOST_i386 -D HOST_LINUX ../threads/switch-linux.s > arch/unknown-i386-linux/objects/tmp.s
as -o arch/unknown-i386-linux/objects/switch-linux.o arch/unknown-i386-linux/objects/tmp.s
../threads/switch-linux.s: Assembler messages:
../threads/switch-linux.s:61: Warning: indirect call without `*'
../threads/switch-linux.s:62: Warning: indirect call without `*'
../threads/switch-linux.s:63: Warning: indirect call without `*'
rm arch/unknown-i386-linux/objects/tmp.s
>>> Linking arch/unknown-i386-linux/bin/nachos <<<
g++ arch/unknown-i386-linux/objects/main.o arch/unknown-i386-linux/objects/list.o arch/unknown-i386-linux/objects/scheduler.o arch/unknown-i386-linux/objects/synch.o arch/unknown-i386-linux/objects/synchlist.o arch/unknown-i386-linux/objects/system.o arch/unknown-i386-linux/objects/thread.o arch/unknown-i386-linux/objects/utility.o arch/unknown-i386-linux/objects/threadtest.o arch/unknown-i386-linux/objects/synchtest.o arch/unknown-i386-linux/objects/interrupt.o arch/unknown-i386-linux/objects/sysdep.o arch/unknown-i386-linux/objects/stats.o arch/unknown-i386-linux/objects/timer.o arch/unknown-i386-linux/objects/bitmap.o arch/unknown-i386-linux/objects/directory.o arch/unknown-i386-linux/objects/filehdr.o arch/unknown-i386-linux/objects/filesys.o arch/unknown-i386-linux/objects/fstest.o arch/unknown-i386-linux/objects/openfile.o arch/unknown-i386-linux/objects/synchdisk.o arch/unknown-i386-linux/objects/disk.o arch/unknown-i386-linux/objects/switch-linux.o -o arch/unknown-i386-linux/bin/nachos
ln -sf arch/unknown-i386-linux/bin/nachos nachos

Run ./nachos, then got:

*** thread 0 looped 0 times
*** thread 1 looped 0 times
*** thread 0 looped 1 times
*** thread 1 looped 1 times
*** thread 0 looped 2 times
*** thread 1 looped 2 times
*** thread 0 looped 3 times
*** thread 1 looped 3 times
*** thread 0 looped 4 times
*** thread 1 looped 4 times
No threads ready or runnable, and no pending interrupts.
Assuming the program completed.
Machine halting!

Ticks: total 1190, idle 1000, system 190, user 0
Disk I/O: reads 2, writes 0
Console I/O: reads 0, writes 0
Paging: faults 0
Network I/O: packets received 0, sent 0

Cleaning up...

Test vm

Make then run:

*** thread 0 looped 0 times
*** thread 1 looped 0 times
*** thread 0 looped 1 times
*** thread 1 looped 1 times
*** thread 0 looped 2 times
*** thread 1 looped 2 times
*** thread 0 looped 3 times
*** thread 1 looped 3 times
*** thread 0 looped 4 times
*** thread 1 looped 4 times
No threads ready or runnable, and no pending interrupts.
Assuming the program completed.
Machine halting!

Ticks: total 130, idle 0, system 130, user 0
Disk I/O: reads 0, writes 0
Console I/O: reads 0, writes 0
Paging: faults 0
Network I/O: packets received 0, sent 0

Cleaning up...

Test monitor

Make then run:

No threads ready or runnable, and no pending interrupts.
Assuming the program completed.
Machine halting!

Ticks: total 590, idle 0, system 590, user 0
Disk I/O: reads 0, writes 0
Console I/O: reads 0, writes 0
Paging: faults 0
Network I/O: packets received 0, sent 0

Cleaning up...

Test network

Make then run:

*** thread 0 looped 0 times
*** thread 1 looped 0 times
*** thread 0 looped 1 times
*** thread 1 looped 1 times
*** thread 0 looped 2 times
*** thread 1 looped 2 times
*** thread 0 looped 3 times
*** thread 1 looped 3 times
*** thread 0 looped 4 times
*** thread 1 looped 4 times

Test userprog

Make but I got:

../Makefile.common:92: recipe for target 'arch/unknown-i386-linux/bin/nachos' failed
make: *** [arch/unknown-i386-linux/bin/nachos] Error 1

Well, forget it.

Test lab3

In prodcons++.cc, add below to use create and write system call

#include <cstdlib>
#include <sys/types.h> /* create */
#include <sys/stat.h> /* create */
#include <fcntl.h> /* create */
#include <unistd.h> /* write */

Then make, it should be OK:

>>> Linking arch/unknown-i386-linux/bin/nachos <<<
g++ -m32 arch/unknown-i386-linux/objects/main.o arch/unknown-i386-linux/objects/list.o arch/unknown-i386-linux/objects/scheduler.o arch/unknown-i386-linux/objects/synch.o arch/unknown-i386-linux/objects/synchlist.o arch/unknown-i386-linux/objects/system.o arch/unknown-i386-linux/objects/thread.o arch/unknown-i386-linux/objects/utility.o arch/unknown-i386-linux/objects/threadtest.o arch/unknown-i386-linux/objects/synchtest.o arch/unknown-i386-linux/objects/interrupt.o arch/unknown-i386-linux/objects/sysdep.o arch/unknown-i386-linux/objects/stats.o arch/unknown-i386-linux/objects/timer.o arch/unknown-i386-linux/objects/prodcons++.o arch/unknown-i386-linux/objects/ring.o arch/unknown-i386-linux/objects/switch-linux.o -o arch/unknown-i386-linux/bin/nachos
ln -sf arch/unknown-i386-linux/bin/nachos nachos

Run ./nachos .

No threads ready or runnable, and no pending interrupts.
Assuming the program completed.
Machine halting!

Ticks: total 10, idle 0, system 10, user 0
Disk I/O: reads 0, writes 0
Console I/O: reads 0, writes 0
Paging: faults 0
Network I/O: packets received 0, sent 0

Cleaning up...

Test lab5

First add a Makefile (copied from lab3), well, forget it…

Test lab7-8

Edit Makefile.local :

# include ../ass2/Makefile.local

Then Make and Run:

*** thread 0 looped 0 times
*** thread 1 looped 0 times
*** thread 0 looped 1 times
*** thread 1 looped 1 times
*** thread 0 looped 2 times
*** thread 1 looped 2 times
*** thread 0 looped 3 times
*** thread 1 looped 3 times
*** thread 0 looped 4 times
*** thread 1 looped 4 times
No threads ready or runnable, and no pending interrupts.
Assuming the program completed.
Machine halting!

Ticks: total 130, idle 0, system 130, user 0
Disk I/O: reads 0, writes 0
Console I/O: reads 0, writes 0
Paging: faults 0
Network I/O: packets received 0, sent 0

Cleaning up...

If using x64 Ubuntu

Install libc6-dev-i386:

sudo apt-get install libc6-dev-i386

In code directory, edit Makefile.common :

# CFLAGS = -g -Wall -Wshadow $(INCPATH) $(DEFINES) $(HOST) -DCHANGED
CFLAGS = -g -Wall -Wshadow -m32 $(INCPATH) $(DEFINES) $(HOST) -DCHANGED

Also edit Makefile.dep :

#CPP=/lib/cpp
#CC = g++
#LD = g++
#AS = as
CPP= gcc -E -m32
CC = g++ -m32
LD = g++ -m32
AS = as --32