Main Page | Alphabetical List | Class List | File List | Class Members | File Members

main.cc

Go to the documentation of this file.
00001 // main.cc 00002 // Bootstrap code to initialize the operating system kernel. 00003 // 00004 // Allows direct calls into internal operating system functions, 00005 // to simplify debugging and testing. In practice, the 00006 // bootstrap code would just initialize data structures, 00007 // and start a user program to print the login prompt. 00008 // 00009 // Most of this file is not needed until later assignments. 00010 // 00011 // Usage: nachos -d <debugflags> -rs <random seed #> 00012 // -s -x <nachos file> -c <consoleIn> <consoleOut> 00013 // -f -cp <unix file> <nachos file> 00014 // -p <nachos file> -r <nachos file> -l -D -t 00015 // -n <network reliability> -m <machine id> 00016 // -o <other machine id> 00017 // -z 00018 // 00019 // -d causes certain debugging messages to be printed (cf. utility.h) 00020 // -rs causes Yield to occur at random (but repeatable) spots 00021 // -z prints the copyright message 00022 // 00023 // USER_PROGRAM 00024 // -s causes user programs to be executed in single-step mode 00025 // -x runs a user program 00026 // -c tests the console 00027 // 00028 // FILESYS 00029 // -f causes the physical disk to be formatted 00030 // -cp copies a file from UNIX to Nachos 00031 // -p prints a Nachos file to stdout 00032 // -r removes a Nachos file from the file system 00033 // -l lists the contents of the Nachos directory 00034 // -D prints the contents of the entire file system 00035 // -t tests the performance of the Nachos file system 00036 // 00037 // NETWORK 00038 // -n sets the network reliability 00039 // -m sets this machine's host id (needed for the network) 00040 // -o runs a simple test of the Nachos network software 00041 // 00042 // NOTE -- flags are ignored until the relevant assignment. 00043 // Some of the flags are interpreted here; some in system.cc. 00044 // 00045 // Copyright (c) 1992-1993 The Regents of the University of California. 00046 // All rights reserved. See copyright.h for copyright notice and limitation 00047 // of liability and disclaimer of warranty provisions. 00048 00049 #define MAIN 00050 #include "copyright.h" 00051 #undef MAIN 00052 00053 #include "utility.h" 00054 #include "thread.h" 00055 #include "system.h" 00056 #include <sys/time.h> 00057 #include <stdio.h> 00058 #include <signal.h> 00059 #include <time.h> 00060 #include <unistd.h> 00061 #include <setjmp.h> 00062 00063 #include "synch.h" 00064 00065 00066 00067 // External functions used by this file 00068 00069 extern void ThreadTest1(int); 00070 extern void Copy(char *unixFile, char *nachosFile); 00071 extern void Print(char *file), PerformanceTest(void); 00072 extern void StartProcess(char *file), ConsoleTest(char *in, char *out); 00073 extern void MailTest(int networkID); 00074 00075 00076 extern sigjmp_buf schd_jmp; // defined in the scheduler.cc 00077 00078 00079 //---------------------------------------------------------------------- 00080 // main 00081 // Bootstrap the operating system kernel. 00082 // 00083 // Check command line arguments 00084 // Initialize data structures 00085 // (optionally) Call test procedure 00086 // 00087 // "argc" is the number of command line arguments (including the name 00088 // of the command) -- ex: "nachos -d +" -> argc = 3 00089 // "argv" is an array of strings, one for each command line argument 00090 // ex: "nachos -d +" -> argv = {"nachos", "-d", "+"} 00091 //---------------------------------------------------------------------- 00092 int main(int argc, char **argv) 00093 { 00094 int argCount; // the number of arguments 00095 // for a particular command 00096 00097 DEBUG('t', "Entering main"); 00098 00099 if (sigsetjmp(schd_jmp, 1) != 0) // entry point for the scheduler 00100 { 00101 schedule(); 00102 00103 if (!scheduler->IsEmpty()) 00104 { 00105 while(1) 00106 ; 00107 } 00108 // never gets here 00109 printf("Yikes...\n"); 00110 } 00111 else 00112 { 00113 (void) Initialize(argc, argv); 00114 00115 for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) 00116 { 00117 argCount = 1; 00118 if (!strcmp(*argv, "-z")) // print copyright 00119 printf (copyright); 00120 #ifdef USER_PROGRAM 00121 if (!strcmp(*argv, "-x")) 00122 { // run a user program 00123 ASSERT(argc > 1); 00124 StartProcess(*(argv + 1)); 00125 argCount = 2; 00126 } 00127 else if (!strcmp(*argv, "-c")) 00128 { // test the console 00129 if (argc == 1) 00130 ConsoleTest(NULL, NULL); 00131 else 00132 { 00133 ASSERT(argc > 2); 00134 ConsoleTest(*(argv + 1), *(argv + 2)); 00135 argCount = 3; 00136 } 00137 interrupt->Halt(); // once we start the console, then 00138 // Nachos will loop forever waiting 00139 // for console input 00140 } 00141 #endif // USER_PROGRAM 00142 #ifdef FILESYS 00143 if (!strcmp(*argv, "-cp")) 00144 { // copy from UNIX to Nachos 00145 ASSERT(argc > 2); 00146 Copy(*(argv + 1), *(argv + 2)); 00147 argCount = 3; 00148 } 00149 else if (!strcmp(*argv, "-p")) 00150 { // print a Nachos file 00151 ASSERT(argc > 1); 00152 Print(*(argv + 1)); 00153 argCount = 2; 00154 } else if (!strcmp(*argv, "-r")) 00155 { // remove Nachos file 00156 ASSERT(argc > 1); 00157 fileSystem->Remove(*(argv + 1)); 00158 argCount = 2; 00159 } 00160 else if (!strcmp(*argv, "-l")) 00161 { // list Nachos directory 00162 fileSystem->List(); 00163 } 00164 else if (!strcmp(*argv, "-D")) 00165 { // print entire filesystem 00166 fileSystem->Print(); 00167 } 00168 else if (!strcmp(*argv, "-t")) 00169 { // performance test 00170 PerformanceTest(); 00171 } 00172 #endif // FILESYS 00173 #ifdef NETWORK 00174 if (!strcmp(*argv, "-o")) 00175 { 00176 ASSERT(argc > 1); 00177 Delay(2); // delay for 2 seconds 00178 // to give the user time to 00179 // start up another nachos 00180 MailTest(atoi(*(argv + 1))); 00181 argCount = 2; 00182 } 00183 #endif // NETWORK 00184 } 00185 00186 currentThread = 0; 00187 timerInit(); 00188 00189 ThreadTest1(0); 00190 if (!scheduler->IsEmpty()) 00191 schedule(); // to start the threads going 00192 } 00193 00194 // returns, then the program "nachos" 00195 // will exit (as any other normal program 00196 // would). But there may be other 00197 // threads on the ready list. We switch 00198 // to those threads by saying that the 00199 // will exit (as any other normal program 00200 // would). But there may be other 00201 // threads on the ready list. We switch 00202 // to those threads by saying that the 00203 // "main" thread is finished, preventing 00204 // it from returning. 00205 return(0); // Not reached... 00206 }

Generated on Thu Sep 16 12:33:45 2004 for NachOS by doxygen 1.3.8