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 / p8 / Main.c < prev    next >
Text File  |  2006-05-17  |  3KB  |  82 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 SerialDriver
  35.       serialDriver = new SerialDriver
  36.       serialDriver.Init ()
  37.  
  38.       -- Initialize the FileManager
  39.       fileManager = new FileManager
  40.       fileManager.Init ()
  41.  
  42.       -- Create a thread and start a user-level program running
  43.       InitFirstProcess ()
  44.  
  45.       -- The main thread has nothing more to do, but do not call ThreadFinish,
  46.       -- since that will result in adding the mainThread to the freeList.
  47.       -- Instead, cause this thread to sleep forever.
  48.       freeze.Init (0)
  49.       freeze.Wait ()
  50.       FatalError ("The main thread should never reach this point")
  51.  
  52.     endFunction
  53.  
  54. -----------------------------  AllocateRandomFrames  ---------------------------------
  55.  
  56.   function AllocateRandomFrames ()
  57.     --
  58.     -- This function allocates every other frame.  It does this by allocating
  59.     -- all frames and then releasing every other frame.  The purpose of this is
  60.     -- to make sure the kernel code can deal with data that straddles page
  61.     -- boundaries when the pages are not in contiguous frames.
  62.     --
  63.     -- Students should call this routine immediately after initializing the
  64.     -- FrameManager.
  65.     --
  66.       var i: int
  67.           a: array [NUMBER_OF_PHYSICAL_PAGE_FRAMES] of AddrSpace
  68.       printIntVar ("AllocateRandomFrames called.  NUMBER_OF_PHYSICAL_PAGE_FRAMES",
  69.                     NUMBER_OF_PHYSICAL_PAGE_FRAMES)
  70.       a = new array of AddrSpace {NUMBER_OF_PHYSICAL_PAGE_FRAMES of new AddrSpace}
  71.       for i = 0 to NUMBER_OF_PHYSICAL_PAGE_FRAMES-1
  72.         a[i].Init ()
  73.         frameManager.GetNewFrames (& a[i], 1)
  74.       endFor
  75.       for i = 0 to NUMBER_OF_PHYSICAL_PAGE_FRAMES-1 by 2
  76.         frameManager.ReturnAllFrames (& a[i] )
  77.       endFor
  78.  
  79.     endFunction
  80.  
  81. endCode
  82.