Please enable JavaScript.
Coggle requires JavaScript to display documents.
Interrupts (Transfer of Control (Processing Interrupts/Exception (Handling…
Interrupts
Transfer of Control
Instructions/events may cause CPU to switch to supervisor mode
Next instruction must be in a well-known part of the kernel
Interrupt Descriptor Table
Contains addresses to load PC with on interrupt
On interrupt, interrupt vector is used to index the table
Loads address in table to PC
Processing Interrupts/Exception
Handling
Interrupt/exception occurs
Push EFLAGS
Push CS register
Push EIP
Push error code if needed
Load new CS and EIP from IDT
Control transfers to ISR
Returning
Done with iret instruction
Reload EIP, CS, EFLAGS
Kernel :arrow_right: Process
Push kernel context to stack
Save kernel stack in stack location
Load process stack pointer
Recover process context from stack
Interrupt return
Process :arrow_right: Kernel
Servicing an Interrupt
Push EFLAGS, CS, EIP
Push process context
Load kernel stack pointer
Recover kernel context from stack
Return
to dispatcher
System Calls
Def:
a call to the kernel for a service request
Semantics
Much like a function call
Takes arguments that are passed to the kernel
Returns a value (result/status of the request)
Calling process is suspended while waiting for result
Mechanism
Pass arguments
Check arguments
Perform request
Return result
Argument Checking
Are pointers valid?
Are ranges valid?
Is process allows to execute call?
Process Side
Each system call has a stub function in the system library
Each stub calls a generic routine (syscall()) to get things ready for the kernel and execute a trap instruction
syscall()
Push arguments to stack or into registers
Push request ID to stack or registers
Execute int instruction
Get return value
Kernel Side
Context Switcher
Saves pointer to arguments in PCB
Returns request ID to dispatcher
Dispatcher
Knows count and type of arguments
Responsible for checking arguments
Timeline
syscall()
Push arguments
Push system call request ID
Execute int # (cause context switch)
Context Switcher
Push process pointers
Save pointer to args in PCB
Switch stacks
Load kernel context
Return
to dispatcher
Dispatcher
Determine which request
Copy and check arguments
Execute request
Save result code in PCB
Put process in blocked queue and select next ready process
Call
context switcher
Context Switcher
Save kernel context
Copy return result from PCB to process context (eax)
Switch stacks
Load process context
iret
syscall()
Copy eax to variable
Return variable
Kernels
Reentrant Kernels
:arrow_up: Efficiency :arrow_up: Complexity
Multiple stacks needed
"Locks" needed to protect shared data
High priority interrupts are serviced first
More complex, harder to debug and get correct
More efficient resource utilization
Design Hints
Break kernel into two parts
Top half deals with system calls and traps (synchronous)
Bottom half deals with hardware interrupts (asynchronous)
Keep the top half functionality like non-reentrant kernel
Bottom half of code services interrupts and modifies global data structure
Bottom half selects new process to run
Top half must lock shared structures when examining or modifying them
Non-reentrant Kernels
:arrow_down: Efficiency :arrow_down: Complexity
All interrupts must be disabled when running kernel code
Kernel is easier to design
Less efficient
High priority interrupts must wait for service
Service time of ISR must be bounded
Interrupts have no priority making certain hardware control difficult
Comparison
Reentrant
Multiple stacks
Premptable
Critical sections exist
High priority interrupts are serviced immediately
ISR code can be long
Complicated kernel design
Non-reentrant
Single stack
Non-preemtable
No synchronization needed
High priority interrupts must wait for service
ISR code must be short
Simple kernel design
Context Switching
Interrupts
Asynchronous
Generated externally from processor
Exceptions
Synchronous
Generated as result of instruction execution
Types of Exceptions
Fault Exceptions
Def:
an exception that can be corrected and restarted
Trap Exceptions
Def:
result from the execution of a trapping instruction
Abort Exceptions
Def:
precise location of problem is not known
Typically results from hardware problems, or inconsistent/illegal values in system tables
Process Destruction
What Needs to be Done
Free all resources
Free process memory
Mark PCB as unused
Caution
Processes may depend on other processes
How to Handle This
Kill dependent processes, too; or
Return an error; or
Allow processes to complete operation; or
Don't allow process termination
Interrupts
Timeline
Interrupt occurs
Control transfers to interrupt-specific address
Save interrupt number
Jump to common entry point
Execute context switching operations and
return
to dispatcher
Dispatcher services hardware
Reset the APIC
Select process to run and call context switcher
Perform context switch
iret
Interrupts vs. System Calls
System calls pass arguments, interrupts do not
System calls have return values, interrupts do not
System calls are made by software, interrupts are
usually
made by hardware
System calls can lead to generation of interrupts
Process Creation
What Needs to be Done
Acquire free PCB
Initialize PCB
Initialize process context
Add process to ready queue
Initializing PCB
Set up process address space
Allocate physical memory to the process
Load code into address space
Initialize Process Context
Process will start by being passed to context switcher
Stack must look like the process had been running and an interrupt occurred
Context goes in high memory
SP starts after this context frame
Context Structure
CS
EIP
EFLAGS
Varios registers