/* * file: sos.c * This is the bare-bones Simple Operating System (SOS) * designed to run on the STM machine. */ #include #include #include #include "stm.h" /* PARSING for sos */ int parse_flags(int argc, char* argv[]) { int ibase = 0, idebug = 0, imax=0, ifilename=1; /* Positions of arguments in command line */ int i; for (i=1; i<9; i=i+2) { if (argv[i][0] == '-') switch (argv[i][1]) { case 'b': ibase = i+1; break; case 'd': idebug = i+1; break; case 'm': imax = i+1; break; } else { ifilename = i; break; } } if (ibase) base=atoi(argv[ibase]); if (idebug) debug=atoi(argv[idebug]); if (imax) maxinst=atoi(argv[imax]); return(ifilename); } /* Load the STML code into memory */ /* It is assumed that STML files are correctly formatted; therefore, this does no error checking */ /* NOTE: You are allowed to change this function for project 1; however, there is no need to do so. */ void load_stm(filename) char filename[]; { int count = base, /* Address */ inst; /* Instruction */ char line[240]; /* max length of line in STM file */ int i; FILE *fp; fp = fopen(filename, "r"); /* Open the STM file */ if (fp == NULL) { printf("File name error %s\n", filename); error = 1; } fgets(procname, NAMESIZE, fp); /* read process name */ procname[strlen(procname)-1] = '\0'; /* get rid of carriage return at end */ fgets(line,240,fp); /* read length of partition */ limit=atoi(line); if (debug == 2) { printf("Process %s index %i loading from base %i length %i\n", procname, procindex, base, limit); printf("Physical address / Virtual address / Instruction\n"); } while (!feof(fp)) { /* read code and load into memory */ fgets(line,240,fp); if (isdigit(line[0])) { sscanf(line, "%i", &mem[count]); count++; } } if (debug==2) for (i=base; i