|
|
@@ -4,6 +4,9 @@
|
|
|
#include "../lib/kernel/print.h"
|
|
|
#include "../lib/kernel/io.h"
|
|
|
|
|
|
+char *intr_name[IDT_DESC_CNT]; // 用于保存异常的名字
|
|
|
+intr_handler idt_table[IDT_DESC_CNT]; // 中断处理函数数组
|
|
|
+
|
|
|
/*创建中断门描述符*/
|
|
|
static void make_idt_desc(gate_desc *p_gdesc, uint8_t attr, intr_handler function)
|
|
|
{
|
|
|
@@ -46,12 +49,58 @@ static void pic_init(void)
|
|
|
put_str(" pic_init done\n");
|
|
|
}
|
|
|
|
|
|
+static void general_intr_handler(uint8_t vec_nr)
|
|
|
+{
|
|
|
+ if (vec_nr == 0x27 || vec_nr == 0x2f)
|
|
|
+ {
|
|
|
+ // IRQ7 和 IRQ15 会产生伪中断,无需处理
|
|
|
+ // 0x2f 是从片8259A上的最后一个 IRQ 引脚,保留项
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ put_str("int vector: 0x");
|
|
|
+ put_int(vec_nr);
|
|
|
+ put_char('\n');
|
|
|
+}
|
|
|
+
|
|
|
+static void exception_init(void)
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ for (i = 0; i < IDT_DESC_CNT; i++)
|
|
|
+ {
|
|
|
+ /*idt_table 数组中的函数是进入中断后根据中断向量号调用的,见 kernel/kernel.S 的 call [itd_table + %1*4]*/
|
|
|
+ idt_table[i] = general_intr_handler; // 默认为 general_intr_handler
|
|
|
+ intr_name[i] = "unknown";
|
|
|
+ }
|
|
|
+ intr_name[0] = "#DE Divide Error";
|
|
|
+ intr_name[1] = "#DB Debug Exception";
|
|
|
+ intr_name[2] = "NMI Interrupt";
|
|
|
+ intr_name[3] = "#BP Breakpoint Exception";
|
|
|
+ intr_name[4] = "#OF Overflow Exception";
|
|
|
+ intr_name[5] = "#BR BOUND Range Exceeded Exception";
|
|
|
+ intr_name[6] = "#UD Invalid Opcode Exception";
|
|
|
+ intr_name[7] = "#NM Device Not Available Exception";
|
|
|
+ intr_name[8] = "#DF Double Fault Exception";
|
|
|
+ intr_name[9] = "Coprocessor Segment Overrun";
|
|
|
+ intr_name[10] = "#TS Invalid TSS Exception";
|
|
|
+ intr_name[11] = "#NP Segment Not Present";
|
|
|
+ intr_name[12] = "#SS Stack Fault Exception";
|
|
|
+ intr_name[13] = "#GP General Protection Exception";
|
|
|
+ intr_name[14] = "#PF Page-Fault Exception";
|
|
|
+ // intr_name[15] 第 15 项是 intel 保留项,未使用
|
|
|
+ intr_name[16] = "#MF x87 FPU Floating-Point Error";
|
|
|
+ intr_name[17] = "#AC Alignment Check Exception";
|
|
|
+ intr_name[18] = "#MC Machine-Check Exception";
|
|
|
+ intr_name[19] = "#XF SIMD Floating-Point Exception";
|
|
|
+ put_str(" exception_init done\n");
|
|
|
+}
|
|
|
+
|
|
|
/* 中断初始化主函数 */
|
|
|
void itd_init(void)
|
|
|
{
|
|
|
put_str("init_idt start\n");
|
|
|
- itd_desc_init();
|
|
|
- pic_init(); // 初始化可编程中断控制器8259A
|
|
|
+ itd_desc_init(); // 初始化中断描述符表
|
|
|
+ exception_init(); // 完成一般中断处理函数注册及异常名称注册
|
|
|
+ pic_init(); // 初始化可编程中断控制器8259A
|
|
|
|
|
|
/* 加载 idt */
|
|
|
uint64_t idt_operand = ((sizeof(idt) - 1) | ((uint64_t)((uint32_t)idt << 16)));
|