Main Page   Compound List   File List   Compound 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 "system.h"
00055 
00056 
00057 // External functions used by this file
00058 
00059 extern void ThreadTest(void), Copy(char *unixFile, char *nachosFile);
00060 extern void Print(char *file), PerformanceTest(void);
00061 extern void StartProcess(char *file), ConsoleTest(char *in, char *out);
00062 extern void MailTest(int networkID);
00063 
00064 //----------------------------------------------------------------------
00065 // main
00066 //      Bootstrap the operating system kernel.  
00067 //      
00068 //      Check command line arguments
00069 //      Initialize data structures
00070 //      (optionally) Call test procedure
00071 //
00072 //      "argc" is the number of command line arguments (including the name
00073 //              of the command) -- ex: "nachos -d +" -> argc = 3 
00074 //      "argv" is an array of strings, one for each command line argument
00075 //              ex: "nachos -d +" -> argv = {"nachos", "-d", "+"}
00076 //----------------------------------------------------------------------
00077 
00078 int
00079 main(int argc, char **argv)
00080 {
00081     int argCount;                       // the number of arguments 
00082                                         // for a particular command
00083 
00084     DEBUG('t', "Entering main");
00085     (void) Initialize(argc, argv);
00086     
00087 #ifdef THREADS
00088     ThreadTest();
00089 #endif
00090 
00091     for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) {
00092         argCount = 1;
00093         if (!strcmp(*argv, "-z"))               // print copyright
00094             printf (copyright);
00095 #ifdef USER_PROGRAM
00096         if (!strcmp(*argv, "-x")) {             // run a user program
00097             ASSERT(argc > 1);
00098             StartProcess(*(argv + 1));
00099             argCount = 2;
00100         } else if (!strcmp(*argv, "-c")) {      // test the console
00101             if (argc == 1)
00102                 ConsoleTest(NULL, NULL);
00103             else {
00104                 ASSERT(argc > 2);
00105                 ConsoleTest(*(argv + 1), *(argv + 2));
00106                 argCount = 3;
00107             }
00108             interrupt->Halt();          // once we start the console, then 
00109                                         // Nachos will loop forever waiting 
00110                                         // for console input
00111         }
00112 #endif // USER_PROGRAM
00113 #ifdef FILESYS
00114         if (!strcmp(*argv, "-cp")) {            // copy from UNIX to Nachos
00115             ASSERT(argc > 2);
00116             Copy(*(argv + 1), *(argv + 2));
00117             argCount = 3;
00118         } else if (!strcmp(*argv, "-p")) {      // print a Nachos file
00119             ASSERT(argc > 1);
00120             Print(*(argv + 1));
00121             argCount = 2;
00122         } else if (!strcmp(*argv, "-r")) {      // remove Nachos file
00123             ASSERT(argc > 1);
00124             fileSystem->Remove(*(argv + 1));
00125             argCount = 2;
00126         } else if (!strcmp(*argv, "-l")) {      // list Nachos directory
00127             fileSystem->List();
00128         } else if (!strcmp(*argv, "-D")) {      // print entire filesystem
00129             fileSystem->Print();
00130         } else if (!strcmp(*argv, "-t")) {      // performance test
00131             PerformanceTest();
00132         }
00133 #endif // FILESYS
00134 #ifdef NETWORK
00135         if (!strcmp(*argv, "-o")) {
00136             ASSERT(argc > 1);
00137             Delay(2);                           // delay for 2 seconds
00138                                                 // to give the user time to 
00139                                                 // start up another nachos
00140             MailTest(atoi(*(argv + 1)));
00141             argCount = 2;
00142         }
00143 #endif // NETWORK
00144     }
00145 
00146     currentThread->Finish();    // NOTE: if the procedure "main" 
00147                                 // returns, then the program "nachos"
00148                                 // will exit (as any other normal program
00149                                 // would).  But there may be other
00150                                 // threads on the ready list.  We switch
00151                                 // to those threads by saying that the
00152                                 // "main" thread is finished, preventing
00153                                 // it from returning.
00154     return(0);                  // Not reached...
00155 }

Generated on Mon Feb 10 09:54:46 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees