Upload
odysseus-marks
View
41
Download
0
Embed Size (px)
DESCRIPTION
Computer Organization. Stored Program Computers and Electronic Devices. Pattern. Jacquard Loom. Variable Program. Stored Program Device. Fixed Electronic Device. Assembly Language. ; Code for a = b + c load R3,b load R4,c add R3,R4 store R3,a - PowerPoint PPT Presentation
Citation preview
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-1
Copyright © 2004 Pearson Education, Inc.
Computer Organization
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-2
Copyright © 2004 Pearson Education, Inc.
Stored Program Computers and
Electronic Devices
Pattern
Fixed Electronic Device
Variable Program
Stored Program Device
Jacquard Loom
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-3
Copyright © 2004 Pearson Education, Inc.
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
; Code for d = a - 100 load R4,=100 subtract R3,R4 store R3,d
Assembly Language
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-4
Copyright © 2004 Pearson Education, Inc.
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
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-5
Copyright © 2004 Pearson Education, Inc.
The von Neumann Architecture
Control Unit(CU)
Central Processing Unit (CPU)
DeviceDevice
Address BusData Bus
Arithmetical Logical Unit(ALU)
Primary Memory Unit(Executable
Memory)
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-6
Copyright © 2004 Pearson Education, Inc.
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
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-7
Copyright © 2004 Pearson Education, Inc.
Control Unit
3046305030543058
Primary Memory
Fetch UnitFetch Unit
Decode UnitDecode Unit
Execute UnitExecute Unit
PC
IR
Control Unit
load R3,bload R4,cadd R3,R4store R3,a
10111001001100…110111001010000…010100111001100…010111010001100…1load R4, c
3050
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-8
Copyright © 2004 Pearson Education, Inc.
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.
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-9
Copyright © 2004 Pearson Education, Inc.
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
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-10
Copyright © 2004 Pearson Education, Inc.
The Device-Controller-Software Relationship
Application Program
Device ControllerDevice Controller
DeviceDevice
Sof
twar
e in
the
CP
U
Abstract I/O Machine
•Device manager•Program to manage device controller•Supervisor mode software
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-11
Copyright © 2004 Pearson Education, Inc.
Device Controller Interface
CommandCommand StatusStatusData 0Data 0
Data 1Data 1
Data n-1Data n-1LogicLogic
busy done Error code . . .. . .busy done 0 0 idle 0 1 finished 1 0 working 1 1 (undefined)
Busy/done bits used to signal event occurrences to software and software to device
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-12
Copyright © 2004 Pearson Education, Inc.
Performing a Write Operation
while(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
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-13
Copyright © 2004 Pearson Education, Inc.
CPU-I/O Overlap
CPUCPU
DeviceDevice
…
Rea
dy P
roce
sses
CPUCPU
DeviceDevice
…
Rea
dy P
roce
sses
I/O Operation
CPUCPU
DeviceDevice
…
Rea
dy P
roce
sses
Uses CPU
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-14
Copyright © 2004 Pearson Education, Inc.
Determining When I/O is Complete
CPUCPU
DeviceDevice DeviceDevice DeviceDevice
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
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-15
Copyright © 2004 Pearson Education, Inc.
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
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-16
Copyright © 2004 Pearson Education, Inc.
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();}
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-17
Copyright © 2004 Pearson Education, Inc.
A Race Condition
saveProcessorState() { 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]};
What happens if a second interrupt comes in the middle of the first?
Block other interrupt while processing first
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-18
Copyright © 2004 Pearson Education, Inc.
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”
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-19
Copyright © 2004 Pearson Education, Inc.
Direct Memory Access
PrimaryMemory
CPU
Controller
Device
PrimaryMemory
CPU
Controller
Device
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-20
Copyright © 2004 Pearson Education, Inc.
Addressing Devices
PrimaryMemory
Device 0
Device 1
Device n-1
PrimaryMemory
Device 0
Device 1
Device n-1
Dev
ice
Add
ress
esM
emor
y A
ddre
sses
Mem
ory
Add
ress
es
copy-in R3, 0x012, 4 Load R3, 0xFFFF0124
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-21
Copyright © 2004 Pearson Education, Inc.
Polling I/O…// Start the device…While((busy == 1) || (done == 1)) wait();// Device I/O complete…done = 0;
…while((busy == 0) && (done == 1)) wait();// Do the I/O operationbusy = 1;…
busy done
Sof
twar
eH
ard
war
e
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-22
Copyright © 2004 Pearson Education, Inc.
Fetch-Execute Cycle with an Interrupt
while (haltFlag not set during execution) { IR = memory[PC]; PC = PC + 1; execute(IR); if (InterruptRequest) { /* Interrupt the current process */ /* Save the current PC in address 0 */ memory[0] = PC; /* Branch indirect through address 1 */ PC = memory[1]; }}
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-23
Copyright © 2004 Pearson Education, Inc.
Detecting an Interrupt
CPUCPU
DeviceDevice DeviceDevice DeviceDevice
InterruptRequest flag
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-24
Copyright © 2004 Pearson Education, Inc.
The Interrupt Handler
Interrupt_Handler{ saveProcessorState(); for (i=0; i<Number_of_devices; i++) if (device[i].done == 1) goto device_handler(i); /* Something wrong if we get here */}
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-25
Copyright © 2004 Pearson Education, Inc.
Disabling Interrupts
if(InterruptRequest && InterruptEnabled) {/* Interrupt current process */ disableInterrupts(); memory[0] = PC; PC = memory[1];}
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-26
Copyright © 2004 Pearson Education, Inc.
The Trap Instruction Operation
SMode
TrustedCode
trap
User Supervisor
Branch Table
2
3
1
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-27
Copyright © 2004 Pearson Education, Inc.
Intel System Initialization
ROM
CMOS
RAM
Boot DevicePOSTPOST
BIOSBIOS
Boot ProgBoot Prog
LoaderLoader
OSOS
…Hardware Process
Data Flow
Power Up
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-28
Copyright © 2004 Pearson Education, Inc.
Bootstrapping
Bootstrap loader (“boot sector”)
Primary Memory
1
0x0001000
Fetch UnitFetch Unit
Decode UnitDecode Unit
Execute UnitExecute Unit
00001000000100
……
PC
IR
BIOS loader 0x0000100
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-29
Copyright © 2004 Pearson Education, Inc.
BootstrappingBootstrap loader (“boot sector”)
Primary Memory
Loader
1
2
Fetch UnitFetch Unit
Decode UnitDecode Unit
Execute UnitExecute Unit
00010000001000
……
PC
IR
BIOS loader 0x00001000x0001000
0x0008000
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-30
Copyright © 2004 Pearson Education, Inc.
BootstrappingBootstrap loader (“boot sector”)
Primary Memory
Loader
OS
12
3Fetch UnitFetch Unit
Decode UnitDecode Unit
Execute UnitExecute Unit
00080000008000
……
PC
IR
BIOS loader 0x00001000x0001000
0x0008000
0x000A000
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-31
Copyright © 2004 Pearson Education, Inc.
Bootstrapping
Bootstrap loader (“boot sector”)
Primary Memory
Loader
OS
12
3
4. Initialize hardware5. Create user environment6. …
Fetch UnitFetch Unit
Decode UnitDecode Unit
Execute UnitExecute Unit
000A000000A000
……
PC
IR
BIOS loader 0x00001000x0001000
0x0008000
0x000A000
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-32
Copyright © 2004 Pearson Education, Inc.
A Bootstrap Loader Program
FIXED_LOC: // Bootstrap loader entry pointload R1, =0load R2, =LENGTH_OF_TARGET
// The next instruction is really more like // a procedure call than a machine instruction// It copies a block from FIXED_DISK_ADDRESS// to BUFFER_ADDRESS
read BOOT_DISK, BUFFER_ADDRESSloop: load R3, [BUFFER_ADDRESS, R1]
store R3, [FIXED_DEST, R1]incr R1bleq R1, R2, loopbr FIXED_DEST
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-33
Copyright © 2004 Pearson Education, Inc.
A Pipelined Function Unit
Function UnitOperand 1Operand 2
Result
Operand 1Operand 2
Result
(a) Monolithic Unit
(b) Pipelined Unit
Operating Systems: A Modern Perspective, Chapter 4
Slide 4-34
Copyright © 2004 Pearson Education, Inc.
A SIMD MachineALU
ControlUnit
ALUControl
Unit
ALU
ALU
ALU
…
(a) Conventional Architecture
(b) SIMD Architecture