From 54f9d98f71fa9f38a74cbfec88138d45c44fca73 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Sat, 30 Jul 2022 12:59:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=9B=E7=A8=8B=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=90=8E=EF=BC=8C=E5=B1=8F=E5=B9=95=E4=B8=8D?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/exception/trap.c | 62 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/kernel/exception/trap.c b/kernel/exception/trap.c index d512692b..1415f624 100644 --- a/kernel/exception/trap.c +++ b/kernel/exception/trap.c @@ -4,7 +4,7 @@ #include #include #include - +#include // 0 #DE 除法错误 void do_divide_error(struct pt_regs *regs, unsigned long error_code) { @@ -12,8 +12,7 @@ void do_divide_error(struct pt_regs *regs, unsigned long error_code) kerror("do_divide_error(0),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\t pid=%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id, current_pcb->pid); traceback(regs); current_pcb->state = PROC_STOPPED; - while (1) - hlt(); + sched_cfs(); } // 1 #DB 调试异常 @@ -59,8 +58,8 @@ void do_overflow(struct pt_regs *regs, unsigned long error_code) printk_color(YELLOW, BLACK, "TRAP"); printk(" ] do_overflow(4),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 5 #BR 越界异常 @@ -79,8 +78,8 @@ void do_undefined_opcode(struct pt_regs *regs, unsigned long error_code) kerror("do_undefined_opcode(6),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d, pid:%ld", error_code, regs->rsp, regs->rip, proc_current_cpu_id, current_pcb->pid); traceback(regs); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 7 #NM 设备异常(FPU不存在) @@ -89,8 +88,8 @@ void do_dev_not_avaliable(struct pt_regs *regs, unsigned long error_code) kerror("do_dev_not_avaliable(7),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 8 #DF 双重错误 @@ -101,8 +100,8 @@ void do_double_fault(struct pt_regs *regs, unsigned long error_code) printk_color(RED, BLACK, "Terminate"); printk(" ] do_double_fault(8),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); traceback(regs); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 9 协处理器越界(保留) @@ -111,8 +110,8 @@ void do_coprocessor_segment_overrun(struct pt_regs *regs, unsigned long error_co kerror("do_coprocessor_segment_overrun(9),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 10 #TS 无效的TSS段 @@ -142,8 +141,8 @@ void do_invalid_TSS(struct pt_regs *regs, unsigned long error_code) printk("\n"); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 11 #NP 段不存在 @@ -152,8 +151,8 @@ void do_segment_not_exists(struct pt_regs *regs, unsigned long error_code) kerror("do_segment_not_exists(11),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 12 #SS SS段错误 @@ -162,15 +161,15 @@ void do_stack_segment_fault(struct pt_regs *regs, unsigned long error_code) kerror("do_stack_segment_fault(12),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 13 #GP 通用保护性异常 void do_general_protection(struct pt_regs *regs, unsigned long error_code) { - kerror("do_general_protection(13),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); + kerror("do_general_protection(13),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\tpid=%ld\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id, current_pcb->pid); if (error_code & 0x01) printk_color(RED, BLACK, "The exception occurred during delivery of an event external to the program,such as an interrupt or an earlier exception.\n"); @@ -187,8 +186,8 @@ void do_general_protection(struct pt_regs *regs, unsigned long error_code) printk_color(RED, BLACK, "Segment Selector Index:%#010x\n", error_code & 0xfff8); traceback(regs); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 14 #PF 页故障 @@ -227,8 +226,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long error_code) traceback(regs); current_pcb->state = PROC_STOPPED; - while (1) - hlt(); + sched_cfs(); } // 15 Intel保留,请勿使用 @@ -249,8 +247,8 @@ void do_alignment_check(struct pt_regs *regs, unsigned long error_code) kerror("do_alignment_check(17),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 18 #MC 机器检测 @@ -259,8 +257,8 @@ void do_machine_check(struct pt_regs *regs, unsigned long error_code) kerror("do_machine_check(18),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 19 #XM SIMD浮点异常 @@ -269,8 +267,8 @@ void do_SIMD_exception(struct pt_regs *regs, unsigned long error_code) kerror("do_SIMD_exception(19),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 20 #VE 虚拟化异常 @@ -279,8 +277,8 @@ void do_virtualization_exception(struct pt_regs *regs, unsigned long error_code) kerror("do_virtualization_exception(20),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); - while (1) - hlt(); + current_pcb->state = PROC_STOPPED; + sched_cfs(); } // 21-21 Intel保留,请勿使用