Linux init/main.c 初始化中硬件中断向量初始化 trap_init()
Linux init/main.c 初始化中硬件中断向量初始化 trap_init()
/init/main.c部分代码
- void main(void) /* This really IS void, no error here. */
- { /* The startup routine assumes (well, ...) this */
- /*
- * Interrupts are still disabled. Do necessary setups, then
- * enable them
- */
- ROOT_DEV = ORIG_ROOT_DEV;
- drive_info = DRIVE_INFO;
- memory_end = (1<<20) + (EXT_MEM_K<<10);
- memory_end &= 0xfffff000;
- if (memory_end > 16*1024*1024)
- memory_end = 16*1024*1024;
- if (memory_end > 12*1024*1024)
- buffer_memory_end = 4*1024*1024;
- else if (memory_end > 6*1024*1024)
- buffer_memory_end = 2*1024*1024;
- else
- buffer_memory_end = 1*1024*1024;
- main_memory_start = buffer_memory_end;
- #ifdef RAMDISK
- main_memory_start += rd_init(main_memory_start, RAMDISK*1024);
- #endif
- mem_init(main_memory_start,memory_end);
- trap_init();
- blk_dev_init();
- chr_dev_init();
- tty_init();
- time_init();
- sched_init();
- buffer_init(buffer_memory_end);
- hd_init();
- floppy_init();
- sti();
- move_to_user_mode();
- if (!fork()) { /* we count on this going ok */
- init();
- }
trap_init()函数位置 /kernel/traps.c
- void trap_init(void)
- {
- int i;
- //设置系统的硬件中断 中断位于kernel/asm.s 或 system_call.s
- set_trap_gate(0,÷_error);//0中断,位于/kernel/asm.s 19行
- 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);
- for (i=17;i<48;i++)
- set_trap_gate(i,&reserved);
- set_trap_gate(45,&irq13);
- outb_p(inb_p(0x21)&0xfb,0x21);
- outb(inb_p(0xA1)&0xdf,0xA1);
- set_trap_gate(39,¶llel_interrupt);
- }
set_trap_gate()函数位于/include/asm/system.h
- //n为中断向量号,addr中断程序的偏移地址
- //&idt[n]对应中断号在中断描述符表中的偏移值
- //中断描述符的类型是 14,特权级是 0。
- #define set_trap_gate(n,addr) \
- _set_gate(&idt[n],15,0,addr)
- //设置中断宏函数
- //参数:gate_addr -描述符地址;type -描述符中类型域值;dpl -描述符特权层值;addr -偏移地址
- // %0 - (由 dpl,type 组合成的类型标志字);%1 - (描述符低 4 字节地址);
- // %2 - (描述符高 4 字节地址);%3 - edx(程序偏移地址 addr);%4 - eax(高字中含有段选择符)。
- #define _set_gate(gate_addr,type,dpl,addr) \
- __asm__ ("movw %%dx,%%ax\n\t" \
- "movw %0,%%dx\n\t" \
- "movl %%eax,%1\n\t" \
- "movl %%edx,%2" \
- : \
- : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
- "o" (*((char *) (gate_addr))), \
- "o" (*(4+(char *) (gate_addr))), \
- "d" ((char *) (addr)),"a" (0x00080000))
评论暂时关闭