Linux1.0内核中断体系的建立

来源:互联网 发布:mac清理垃圾软件 编辑:程序博客网 时间:2024/06/05 03:26

head.S中设置了IDT的指针,共256项,都指向ignore_int函数

ignore_int:    cld    pushl %eax    pushl %ecx    pushl %edx    push %ds    push %es    push %fs    movl $(KERNEL_DS),%eax    mov %ax,%ds    mov %ax,%es    mov %ax,%fs    pushl $int_msg    call _printk    popl %eax    pop %fs    pop %es    pop %ds    popl %edx    popl %ecx    popl %eax    iret

而在Traps.c文件中,对可能出现的异常进行初始化

void trap_init(void){    int i;    set_trap_gate(0,&divide_error);    set_trap_gate(1,&debug);    set_trap_gate(2,&nmi);    set_system_gate(3,&int3);   /* int3-5 can be called from all */    set_system_gate(4,&overflow);    set_system_gate(5,&bounds);    set_trap_gate(6,&invalid_op);    set_trap_gate(7,&device_not_available);    set_trap_gate(8,&double_fault);    set_trap_gate(9,&coprocessor_segment_overrun);    set_trap_gate(10,&invalid_TSS);    set_trap_gate(11,&segment_not_present);    set_trap_gate(12,&stack_segment);    set_trap_gate(13,&general_protection);    set_trap_gate(14,&page_fault);    set_trap_gate(15,&reserved);    set_trap_gate(16,&coprocessor_error);    set_trap_gate(17,&alignment_check);    for (i=18;i<48;i++)        set_trap_gate(i,&reserved);}

至于硬件设备产生的中断,Linux1.0内核专门建立了对应的函数调用表,当产生中断则调用相应的函数。在IRQ.c文件中处理。

void init_IRQ(void){    int i;    //初始化16个中断执行函数,初始化16个中断处理    for (i = 0; i < 16 ; i++)        set_intr_gate(0x20+i,bad_interrupt[i]);    //挂接2号,2号为连接从芯片,不执行任何事    if (irqaction(2,&ignore_IRQ))        printk("Unable to get IRQ2 for cascade\n");    //挂接irq与math操作,数学协处理器中断    if (request_irq(13,math_error_irq))        printk("Unable to get IRQ13 for math-error handler\n");    /* intialize the bottom half routines. */    for (i = 0; i < 32; i++) {        bh_base[i].routine = NULL;        bh_base[i].data = NULL;    }    bh_active = 0;    intr_count = 0;}
0 0
原创粉丝点击