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