Nachos源代码分析(一)
//
main.cc 
//   初始化操作系统内核
//
//   这部分代码一般是初始化各个数据结构,并且而启动一个用户程序来输出登陆提示信息
//   (具体命令行参数用法省略)
#define
#include
"copyright.h"
#undef
#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...
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
posted on 2007-10-31 22:24 Phinecos(洞庭散人) 阅读(3418) 评论(0) 收藏 举报
                    
                
                
            
        
浙公网安备 33010602011771号