kernel/traps.c中trap_init()函数的反汇编如下图:
这段汇编代码是"set_trap_gate(0, ÷_error);"的反汇编,第一行mov 0x6000, %ecx会将ds:[0x6000]处的数据放入ecx寄存器中,导致第六行和第七行无法将中断描述符放入中断描述符表里(我的中断描述符表从地址0x6000开始)。我想第一行应该是mov $0x6000, %ecx才对,应该将立即数0x6000放入ecx,然而实际情况却是如上图所示。set_tarp_gate(), _set_gate()完全参考linux0.11内核,如下:
#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))
#define set_intr_gate(n, addr) \
_set_gate(&idt_table[n], 14, 0, addr) // idt_table from head.s
#define set_trap_gate(n, addr) \
_set_gate(&idt_table[n], 15, 0, addr) // idt_table from head.s
环境: Ubuntu16.04, gcc-5.4.0