00001 // exception.cc 00002 // Entry point into the Nachos kernel from user programs. 00003 // There are two kinds of things that can cause control to 00004 // transfer back to here from user code: 00005 // 00006 // syscall -- The user code explicitly requests to call a procedure 00007 // in the Nachos kernel. Right now, the only function we support is 00008 // "Halt". 00009 // 00010 // exceptions -- The user code does something that the CPU can't handle. 00011 // For instance, accessing memory that doesn't exist, arithmetic errors, 00012 // etc. 00013 // 00014 // Interrupts (which can also cause control to transfer from user 00015 // code into the Nachos kernel) are handled elsewhere. 00016 // 00017 // For now, this only handles the Halt() system call. 00018 // Everything else core dumps. 00019 // 00020 // Copyright (c) 1992-1993 The Regents of the University of California. 00021 // All rights reserved. See copyright.h for copyright notice and limitation 00022 // of liability and disclaimer of warranty provisions. 00023 00024 #include "copyright.h" 00025 #include "system.h" 00026 #include "syscall.h" 00027 00028 //---------------------------------------------------------------------- 00029 // ExceptionHandler 00030 // Entry point into the Nachos kernel. Called when a user program 00031 // is executing, and either does a syscall, or generates an addressing 00032 // or arithmetic exception. 00033 // 00034 // For system calls, the following is the calling convention: 00035 // 00036 // system call code -- r2 00037 // arg1 -- r4 00038 // arg2 -- r5 00039 // arg3 -- r6 00040 // arg4 -- r7 00041 // 00042 // The result of the system call, if any, must be put back into r2. 00043 // 00044 // And don't forget to increment the pc before returning. (Or else you'll 00045 // loop making the same system call forever! 00046 // 00047 // "which" is the kind of exception. The list of possible exceptions 00048 // are in machine.h. 00049 //---------------------------------------------------------------------- 00050 00051 void 00052 ExceptionHandler(ExceptionType which) 00053 { 00054 int type = machine->ReadRegister(2); 00055 00056 if ((which == SyscallException) && (type == SC_Halt)) { 00057 DEBUG('a', "Shutdown, initiated by user program.\n"); 00058 interrupt->Halt(); 00059 } else { 00060 printf("Unexpected user mode exception %d %d\n", which, type); 00061 ASSERT(FALSE); 00062 } 00063 }
1.2.14 written by Dimitri van Heesch,
© 1997-2002