Because NachOS need to be built under 32bit.
- How to compile 32-bit program on 64-bit gcc in C and C++
- HowTo Compile a 32-bit Application Using gcc On the 64-bit Linux Version
- Ubuntu apt-get install ia32 for 32-bit on 64-bit
sudo apt-get install gcc-multilib g++-multilib
Test:
#include <stdio.h>
int main(){
long z;
printf("Long int size is %i bytes long!\n", sizeof(z));
return 0;
}
$ gcc -m32 -o output32 hello.c
$ ./output32
Long int size is 4 bytes long!
$ gcc -m64 -o output64 hello.c
$ ./output64
Long int size is 8 bytes long!
...
Build the clean version given by TA
bash build_clean_nachos.sh
# the outcome image will be nachos:0.0.1
Build the modified version in this github repository
bash build_modified_nachos.sh
# the outcome image will be nachos:latest and nachos:0.1 (default)
# it can also take an argument of a specific version
./build_modified_nachos.sh 0.1.1
Build only the specific subdirectory (Recommend, especially when you're just dealing with a specific Lab)
# build threads for example (use any subdirectory name under nachos-3.4/code/)
./build_subdir_nachos.sh threads
# the outcome image will be nachos_<subdir>:latest
Running example
# Interactive
$ docker run -it nachos:0.0.1
# Interactive with mount local project
# (Run this in the root of this repository)
$ docker run -it -v $(pwd)/Nachos:/Nachos nachos:latest
# Run a single test
$ docker run nachos:latest nachos/nachos-3.4/code/threads/nachos
*** 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...
# Other ways to playing around
# Interactive concole test
$ docker run -it nachos nachos/nachos-3.4/code/userprog/nachos -c
# Step by step user program
& docker run -it nachos nachos/nachos-3.4/code/userprog/nachos -s -d a -x nachos/nachos-3.4/code/test/halt
GDB debugging
# Example of debugging threads/nachos built by `./build_subdir_nachos.sh threads`
$ docker run -it nachos_threads gdb nachos/nachos-3.4/code/threads/nachos
(gdb) run -d t -q 1
- docker for beginners
- Docker ENTRYPOINT & CMD: Dockerfile best practices
- Arguments and variables in Docker
- docker run
- docker build
- docker docs - docker build -t
- docker docs - Best practices for writing Dockerfiles
- docker docs - Create a base image
- docker arg
- docker cache
- Multi-stage builds
- docker alpine
- default-value syntax
- Default shell variables value
- How to write a bash script that takes optional input arguments?
- somecommand ${1:-foo}
- Assigning default values to shell variables with a single command in bash
- {var:=default} vs {var:-default} - what is difference?
- Positional or special parameters cannot be assigned using := way