操作系統實踐之設置中斷

  在保護模式下設置中斷的步驟如下:

  初始化8259A中斷控制器,設置IDT的內容

PUBLIC void init_8259A()
{
 out_byte(INT_M_CTL, 0x11);   // Master 8259, ICW1.
 out_byte(INT_S_CTL, 0x11);   // Slave  8259, ICW1.
 out_byte(INT_M_CTLMASK, INT_VECTOR_IRQ0); // Master 8259, ICW2. 

 out_byte(INT_S_CTLMASK, INT_VECTOR_IRQ8); // Slave  8259, ICW2.

 out_byte(INT_M_CTLMASK, 0x4);   
 out_byte(INT_S_CTLMASK, 0x2);   

 out_byte(INT_M_CTLMASK, 0x1);   // Master 8259, ICW4.
 out_byte(INT_S_CTLMASK, 0x1);   // Slave  8259, ICW4.

 out_byte(INT_M_CTLMASK, 0xFE); // Master 8259, OCW1. 
 out_byte(INT_S_CTLMASK, 0xFF); // Slave  8259, OCW1. 
}  

  以上設置IDT中的中斷門

    init_idt_desc(INT_VECTOR_DIVIDE,    DA_386IGate, divide_error,        PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_DEBUG,        DA_386IGate, single_step_exception,    PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_NMI,        DA_386IGate, nmi,            PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_BREAKPOINT,    DA_386IGate, breakpoint_exception,    PRIVILEGE_USER);
    init_idt_desc(INT_VECTOR_OVERFLOW,    DA_386IGate, overflow,            PRIVILEGE_USER);
    init_idt_desc(INT_VECTOR_BOUNDS,    DA_386IGate, bounds_check,        PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_INVAL_OP,    DA_386IGate, inval_opcode,        PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_COPROC_NOT,    DA_386IGate, copr_not_available,    PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_DOUBLE_FAULT,    DA_386IGate, double_fault,        PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_COPROC_SEG,    DA_386IGate, copr_seg_overrun,        PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_INVAL_TSS,    DA_386IGate, inval_tss,            PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_SEG_NOT,    DA_386IGate, segment_not_present,    PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_STACK_FAULT,    DA_386IGate, stack_exception,        PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_PROTECTION,    DA_386IGate, general_protection,    PRIVILEGE_KRNL);
    init_idt_desc(INT_VECTOR_PAGE_FAULT,    DA_386IGate, page_fault,      

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章