Interrupts and Traps
Interrupts
Interrupt - Is a signal that indicates that hardware/software needs immediate attention
they are used so that the OS can run multiple programs at once

CYCLE
- I/O event occurs, current program is suspended
- Processor switches execution to another program
- When I/O is complete, an interrupt for the interrupt handling routine will occur
- If all the conditions are met the program will resume
TYPES
- I/O interrupt: caused by input output to signal completion or a error
- Timer interrupt: caused by a processor timer used to alert the OS at specific times
- Program interrupt: caused by error conditions within a program (traps) or fatal errors (fatal exceptions)
REASONS
- Slow devices: shouldn't have to wait "keyboard mouse"
- Fast devices: need precise timing "disk drives, displays"
- OS: regular interrupts so can manage multiple programs - timer interrupt
INTERRUPT CONTROLLER
- "Jump to Interrupt" is executed (same as Jump to Sub except stores the status or condition code)
- After "service routine" is complete
- "return from interrupt" is executed (this restores the status bits and PC, program execution continues)

DETAILED STEPS
- Save registers not save by interrupt hardware
- Setup context for new interrupt service routine
- Setup stack for interrupt service routine
- Acknowledge interrupt controller
- Copy registers from where they are stored to the program tabel
- Run interrupt service procedure to get data from the device control registers
- Choose which program to run next
- Load new process' registers
- Start running new process
NOTES ON: INTERRUPT SERVICE ROUTINES (ISR)
- Address is not specified in the instruction
- Address is specified by hardware
- Address can be built into the processor
- Address can be supplied by external hardware (interrupt controller)
LARGE ADDRESS SPACE ISSUE
- If there is a large address space then the address will be too long
- If the addresses are built in then the space available for the ISR will be predetermined, inflexable
Solution
- Interrupt Vector Table
- Here we build the address of the address into the hardware
- Stored in ROM
- Occupies bottom of memory 0 upwards
- 68000 table is 1024 bytes, with a 4-byte address
Types of interrupts

68000 modes of operation
User Mode
- resources are restricted
- Uses a different stack and pointer
- Switches to supervisor mode when a interrupt happens (no instruction for this)
Supervisor Mode
- There is an instruction to switch back
- Access to privileged instructions
Software Interrupts - Traps
- Programmers will try and access supervisor mode by using a "artificial" interrupt, this gives software supervisor mode access, this is called a trap
- This transfer of control is given to the operating system
- Most processors use traps to handle anomalous events e.g. user mode trying to execute privileged instructions
Exceptions
Exception is ether an Interrupt, fatal error or trap
Thus RTE (return from exception) rather than RTI
Occur For Errors




Occur For Traps


Interrupt masking
This is were interrupts with a higher priority cannot be interrupted by a interrupt with a lower priority
- 68000 provides 7 levels
- There are 3 mask bits, on wires ip0 ip1 and ip2 = Nm
- Future interrupts can only happen if Ni (the new one) > Nm
- Cannot mask level 7