nachos实验一代码(共23页).doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《nachos实验一代码(共23页).doc》由会员分享,可在线阅读,更多相关《nachos实验一代码(共23页).doc(23页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上Test文件下: shell.c: #include syscall.hintmain() SpaceId newProc; OpenFileId input = ConsoleInput; OpenFileId output = ConsoleOutput; char ch, buffer60; int i;Write( ttn, 34, output); while( 1 ) Write( :, 20, output);i = 0;do Read(&bufferi, 1, input); while( bufferi+ != n );buffer-i = 0; i
2、f(Strncmp(buffer,exit,4)=0) Halt(); if( i 0 ) newProc = Exec(buffer);Join(newProc); Start.s :/* Start.s *Assembly language assist for user programs running on top of Nachos. * *Since we dont want to pull in the entire C library, we define *what we need for a user program here, namely Start and the s
3、ystem *calls. */#define IN_ASM#include syscall.h .text .align 2/* - * _start *Initialize running a C program, by calling main. * * NOTE: This has to be first, so that it gets loaded at location 0. *The Nachos kernel always starts a program by jumping to location 0. * - */.globl _start.ent_start_star
4、t:jalmainmove$4,$0jalExit /* if we return from main, exit(0) */.end _start/* - * System call stubs: *Assembly language assist to make system calls to the Nachos kernel. *There is one stub per system call, that places the code for the *system call into register r2, and leaves the arguments to the *sy
5、stem call alone (in other words, arg1 is in r4, arg2 is *in r5, arg3 is in r6, arg4 is in r7) * * The return value is in r2. This follows the standard C calling * convention on the MIPS. * - */.globl Halt.entHaltHalt:addiu $2,$0,SC_Haltsyscallj$31.end Halt.globl Add.entAddAdd:addiu $2,$0,SC_Addsysca
6、llj $31.end Add.globl Exit.entExitExit:addiu $2,$0,SC_Exitsyscallj$31.end Exit.globl Exec.entExecExec:addiu $2,$0,SC_Execsyscallj$31.end Exec.globl ExecV.entExecVExecV:addiu $2,$0,SC_ExecVsyscallj$31.end ExecV.globl Join.entJoinJoin:addiu $2,$0,SC_Joinsyscallj$31.end Join.globl Create.entCreateCreat
7、e:addiu $2,$0,SC_Createsyscallj$31.end Create.globl Remove.entRemoveRemove:addiu $2,$0,SC_Removesyscallj$31.end Remove.globl Open.entOpenOpen:addiu $2,$0,SC_Opensyscallj$31.end Open.globl Read.entReadRead:addiu $2,$0,SC_Readsyscallj$31.end Read.globl Write.entWriteWrite:addiu $2,$0,SC_Writesyscallj$
8、31.end Write.globl Close.entCloseClose:addiu $2,$0,SC_Closesyscallj$31.end Close.globl Seek.entSeekSeek:addiu $2,$0,SC_Seeksyscallj$31.end Seek.globl Delete.entDeleteDelete: addiu $2,$0,SC_Deletesyscallj$31.end Delete .globl ThreadFork .ent ThreadForkThreadFork: addiu $2,$0,SC_ThreadFork syscall j $
9、31 .end ThreadFork .globl ThreadYield .ent ThreadYieldThreadYield: addiu $2,$0,SC_ThreadYield syscall j $31 .end ThreadYield.globl ThreadExit.ent ThreadExitThreadExit:addiu $2, $0, SC_ThreadExitsyscallj $31.end ThreadExit.globl ThreadJoin.ent ThreadJoinThreadJoin:addiu $2, $0, SC_ThreadJoinsyscallj
10、$31.end ThreadJoin.globl getSpaceID.entgetSpaceIDgetSpaceID:addiu $2,$0,SC_getSpaceIDsyscallj$31.end getSpaceID.globl getThreadID.entgetThreadIDgetThreadID:addiu $2,$0,SC_getThreadIDsyscallj$31.end getThreadID.globl Ipc.ent IpcIpc: addiu $2,$0,SC_Ipcsyscallj $31.end Ipc.globl Clock.ent ClockClock:ad
11、diu $2,$0,SC_Clocksyscallj $31.end Clock/* dummy function to keep gcc happy */ .globl _main .ent _main_main: j $31 .end _main.globl Strncmp.ent StrncmpStrncmp: addiu $2,$0,SC_Strncmp syscall j $31 .end Strncmp .globl Exit .ent ExitUserprog文件夹下Exception.cc: / exception.cc /Entry point into the Nachos
12、 kernel from user programs./There are two kinds of things that can cause control to/transfer back to here from user code:/syscall - The user code explicitly requests to call a procedure/in the Nachos kernel. Right now, the only function we support is/Halt./exceptions - The user code does something t
13、hat the CPU cant handle./For instance, accessing memory that doesnt exist, arithmetic errors,/etc. /Interrupts (which can also cause control to transfer from user/code into the Nachos kernel) are handled elsewhere./ For now, this only handles the Halt() system call./ Everything else core dumps./ Cop
14、yright (c) 1992-1996 The Regents of the University of California./ All rights reserved. See copyright.h for copyright notice and limitation / of liability and disclaimer of warranty provisions.#include copyright.h#include main.h#include syscall.h#include ksyscall.h/-/ ExceptionHandler/ Entry point i
15、nto the Nachos kernel. Called when a user program/is executing, and either does a syscall, or generates an addressing/or arithmetic exception./ For system calls, the following is the calling convention:/ system call code - r2/arg1 - r4/arg2 - r5/arg3 - r6/arg4 - r7/The result of the system call, if
16、any, must be put back into r2. / If you are handling a system call, dont forget to increment the pc/ before returning. (Or else youll loop making the same system call forever!)/which is the kind of exception. The list of possible exceptions /is in machine.h./-voidExceptionHandler(ExceptionType which
17、) int type = kernel-machine-ReadRegister(2); DEBUG(dbgSys, Received Exception which type: type n); switch (which) case SyscallException: switch(type) case SC_Halt:DEBUG(dbgSys, Shutdown, initiated by user program.n);SysHalt();ASSERTNOTREACHED();break;case SC_Write:DEBUG(dbgSys,Write from buffer to c
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- nachos 实验 代码 23
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内