📄 exception.c
字号:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/kernel/exception.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
07500 /* This file contains a simple exception handler. Exceptions in user
07501 * processes are converted to signals. Exceptions in the kernel, MM and
07502 * FS cause a panic.
07503 */
07504
07505 #include "kernel.h"
07506 #include <signal.h>
07507 #include "proc.h"
07508
07509 /*==========================================================================*
07510 * exception *
07511 *==========================================================================*/
07512 PUBLIC void exception(vec_nr)
07513 unsigned vec_nr;
07514 {
07515 /* An exception or unexpected interrupt has occurred. */
07516
07517 struct ex_s {
07518 char *msg;
07519 int signum;
07520 int minprocessor;
07521 };
07522 static struct ex_s ex_data[] = {
07523 "Divide error", SIGFPE, 86,
07524 "Debug exception", SIGTRAP, 86,
07525 "Nonmaskable interrupt", SIGBUS, 86,
07526 "Breakpoint", SIGEMT, 86,
07527 "Overflow", SIGFPE, 86,
07528 "Bounds check", SIGFPE, 186,
07529 "Invalid opcode", SIGILL, 186,
07530 "Coprocessor not available", SIGFPE, 186,
07531 "Double fault", SIGBUS, 286,
07532 "Copressor segment overrun", SIGSEGV, 286,
07533 "Invalid TSS", SIGSEGV, 286,
07534 "Segment not present", SIGSEGV, 286,
07535 "Stack exception", SIGSEGV, 286, /* STACK_FAULT already used */
07536 "General protection", SIGSEGV, 286,
07537 "Page fault", SIGSEGV, 386, /* not close */
07538 NIL_PTR, SIGILL, 0, /* probably software trap */
07539 "Coprocessor error", SIGFPE, 386,
07540 };
07541 register struct ex_s *ep;
07542 struct proc *saved_proc;
07543
07544 saved_proc= proc_ptr; /* Save proc_ptr, because it may be changed by debug
07545 * statements.
07546 */
07547
07548 ep = &ex_data[vec_nr];
07549
07550 if (vec_nr == 2) { /* spurious NMI on some machines */
07551 printf("got spurious NMI\n");
07552 return;
07553 }
07554
07555 if (k_reenter == 0 && isuserp(saved_proc)) {
07556 unlock(); /* this is protected like sys_call() */
07557 cause_sig(proc_number(saved_proc), ep->signum);
07558 return;
07559 }
07560
07561 /* This is not supposed to happen. */
07562 if (ep->msg == NIL_PTR || processor < ep->minprocessor)
07563 printf("\nIntel-reserved exception %d\n", vec_nr);
07564 else
07565 printf("\n%s\n", ep->msg);
07566 printf("process number %d, pc = 0x%04x:0x%08x\n",
07567 proc_number(saved_proc),
07568 (unsigned) saved_proc->p_reg.cs,
07569 (unsigned) saved_proc->p_reg.pc);
07570 panic("exception in system code", NO_NUM);
07571 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -