1 CPU interrupt INT trap CPU exception
2 X86 CPU gate
64 16 1 2 5 8 16 16 P DPL 00101 TSS 101 DPL P 1
64 16 1 2 1 1 3 3 5 16 16 16 P DPL 0 D 000 16 110 111 100 D 1=32 0=16 DPL P 1
INT DPL1>=CPL>=DPL CPU CPL>=DPL1 DPL1 CPL CPU DPL
SS OLD ESP ESP OLD EFLAGS CS EIP ERRORCODE EFLAGS CS EIP ERRORCODE ESP ESP
IDT IDTR V GDT GDTR
3 IDT Linux trap_init() init_irq() trap_init() Init_IRQ()
3.1 trap_init() 20 0-19 set_trap_gate( 0 set_system_gate(syscall_vector,&syste m_call) 0x80
_set_gate (gate-addr,type,dpl,addr) n gate-addr idt Type Dpl Addr Set-intr-gate set_trap_gate set_system_gate _set_gate set_set_trap_gate(unsigned int n, void *addr) { _set_gate(idt_table+n,15,0,addr); }
3.2 Init_IRQ() (1) init_isa_irqs PC 8259A (2) set_intr_gate(vector,interrupt[i]) 0x20 224 0x80 Interrput[I] I
Interrput[] IRQ0x01_interrupt() IRQ0x0f_interrupt() IRQ0x01_interrupt()
IRQ0xXX_interrupt() IRQ0xXX_interrupt() 1 2 common_interrupt
4 0x20 0x80
1 Irq_desc[] 224 224 handler hw_interrupt_type Action
2 Hw_interrupt_type init_irq ini_isa_irqs()
3 Irqaction Handler Dev_id Next
0x20 Irq_dest_t handler action Hw_interrup_controller irqaction Handler 0x21 handler action next 0x22 handler action Handler next CPU Irq_dest_t 16
Request_irq() IRQ irqaction setup_irq()
setup_irq() iqraction
5 8259A CPU INTR CPU
Step 1 CPU 8259A IDTR IDT ( ) CPU CPL DPL 3>0 CPL DPL CPU TSS 0 ESP SS ESP SS CPU EFLAGS CS EIP
Step 2 CPU IRQ0xXX_interrupt IRQ0x03_interrupt IRQ0x03_interrupt -256 common_interrupt
SS Step 3 ESP EFLAGS CS common_interrupt EIP -256 SAVE_ALL ES DS EAX ret_from_intr EBP EDI ESI do_irq() EDX ECX EBX
Step 4 do_irq() 1 0x03 2 irq_desc[] 3 4 handle_irq_event()
Step 5 handle_irq_event() do-while 4
Step 6 handle_irq_event() do_irq() do_irq() bottom half) do_irq() entry.s ret_from_intr ret_from_intr do_irq() CPU
Step 7 ret_from_intr CPU VM86 CPU restore_all ret_with_reschedule ret_with_reschedule
Step 8 ret_with_reschedule schedule() RESTORE_ALL SAVE_ALL ret CPU
6 Bottom Half(BH) * CPU * Bottom Half
Bh top half bottom half bh
Bh 1 bh_base[] 32 bh 32 mark_bh(), 1 do_irq(),
Bh 2 1 do_softirq() do_softirq() bh_action() Bh_action() bh_base[] TIMER_BH
Bh cpu tasklet Tasklet cpu
7 * page_fault * CPU page_fault() *
1 page_fault * do_page_fault * error_code error_code common_interrupt)
2 error_code * * do_page_fault EDI ESI EDX do_page_fault * call *%edi do_page_fault SS ESP EFLAGS CS EIP Do_page_fault DS EAX EBP EDI ESI EDX ECX EBX
do_page_fault * * ret_from_intr *
8 * CPU * time_init() time_interrupt
time_interrupt * * do_timer_interrupt() * do_timer_interrupt() * do_timer() mk_bh() bh_task_vec[timeer_bh] tasklet_hi_vec CPU TIMER_BH timer_bh()
timer_bh() * update_times() CPU * run_timer_list() timer
BH bh
9 INT 0x80 sethostname Sethostname name len name len name
1 sethostname * name len * sethostname 0x4a eax * int $0x80 CPU 0x80 system_call
2 system_call * SAVE_ALL * eax * sys_call_table eax 0x4a 74 sys_sethostname sys_call_table 256 linux 221
3 sys_sethostname: * *
4 (sys_sethostname system_call(): * eax ret_from_sys_call * * sethostname
5 sethostname * eax syscall_error() * syscall_error() eax error_location errono * eax 0