Title: Computer Organization (Review of Prerequisite Material)
1Computer Organization(Review of Prerequisite
Material)
2Program Specification
Source
int a, b, c, d . . . a b c d a - 100
3Machine Language
Assembly 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
4von Neumann Computer
Arithmetic-Logical Unit (ALU)
Control Unit
Primary Memory (Executable Memory)
5Primary Memory Unit
0
MAR
1
2
MDR
Command
1234
98765
Read Op
n-1
6Control Unit
3046 3050 3054 3058
Primary Memory
7Control Unit Operation
- Fetch phase Instruction retrieved from memory
- Execute phase ALU op, memory data reference,
I/O, etc.
PC ltmachine start addressgt IR
memoryPC haltFlag CLEAR while(haltFlag not
SET) execute(IR) PC PC
sizeof(INSTRUCT) IR memoryPC // fetch
phase
8The ALU
load R3,b load R4,c add R3,R4 store R3,a
Right Operand
Left Operand
R1
R2
. . .
Rn
Functional Unit
Status Registers
Result
To/from Primary Memory
9Bootstrapping
Bootstrap loader (boot sector)
1
0x0001000
Primary Memory
10Bootstrapping
Bootstrap loader (boot sector)
1
0x0000100
2
BIOS loader
0x0001000
0x0008000
Loader
Primary Memory
11Bootstrapping
Bootstrap loader (boot sector)
1
0x0000100
2
BIOS loader
0x0001000
0x0008000
Loader
3
0x000A000
OS
Primary Memory
12Bootstrapping
Bootstrap loader (boot sector)
1
0x0000100
2
BIOS loader
0x0001000
0x0008000
Loader
Fetch Unit
3
000A000
PC
0x000A000
Decode Unit
OS
IR
Primary Memory
Execute Unit
4. Initialize hardware 5. Create user
environment 6.
13Von Neumann Computer
Arithmetic-Logical Unit (ALU)
Control Unit
Primary Memory (Executable Memory)
14Device Organization
Application Program
Software in the CPU
Device Controller
Device
15Device Controller Interface
busy
done
Error code
. . .
. . .
Command
Status
Data 0
Data 1
Logic
Data n-1
16Performing a Write Operation
while(deviceNo.busy deviceNo.done)
ltwaitinggt deviceNo.data0 ltvalue to
writegt deviceNo.command WRITE while(deviceNo.bu
sy) ltwaitinggt 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
17CPU-I/O Overlap
CPU
Device
18Determining When I/O is Complete
CPU
Interrupt Pending
Device
Device
Device
- 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
19Control Unit with Interrupt (Hardware)
PC ltmachine start addressgt IR
memoryPC haltFlag CLEAR while(haltFlag not
SET) execute(IR) PC PC
sizeof(INSTRUCT) IR memoryPC
if(InterruptRequest) memory0 PC
PC memory1
20Interrupt Handler (Software)
interruptHandler() saveProcessorState()
for(i0 iltNumberOfDevices i)
if(devicei.done) goto deviceHandler(i) /
something wrong if we get to here /
deviceHandler(int i) finishOperation()
returnToScheduler()
21A Race Condition
saveProcessorState() for(i0
iltNumberOfRegisters i) memoryKi
Ri for(i0 iltNumberOfStatusRegisters
i) memoryKNumberOfRegistersi
StatusRegisteri
PC ltmachine start addressgt IR
memoryPC haltFlag CLEAR while(haltFlag not
SET) execute(IR) PC PC
sizeof(INSTRUCT) IR memoryPC
if(InterruptRequest InterruptEnabled)
disableInterupts() memory0 PC
PC memory1
22Revisiting the trap Instruction (Hardware)
executeTrap(argument) setMode(supervisor)
switch(argument) case 1 PC
memory1001 // Trap handler 1 case 2 PC
memory1002 // Trap handler 2 . . .
case n PC memory1000n// Trap handler n
- The trap instruction dispatches a trap handler
routine atomically - Trap handler performs desired processing
- A trap is a software interrupt