Title: Outline
1Outline
- Computer Organization
- Computer architecture
- Central processing unit
- Instruction execution
- Devices
- Interrupts
Please pick up Homework 1 from the front desk if
you have not got a copy
2Review System Overview
3Stored Program Computers and Electronic Devices
Fixed Electronic Device
4Jacquard Loom
5von Neumann Architecture
6The von Neumann Architecture cont.
- A von Neumann architecture consists of
- A central processing unit made up of ALU and
control unit - A primary memory unit
- I/O devices
- Buses to interconnect the other components
7von Neumann Architecture cont.
- The crucial difference between computers and
other - electronic devices is the variable program
8Central Processing Unit
- Datapath
- ALU Arithmetic/Logic Unit
- Registers
- General-purpose registers
- Control registers
- Communication paths between them
- Control
- Controls the data flow and operations of ALU
9S1 bus
Dest bus
S2 bus
Control unit
ALU
A
R0, r1,... (registers)
C
B
ia(PC)
psw...
MAR
MDR
IR
MAR memory address register MDR memory data
register IR instruction register
Memory
10ALU Unit
11Memory Organization
12Instruction Execution
- Instruction fetch (IF)
- MAR ? PC IR ? MMAR
- Instruction Decode (ID)
- A ? Rs1 B ? Rs2 PC ? PC 4
- Execution (EXE)
- Depends on the instruction
- Memory Access (MEM)
- Depends on the instruction
- Write-back (WB)
13Arithmetic Instruction Example
- r3 ? r1 r2
- IF MAR ? PC IR ? MMAR
- ID A ? r1 B ? r2 PC ? PC 4
- EXE ALUoutput ? A B
- MEM
- WB r3 ? ALUoutput
14S1 bus
Dest bus
S2 bus
Control unit
ALU
A
R0, r1,... (registers)
C
B
ia(PC)
psw...
MAR
MDR
IR
MAR memory address register MDR memory data
register IR instruction register
Memory
15Memory Instruction Example
- load 30(r1), r2
- IF MAR ? PC IR ? MMAR
- ID A ? r1 PC ? PC 4
- EXE MAR ? A 30
- MEM MDR ? MMAR
- WB r2 ? MDR
16S1 bus
Dest bus
S2 bus
Control unit
ALU
A
R0, r1,... (registers)
C
B
ia(PC)
psw...
MAR
MDR
IR
MAR memory address register MDR memory data
register IR instruction register
Memory
17Branch/jump Instruction Example
- bnez r1, -16
- IF MAR ? PC IR ? MMAR
- ID A ? r1 PC ? PC 4
- EXE ALUoutput ? PC -16
- cond ? (A op 0)
- MEM if (cond)
- PC ? ALUoutput
- WB
r1 100 r4 0 r3 1 L1 r4 r4 r3 r3
r3 2 r1 r1-1 if (r1!0) goto
L1 // Outside loop // r4 ?
18S1 bus
Dest bus
S2 bus
Control unit
ALU
A
R0, r1,... (registers)
C
B
ia(PC)
psw...
MAR
MDR
IR
MAR memory address register MDR memory data
register IR instruction register
Memory
19Devices
- I/O devices are used to place data into primary
memory and to store its contents on a more
permanent medium - Logic to control detailed operation
- Physical device itself
- Each device uses a device controller to connect
it to the computers address and data bus - Many types of I/O devices
20Devices cont.
21Devices cont.
- General device characteristics
- Block-oriented devices
- Character-oriented devices
- Input devices
- Output devices
- Storage devices
- Communication devices
22Device Controllers
- A hardware component to control the detailed
operations of a device - Interface between controllers and devices
- Interface between software and the controller
- Through controllers registers
23Device Controllers cont.
24Communication Between CPU and Devices
- Through busy-done flag
- Called polling
- A busy-waiting implementation
- Not effective
25Polling I/O
26Polling I/O cont.
while(deviceNo.busy deviceNo.done)
ltwaitinggt deviceNo.data0 ltvalue to
writegt deviceNo.command WRITE while(deviceNo.bu
sy) ltwaitinggt deviceNo.done TRUE
- It introduces busy-waiting
- The CPU is busy, but is effectively waiting
- Devices are much slower than CPU
- CPU waits while device operates
- Would like to multiplex CPU to a different
process while I/O is in process
27A More Efficient Approach
- When a process is waiting for its I/O to be
completed, it would be more effective if we can
let another process to run to fully utilize the
CPU - It requires a way for the device to inform the
CPU when it has just completed I/O
28Better Utilization of CPU
29Interrupts
30Interrupt Handling cont.
31Interrupts cont.
32Interrupts cont.
- An interrupt is an immediate (asynchronous)
transfer of control caused by an event in the
system to handle real-time events and
running-time errors - Interrupt can be either software or hardware
- I/O device request (Hardware)
- System call (software)
- Signal (software)
- Page fault (software)
- Arithmetic overflow
- Memory-protection violation
- Power failure
33Interrupts cont.
- Causes of interrupts
- System call (syscall instruction)
- Timer expires (value of timer register reaches 0)
- I/O completed
- Program performed an illegal operation
- Divide by zero
- Address out of bounds while in user mode
- Segmentation fault
34Synchronous vs. Asynchronous
- Synchronous
- Events occur at the same place every time the
program is executed with the same data and memory - Can be predicted
- Asynchronous
- Caused by devices external to the processor or
memory
35Interrupt Handling
- When an interrupt occurs, the following steps are
taken - Save current program state
- Context switch to save all the general and status
registers of the interrupted process - Find out the interrupt source
- Go to the interrupt handler
36Interrupt Handling cont.
- Problem when two or more devices finish during
the same instruction cycle - Race condition between interrupts
37A Race Condition
saveProcessorState() for(i0
iltNumberOfRegisters i) memoryKi
Ri for(i0 iltNumberOfStatusRegisters
i) memoryKNumberOfRegistersi
StatusRegisteri
38Interrupt Handling cont.
- Race condition between interrupts
- Interrupt-enabled flag
39Trap Instruction
40Signal in UNIX
- Signal can be an asynchronous or synchronous
event - For example, CTRL-C generates SIGINT
- Divide-by-zero is a synchronous event
- Signals sent to a process
- Are handled by the operating system on behalf of
the running process - The program can change the default action taken
by the operating system for a particular signal - Function signal does not handle any signal by
itself
41Memory-mapped I/O
- Instructions to access device controllers
registers - Special I/O instructions
- Memory-mapped I/O
42Addressing Devices
Primary Memory
Primary Memory
Memory Addresses
Device 0
Device 0
Memory Addresses
Device 1
Device 1
Device Addresses
Device n-1
Device n-1
43Intel System Initialization
RAM
Boot Prog
ROM
Loader
Boot Device
Power Up
POST
OS
BIOS
CMOS
Hardware Process
Data Flow
44Bootstrapping
Bootstrap loader (boot sector)
1
0x0001000
Primary Memory
45Bootstrapping cont.
Bootstrap loader (boot sector)
1
0x0000100
2
BIOS loader
0x0001000
0x0008000
Loader
Primary Memory
46Bootstrapping
Bootstrap loader (boot sector)
1
0x0000100
2
BIOS loader
0x0001000
0x0008000
Loader
3
0x000A000
OS
Primary Memory
47Bootstrapping cont.
48A Bootstrap Loader Program
FIXED_LOC // Bootstrap loader entry
point load R1, 0 load 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_ADDRESS loop load R3, BUFFER_ADDRESS,
R1 store R3, FIXED_DEST, R1 incr R1 bleq R1,
R2, loop br FIXED_DEST
49A Pipelined Function Unit
Operand 1
Function Unit
Result
Operand 2
(a) Monolithic Unit
Operand 1
Result
Operand 2
(b) Pipelined Unit
50A SIMD Machine
51Multiprocessor Machines
- Shared memory multiprocessors
- Distributed memory multiprocessors
52Summary
- The von Neumann architecture is used in most
computers - To manage I/O devices or effectively, interrupts
are used - Interrupt handling involves hardware and software
support - There are also machines which use a different
architecture - Array processors multiprocessors