A Timely Question.: Pre-Emptively
A Timely Question.: Pre-Emptively
Memory-mapped I/O
With memory-mapped I/O, one address space is divided
into two parts.
Some addresses refer to physical memory locations.
Other addresses actually reference peripherals.
For example, an Apple IIe had a 16-bit address bus which
could access a whole 64KB of memory.
Addresses C000-CFFF in hexadecimal were not part
of memory, but were used to access I/O devices.
All the other addresses did reference main memory.
The I/O addresses are shared by many peripherals. In
the Apple IIe, for instance, C010 is attached to the
keyboard while C030 goes to the speaker.
Some devices may need several I/O addresses.
FFFF
Memory
I/O
D000
C000
Memory
0000
CPU
Memory
Hard disks
CD-ROM
Network
Display
To send data to a device, the CPU writes to the appropriate I/O address.
The address and data are then transmitted along the bus.
Each device has to monitor the address bus to see if it is the target.
The Apple IIe main memory ignores any transactions whose address
begins with bits 1100 (addresses C000-CFFF).
The speaker only responds when C030 appears on the address bus.
Isolated I/O
Another approach is to support separate address
spaces for memory and I/O devices, with special
instructions that access the I/O space.
For instance, 8086 machines have a 32-bit address
space.
Regular instructions like MOV reference RAM.
The special instructions IN and OUT access a
separate 64KB I/O address space.
FFFFFFFF
Main
memory
00000000
I/O
devices
0000FFFF
00000000
No
Done?
Yes
Interrupt-driven I/O
Interrupt-driven I/O attacks the problem of the
processor having to wait for a slow device.
Instead of waiting, the CPU continues with other
calculations. The device interrupts the processor
when the data is ready.
The data transfer steps are still the same as with
programmed I/O, and still occupy the CPU.
No
Done?
Yes
10
Interrupts
Interrupts are external events that require the processors attention.
Peripherals and other I/O devices may need attention.
Timer interrupts to mark the passage of time.
These situations are not errors.
They happen normally.
All interrupts are recoverable:
The interrupted program will need to be resumed after the
interrupt is handled.
It is the operating systems responsibility to do the right thing, such as:
Save the current state.
Find and load the correct data from the hard disk
Transfer data to/from the I/O device.
11
Exception handling
Exceptions are typically errors that are detected within the processor.
The CPU tries to execute an illegal instruction opcode.
An arithmetic instruction overflows, or attempts to divide by 0.
The a load or store cannot complete because it is accessing a virtual
address currently on disk
well talk about virtual memory later in 378.
There are two possible ways of resolving these errors.
If the error is un-recoverable, the operating system kills the program.
Less serious problems can often be fixed by the O/S or the program
itself.
12
Kernel
Execute Application
Illegal opcode
exception
Return from
exception
Execute Application
Its slower, but it works. (if you wanted fast, you wouldnt have a Pentium)
13
14
15
0000
16
(Flowchart again.)
17
CPU &
cache
Memory
DMA unit
Hard disks
CD-ROM
Network
18