Linux Kernel series-7. OS development interruptions and exceptions, Linux Kernel
A. Overview
The mechanism of the interrupt and trap doors is almost the same, except that the call command is used to call the door. Here we use the int command. The structure of the interrupt door and trap door is as follows:
The four-digit TYPE is changed to 0xE (Interrupt gate) or 0xF (trap gate ).
As shown in the case when the int n command is interrupted, n is the vector number, which is similar to the use of the call door.
B. Create an IDT
; IDT [SECTION. idt] ALIGN32 [BITS32] LABEL_IDT:; Target Selection Sub-, offset, DCount, attribute % rep 255GateSelectorCode32, SpuriousHandler, 0, DA_386IGate % rows $-rows-1; Segment limit dd0; base address; END of [SECTION. idt]
Each descriptor is set to the interrupt gate pointing to SelectorCode32: SpuriousHandler.
Prepare xoreax, eaxmovax, dsshleax, 4 addeax, LABEL_IDT; eax <-idt base address movdword [IdtPtr + 2], eax; [IdtPtr + 2] <-idt base address; disconnect cli; load IDTRlidt [IdtPtr]
C. Implement an interruption
callInit8259Aint080h
The running result is as follows:
Next, modify the IDT and list the 80h interrupt separately.
; IDT [SECTION. idt] ALIGN32 [BITS32] LABEL_IDT:; Target Selection Sub-, offset, DCount, attribute % rep handler, SpuriousHandler, 0, DA_386IGate % handler: GateSelectorCode32, UserIntHandler, 0, DA_386IGateIdtLenequ $-LABEL_IDTIdtPtrdwIdtLen-1; Segment boundaries dd0; base address; END of [SECTION. idt]
The running result is as follows:
【Source code]