



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Project Specification – Phase 1 CS 3243/5243 – Operating Systems The semester course project is on the design and implementation of an OS simulator. The simulator will run on a virtual CPU, which is to be implemented as a part of the project. The CPU’s architecture and instruction repertoire are posted at the course website. In this phase, we shall assume a simple batched system that first executes one user task/process; and then, modified slightly to schedule and execute two processes at a time. The memory hierarchy comprises a set of simulated registers , a program/data simulated RAM, called memory and a simulated hard drive called disk. The contents of the disk and RAM are hex characters; and of sizes 2048 and 1024 words, respectively. (Each word is 4 bytes or 8 hex characters long.) The following sections describe the components of the simulator and its virtual machine environments. You are to design and develop software architecture (objects, object classes, methods, etc.) for your simulator and implement each component to complete Phase 1. You are to write a loader module, which does the loading of the programs into your disk. Programs are loaded into disk according to the format of the batched programs in the program-file. You will need to write ancillary programs to process (strip off) the special program “cards” – which start as, e.g., ‘// Job 17 2 ’, while storing the hex-code and the data sections, which start with, e.g., ‘// Data B C C’. // Job1 17 2 means program 1 is of size 17(hex) or (23 in decimal ) words with the priority set to 2. Data segment of the program starts with // Data B C C which means the number of inputs in the input buffer in B(11 in hex), size of output buffer is 12(C in hex) words and size of temporary buffer is 12(in hex) words. Ancillary programs to dispatch processes/programs from disk to RAM, to compute effective addresses, to access memory, to fetch instructions and decode instructions will also be needed. Additional support programs for conversions between hex, decimal, and binary numbers will be necessary. The Driver: The OS driver constitutes the core, or the main thread, of the simulator. Its function is to simply call the loader to load user programs, which are already assembled (given as a stream of hex character) and call the CPU to execute the programs in RAM. When a program completes, or an interrupt is received, the Driver dispatches the next program, or responds to interrupts accordingly. This cycle continues forever or until your simulator is shut down when no more user programs are pending.. The following program sketch should help you design and implement the Driver module for a single batched system: Driver { loader(); loop scheduler(); dispatcher(); CPU(); waitforinterrupt(); endloop; }
The Loader The Loader method opens (once at the start) the program-file and loads the hex-code into disk. The control cards in the program-file contain directives – attribute data about each program, which must be extracted and stored in the program’s profile/history in the Process Control Block (PCB) (see below). The basic steps of the loader are: while not end-of-programdata-file do { Read-File(); Insert hex-code into disk[disk-base-reg + j-th index]; } The Scheduler The Scheduler loads programs from the disk into RAM. The scheduler must note in the PCB, which physical addresses in RAM each program/process begins. This ‘start’ address must be stored in the base-register of the process. It must also use the Input/Output buffer size information (in the control cards) about the space allocation in RAM. The Scheduler method either loads one program at a time (in a simple batching system) or multiple programs (in a multiprogramming system) depending on passed parameter(s). Thus, the Scheduler works closely with the Memory manager and the Effective-Address method. The basic steps of the scheduler are: b := 0; for (j=0; j < N; j++) { // N is the number of programs to load to fit memory k := 0; // k controls the number of lines of hex-chars of program while not end-of-program do // each line has 4 instructions (or words) or 32 hex characters (16 bytes) if (size[j] – 32k >= 32) { // you may change this logic to suit your purpose for(i=0; i<32; i++) { memory[b+memory-base-reg + i + 32k] := disk[b+disk-base-reg + i + 32k]; //base-reg points to 1st^ byte b := i + 32k; } } // end of if==true else { for (t=0; t < size-32k; t++) { memory[b+memory-base-reg + t + 32k] := disk[disk-base-reg + t+ 32k]; b := t + 32k; } } // end of else k++; end do; } Memory This method is the only means/unit by which RAM can be accessed. A known absolute/physical address must always be passed to this method. The Memory simply fetches an instruction or datum or writes datum into RAM. Effective-Address This method takes a logical address and returns the corresponding absolute/physical address for the calling unit (e.g., the CPU). The Effective-Address method also supports the Fetch and Decode methods – a part of the CPU, during instruction fetch-decode-execute cycle. The Effective-Address supports two kinds of address translations – direct and indirect using the index register.
loop switch(type) { case 0: Read(ch, next(p_rec), buf[next_io]); case 1: Write(ch, next(p_rec), buf[next_io]); } signal(ComputeOnly) // signal the main CPU to use the channel/bus next_io := next_io + 4; // assuming 1 word of 4 bytes at a time end; //loop ComputeOnly This method implements a simple instruction cycle algorithm with dynamic relocation of the program (via the base-register technique). loop w : = Fetch(memory[map(PC)]);// fetch instruction at RAM address – mapped PC Decode(w, oc, addrptr); // part of decoding of the instruction in w PC := PC + 1; // getting ready for next instruction Execute(oc) { case 0: // corresponding code using addrptr of operands case 1: // corresponding code or send interrupt … } end; // loop The CPU is supported by a PCB, which may have the following (suggested) structure: typedef struct PCB { id: struct state: // record of environment that is saved on interrupt // including the pc, registers, permissions, buffers, caches, active // pages/blocks code-size; struct registers: // accumulators, index, general struct sched: // burst-time, priority, queue-type, time-slice, remain-time struct accounts: // cpu-time, time-limit, time-delays, start/end times, io-times struct memories: // page-table-base, pages, page-size // base-registers – logical/physical map, limit-reg struct progeny: // child-procid, child-code-pointers parent: ptr; // pointer to parent (if this process is spawned, else ‘null’) struct resources: // file-pointers, io-devices – unitclass, unit#, open-file-tables status; // {running, ready, blocked, new} status_info: // pointer to ‘ready-list of active processes’ or // ‘resource-list on blocked processes’ priority: integer; // of the process processor: integer; // in case there are multiple CPUs } Queues and other code Need – queues (new, ready, block-on-io, suspend) Need – conversion routines or use built-in calls (C,C++,Java) between hex, decimal, binary types. WHAT IS TO BE DONE:
In Phase 1, you are to simply implement the OS simulator and get all of its component object/modules working correctly for a) a single process and b) the case of 2 processes at a time. Record timing information – cpu, io delays, total runtime; and memory usage. In Phase 2, you will modify the simulator to implement newer OS concepts to be discussed in class. Turn in a 3-4 page of summary report, along with data tables and graphs (if any) and the code (on a disk). Compute the averages for cpu-time, average IO delays, average run-time and average memory usage. show these in a table.