Author:duxingxia(中文作者, 查看 QQ 空间) Linuxayn(English)
1. Install NachOS & Build Development Environment
1.1 Build Development Environment
Though NachOS has been ported to MultiPlatform,this experiment is based on CygWin.
I trust you can finish the installation easily.(TIP:after the installation,if GCC isn’t enable,you should haven’t choose install ALL.)
Remember your disk space should be enough for the FAT CygWin.
1.2 Install NachOS
Do this follow the Documentation by ZYD.
Duxingxia said that the “shell” did nothing good to our experiment.
Suppose that NachOS is in code/build.cygwin and the testing program in code/test/add.c.
Our tests and operations are all processing in add.c.
1.3 Install SourceInsight(optional)
SourceInsight is a program that provides convenience for viewing codes.Duxingxia suggests a attempt of this software.Download it yourself.
What a pity,it cannot deal with .cc files.So you should rename all your .cc files into .cpp files.(You should BACKUP your files first!)
Open SourceInsight.Click Project->New Project.Tell it where you put your codes.
2. NachOS Experiment
2.1 Implement of Syscall
See the documentation.
2.2 Implement of First System Call:PrintNum(int)
Do: output a number in the standard output console.
Param: a int.
Return: if success,return the Param int.
//We are just telling you how to do,not why do so.Welcome any feedback.
1.Modify start.s(important!)
Like other system calls,add a section about your PrintNum.
.globl PrintNum
.ent PrintNum
PrintNum:
addiu $2,$0,SC_PrintNum
syscall
j $31
.end PrintNum
2.Modify syscall.h
Add a system call interface to let user program know.
Add two lines:
#define SC_PrintNum 43
int PrintNum(int);
//add.c
#include “syscall.h”
void main()
{
PrintNum(15);
Halt();//shut down NachOS
}
Build add.c to add.noff:
#make clean
#make
3.Modify exception.h (importan!)
In ExceptionHandler(),add:
case SC_PrintNum:
int result;
DEBUG(dbgSys, “PrintNum”<<kernel->machine->ReadRegister(4)<<“n”);
result = kernel->machine->ReadRegister(4);
cout<<“Print Num:”<<result<<endl;
/* Prepare Result */
kernel->machine->WriteRegister(2, (int)result);
{
/* set previous programm counter (debugging only)*/
kernel->machine->WriteRegister(PrevPCReg, kernel->machine->ReadRegister(PCReg));
/* set programm counter to next instruction (all Instructions are 4 byte wide)*/
kernel->machine->WriteRegister(PCReg, kernel->machine->ReadRegister(PCReg) + 4);
/* set next programm counter for brach execution */
kernel->machine->WriteRegister(NextPCReg, kernel->machine->ReadRegister(PCReg)+4);
}
return;
ASSERTNOTREACHED();
break;
4.Modify ksycall.h if neccesary.
2.3 Implement of Creat()
Your files created are in code/build.If success,you can see your files there.
2.4 Others
2.4.1 Implement of Open()
2.4.2 Implement of Close()
2.4.3 Implement of Write()
2.4.4 Implement of Read()
2.4.5 Implement of Seek()
Is it easy? Here we post our notes because we need your feedback sharing your problems,your happiness…
To be continued…
术业有专攻