Nachos源代码分析(一)

 

// main.cc

//   初始化操作系统内核

//

//   这部分代码一般是初始化各个数据结构,并且而启动一个用户程序来输出登陆提示信息

//   (具体命令行参数用法省略)

 

#define MAIN

#include "copyright.h"

#undef MAIN

 

#include "utility.h"

#include "system.h"

 

//引入文件中使用的外部函数

extern void ThreadTest(void), Copy(char *unixFile, char *nachosFile);

extern void Print(char *file), PerformanceTest(void);

extern void StartProcess(char *file), ConsoleTest(char *in, char *out);

extern void MailTest(int networkID);

 

//----------------------------------------------------------------------

// main

//   功能:启动操作系统内核

//  

//   1检查命令行参数

//   2初始化数据结构

//   3(可选) 调用测试方法

//----------------------------------------------------------------------

 

int main(int argc, char **argv)

{

    int argCount;                 // the number of arguments for a particular command

    DEBUG('t', "Entering main");

    (void) Initialize(argc, argv);//具体的初始化工作

   

#ifdef THREADS

    ThreadTest();//线程管理测试

#endif

 

    for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) {

      argCount = 1;

        if (!strcmp(*argv, "-z"))               // print copyright

            printf (copyright);

#ifdef USER_PROGRAM                          //用户程序运行测试

        if (!strcmp(*argv, "-x")) {           // run a user program

          ASSERT(argc > 1);

            StartProcess(*(argv + 1));

            argCount = 2;

        } else if (!strcmp(*argv, "-c")) {      // test the console

          if (argc == 1)

              ConsoleTest(NULL, NULL);

          else {

           ASSERT(argc > 2);

              ConsoleTest(*(argv + 1), *(argv + 2));

              argCount = 3;

          }

          interrupt->Halt();           // once we start the console, then

                            // Nachos will loop forever waiting

                            // for console input

      }

#endif // USER_PROGRAM

#ifdef FILESYS                         //文件管理测试

      if (!strcmp(*argv, "-cp")) {         // copy from UNIX to Nachos

          ASSERT(argc > 2);

          Copy(*(argv + 1), *(argv + 2));

          argCount = 3;

      } else if (!strcmp(*argv, "-p")) {  // print a Nachos file

          ASSERT(argc > 1);

          Print(*(argv + 1));

          argCount = 2;

      } else if (!strcmp(*argv, "-r")) {  // remove Nachos file

          ASSERT(argc > 1);

          fileSystem->Remove(*(argv + 1));

          argCount = 2;

      } else if (!strcmp(*argv, "-l")) {   // list Nachos directory

            fileSystem->List();

      } else if (!strcmp(*argv, "-D")) { // print entire filesystem

            fileSystem->Print();

      } else if (!strcmp(*argv, "-t")) {  // performance test

            PerformanceTest();

      }

#endif // FILESYS

#ifdef NETWORK                       //网络管理测试

        if (!strcmp(*argv, "-o")) {

          ASSERT(argc > 1);

            Delay(2);                       // delay for 2 seconds

                                  // to give the user time to

                                  // start up another nachos

            MailTest(atoi(*(argv + 1)));

            argCount = 2;

        }

#endif // NETWORK

    }

currentThread->Finish(); //main快结束了,切换到其他生成的线程,从而让main函数无法终止

    return(0);                // Not reached...

}

你可能感兴趣的:(Nachos源代码分析(一))