



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to exceptions and processes in computer systems. It covers the concept of control flow, alterations to the control flow through jumps, branches, call and return, and the role of the operating system in handling exceptions. The document also discusses synchronous and asynchronous exceptions, interrupts, and traps.
Typology: Study notes
1 / 27
This page cannot be seen from the preview
Don't miss anything!




















Gerson Robboy
Portland State University
15-213, F’ 02
inst
1
inst
2
inst
3
…
inst
n
Computers Do One Thing
Computers Do One Thing
From startup to shutdown, a CPU reads and executes
(interprets) a sequence of instructions, one at a time.
Physical control flow
Time
15-213, F’ 02
Some events cause abrupt changes to flow of control.
Some events cause abrupt changes to flow of control.
Exceptions are kind of like procedure calls into the
Exceptions are kind of like procedure calls into the
kernel
kernel
Change in control flow in response to an event
Combination of hardware and OS software
15-213, F’ 02
User code dereferences a NULL pointer
User code dereferences a NULL pointer
Not a valid address in user space.
What happens next?
What happens next?
What does the CPU do?
What does the CPU do?
Where does flow of control go?
Where does flow of control go?
What does the operating system do?
What does the operating system do?
15-213, F’ 02
Events external to the processor
Events external to the processor
Suppose you have a CPU and many devices.
Suppose you have a CPU and many devices.
At any moment each device may have data available
At any moment each device may have data available
The user may have hit a key on the keyboard
There may be an incoming packet on the network
The CPU may have requested data from the disk, and that
sector may be rolling around under the read head now
One method: Poll all devices for data
One method: Poll all devices for data
How often?
How often?
What happens if you poll too often?
Not often enough?
What if a subroutine runs a long time and has no polling
code in it?
15-213, F’ 02
Examples:
Examples:
I/O interrupts
hitting a key at the keyboard
arrival of a packet from a network
arrival of a data sector from a disk
Hard reset interrupt
hitting the reset button
Timer interrupt
A procedure in the kernel ( A procedure in the kernel (““handlerhandler””) handles in the) handles in the
event.
event.
Flow of control returns to the interrupted code
Like a call/return.
15-213, F’ 02
Events that occur as a result of executing an
Events that occur as a result of executing an
instruction:
instruction:
Traps
Intentional
Examples: system calls, breakpoint traps
Faults
Unintentional but possibly recoverable
Examples: page faults (recoverable), protection faults
(unrecoverable).
Aborts
unintentional and unrecoverable
Examples: parity error, machine check.
15-213, F’ 02
A software interrupt.
A software interrupt.
A mechanism for making system calls into the kernel.
On ia32, the
On ia32, the
instruction invokes an interrupt.
instruction invokes an interrupt.
The interrupt handler, in this case, serves a system call.
The interrupt handler, in this case, serves a system call.
After it ’ s done, then what?
Where does control resume?
Why do we need traps?
Why do we need traps?
Why not just do system calls by calling to an address in Why not just do system calls by calling to an address in
the kernel?
the kernel?
15-213, F’ 02
A hardware error requiring action by the kernel.
A hardware error requiring action by the kernel.
Example: The computer
Example: The computer ’
s memory is physically broken
s memory is physically broken
at a certain address. Acess to that address causes a
at a certain address. Acess to that address causes a
machine check.
machine check. ”
The kernel should isolate that part
The kernel should isolate that part
of memory and not use it again.
of memory and not use it again.
There is no recovery. The faulting process must be
There is no recovery. The faulting process must be
aborted.
aborted.
But the operating system itself may be able to keep running
What if a machine check occurs at an address in the
What if a machine check occurs at an address in the
kernel?
kernel?
15-213, F’ 02
Local/IO Bus
Memory
Network
adapter
IDE disk
controller
Video
adapter
Display
Network
Processor
Interrupt
controller
SCSI
controller
SCSI bus
Serial port
controller
Parallel port
controller
Keyboard
controller
Keyboard Mouse Modem Printer
disk
disk CDROM
15-213, F’ 02
An interrupt vector is an array in memory of pointers to
An interrupt vector is an array in memory of pointers to
procedures, nothing more.
procedures, nothing more.
Each entry is initialized with a pointer to the handler for that
level of interrupt.
How does the vector get initialized?
When an exception occurs, the hardware causes a sort
When an exception occurs, the hardware causes a sort
of indirect jump via that pointer to the handler.
of indirect jump via that pointer to the handler.
The hardware also saves the information necessary to return
to the interrupted code
15-213, F’ 02
What prevents us, the users, from writing our own
What prevents us, the users, from writing our own
interrupt vector, and then handling the exceptions
interrupt vector, and then handling the exceptions
ourselves?
ourselves?
Does the CPU hardware inherently prevent this?
Does the CPU hardware inherently prevent this?
What problem would it cause if we could do it?
What problem would it cause if we could do it?
15-213, F’ 02
This is an operating system concept.
This is an operating system concept.
The operating system manages a set of processes.
The operating system manages a set of processes.
At a given moment in time, one process is running on
At a given moment in time, one process is running on
the CPU.
the CPU.
Other processes are waiting for a chance to have CPU time.
The Operating System schedules processes so they each
get their share of CPU time.
15-213, F’ 02
For any one process, the computer behaves as though
that process owns its own computer, complete with CPU
and dedicated memory.
To that process, what do other processes look like?
To that process, what do I/O devices look like?