cop 4600 project obj2 spring 2012

19
COP 4600 Project obj2 Spring 2012 Instructor: Dr. Euripides Montagne TA: Yuan Li

Upload: mahlah

Post on 13-Jan-2016

29 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: COP 4600 Project obj2 Spring 2012

COP 4600 Project obj2Spring 2012

Instructor:Dr. Euripides Montagne

TA:Yuan Li

Page 2: COP 4600 Project obj2 Spring 2012

University of Central Florida

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

Page 3: COP 4600 Project obj2 Spring 2012

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)

Page 4: COP 4600 Project obj2 Spring 2012

Step (1): Load the boot program from boot.dat

An example of boot.datDetailed

description

Page 5: COP 4600 Project obj2 Spring 2012

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

Page 6: COP 4600 Project obj2 Spring 2012

University of Central Florida

4, 0x01, 0

4, 0x02, 4

8, 0x03, 8

1, 0x04, 16

SIO 75

DISK 2000

SKIP 0

JUMP [2,0]

0

1

2

3

Mem_Map

SKIP 1

JUMP [3,0]

SKIP 0

JUMP [2,6]

SIO 400

PRNT 150

WIO 500

REQ [0,1]

WIO 0

REQ [2,1]

SKIP 0

END 20

JUMP [1,0]

Mem

01

23

4

56

7

8

910

1112

1314

15

16

Segment table

Memory

Memory Structure

#Inst, Acc, Base

Page 7: COP 4600 Project obj2 Spring 2012

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

Page 8: COP 4600 Project obj2 Spring 2012

Instruction Set

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……

⧫ SIO 75

⧫ DISK 2000

REQ [segment, offset]

− Always follows WIO

⧫ PRNT 150

⧫ WIO 0

⧫ REQ [2,1]

Page 9: COP 4600 Project obj2 Spring 2012

University of Central Florida

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

Page 10: COP 4600 Project obj2 Spring 2012

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)

……

Exec_Program( ….); // Simulate a cpu cycle (generate one event)

……

}

}

Page 11: COP 4600 Project obj2 Spring 2012

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

University of Central Florida

Description of functions

Next

Page 12: COP 4600 Project obj2 Spring 2012

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

Page 13: COP 4600 Project obj2 Spring 2012

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

Page 14: COP 4600 Project obj2 Spring 2012

University of Central Florida

Back

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

Page 15: COP 4600 Project obj2 Spring 2012

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

Page 16: COP 4600 Project obj2 Spring 2012

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

Page 17: COP 4600 Project obj2 Spring 2012

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

Page 18: COP 4600 Project obj2 Spring 2012

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

Page 19: COP 4600 Project obj2 Spring 2012

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

Compile, test and submit your code