nachos 5.0j(java版)学习笔记一:环境搭建

nachos 5.0j(java版)学习笔记一:环境搭建

梗概:
  1. jdk安装配置
  2. proj1运行
  3. mips交叉编译器(附完整代码记录)
  4. proj2运行(附完整代码记录)
  5. nachos整理(包括proj1/2,项目源码/使用说明/实验报告)
写在前面:

nachos 5.0j可以在windows和Linux系统上运行;
对于proj1,可以直接导入eclipse进行编译;
project2需要交叉编译,而对于win系统中的此类的资料比较少,所以还是投向了linux的怀抱;(修改:后来,我发现,可以在Linux系统中交叉编译,然后将coff文件拷贝到eclipse里就行。)
但是笔者的笔记本过于垃圾,不想和虚拟机作斗争了,笔者最后用的是阿里云学生轻量级服务器(无图形界面);
下面我的环境搭建其实是针对无图形界面的Linux系统的,当然也适用于有图形界面的Linux系统;

1.java开发环境:jdk的安装配置
  1. 笔者用的是jdk-13_linux-x64_bin.tar.gz

  2. 解压文件
    $tar -xzvf jdk-13_linux-x64_bin.tar.gz
    ps:为了保持接下来目录一致,建议将解压文件移动到/root/usr/local/java目录下

  3. 配置环境变量
    $vi /etc/profile
    在最后面添加几句话:

    	# jdk
    	export JAVA_HOME=/root/usr/local/java/jdk-13
    	export CLASSPATH=.:$JAVA_HOME/jre/bin/lib.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
    	export PATH=$PATH:$JAVA_HOME/bin
    

    保存后,更新一下
    #source /etc/profile

  4. 验证安装是否成功
    $ java -version
    $ javac -version
    以上两个指令返回相应的版本信息,即为安装成功

2.运行proj1

将nachos-java.tar.gz解压

#tar -xzvf jdk-8u211-linux-x86.tar.gz

将nachos文件移动到root/usr/wp文件夹下,为了方便配置环境变量,建议跟我的目录一致,移动完之后用pwd和ls命令检验一下

# pwd
/root/usr/wp/nachos
# ls
ag  bin  machine  Makefile  network  proj1  proj2  proj3  proj4  README  security  test  threads  userprog  vm

添加nochos/bin目录到PATH环境变量

回到根目录,用vi编辑器编辑/etc/profile

#vi /etc/profile

在/etc/profile文件尾部添加

# nachos excutation
export PATH=$PATH:/root/usr/wp/nachos/bin

保存文件,更新一下

# source /etc/profile

在nochos/proj1目录下,执行编译make、运行nachos

root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/proj1# ls
Makefile  nachos  nachos.conf
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/proj1# make
javac -classpath . -d . -sourcepath ../.. -g ../threads/ThreadedKernel.java
../../nachos/threads/KThread.java:311: warning: 'yield' may become a restricted identifier in a future release
            public void run() { while (true) yield(); }
                                             ^
  (to invoke a method called yield, qualify the yield with a receiver or type name)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: ../../nachos/machine/Lib.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
javac -classpath . -d . -sourcepath ../.. -g ../threads/Boat.java
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/proj1# nachos
nachos 5.0j initializing... config interrupt timer user-check grader
*** 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
Machine halting!

Ticks: total 2130, kernel 2130, user 0
Disk I/O: reads 0, writes 0
Console I/O: reads 0, writes 0
Paging: page faults 0, TLB misses 0
Network I/O: received 0, sent 0

此后,便可以修改代码,完成proj1的相关问题了,make命令-对整个项目进行编译,nachos命令-运行项目

3.mips交叉编译器

将mips-x86.linux-xgcc.tgz解压到nachos目录下
进入nachos/test目录下,配置环境变量

# export ARCHDIR=../mips-x86.linux-xgcc
# export PATH=/root/usr/wp/nachos/mips-x86.linux-xgcc:$PATH

检验一下

# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/usr/local/java/jdk-13/bin:/root/usr/wp/nachos/bin

编译

#make clean
#make

完整操作记录:

root@iZ2ze1vavqma9q8lhrqq6wZ:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/usr/local/java/jdk-13/bin:/root/usr/wp/nachos/bin
root@iZ2ze1vavqma9q8lhrqq6wZ:~# cd usr/wp/nachos
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos# ls
ag  bin  machine  Makefile  mips-x86.linux-xgcc  mips-x86.linux-xgcc.tgz  network  proj1  proj2  proj3  proj4  README  security  test  threads  userprog  vm
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos# cd test
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/test# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/usr/local/java/jdk-13/bin:/root/usr/wp/nachos/bin
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/test# export ARCHDIR=../mips-x86.linux-xgcc
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/test# export PATH=/root/usr/wp/nachos/mips-x86.linux-xgcc:$PATH
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/test# echo $PATH
/root/usr/wp/nachos/mips-x86.linux-xgcc:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/root/usr/local/java/jdk-13/bin:/root/usr/wp/nachos/bin
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/test# make clean
rm -f strt.s *.o *.coff libnachos.a
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/test# make
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c assert.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a assert.o
a - assert.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c atoi.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a atoi.o
a - atoi.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c printf.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a printf.o
a - printf.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c readline.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a readline.o
a - readline.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c stdio.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a stdio.o
a - stdio.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c strncmp.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a strncmp.o
a - strncmp.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c strcat.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a strcat.o
a - strcat.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c strcmp.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a strcmp.o
a - strcmp.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c strcpy.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a strcpy.o
a - strcpy.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c strlen.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a strlen.o
a - strlen.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c memcpy.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a memcpy.o
a - memcpy.o
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c memset.c
../mips-x86.linux-xgcc/mips-ar rv libnachos.a memset.o
a - memset.o
../mips-x86.linux-xgcc/mips-cpp  start.s > strt.s
../mips-x86.linux-xgcc/mips-as -mips1 -o start.o strt.s
rm strt.s
../mips-x86.linux-xgcc/mips-ranlib libnachos.a
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c halt.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o halt.coff halt.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c sh.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o sh.coff sh.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c matmult.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o matmult.coff matmult.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c sort.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o sort.coff sort.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c echo.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o echo.coff echo.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c cat.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o cat.coff cat.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c cp.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o cp.coff cp.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c mv.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o mv.coff mv.o start.o -lnachos
../mips-x86.linux-xgcc/mips-gcc -O2 -B../mips-x86.linux-xgcc/mips- -G 0 -Wa,-mips1 -nostdlib -ffreestanding -c rm.c
../mips-x86.linux-xgcc/mips-ld -s -T script -N -warn-common -warn-constructors -warn-multiple-gp -o rm.coff rm.o start.o -lnachos
4.运行proj2

进入proj2
编译

#make

将test中的halt.coff复制到proj2

# cp ../test/halt.coff ../proj2

运行

# nachos -x halt.coff

完整记录如下:

root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/test# cd ../proj2
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/proj2# make
javac -classpath . -d . -sourcepath ../.. -g ../userprog/UserKernel.java
../../nachos/threads/KThread.java:311: warning: 'yield' may become a restricted identifier in a future release
            public void run() { while (true) yield(); }
                                             ^
  (to invoke a method called yield, qualify the yield with a receiver or type name)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: ../../nachos/machine/Lib.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
javac -classpath . -d . -sourcepath ../.. -g ../threads/Boat.java
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/proj2# cp ../test/halt.coff ../proj2
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/proj2# ls
halt.coff  Makefile  nachos  nachos.conf
root@iZ2ze1vavqma9q8lhrqq6wZ:~/usr/wp/nachos/proj2# nachos -x halt.coff
nachos 5.0j initializing... config interrupt timer processor console user-check grader
*** 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
Testing the console device. Typed characters
will be echoed until q is typed.

接下来就可以开始着手proj2的相关问题了。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值