home *** CD-ROM | disk | FTP | other *** search
- // This may look like C code, but it is really -*- C++ -*-
- /*
- ************************************************************************
- *
- * UNT Virtual Machine
- *
- * "Booting up" the virtual machine
- *
- * This is the main module that boots up the virtual machine and lets
- * it run.
- * Parameters (specified in the command while calling the vm_unt)
- *
- * vm_unt [-card=card_file] [-lp=printer_file] [-harddisk=disk_file]
- * drum_file_name
- *
- * where drum_file_name specifies the file to be used for drum
- * operations.
- *
- * $Id: bootstrap.cc,v 5.0 1992/11/15 18:17:39 oleg Exp oleg $
- *
- ************************************************************************
- */
-
- #pragma implementation "hardware.h"
- #pragma implementation "computer.h"
- #pragma implementation "oper_system.h"
- #include "oper_system.h"
- #include "myenv.h"
- #include <std.h>
- #include <stdarg.h>
-
- /*
- *------------------------------------------------------------------------
- * Diagnostics
- */
-
- Semaphore DiagnosticPanel::printing_diagnostics("Diagnostics",1);
-
- DiagnosticPanel::DiagnosticPanel(void)
- {
- is_tracing = 1;
- }
-
- // Print the message only if tracing is on
- void DiagnosticPanel::single_message(const char * text,...)
- {
- if( !is_tracing )
- return;
- printing_diagnostics--;
- va_list args;
- va_start(args,text);
- fprintf(stderr,"\n");
- vfprintf(stderr,text,args);
- fprintf(stderr,"\n");
- printing_diagnostics++;
- }
-
- // Print a message on the operator console
- void DiagnosticPanel::console(const char * text,...)
- {
- printing_diagnostics--;
- va_list args;
- va_start(args,text);
- fprintf(stderr,"\n");
- vfprintf(stderr,text,args);
- fprintf(stderr,"\n");
- printing_diagnostics++;
- }
-
- void DiagnosticPanel::begin_printing(void)
- {
- printing_diagnostics--;
- }
-
- void DiagnosticPanel::end_printing(void)
- {
- printing_diagnostics++;
- }
-
-
- /*
- *------------------------------------------------------------------------
- * Root module of the VM UNT
- */
-
-
- // Print the help as how to use the program
- static volatile void help_usage(const char * error_message)
- {
- message("\n%s\n",error_message);
- message("\n\n\t\tRunning the UNT Virtual Machine\n");
- message("\nUsage");
- message("\n\tvm_unt [-card=card_file] [-lp=printer_file]");
- message("\n\t\t[-harddisk=disk_file] drum_file_name");
- message("\n\nwhere\n");
- message("\tfile names specify files to be used by the corresponding\n");
- message("\tVM_UNT \"devices\"\n");
- message("\n\nExample:");
- message("\n\tvm_unt test.dat\n\n");
- exit(4);
- }
-
- static char card_file_name[40];
- static char printer_file_name[40];
- static char hdisk_file_name[40];
-
- // Scan through the command parameters in
- // search for options.
- // Return the no. of options parsed
- static int parse_options(const int argc, char * argv[])
- {
- int noptions;
- for(noptions=0; noptions < argc-1; noptions++)
- {
- char * str = argv[1+noptions]; // argv[0] is a pgm name, skip
- if( *str++ != '-' ) // Option should begin with -
- break;
-
- char * p = strchr(str,'=');
- if( p == 0 )
- message("\nFailed to find '=' in option '%s'\n",str),
- help_usage("");
-
- if( strncmp(str,"card",p-str) == 0 )
- strncpy(card_file_name,p+1,sizeof(card_file_name)-1);
- else if( strncmp(str,"lp",p-str) == 0 )
- strncpy(printer_file_name,p+1,sizeof(printer_file_name)-1);
- else if( strncmp(str,"harddisk",p-str) == 0 )
- strncpy(hdisk_file_name,p+1,sizeof(hdisk_file_name)-1);
- else
- message("Unknown option - '%s'\n",str),
- help_usage("");
- }
- return noptions;
- }
-
-
- // This is a bootstrap
- main(const int argc, const char * argv[])
- {
- extern int _stackint;
- const int noptions = parse_options(argc,argv);
- if( argc != 1 + noptions + 1 )
- help_usage("One parameter (drum file name) has got to be specified");
-
- asm("movl %esp,__stackinit");
- static OperatingSystem VM_UNT;
- VM_UNT.memory.drum_open(argv[1+noptions]);
- if( card_file_name[0] != '\0' )
- VM_UNT.card_reader.associate_with_unix_file(card_file_name);
- if( printer_file_name[0] != '\0' )
- VM_UNT.line_printer.associate_with_unix_file(printer_file_name);
- if( hdisk_file_name[0] != '\0' )
- VM_UNT.hard_disk.associate_with_unix_file(hdisk_file_name);
- VM_UNT.cpu_manager.commence();
-
- VM_UNT.cpu_manager.wait_for_halt();
- message("\n\n\n>>>>>>>>>>>>>>>>>> Computer is halted "
- "<<<<<<<<<<<<<<<<<<<<<\n\n");
- }
-