190 likes | 321 Views
COP 4600 /EEL 4882 Project 2. Task. Read instruction file boot.dat, save in memory Interpret and run boot.dat. Input. boot.dat logon.dat (no change) This time, only one logon event is there Config.dat CPURATE How long one cpu cycle take in nanoseconds/instruction MEMSIZE MAXSEGMENTS.
E N D
Task • Read instruction file boot.dat, save in memory • Interpret and run boot.dat University of Central Florida
Input • boot.dat • logon.dat (no change) • This time, only one logon event is there • Config.dat • CPURATE • How long one cpu cycle take in nanoseconds/instruction • MEMSIZE • MAXSEGMENTS CPURATE=2000 Every CPU cycle takes 2000ns = 2ms “SIO 75” takes 150ms to run University of Central Florida
Boot.dat • Three parts • Program attribute • Segment attribute • Instructions • Project 2 • Only one program: boot Program 1 Segment 1 Segment 2 Program 2 Segment 1 Segment 2 Segment 3 Segment 4 Memory Layout University of Central Florida
Boot.dat Program has 4 segments segment table. Load into MEMMAP Segment length Segment access bit one segment Input file boot.dat University of Central Florida
Output • Memory layout (boot.dat) (30% of work) • Event generated when running boot (70% of work) University of Central Florida
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) …… XPGM( ….); // Simulate a cpu cycle (generate one event) …… } } University of Central Florida
Memory Structure • Array MEM is your memory From simulator.c struct instr_type* MEM MEM = calloc(MEMSIZE, sizeof(struct instr_type)); • Array MEMMAP is your segment table From simulator.c struct segment_type* MEMMAP MEMMAP = calloc(2*MAXSEGMENTS, sizeof(struct segment_type)); University of Central Florida
Memory Structure 0 SIO 75 1 DISK 2000 SKIP 0 2 3 JUMP [2,0] 4 SKIP 1 0 Boot.Seg1 JUMP [3,0] 5 6 SKIP 0 1 Boot.Seg2 JUMP [2,6] 7 2 Boot.Seg3 8 SIO 400 3 Boot.Seg4 PRNT 150 9 10 WIO 500 MEMMAP REQ [0,1] 11 12 WIO 0 REQ [2,1] 13 14 SKIP 0 JUMP [1,0] 15 END 20 16 MEM University of Central Florida
Instruction Set • SIO n • CPU burst for n cycles • Start IO • WIO n • CPU burst for n cycles • Wait IO (block) • END n • CPU burst for n cycles • End program University of Central Florida
Instruction Set • Device n • Always follows SIO • n is the bytes transferred (used to calculate time needed) • Device can be DISK, PRNT…… • Sample: SIO 75 DISK 2000 • REQ [seg, off] • Always follows WIO • [seg, off] refers to the device instruction waiting for • Sample: [2, 1] PRNT 150 …… WIO 0 REQ [2,1] University of Central Florida
Instruction Set • JUMP [seg, off] • Jump to [seg, off] • SKIP n • Skip the next instruction for n times • Sample SKIP 1 JUMP [3,0] SIO 400 University of Central Florida
Functions • Boot • Get_Instr // Read one instruction from boot.dat • Display_pgm // display memory layout • XPGM • CPU // One CPU cycle • Fetch // Read one instruction from memory • Util • Read • Write // Write one instruction to memory • Mu // convert [seg, off] to physical memory University of Central Florida
CPU • Every invocation of CPU() will execute one CPU burst instruction • SIO/WIO/END • SKIP • Skip or continue to next instruction • Jump • Jump to destination and continue • SIO • Skip the next instruction (device) • WIO • Skip the next instruction (req) University of Central Florida
Events • For every CPU invocation • Run one CPU burst, SIO/WIO/END • Generate one event of type “SIO/WIO/END” • Timestamp: the finish time of CPU burst [0,0] SIO 75 DISK 2000 SIO, 150ms [0,2] SKIP 0 JUMP [2,0] SIO 400 PRNT 150 SIO, 950ms 950ms = 150ms + 400(cpu burst)*2000ns = 950ms [2,0] Events CPU() invocations University of Central Florida
Events • Ignore device related operations in project 2 • Device instructions (disk, prnt) • Req instructions University of Central Florida
Develop process • Make copyfiles • 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
Segment Fault • You can use gdb to debug • gdb sim • (gdb)run • ……segment fault • (gdb)bt • Now you can see which line cause the error • More gdb command • b obj2.c:87 // stop at obj2.c, line 87 • next // run next instruction • p new_events // print out variable new_events • cont // continue to execute the program University of Central Florida
Deadline • Deadline is Feb 15 (Friday) midnight • Late assignments are accepted five days after the due date with a penalty of 20 % off. After five days, assignments will not be accepted. The grade for those assignments will be zero. University of Central Florida