1 / 19

COP 4600 Project obj2 Spring 2012

COP 4600 Project obj2 Spring 2012. Instructor: Dr. Euripides Montagne TA: Yuan Li. Task: simulate booting the OS. Load and execute the boot program Input file: boot.dat (1) segment table info (2) instructions Procedures: (1) Load the boot program from boot.dat

mahlah
Download Presentation

COP 4600 Project obj2 Spring 2012

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. COP 4600 Project obj2Spring 2012 Instructor: Dr. Euripides Montagne TA: Yuan Li

  2. Task: simulate booting the OS • Load and execute the boot program • Input file: boot.dat • (1) segment table info • (2) instructions • Procedures: • (1) Load the boot program from boot.dat • (2) Save the segment table info and instructions to memory • (3) Interpret and execute instructions of the program • What you need to do: • Implement 11 functions described in obj2.c University of Central Florida

  3. Functions to implement • Functions include • void boot(); • void Get_Instr(int prog_id, struct instr_type* instruction); • void Cpu(); • void Exec_Program(struct state_type* state); • int Memory_Unit(); • void Set_MAR(struct addr_type* addr); • int Fetch(struct instr_type* instruction); • int Read(struct instr_type* instruction); • int Write(struct instr_type* instruction); • void Display_pgm(segment_type* seg_table, int seg_num, pcb_type* pcb)

  4. Step (1): Load the boot program from boot.dat Detailed description • An example of boot.dat

  5. Step (2): Initialize memory and save the boot data to memory • Save segment information to segment table (Mem_Map) • struct segment_type * Mem_Map • See osdef.h for prototype of struct segment_type • See externs.h for declaration of Mem_Map • See simulator.c for initilization of Mem_Map Save instructions to main memory (Mem) • Struct instr_type* Mem

  6. Memory Structure 0 SIO 75 1 DISK 2000 SKIP 0 2 #Inst, Acc, Base 3 JUMP [2,0] 4 SKIP 1 0 4, 0x01, 0 JUMP [3,0] 5 6 SKIP 0 1 4, 0x02, 4 JUMP [2,6] 7 2 8, 0x03, 8 8 SIO 400 3 1, 0x04, 16 PRNT 150 9 10 WIO 500 Mem_Map REQ [0,1] 11 12 WIO 0 REQ [2,1] 13 Segment table 14 SKIP 0 JUMP [1,0] 15 Memory END 20 16 Mem University of Central Florida

  7. Instruction Set • Instruction format: opcode oprand • opcode_type: SIO, WIO, END, Device, REQ, JUMP, SKIP • SIO n • CPU burst for n cycles and start IO • WIO n • CPU burst for n cycles and wait for IO • END n • CPU burst for n cycles and end program

  8. Instruction Set Instruction set • Device n • Always follows SIO • n is the bytes transferred (used to calculate time needed) • Device can be DISK, PRNT…… • SIO 75 • DISK 2000 • REQ [segment, offset] • Always follows WIO • PRNT 150 • WIO 0 • REQ [2,1] University of Central Florida

  9. Instruction Set • JUMP [seg, off] • Jump to memory [seg, off] • SKIP n • Skip the next instruction for n times • SKIP 1 • JUMP [3,0] • SIO 400 University of Central Florida

  10. Program Skeleton • In simulator.c • Main() • { • …… • Boot(); // Load boot.dat into memory, print out memory layout • …… • while( new_events != NULL ) { • …… • Interrupt(); // take out one event, print it out (consume one event) • …… • Exec_Program( ….); // Simulate a cpu cycle (generate one event) • …… • } • } University of Central Florida

  11. Description of functions • Boot() reads in the file boot.dat to load the kernel and initialize Mem_Map and Mem • Get_Instr() // Read one instruction from a program • Display_pgm() // Display memory layout • Exec_Program() simulates a context switch that places a user program in execution • CPU() // Simulate one CPU cycle Next University of Central Florida

  12. Function: Get_Instr() • viod Get_Instr( int prog_id, struct instr_type* instruction ) • Read an instruction from file Prog_Files[prog_id] • Load the instruction to struct instr_type* instruction • Process different types of instructions according to their specific format Back

  13. Function: Display_pgm() • void Display_pgm( segment_type* seg_table, int seg_num, pcb_type* pcb ) • Display a single segment to output file. • seg_table: the segment table • seg_num: the index of the segment within seg_table to display (seg_table[seg_num]) • pcb: process control block that the segment table belongs to • See intro.doc at eustis.eecs.ucf.edu for detailed format of output Back

  14. Function: CPU() • CPU() simulates the Central processing Unit • Fetches the next instruction from memory • Fetch() • Interprets the instruction • SIO, WIO, END, SKIP, JUMP • Creates a further event and insert it to the event queue if the instruction is • SIO, WIO, END Back University of Central Florida

  15. Functions used by CPU() • void Set_MAR(struct addr_type* addr ) • Set Memory Address Register (MAR) to the given address and prepare the next memory location for the next Fetch(), read() or Write() operation • MAR = [segment, offset], logic address • int Memory_Unit( ) • Simulate the Memory Management Unit (MMU) that translates the logic address in the Memory Address Register (MAR) to a real physical address. • Address = base of segment in Mem_Map + offset in MAR • int Fetch(struct instr_type* instruction) • Get the instruction from memory, Mem[Memory_Unit()] and save to struct instr_type* instruction Back

  16. Summary obj2 • The simulator (the main() function of simulator.c) calls Boot() to load programs from boot.dat • Boot() • first initializes the memory, • then call Get_Instr() repeatedly to read instructions from boot.dat, • and finally call Display_pgm() to print out the memory layout

  17. Summary of obj2 • After Boot() is done, the simulator calls Exec_Program() to simulate a context switch • Then Exec_Program() calls CPU() to simulate Central Processing Unit • CPU() calls Set_MAR() to set the memory address register (MAR) to the value of CPU.state.pc • CPU() calls Fetch() to the next instruction from memory

  18. Summary of obj2 • Fetch() • Calls Memory_Unit() to convert the logic address in MAR to real physical address • Then fetch the instruction in Mem[Memory_Unit()] • Finally, return to CPU() • CPU() then processes the instruction accordingly • The simulator terminates when all the events are done

  19. Compile, test and submit your code • Make copyfiles • You do not need to execute this command if your obj2.c already exists. • This command can copy *.h and *.c from Dr. Montagne's home folder to yours. • Be careful, if you have already modified any objx.c file, please back up your *.c files before you run this comment. Otherwise, your code will be lost. • Make data2files • Modify obj2.c • Reuse obj1.c, you may need to modify obj1.c • Make sim, then run “sim” • Make compare OBJ=2 • If error happens, manually check data2.out and ossim.out, see what is wrong • You should expect “Done. Looks OK to me...” • Make submit • You should see “If you dont get any error message,submit is successful.” University of Central Florida

More Related