1 / 21

OSSIM – Objective 2

OSSIM – Objective 2. Overview Develop functions which initialize the memory and memory management data structures of the simulator simulate the basic functions of the CPU, as well as provide more simulation output. Boot :

tyrell
Download Presentation

OSSIM – Objective 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OSSIM – Objective 2 • Overview • Develop functions which initialize the memory and memory management data structures of the simulator • simulate the basic functions of the CPU, as well as provide more simulation output. • Boot: • The simulator will initally call your Boot() function that will load programs from boot.dat that are stored in the format described in intro.doc. • Boot() will also initialize the data structures responsible for managing the simulated memory and will call Get_Instr() repeatedly to read instructions from boot.dat and will store them in the simulated memory. • Finally, Boot() will call Display_pgm() for each program in boot.dat to output it to simout.

  2. OSSIM – Objective 2 • Overview • After Boot() has completed XPGM() will be called which simulates a context switch and then calls Cpu(). • Cpu() sets the memory address register (MAR) to the value passed to it by XPGM(), this will be 0 initially. • Cpu() then calls Fetch() to get the next instruction to execute from memory. • Fetch() calls Mu() to determine the physical location in memory of the requested instruction and uses the result to return the instruction to Cpu(). • Cpu() then handles the instruction accordingly depending on the operation. This entire cycle then repeats until there are no more simulation events.

  3. OSSIM - Objective 2 • Call Tree of function you write: • Program: • Boot() • Get_Instr() • Display_pgm() • XPGM() • Cpu() • Fetch() • Mu()

  4. OSSIM – Objective 2 • Important Variables • MEMMAP • A pointer to 2* MAXSEGMENTS of type struct segment_type • User memory • MEMMAP[0] ... MEMMAP[MAXSEGMENTS - 1] • Kernel Memory • MEMMAP[MAXSEGMENTS] ... MEMMAP[2 * MAXSEGMENTS - 1] • Each segment_type • segment length in instructions (seglen) • the base address (membase) in memory where the segment begins.

  5. freemem OSSIM – Objective 2 • Important Variables • MEM • A pointer to MEMSIZE array of data types of type struct instr_type (defined in osdefs.h). • FreeMem segsize = 5 segptr *next

  6. OSSIM - Objective 2 • Global Variables: Declared in extern.h: • extern FILE …*PROGM_FILE[]; • extern struct addr_type MAR; /* Memory Address Register */ • extern struct simtime CLOCK; /* System Hardware Clock */ addr_type int segment unsigned int offset simtime unsigned long seconds unsigned long nanosec

  7. cpu_type pcb_list This pcb is not in the ready queue. It is the active pcb! unsigned long rate unsigned long CPU_burst unsigned char mode struct address_type pc struct pcb_type *actvpcb struct simtime busy struct simtime qwait struct simtime response struct simtime idle int served int maxq int qlen double utilize struct pcb_list *ready struct pcb_list *tail struct pcb_type *pcb struct pcb_list *next struct pcb_list *prev pcb_type pcb_type pcb_type pcb_list pcb_list pcb_list OSSIM - Objective 2 Global Variables: Declared in externs.h: extern struct cpu_type CPU; /* Central Processor */

  8. OSSIM – Objective 2 • void Boot(void) • This function is called from simulator.c and reads from boot.dat and initializes the memory and memory management data structures. • The programs from boot.dat represent the OS and are loaded into the upper half of MEMMAP.

  9. freemem OSSIM – Objective 2 • Directions: • Read the file boot.dat whose file pointer is PROGM_FILE[BOOT] and whose format is given in intro.doc. You will have to check for PROGRAM on the first line and read in the number of programs in the file. • For each program: • Read in each segment and store the access bits and number of instructions. • With the program and segment data initialize MEMMAP starting at segment MAXSEGMENTS. The size of MEMMAP is 2 * MAXSEGMENTS. The first half is reserved for user memory, while the upper half is reserved for the OS. • Call Get_Instr() repeatedly to read instructions from boot.dat and update TotalFree and FreeMem based on the number of instructions read from boot.dat. • Call Display_pgm() to display each program. MEMMAP: array of segment_type unsigned char accbits unsigned int seglen unsigned long membase segsize = 5 segptr *next

  10. OSSIM – Objective 2 • void Get_Instr(int pgmid, struct instr_type *instr) • This function reads the next instruction from file (fp) into instr. • The external file (fp) is PROGM_FILE[pgmid]. • The format of the file is a series of statements of the form: OPCODE x y z where the form and type of the operands (x,y,z) depend on OPCODE. • Each instruction starts on a new line. There is more information in intro.doc on the format of boot.dat.

  11. OSSIM – Objective 2 • Directions: • Read the instructions from boot.dat (PROGM_FILE[BOOT]). • Convert the instruction to its opcode by using the lookup table opidtab which is defined in simulator.c if the instruction is not a device. • If it is a device look up its opcode in the devid field of the devtable. • After determining the opcode set the operand as described in intro.doc. • Each instruction has a field for the opcode and operand. • The operand field is a C union and depending on the opcode, only certain fields will be used in the operand. • The address field is used for REQ and JUMP instructions • The count field is used for SKIP instructions • The burst field is used for SIO, WIO, and END instructions, and • The bytes field is used for device instructions.

  12. OSSIM – Objective 2 • Data structures • IREG: struct instr_type { unsigned char opcode; union opernd_type operand; }; • union opernd_type { struct addr_type address; unsigned int count; unsigned long burst; unsigned long bytes; };

  13. OSSIM – Objective 2 • void Cpu(void) • This function simulates the basic functions of a CPU. • It fetches instructions from memory and handles them accordingly. • Directions • In a loop: • SetMAR(&CPU.pc) • Fetch(&IREG); • If Fetch() returns negative, a FAULT has occurred. In this case, CPU() returns. Otherwise, continue.

  14. OSSIM – Objective 2 • Directions: • Decode IREG and execute the instruction:i.e. Look at IREG.opcode • SIO, WIO, and END instructions: compute the deltaT defined by the operand, add to CLOCK to get future event time, and add this new event to the event list, i.e get the appropriate event number, and call Add_event( &deltaT, event, agent_code) (See note 3). Increment CPU.pc.offset by 2 and return • FOR SKIP, evaluate the operand (i.e. look at IREG.operand.count). If the operand of IREG changes (i.e. count > 0), you must decrement IREG.operand.count and update MEM by a call to Write() with the modified IREG. Increment CPU.pc.offset by 2 if the next instruction is to be skipped (count > 0 ) and repeat from step (1). • Otherwise, Fetch() the JUMP instruction at CPU.pc.offset+1, i.e. increment CPU.pc.offset, call SetMAR(&CPU.pc), and then Fetch(). Execute the JUMP by placing its operand in CPU.pc and repeat from step (1). • NOTE 1: you will find the function Burst_time(deltaT, IREG.operand.burst) in SIMLATOR.C of use when converting from CPU cycles to simulation time. • 2: Add_time( &CLOCK, &deltaT) • 3: NOTE: For OBJECTIVE 2 you should use a special agent code (0) to identify the BOOT program. For all other OBJECTIVES the agent code should be: CPU.actvpcb->termnl+1. Ue this in Add_event()

  15. OSSIM – Objective 2 • void SetMar(struct addr_type *addr) • This function sets a global variable MAR representing the memory address register. • Directions: • Set the MAR with the value of (addr) and return. • This function must be called to define the logical MEM address of the next Fetch(),Read(), or Write() operation on memory. addr_type int segment unsigned int offset

  16. OSSIM – Objective 2 • int Fetch(struct instr_type *instr) • This function will try and fetch an instruction from memory and store it in instr. • Directions: • This function calls Mu(void) to validate and map the logical address in MAR to a physical address. Mu() will return a negative value if some kind of FAULT was generated. In this case, Fetch() returns -1. • If Mu() returns a non-negative value, say x, then Fetch sets *instr = MEM[x] and returns +1.

  17. OSSIM – Objective 2 • int Mu(void) • This function simulates the address translation hardware of the memory unit. • It uses the contents of MAR = [s(=segment), d(=offset)] as the logical address to be translated to a physical address, x. addr_type int segment unsigned int offset

  18. OSSIM – Objective 2 • Directions: • First compute the effective entry in MEMMAP. • Set SEG = s + CPU.mode*MAXSEGMENTS. • This forces the upper half of the MEMMAP to be used if CPU.mode == 1 (privileged mode) and the lower half if CPU.mode != 1 (user mode). • If MEMMAP[SEG].accbits == 0x00, then generate an SEGFAULT event at the current CLOCK time and add it to the event_list using Add_event(). return -1. • use Agent = CPU.actvpcb->termnl+1. (agent = 0 for objective 2) • If MEMMAP[SEG].seglen <= d, then generate an ADRFAULT event at the current CLOCK time and add it to the event_list. return -1. • use Agent = CPU.actvpcb->termnl+1. (agent = 0 for objective 2) • return x = MEMMAP[SEG].membase + d.

  19. OSSIM – Objective 2 • void XPGM(struct state_type *state) • This function simulates a privileged instruction (in this case, loading and starting your program) causing a context switch. • Directions: • switch placing a user program in execution. It does this by copying (state->mode) into CPU.mode and (state->pc) into CPU.pc. • After the state of the CPU has been redefined, the CPU resumes execution at CPU.pc -- this is implemented by simply calling the function, Cpu().

  20. OSSIM – Objective 2 • int Read(struct instr_type *instr) • This function is identical to Fetch() • Directions • This function calls Mu() to validate and map the logical address in MAR to a physical address. Mu() will return a negative value if some kind of FAULT was generated. In this case, Read() returns -1. • If Mu() returns a non-negative value, say x, then Read sets *instr = MEM[x] and returns +1. • int Write(struct instr_type *instr) • This function is similar to Fetch • Directions • This function calls Mu() to validate and map the logical address in MAR to a physical address. Mu() will return a negative value if some kind of FAULT was generated. In this case, Write() returns -1 • If Mu() returns a non-negative value, say x, then Write setsMEM[x] = *instr and returns +1.

  21. OSSIM – Objective 2 • void Display_pgm(struct segment_type *segtab, int numseg, struct pcb_type *pcb) • This function outputs a program to simout. • Use this function after every program load. • Use segtab, segment table * to locate each segment. Use the provided sample output in intro.doc as an example of the format of the dump and what information should be output. • Note: Be sure to print the process and program names as "BOOT" in Objective 2 since pcb will always be null. • That is, test whether pcb is null. If it is, output “BOOT” for the process and program names. segment_type unsigned char accbits unsigned int seglen unsigned long membase

More Related