home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.pdx.edu / 2014.02.ftp.ee.pdx.edu.tar / ftp.ee.pdx.edu / pub / users / Harry / Blitz / version-1-0 / OSProject / p6 / Main.c < prev    next >
Text File  |  2006-05-10  |  2KB  |  78 lines

  1. code Main
  2.  
  3. -----------------------------  Main  ---------------------------------
  4.  
  5.   function main ()
  6.     --
  7.     -- This function initializes the OS kernel and then starts up the
  8.     -- initial user-level program.
  9.     --
  10.       var freeze: Semaphore = new Semaphore
  11.  
  12.       -- Initialize the Thread Scheduler
  13.       InitializeScheduler ()
  14.  
  15.       -- Initialize the ProcessManager
  16.       processManager = new ProcessManager
  17.       processManager.Init ()
  18.  
  19.       -- Initialize the ThreadManager
  20.       threadManager = new ThreadManager
  21.       threadManager.Init ()
  22.  
  23.       -- Initialize the FrameManager
  24.       frameManager = new FrameManager
  25.       frameManager.Init ()
  26.  
  27.       -- Call this function to more completely exercise the kernel code
  28.       AllocateRandomFrames ()
  29.  
  30.       -- Initialize the DiskDriver
  31.       diskDriver = new DiskDriver
  32.       diskDriver.Init ()
  33.  
  34.       -- Initialize the FileManager
  35.       fileManager = new FileManager
  36.       fileManager.Init ()
  37.  
  38.       -- Create a thread and start a user-level program running
  39.       InitFirstProcess ()
  40.  
  41.       -- The main thread has nothing more to do, but do not call ThreadFinish,
  42.       -- since that will result in adding the mainThread to the freeList.
  43.       -- Instead, cause this thread to sleep forever.
  44.       freeze.Init (0)
  45.       freeze.Wait ()
  46.       FatalError ("The main thread should never reach this point")
  47.  
  48.     endFunction
  49.  
  50. -----------------------------  AllocateRandomFrames  ---------------------------------
  51.  
  52.   function AllocateRandomFrames ()
  53.     --
  54.     -- This function allocates every other frame.  It does this by allocating
  55.     -- all frames and then releasing every other frame.  The purpose of this is
  56.     -- to make sure the kernel code can deal with data that straddles page
  57.     -- boundaries when the pages are not in contiguous frames.
  58.     --
  59.     -- Students should call this routine immediately after initializing the
  60.     -- FrameManager.
  61.     --
  62.       var i: int
  63.           a: array [NUMBER_OF_PHYSICAL_PAGE_FRAMES] of AddrSpace
  64.       printIntVar ("AllocateRandomFrames called.  NUMBER_OF_PHYSICAL_PAGE_FRAMES",
  65.                     NUMBER_OF_PHYSICAL_PAGE_FRAMES)
  66.       a = new array of AddrSpace {NUMBER_OF_PHYSICAL_PAGE_FRAMES of new AddrSpace}
  67.       for i = 0 to NUMBER_OF_PHYSICAL_PAGE_FRAMES-1
  68.         a[i].Init ()
  69.         frameManager.GetNewFrames (& a[i], 1)
  70.       endFor
  71.       for i = 0 to NUMBER_OF_PHYSICAL_PAGE_FRAMES-1 by 2
  72.         frameManager.ReturnAllFrames (& a[i] )
  73.       endFor
  74.  
  75.     endFunction
  76.  
  77. endCode
  78.