⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exception.c

📁 一个操作系统的源代码
💻 C
字号:
/** exception.c ** ** Original Author: Guido de Jong ** Date: 10/18/99 ** ** Description: ** General exception handler. Called by all exception ISR's. ** The number of the original exception and errorcode are passed as ** parameters.  **  ** This program is free software, you can redistribute it and/or ** modify it under the terms of the GNU General Public License ** as published by the Free Software Foundation; either version ** 2 of the License, or (at your option) any later version. ** ** This program is distributed in the hope that it will be ** useful, but WITHOUT ANY WARRANTY; without even the implied ** warranty or MERCHANTABILITY or FITNESS FOR A PARTICULAR ** PURPOSE.  See the GNU General Public License for more ** details. ** ** You should have received a copy of the GNU General Public ** License along with this program; if not, write to the ** Free Software Foundation, Inc., 59 Temple Place, Suite 330, ** Boston, MA 02111-1307 USA ** *********************************************************Apostle OS**/#include <exception.h>#include <idt.h>#include <gdt.h>#include <halt.h>#include <types.h>#ifdef DEBUG#include <debug/conio.h>#endiftypedef char ExceptionMessage[32];void setupExceptions(void){  interruptIDT(&IDT[0], KERNEL_CS, (dword)&__DivideError, 0);  interruptIDT(&IDT[1], KERNEL_CS, (dword)&__DebugException, 0);  interruptIDT(&IDT[2], KERNEL_CS, (dword)&__NonMaskableInterrupt, 0);  interruptIDT(&IDT[3], KERNEL_CS, (dword)&__Breakpoint, 3); /* can be called from user mode */  interruptIDT(&IDT[4], KERNEL_CS, (dword)&__Overflow, 0);  interruptIDT(&IDT[5], KERNEL_CS, (dword)&__BoundsCheck, 0);  interruptIDT(&IDT[6], KERNEL_CS, (dword)&__InvalidOpcode, 0);  interruptIDT(&IDT[7], KERNEL_CS, (dword)&__CoprocessorNotAvailable, 0);  interruptIDT(&IDT[8], KERNEL_CS, (dword)&__DoubleFault, 0);  interruptIDT(&IDT[9], KERNEL_CS, (dword)&__CoprocessorSegmentOverrun, 0);  interruptIDT(&IDT[10], KERNEL_CS, (dword)&__InvalidTSS, 0);  interruptIDT(&IDT[11], KERNEL_CS, (dword)&__SegmentNotPresent, 0);  interruptIDT(&IDT[12], KERNEL_CS, (dword)&__StackException, 0);  interruptIDT(&IDT[13], KERNEL_CS, (dword)&__GeneralProtection, 0);  interruptIDT(&IDT[14], KERNEL_CS, (dword)&__PageFault, 0);  interruptIDT(&IDT[15], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[16], KERNEL_CS, (dword)&__CoprocessorError, 0);  interruptIDT(&IDT[17], KERNEL_CS, (dword)&__AlignmentCheck, 0);  interruptIDT(&IDT[18], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[19], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[20], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[21], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[22], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[23], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[24], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[25], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[26], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[27], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[28], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[29], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[30], KERNEL_CS, (dword)&__Reserved, 0);  interruptIDT(&IDT[31], KERNEL_CS, (dword)&__Reserved, 0);}static const ExceptionMessage exceptionDescription[N_EXCEPTIONS] = { "Divide Error",  "Debug Exception",  "Non-Maskable Interrupt",  "Breakpoint",  "Overflow",  "Bounds Check",  "Invalid Opcode",  "Coprocessor Not Available",  "Double Fault",  "Coprocessor Segment Overrun",  "Invalid TSS",  "Segment Not Present",  "Stack Exception",  "General Protection Fault",  "Page Fault",  "Reserved",  "Coprocessor Error",  "Alignment Check",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved",  "Reserved"};void exceptionHandler(dword edi, dword esi, dword ebp, dword esp,                             dword ebx, dword edx, dword ecx, dword eax,                             dword gs, dword fs, dword es, dword ds,                             dword nr, dword errorCode,                             dword eip, dword cs, dword eflags){#ifdef DEBUG  dword *p = (dword *)(esp + (cs & 0x03 ? 44 : 36));  DebugPrintF("\n%s", exceptionDescription[nr]);  switch (nr)    {    case 14:      if (!(errorCode & 0x01))	DebugPrintF(" : non-present page\n");      else	DebugPrintF(" : protection violation\n");    default:      DebugPrintF("\nERROR CODE=%08X\n", errorCode);      DebugPrintF("EAX=%08X  EBX=%08X  ECX=%08X  EDX=%08X\n", \		  eax, ebx, ecx, edx);      DebugPrintF("EBP=%08X  ESP=%08X  ESI=%08X  EDI=%08X\n", \		  ebp, esp + (cs & 0x03 ? 44 : 36), esi, edi);      DebugPrintF("DS =%04X      ES =%04X      FS =%04X      GS =%04X\n", \	 	  ds & 0xffff, es & 0xffff, fs & 0xffff, gs & 0xffff);      DebugPrintF("CS =%04X      EIP=%08X  EFLAGS=%08X\n", \		  cs & 0xffff, eip, eflags);      DebugPrintF("STACK=%08X %08X %08X %08X %08X %08X\n", \		  p[0], p[1], p[2], p[3], p[4], p[5]);      break;    }#endif  if (nr != 3)      halt();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -