Fall 2017 :: CSE 306
Interrupts & System Calls
Nima Honarmand
System Calls Nima Honarmand Fall 2017 :: CSE 306 Previously on - - PowerPoint PPT Presentation
Fall 2017 :: CSE 306 Interrupts & System Calls Nima Honarmand Fall 2017 :: CSE 306 Previously on CSE306 Ok, heres Open file handle 4 hw1.txt App App App Libraries Libraries Libraries User System Call Table (350
Fall 2017 :: CSE 306
Nima Honarmand
Fall 2017 :: CSE 306
App
Hardware Libraries Kernel User Supervisor App Libraries App Libraries System Call Table (350—1200) Open file “hw1.txt” Ok, here’s handle 4
Fall 2017 :: CSE 306
pointer) register
instead of incrementing
program itself determines the next instruction at any step
Fall 2017 :: CSE 306
x = 2, y = true if (y) { x /= 2; printf(x); } //...
void printf(va_args) { //... } Regular control flow: branches and calls (logically follows source code)
ip
Fall 2017 :: CSE 306
be transferred to somewhere outside the program
this case, we call it irregular control flow
timer ticks, network card interrupts
system call
execution, e.g., a page fault or a device-by-zero fault
Fall 2017 :: CSE 306
User Kernel Stack Stack
if (x) { printf(“Boo”); ... printf(va_args…){ ... Disk_handler (){ ... } SP IP SP IP
Disk Interrupt!
Fall 2017 :: CSE 306
1) Transfer control to a pre-specified instruction in the kernel code
2) Save current thread’s “context” on the kernel stack
3) Execute a service routine to handle the situation 4) Restore the current thread context 5) Return to the interrupted code, right after the last executed instruction
Fall 2017 :: CSE 306
the same five-step procedure
handle all of them
them, unless stated otherwise
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
type
breakpoint
Descriptor Table (IDT) stored in memory
Fall 2017 :: CSE 306
Intel
Fall 2017 :: CSE 306
255 … 31 … … 47 Pre-defined by x86 OS Configurable Device IRQs
64 = xv6 System Call 128 = Linux System Call
Fall 2017 :: CSE 306
software to raise an interrupt
it’s a system call
int 14 (page fault)
Protection (#GP) fault
Fall 2017 :: CSE 306
memory, called Interrupt Descriptor Table, or IDT
255 … 31 … … 47 idtr
Fall 2017 :: CSE 306
interrupt (using int instruction)
Fall 2017 :: CSE 306
255 … 31 … … 47 idtr
Code Segment: Kernel Code Segment Offset: &page_fault_handler Ring: 0 // user code may not raise this exception Present: 1
14 (page fault)
Fall 2017 :: CSE 306
255 … 31 … … 64 idtr
Code Segment: Kernel Code Segment Offset: &syscall_handler Ring: 3 // user code may raise this exception Present: 1
64 (syscall)
Fall 2017 :: CSE 306
(legacy) features that are rarely used
confusing
Fall 2017 :: CSE 306
1) Transfer control to a pre-specified instruction in the kernel code 2) Save current thread’s “context” on the kernel stack 3) Execute a service routine to handle the situation 4) Restore the current thread context 5) Return to the interrupted code, right after the last executed instruction
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
1) Transfer control to a pre-specified instruction in the kernel code 2) Save current thread’s “context” on the kernel stack 3) Execute a service routine to handle the situation 4) Restore the current thread context 5) Return to the interrupted code, right after the last executed instruction
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
eax register before executing the int instruction
specified by the OS
Fall 2017 :: CSE 306
APIs, and another 800 for GUI methods
Fall 2017 :: CSE 306
in Lab 1!
Fall 2017 :: CSE 306
Around Pentium 4 era (2000):
Pentium 4
Fall 2017 :: CSE 306
call in a special CPU register?
be worth the transistor budget to implement this
Fall 2017 :: CSE 306
registers) to store syscall entry point and code segment