00001 // kernel.cc 00002 // Initialization and cleanup routines for the Nachos kernel. 00003 // 00004 // Copyright (c) 1992-1996 The Regents of the University of California. 00005 // All rights reserved. See copyright.h for copyright notice and limitation 00006 // of liability and disclaimer of warranty provisions. 00007 00008 #include "copyright.h" 00009 #include "debug.h" 00010 #include "main.h" 00011 #include "kernel.h" 00012 #include "sysdep.h" 00013 #include "synch.h" 00014 #include "synchlist.h" 00015 #include "libtest.h" 00016 #include "elevatortest.h" 00017 #include "string.h" 00018 00025 ThreadedKernel::ThreadedKernel(int argc, char **argv) 00026 { 00027 randomSlice = FALSE; 00028 for (int i = 1; i < argc; i++) { 00029 if (strcmp(argv[i], "-rs") == 0) { 00030 ASSERT(i + 1 < argc); 00031 RandomInit(atoi(argv[i + 1])); 00034 randomSlice = TRUE; 00035 i++; 00036 } else if (strcmp(argv[i], "-u") == 0) { 00037 cout << "Partial usage: nachos [-rs randomSeed]\n"; 00038 } 00039 } 00040 } 00041 00049 void 00050 ThreadedKernel::Initialize() 00051 { 00052 stats = new Statistics(); 00053 interrupt = new Interrupt; 00054 scheduler = new Scheduler(); 00055 alarm = new Alarm(randomSlice); 00056 00057 // We didn't explicitly allocate the current thread we are running in. 00058 // But if it ever tries to give up the CPU, we better have a Thread 00059 // object to save its state. 00060 currentThread = new Thread("main"); 00061 currentThread->setStatus(RUNNING); 00062 00063 interrupt->Enable(); 00064 } 00065 00071 ThreadedKernel::~ThreadedKernel() 00072 { 00073 delete alarm; 00074 delete scheduler; 00075 delete interrupt; 00076 delete stats; 00077 00078 Exit(0); 00079 } 00080 00088 void 00089 ThreadedKernel::Run() 00090 { 00091 // NOTE: if the procedure "main" returns, then the program "nachos" 00092 // will exit (as any other normal program would). But there may be 00093 // other threads on the ready list (started in SelfTest). 00094 // We switch to those threads by saying that the "main" thread 00095 // is finished, preventing it from returning. 00096 currentThread->Finish(); 00097 // not reached 00098 } 00099 00105 void 00106 ThreadedKernel::SelfTest() { 00107 Semaphore *semaphore; 00108 SynchList<int> *synchList; 00109 00110 LibSelfTest(); 00111 00112 currentThread->SelfTest(); 00113 00114 00115 semaphore = new Semaphore("test", 0); 00116 semaphore->SelfTest(); 00117 delete semaphore; 00118 00119 00120 synchList = new SynchList<int>; 00121 synchList->SelfTest(9); 00122 00123 delete synchList; 00124 00125 ElevatorSelfTest(); 00126 }
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001