00001
00002
00003
00004
00005
00006
00007
00008 #include "copyright.h"
00009 #include "system.h"
00010
00011
00012
00013
00014 Thread *currentThread;
00015 Thread *threadToBeDestroyed;
00016 Scheduler *scheduler;
00017 Interrupt *interrupt;
00018 Statistics *stats;
00019 Timer *timer;
00020
00021
00022 #ifdef FILESYS_NEEDED
00023 FileSystem *fileSystem;
00024 #endif
00025
00026 #ifdef FILESYS
00027 SynchDisk *synchDisk;
00028 #endif
00029
00030 #ifdef USER_PROGRAM // requires either FILESYS or FILESYS_STUB
00031 Machine *machine;
00032 #endif
00033
00034 #ifdef NETWORK
00035 PostOffice *postOffice;
00036 #endif
00037
00038
00039
00040 extern void Cleanup();
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 static void
00061 TimerInterruptHandler(int dummy)
00062 {
00063 if (interrupt->getStatus() != IdleMode)
00064 interrupt->YieldOnReturn();
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 void
00078 Initialize(int argc, char **argv)
00079 {
00080 int argCount;
00081 char* debugArgs = "";
00082 bool randomYield = FALSE;
00083
00084 #ifdef USER_PROGRAM
00085 bool debugUserProg = FALSE;
00086 #endif
00087 #ifdef FILESYS_NEEDED
00088 bool format = FALSE;
00089 #endif
00090 #ifdef NETWORK
00091 double rely = 1;
00092 int netname = 0;
00093 #endif
00094
00095 for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) {
00096 argCount = 1;
00097 if (!strcmp(*argv, "-d")) {
00098 if (argc == 1)
00099 debugArgs = "+";
00100 else {
00101 debugArgs = *(argv + 1);
00102 argCount = 2;
00103 }
00104 } else if (!strcmp(*argv, "-rs")) {
00105 ASSERT(argc > 1);
00106 RandomInit(atoi(*(argv + 1)));
00107
00108 randomYield = TRUE;
00109 argCount = 2;
00110 }
00111 #ifdef USER_PROGRAM
00112 if (!strcmp(*argv, "-s"))
00113 debugUserProg = TRUE;
00114 #endif
00115 #ifdef FILESYS_NEEDED
00116 if (!strcmp(*argv, "-f"))
00117 format = TRUE;
00118 #endif
00119 #ifdef NETWORK
00120 if (!strcmp(*argv, "-l")) {
00121 ASSERT(argc > 1);
00122 rely = atof(*(argv + 1));
00123 argCount = 2;
00124 } else if (!strcmp(*argv, "-m")) {
00125 ASSERT(argc > 1);
00126 netname = atoi(*(argv + 1));
00127 argCount = 2;
00128 }
00129 #endif
00130 }
00131
00132 DebugInit(debugArgs);
00133 stats = new Statistics();
00134 interrupt = new Interrupt;
00135 scheduler = new Scheduler();
00136 if (randomYield)
00137 timer = new Timer(TimerInterruptHandler, 0, randomYield);
00138
00139 threadToBeDestroyed = NULL;
00140
00141
00142
00143
00144 currentThread = new Thread("main");
00145 currentThread->setStatus(RUNNING);
00146
00147 interrupt->Enable();
00148 CallOnUserAbort(Cleanup);
00149
00150 #ifdef USER_PROGRAM
00151 machine = new Machine(debugUserProg);
00152 #endif
00153
00154 #ifdef FILESYS
00155 synchDisk = new SynchDisk("DISK");
00156 #endif
00157
00158 #ifdef FILESYS_NEEDED
00159 fileSystem = new FileSystem(format);
00160 #endif
00161
00162 #ifdef NETWORK
00163 postOffice = new PostOffice(netname, rely, 10);
00164 #endif
00165 }
00166
00167
00168
00169
00170
00171 void
00172 Cleanup()
00173 {
00174 printf("\nCleaning up...\n");
00175 #ifdef NETWORK
00176 delete postOffice;
00177 #endif
00178
00179 #ifdef USER_PROGRAM
00180 delete machine;
00181 #endif
00182
00183 #ifdef FILESYS_NEEDED
00184 delete fileSystem;
00185 #endif
00186
00187 #ifdef FILESYS
00188 delete synchDisk;
00189 #endif
00190
00191 delete timer;
00192 delete scheduler;
00193 delete interrupt;
00194
00195 Exit(0);
00196 }
00197
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