computer organization (review of prerequisite material)

22
Computer Organization (Review of Prerequisite Material)

Upload: denis-mcbride

Post on 18-Jan-2018

218 views

Category:

Documents


0 download

DESCRIPTION

Machine Language ; Code for a = b + c load R3,b load R4,c add R3,R4 store R3,a ; Code for d = a load R4,=100 subtract R3,R4 store R3,d Assembly Language … … … … … … …1 Machine Language

TRANSCRIPT

Page 1: Computer Organization (Review of Prerequisite Material)

Computer Organization(Review of Prerequisite Material)

Page 2: Computer Organization (Review of Prerequisite Material)

Program Specification

int a, b, c, d;. . .a = b + c;d = a - 100;

Source

; Code for a = b + c load R3,b load R4,c add R3,R4 store R3,a

Assembly Language

; Code for d = a - 100 load R4,=100 subtract R3,R4 store R3,d

Page 3: Computer Organization (Review of Prerequisite Material)

Machine Language

; Code for a = b + c load R3,b load R4,c add R3,R4 store R3,a

; Code for d = a - 100 load R4,=100 subtract R3,R4 store R3,d

Assembly Language

10111001001100…110111001010000…010100111001100…010111010001100…110111001010000…010100110001100…010111001101100…1

Machine Language

Page 4: Computer Organization (Review of Prerequisite Material)

von Neumann Computer

Arithmetic-Logical Unit(ALU) Control Unit

Primary Memory(Executable Memory)

Address

Data

Page 5: Computer Organization (Review of Prerequisite Material)

Primary Memory Unit

MAR

MDR

Command

012

n-1

1234 98765Read Op:

1234

1. Load MAR with address

read

2. Load Command with “read”

98765

3. Data will then appear in the MDR

Page 6: Computer Organization (Review of Prerequisite Material)

Control Unit

3046305030543058

Primary Memory

Fetch Unit

Decode Unit

Execute Unit

PC

IR

Control Unit

load R3,bload R4,cadd R3,R4store R3,a

10111001001100…110111001010000…010100111001100…010111010001100…1load R4, c

3050

Page 7: Computer Organization (Review of Prerequisite Material)

Control Unit Operation

PC = <machine start address>;IR = memory[PC];haltFlag = CLEAR;while(haltFlag not SET) { execute(IR); PC = PC + sizeof(INSTRUCT); IR = memory[PC]; // fetch phase};

• Fetch phase: Instruction retrieved from memory

• Execute phase: ALU op, memory data reference, I/O, etc.

Page 8: Computer Organization (Review of Prerequisite Material)

The ALU

R1R2

Rn

. . .

Status RegistersFunctional Unit

Left Operand

Right Operand

Result

To/from Primary Memory

load R3,bload R4,cadd R3,R4store R3,a

Page 9: Computer Organization (Review of Prerequisite Material)

BootstrappingBootstrap loader (“boot sector”)

Primary Memory

1

0x0001000

Fetch Unit

Decode Unit

Execute Unit

0000100

PC

IR

BIOS loader 0x0000100

Page 10: Computer Organization (Review of Prerequisite Material)

BootstrappingBootstrap loader (“boot sector”)

Primary Memory

Loader

1

2

Fetch Unit

Decode Unit

Execute Unit

0001000

PC

IR

BIOS loader 0x00001000x0001000

0x0008000

Page 11: Computer Organization (Review of Prerequisite Material)

BootstrappingBootstrap loader (“boot sector”)

Primary Memory

Loader

OS

12

3Fetch Unit

Decode Unit

Execute Unit

0008000

PC

IR

BIOS loader 0x00001000x0001000

0x0008000

0x000A000

Page 12: Computer Organization (Review of Prerequisite Material)

BootstrappingBootstrap loader (“boot sector”)

Primary Memory

Loader

OS

12

3

4. Initialize hardware5. Create user environment6. …

Fetch Unit

Decode Unit

Execute Unit

000A000

PC

IR

BIOS loader 0x00001000x0001000

0x0008000

0x000A000

Page 13: Computer Organization (Review of Prerequisite Material)

Address

Data

Von Neumann Computer

Arithmetic-Logical Unit(ALU) Control Unit

Primary Memory(Executable Memory)

DeviceDevice

Device

Page 14: Computer Organization (Review of Prerequisite Material)

Device OrganizationApplication Program

Device Controller

Device

Softw

are

in th

e C

PU

•Device manager•Program to manage device controller•Supervisor mode software

Abstract I/O Machine

Page 15: Computer Organization (Review of Prerequisite Material)

Device Controller Interface

Command Status Data 0

Data 1

Data n-1Logic

busy done Error code . . .. . .busy done 0 0 idle 0 1 finished 1 0 working 1 1 (undefined)

Page 16: Computer Organization (Review of Prerequisite Material)

Performing a Write Operationwhile(deviceNo.busy || deviceNo.done) <waiting>;deviceNo.data[0] = <value to write>deviceNo.command = WRITE;while(deviceNo.busy) <waiting>;deviceNo.done = TRUE;

• Devices much slower than CPU• CPU waits while device operates• Would like to multiplex CPU to a different

process while I/O is in process

Page 17: Computer Organization (Review of Prerequisite Material)

CPU-I/O Overlap

CPU

Device

Rea

dy P

roce

sses

CPU

Device

Rea

dy P

roce

sses

I/O Operation

CPU

Device

Rea

dy P

roce

sses

Uses CPU

Page 18: Computer Organization (Review of Prerequisite Material)

Determining When I/O is Complete

CPU

Device Device Device

Interrupt Pending

• CPU incorporates an “interrupt pending” flag• When device.busy FALSE, interrupt pending flag is set• Hardware “tells” OS that the interrupt occurred• Interrupt handler part of the OS makes process ready to run

Page 19: Computer Organization (Review of Prerequisite Material)

Control Unit with Interrupt (Hardware)

PC = <machine start address>;IR = memory[PC];haltFlag = CLEAR;while(haltFlag not SET) { execute(IR); PC = PC + sizeof(INSTRUCT); IR = memory[PC]; if(InterruptRequest) { memory[0] = PC; PC = memory[1]};

memory[1] contains the address of the interrupt handler

Page 20: Computer Organization (Review of Prerequisite Material)

Interrupt Handler (Software)interruptHandler() { saveProcessorState(); for(i=0; i<NumberOfDevices; i++) if(device[i].done) goto deviceHandler(i); /* something wrong if we get to here … */

deviceHandler(int i) { finishOperation(); returnToScheduler();}

Page 21: Computer Organization (Review of Prerequisite Material)

A Race ConditionsaveProcessorState() { for(i=0; i<NumberOfRegisters; i++) memory[K+i] = R[i]; for(i=0; i<NumberOfStatusRegisters; i++) memory[K+NumberOfRegisters+i] = StatusRegister[i];}

PC = <machine start address>;IR = memory[PC];haltFlag = CLEAR;while(haltFlag not SET) { execute(IR); PC = PC + sizeof(INSTRUCT); IR = memory[PC]; if(InterruptRequest && InterruptEnabled) { disableInterupts(); memory[0] = PC; PC = memory[1]};

Page 22: Computer Organization (Review of Prerequisite Material)

Revisiting the trap Instruction (Hardware)

executeTrap(argument) { setMode(supervisor); switch(argument) { case 1: PC = memory[1001]; // Trap handler 1 case 2: PC = memory[1002]; // Trap handler 2 . . . case n: PC = memory[1000+n];// Trap handler n};

• The trap instruction dispatches a trap handler routine atomically

• Trap handler performs desired processing

• “A trap is a software interrupt”