10. Processor Exceptions Flashcards
What is the difference between interrupts and traps?
Interrupts are external (not caused by program execution), such as a keyboard interrupt.
Traps are internal (caused by program execution), such as syscall or a TLB miss.
What is the OS?
The system software that manages resources.
What is the kernel?
The ‘nucleus’ of the OS. It’s first to be loaded on booting up, and manages interrupts, fork processes, schedules processes and manages memory.
How is syscall() used in MIPS?
$v0 is set to the special value denoting the particular syscall exception and $a0 is set to the argument of the call.
Control is then passed to the exception handler.
What is the exception mechanism?
- Save the address of current instruction into the EPC (exception program counter)
- Transfer control to the OS at a known address.
- Handle the exception (all registers are preserved by the callee)
- Return to program execution (uses the ‘eret’ instruction to restore user program’s registers and jumps back via EPC)
What are the two approaches to finding the exception handler?
- Jump to a predefined address, and use the ‘cause’ register to branch to the right handler.
- Directly jump to a specific handler depending on the exception (vectored interrupt)
What are the options for the exception?
Take corrective action and use EPC to return.
OR
Terminate program and report error using EPC and cause.
How are further interrupts prevented during an interrupt?
Interrupts are masked by setting the exception level (EXL) in the status register.
Why do we use syscall, eret … instead of j, jr…?
The OS needs to guarantee safe and orderly access to critical system resources.
What is kernel mode?
Kernel mode is where privileged instructions have to be executed (i.e. accessing I/O devices, handling TLB updates, changing voltage of processor.)
How can kernel mode be entered/exited?
Entered through an exception, and left via ‘eret’. It is indicated by a bit in the process status register.
What are the benefits of dual-mode architecture?
Guarantees that control is transferred to the OS when the user is performing dangerous tasks.
Allows OS to ensure programs don’t interfere with each other.
Allows OS to ensure programs don’t have access to resources for which they don’t have permission.
Ensures that user programs do not have indefinite control of the processor.
How do we avoid one program taking up the processor or stalling the processor?
We time-share the CPU by switching from one process to another when it performs I/O or when its time slice expires.
Give the stages involved in switching to a new process.
The process calls the OS or a time-interrupt occurs.
The OS’ dispatcher performs a context switch:
- context is saved (registers, etc.) in PCB (process control block)
- Dispatcher chooses new process to run
- Processes’ states are updated
How do we solve the issue of not having enough physical memory for all processes?
Processes can be swapped out from memory to disk, and placed in an inactive state.
PCB of inactive processes are still kept in OS memory.
Inactive processes are resumed by swapping in the data from disk back to memory.