【nachos】nachos学习笔记(五) 用户进程与系统调用

一、实验目的

 In this lab, you are required to
• experiment with user programs in Nachos, and
• get familiar with the code which you need to implement Nachos system calls.
The purpose is to enable you to gain a understanding of
• how user processes are started
• how user processes interact with an OS kernel through system calls
• how system calls are implemented

二、MIPS的安装

将nachos压缩包中的gcc-2.8.1-mips.tar.gz复制到/usr/local文件夹中,然后对其进行解压。

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

Nachos中运行用户程序的方法为实现一个MIPS的虚拟机。用户写了一段C程序后,使用MIPS编译器对其编译,nachos读取每一条机器指令,然后对其进行解释执行。可以在machine文件夹下的mipssim.cc中看到各个指令的具体实现。

三、实验题目

1、Nachos executables

将test文件夹中的halt.c文件修改为如下形式,然后使用make命令对其进行编译。
可以使用如下命令使用MIPS的编译器对其进行编译,生成.s文件,以便查看他的汇编指令。

/usr/local/mips/bin/decstation-ultrix-gcc -I../userprog -I../threads -S halt.c


这是汇编后的汇编代码。

汇编代码的分析可以查看学习笔记(一)中的汇编部分。MIPS的汇编指令名与windows下有些不同,具体可以在网上查询。
其中,jal __main这条指令跳转到了__main函数,应该为MIPS中在装载函数等初始化的操作,nachos只保留了这个函数的接口,并未对其实现,可以忽略。

接着进入userprog文件夹中,先执行make clean命令清除以前编译的文件,然后执行make进行编译。

然后执行以下命令,使用nachos执行。

./nachos -d m -x ../test/halt.noff


可以加入 -d m 参数查看具体执行的指令。

./nachos -d m -x ../test/halt.noff

2、查看页表信息

为AddrSpace类添加一个Print方法,然后在其构造函数中调用。

void AddrSpace::Print() {
printf("page table dump: %d pages in total\n", numPages); printf("============================================\n"); 
printf("\tVirtPage, \tPhysPage\n");
for (int i=0; i < numPages; i++) { 
printf("\t%d, \t\t%d\n", pageTable[i].virtualPage, pageTable[i].physicalPage); 
} 
printf("============================================\n\n");
}



重新编译后再次执行halt

3、扩大地址空间

在halt.c中加入一个长度为40的静态int数组,然后重新make编译


可以发现比原先多了1页。

猜你喜欢

转载自blog.csdn.net/darord/article/details/84325090