COMP 530: Operating Systems
Interrupts and System Calls
Don Porter
1
Interrupts and System Calls Don Porter 1 COMP 530: Operating - - PowerPoint PPT Presentation
COMP 530: Operating Systems Interrupts and System Calls Don Porter 1 COMP 530: Operating Systems First lecture Ok, heres Open file handle 4 hw1.txt App App App Libraries Libraries Libraries User Super- System Call Table
COMP 530: Operating Systems
1
COMP 530: Operating Systems
App
2-2
Hardware Libraries Kernel User Super- visor App Libraries App Libraries System Call Table (350—1200) Open file “hw1.txt” Ok, here’s handle 4
COMP 530: Operating Systems
– As well as how exceptions (e.g., divide by zero) work
– I.e., things other than a branch in a running program
3
COMP 530: Operating Systems
void printf(va_args) { //... }
4
COMP 530: Operating Systems
void handle_divzero(){ x = 2; }
Divide by zero! Program can’t make progress!
5
COMP 530: Operating Systems
– Divide by zero – System call – Bad pointer dereference
– Usually device I/O – Timer ticks (well, clocks can be considered a device)
6
COMP 530: Operating Systems
if (x) { printf(“Boo”); ... printf(va_args…){ ... Disk_handler (){ ... } RSP RIP RSP RIP
7
COMP 530: Operating Systems
8
COMP 530: Operating Systems
9
COMP 530: Operating Systems
10
COMP 530: Operating Systems
0x2e = Windows System Call 128 = Linux System Call
11
COMP 530: Operating Systems
– E.g., 14 is always for page faults
– 32—47 are for device interrupts (IRQs) in JOS
– 0x80 issues system call in Linux (more on this later)
12
COMP 530: Operating Systems
– 0x80 is just a Linux convention. JOS uses 0x30
– You could have multiple system call tables for different purposes or types of processes!
13
COMP 530: Operating Systems
– Generally, user programs can’t issue an int 14 (page fault) manually – An unauthorized int instruction causes a general protection fault
14
COMP 530: Operating Systems
– At a prescribed address (the interrupt handler)
– Sometimes, extra info is loaded into CPU registers – E.g., page faults store the address that caused the fault in the cr2 register
15
COMP 530: Operating Systems
– The state of a program’s execution is succinctly and completely represented by CPU register state
16
COMP 530: Operating Systems
– Can be anywhere in memory – Pointed to by special register (idtr)
17
COMP 530: Operating Systems
18
COMP 530: Operating Systems
Code Segment: Kernel Code Segment Offset: &page_fault_handler //linear addr Ring: 0 // kernel Present: 1 Gate Type: Exception
19
COMP 530: Operating Systems
– What code to execute, privilege level to raise the interrupt
20
COMP 530: Operating Systems
21
COMP 530: Operating Systems
– Network packet arrives – Disk read completion – Divide by zero – System call
22
COMP 530: Operating Systems
– Sort of like exception handlers in Java – But separated from the control flow of the program
23
COMP 530: Operating Systems
24
COMP 530: Operating Systems
– Generally to use a hardware abstraction (file, socket) – Or OS-provided software abstraction (IPC, scheduling)
– Protection of the OS/hardware from buggy/malicious programs – Applications are not allowed to directly interact with hardware, or access kernel data structures
COMP 530: Operating Systems
– See arch/x86/kernel/syscall_table*.S in Linux source
– Arguments go in the other registers by calling convention – Return value goes in eax
26
COMP 530: Operating Systems
COMP 530: Operating Systems
– Rather than calling arbitrary internal kernel functions
Calling _foo() directly would circumvent permission check
COMP 530: Operating Systems