Author: Harold Wang
Basic knowledge
In interrupt is usually defined as an event that alters the sequence of instructions executed by a processor, providing a way to divert the processor to code outside the normal flow of control.
Interrupt are often divided into synchronous and asynchronous interrupts:
--Synchronous interrupts(exceptions): produced by the CPU control unit while executing instructions and are called synchronous because the control unit issues them only after terminating the executing of an instruction
like… Processor-detected exceptions/Faults/Traps/Aborts/Programmed exceptions
Caused by…programming errors/anomalous conditions that must be handled by the kernel
--Asynchronous interrupts(interrupts): generated by other hardware devices at arbitrary times with respect to the CPU clock signals.
Caused by…timers/I/O devices/
--Interrupt vectorEach interrupt or exception is identified by a number ranging from 0 to 255 (8-bit unsigned number)
--The vectors of nonmaskable interrupts and exceptions are fixed
--The vectors of maskable interrupts can be altered by programming the Interrupt Controller
Relavent Instructions:
CALL procedure name
INT interrupt vector
IRET return
LIDT 48 bit interrupt description table
IDTR in CPU save the baseaddress of the IDT which is filled with gate descriptors(called interrupt vector N years ago)
----IDTR 48 bit , lower 16 bit indicate the size of the IDT, higher 32 bit indicate the line base address of the IDT.
interrupt gate and trap gate can not be accessed by user mode.
system gate (call gate) can be accessed by user mode. there are 4 linux exception program, their vector are 3,4,5,128. so user mode can publish int3,into,bound,int $0x80 asmble instructions. using set_system_gate() function to insert a system gate into the IDT.
Author: Harold Wang
Interrupt Handling
setup_idt()
--initialize IDT’s 256 items with ignore_int() function’s result.
--initizlize items with meaningful trap and interrupt handlers, using start_kernel() function--->trap_init() and init_IRQ() functions.
NOTE: interrupt handler can not be blocked or go to sleep. So there are some limitations: interrupt handler MUST ASAP--->solutions: divide into two parts:
--Top half: simple and fast, dealing with time-critical hardware tasks. like: packets transmission and receiving
--Bottom half: deferring work to a later point where interrupt can be enabled. like: network protocols processing
Author: Harold Wang
Bottom Half
mechnisam of realization:
--softirq
--tasklet
--work queue
Bottom Half to Use?
NOTE: if needs to sleep, use work queue.
if doesn’t need to sleep, use tasklet.
Interrupt Applications
Timer application:
struct timer_list my_timer;
init_timer(&my_timer);
add_timer(&my_timer);
del_timer(&my_timer);
System call application:
kernel initialize: trap_init()—>set_system_gate(0x80,$system_call); more information can see arch/i386/kernel/traps.c
NOTE: eax reg is used for save syscall number! eax,ebx,ecx,edx,esi,edi save paramters. by calling call* sys_call_table(%eax,4); return value saved in eax
see include/asm/unistd_32.h
kernel/syscall_table.S
Author: Harold Wang
没有评论:
发表评论