#include "copyright.h"#include "utility.h"#include "system.h"Go to the source code of this file.
Defines | |
| #define | MAIN |
Functions | |
| void | ThreadTest (void) |
| void | Copy (char *unixFile, char *nachosFile) |
| void | Print (char *file) |
| void | PerformanceTest (void) |
| void | StartProcess (char *file) |
| void | ConsoleTest (char *in, char *out) |
| void | MailTest (int networkID) |
| int | main (int argc, char **argv) |
|
|
|
|
||||||||||||
|
Definition at line 69 of file progtest.cc.
00070 {
00071 char ch;
00072
00073 console = new Console(in, out, ReadAvail, WriteDone, 0);
00074 readAvail = new Semaphore("read avail", 0);
00075 writeDone = new Semaphore("write done", 0);
00076
00077 for (;;) {
00078 readAvail->P(); // wait for character to arrive
00079 ch = console->GetChar();
00080 console->PutChar(ch); // echo it!
00081 writeDone->P() ; // wait for write to finish
00082 if (ch == 'q') return; // if q, quit
00083 }
00084 }
|
|
||||||||||||
|
Definition at line 32 of file fstest.cc. Referenced by main.
00033 {
00034 FILE *fp;
00035 OpenFile* openFile;
00036 int amountRead, fileLength;
00037 char *buffer;
00038
00039 // Open UNIX file
00040 if ((fp = fopen(from, "r")) == NULL) {
00041 printf("Copy: couldn't open input file %s\n", from);
00042 return;
00043 }
00044
00045 // Figure out length of UNIX file
00046 fseek(fp, 0, 2);
00047 fileLength = ftell(fp);
00048 fseek(fp, 0, 0);
00049
00050 // Create a Nachos file of the same length
00051 DEBUG('f', "Copying file %s, size %d, to file %s\n", from, fileLength, to);
00052 if (!fileSystem->Create(to, fileLength)) { // Create Nachos file
00053 printf("Copy: couldn't create output file %s\n", to);
00054 fclose(fp);
00055 return;
00056 }
00057
00058 openFile = fileSystem->Open(to);
00059 ASSERT(openFile != NULL);
00060
00061 // Copy the data in TransferSize chunks
00062 buffer = new char[TransferSize];
00063 while ((amountRead = fread(buffer, sizeof(char), TransferSize, fp)) > 0)
00064 openFile->Write(buffer, amountRead);
00065 delete [] buffer;
00066
00067 // Close the UNIX and the Nachos files
00068 delete openFile;
00069 fclose(fp);
00070 }
|
|
|
Definition at line 34 of file nettest.cc. Referenced by main.
00035 {
00036 PacketHeader outPktHdr, inPktHdr;
00037 MailHeader outMailHdr, inMailHdr;
00038 char *data = "Hello there!";
00039 char *ack = "Got it!";
00040 char buffer[MaxMailSize];
00041
00042 // construct packet, mail header for original message
00043 // To: destination machine, mailbox 0
00044 // From: our machine, reply to: mailbox 1
00045 outPktHdr.to = farAddr;
00046 outMailHdr.to = 0;
00047 outMailHdr.from = 1;
00048 outMailHdr.length = strlen(data) + 1;
00049
00050 // Send the first message
00051 postOffice->Send(outPktHdr, outMailHdr, data);
00052
00053 // Wait for the first message from the other machine
00054 postOffice->Receive(0, &inPktHdr, &inMailHdr, buffer);
00055 printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
00056 fflush(stdout);
00057
00058 // Send acknowledgement to the other machine (using "reply to" mailbox
00059 // in the message that just arrived
00060 outPktHdr.to = inPktHdr.from;
00061 outMailHdr.to = inMailHdr.from;
00062 outMailHdr.length = strlen(ack) + 1;
00063 postOffice->Send(outPktHdr, outMailHdr, ack);
00064
00065 // Wait for the ack from the other machine to the first message we sent.
00066 postOffice->Receive(1, &inPktHdr, &inMailHdr, buffer);
00067 printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
00068 fflush(stdout);
00069
00070 // Then we're done!
00071 interrupt->Halt();
00072 }
|
|
||||||||||||
|
Definition at line 79 of file main.cc. References ASSERT, atoi, ConsoleTest, Copy, DEBUG, Delay, Initialize, MailTest, NULL, PerformanceTest, Print, StartProcess, and ThreadTest.
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 }
|
|
|
Definition at line 173 of file fstest.cc.
|
|
|
Referenced by main. |
|
|
Definition at line 24 of file progtest.cc.
00025 {
00026 OpenFile *executable = fileSystem->Open(filename);
00027 AddrSpace *space;
00028
00029 if (executable == NULL) {
00030 printf("Unable to open file %s\n", filename);
00031 return;
00032 }
00033 space = new AddrSpace(executable);
00034 currentThread->space = space;
00035
00036 delete executable; // close file
00037
00038 space->InitRegisters(); // set the initial register values
00039 space->RestoreState(); // load page table register
00040
00041 machine->Run(); // jump to the user progam
00042 ASSERT(FALSE); // machine->Run never returns;
00043 // the address space exits
00044 // by doing the syscall "exit"
00045 }
|
|
|
Definition at line 42 of file threadtest.cc. Referenced by main.
00043 {
00044 DEBUG('t', "Entering SimpleTest");
00045
00046 Thread *t = new Thread("forked thread");
00047
00048 t->Fork(SimpleThread, 1);
00049 SimpleThread(0);
00050 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002