home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume44 / toy_os / part03 / bootstrap.cc next >
Encoding:
C/C++ Source or Header  |  1994-09-05  |  4.3 KB  |  161 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /*
  3.  ************************************************************************
  4.  *
  5.  *               UNT Virtual Machine
  6.  *
  7.  *           "Booting up" the virtual machine
  8.  *
  9.  * This is the main module that boots up the virtual machine and lets
  10.  * it run.
  11.  * Parameters (specified in the command while calling the vm_unt)
  12.  *
  13.  *    vm_unt [-card=card_file] [-lp=printer_file] [-harddisk=disk_file]
  14.  *           drum_file_name
  15.  *
  16.  * where drum_file_name specifies the file to be used for drum
  17.  * operations.
  18.  *
  19.  * $Id: bootstrap.cc,v 5.0 1992/11/15 18:17:39 oleg Exp oleg $
  20.  *
  21.  ************************************************************************
  22.  */
  23.  
  24. #pragma implementation "hardware.h"
  25. #pragma implementation "computer.h"
  26. #pragma implementation "oper_system.h"
  27. #include "oper_system.h"
  28. #include "myenv.h"
  29. #include <std.h>
  30. #include <stdarg.h>
  31.  
  32. /*
  33.  *------------------------------------------------------------------------
  34.  *                Diagnostics
  35.  */
  36.  
  37. Semaphore DiagnosticPanel::printing_diagnostics("Diagnostics",1);
  38.  
  39. DiagnosticPanel::DiagnosticPanel(void)
  40. {
  41.   is_tracing = 1;
  42. }
  43.  
  44.                 // Print the message only if tracing is on
  45. void DiagnosticPanel::single_message(const char * text,...)
  46. {
  47.   if( !is_tracing )
  48.     return;
  49.   printing_diagnostics--;
  50.   va_list args;
  51.   va_start(args,text);
  52.   fprintf(stderr,"\n");
  53.   vfprintf(stderr,text,args);
  54.   fprintf(stderr,"\n");
  55.   printing_diagnostics++;
  56. }
  57.  
  58.                 // Print a message on the operator console
  59. void DiagnosticPanel::console(const char * text,...)
  60. {
  61.   printing_diagnostics--;
  62.   va_list args;
  63.   va_start(args,text);
  64.   fprintf(stderr,"\n");
  65.   vfprintf(stderr,text,args);
  66.   fprintf(stderr,"\n");
  67.   printing_diagnostics++;
  68. }
  69.  
  70. void DiagnosticPanel::begin_printing(void)
  71. {
  72.   printing_diagnostics--;
  73. }
  74.  
  75. void DiagnosticPanel::end_printing(void)
  76. {
  77.   printing_diagnostics++;
  78. }
  79.  
  80.  
  81. /*
  82.  *------------------------------------------------------------------------
  83.  *            Root module of the VM UNT
  84.  */
  85.  
  86.  
  87.                 // Print the help as how to use the program
  88. static volatile void help_usage(const char * error_message)
  89. {
  90.   message("\n%s\n",error_message);
  91.   message("\n\n\t\tRunning the UNT Virtual Machine\n");
  92.   message("\nUsage");
  93.   message("\n\tvm_unt [-card=card_file] [-lp=printer_file]");
  94.   message("\n\t\t[-harddisk=disk_file] drum_file_name");
  95.   message("\n\nwhere\n");
  96.   message("\tfile names specify files to be used by the corresponding\n");
  97.   message("\tVM_UNT \"devices\"\n");
  98.   message("\n\nExample:");
  99.   message("\n\tvm_unt test.dat\n\n");
  100.   exit(4);
  101. }
  102.  
  103. static char card_file_name[40];
  104. static char printer_file_name[40];
  105. static char hdisk_file_name[40];
  106.  
  107.                 // Scan through the command parameters in
  108.                 // search for options.
  109.                 // Return the no. of options parsed
  110. static int parse_options(const int argc, char * argv[])
  111. {
  112.   int noptions;
  113.   for(noptions=0; noptions < argc-1; noptions++)
  114.   {
  115.     char * str = argv[1+noptions];        // argv[0] is a pgm name, skip
  116.     if( *str++ != '-' )                // Option should begin with -
  117.       break;
  118.  
  119.     char * p = strchr(str,'=');
  120.     if( p == 0 )
  121.       message("\nFailed to find '=' in option '%s'\n",str),
  122.       help_usage("");
  123.  
  124.     if( strncmp(str,"card",p-str) == 0 )
  125.       strncpy(card_file_name,p+1,sizeof(card_file_name)-1);
  126.     else if( strncmp(str,"lp",p-str) == 0 )
  127.       strncpy(printer_file_name,p+1,sizeof(printer_file_name)-1);
  128.     else if( strncmp(str,"harddisk",p-str) == 0 )
  129.       strncpy(hdisk_file_name,p+1,sizeof(hdisk_file_name)-1);
  130.     else
  131.       message("Unknown option - '%s'\n",str),
  132.       help_usage("");
  133.   }
  134.   return noptions;
  135. }
  136.  
  137.  
  138.                 // This is a bootstrap
  139. main(const int argc, const char * argv[])
  140. {
  141.   extern int _stackint;
  142.   const int noptions = parse_options(argc,argv);
  143.   if( argc != 1 + noptions + 1 )
  144.     help_usage("One parameter (drum file name) has got to be specified");
  145.  
  146.   asm("movl %esp,__stackinit");
  147.   static OperatingSystem VM_UNT;
  148.   VM_UNT.memory.drum_open(argv[1+noptions]);
  149.   if( card_file_name[0] != '\0' )
  150.     VM_UNT.card_reader.associate_with_unix_file(card_file_name);
  151.   if( printer_file_name[0] != '\0' )
  152.     VM_UNT.line_printer.associate_with_unix_file(printer_file_name);
  153.   if( hdisk_file_name[0] != '\0' )
  154.     VM_UNT.hard_disk.associate_with_unix_file(hdisk_file_name);
  155.   VM_UNT.cpu_manager.commence();
  156.  
  157.   VM_UNT.cpu_manager.wait_for_halt();
  158.   message("\n\n\n>>>>>>>>>>>>>>>>>> Computer is halted "
  159.          "<<<<<<<<<<<<<<<<<<<<<\n\n");
  160. }
  161.