Main Page | Modules | File List | File Members

idt.c

00001 /* ndk - [ idt.c ]
00002  *
00003  * Contains code to initialize the idt, and the C
00004  * part of the general purpose exception handlers.
00005  *
00006  * Please see:
00007  *   /src/array.c
00008  *   /src/isr.asm
00009  *
00010  * (c)2002 dcipher / neuraldk
00011  *           www.neuraldk.org
00012  */
00013 
00014 #include "idt.h"
00015 
00016 /* IDT @ 0x0, 256 entries, 8 bytes long */
00017 Array IDT = { 0x0, 256, 8 };
00018 
00019 char *exceptionNames[19] = {
00020   "Divide by Zero",
00021   "Debug",
00022   "NMI",
00023   "Breakpoint",
00024   "Overflow",
00025   "Out of Bounds",
00026   "Invalid Opcode",
00027   "FPU Not Found",
00028   "Double-Fault",
00029   "CoProcessor Segment Overrun",
00030   "Invalid TSS",
00031   "Segment Not Present",
00032   "Stack",
00033   "General Protection",
00034   "Page Fault",
00035   "Reserved",
00036   "FPU Error",
00037   "Alignment Check",
00038   "Machine Check" };
00039 
00040 void idtInit(void) {
00041   /* All the below wrappers are created in isr.asm
00042    *
00043    * They simply push all registers to the stack, and
00044    * call stdHandler, which, in turn prints them out and
00045    * halts.
00046    */
00047   createGate(&IDT, 0x00, (long)int00h_wrapper, SEL_P0_CODE, D_INT);
00048   createGate(&IDT, 0x01, (long)int01h_wrapper, SEL_P0_CODE, D_INT);
00049   createGate(&IDT, 0x02, (long)int02h_wrapper, SEL_P0_CODE, D_INT);
00050   createGate(&IDT, 0x03, (long)int03h_wrapper, SEL_P0_CODE, D_INT);
00051   createGate(&IDT, 0x04, (long)int04h_wrapper, SEL_P0_CODE, D_INT);
00052   createGate(&IDT, 0x05, (long)int05h_wrapper, SEL_P0_CODE, D_INT);
00053   createGate(&IDT, 0x06, (long)int06h_wrapper, SEL_P0_CODE, D_INT);
00054   createGate(&IDT, 0x07, (long)int07h_wrapper, SEL_P0_CODE, D_INT);
00055   createGate(&IDT, 0x08, (long)int08h_wrapper, SEL_P0_CODE, D_INT);
00056   createGate(&IDT, 0x09, (long)int09h_wrapper, SEL_P0_CODE, D_INT);
00057   createGate(&IDT, 0x0A, (long)int0Ah_wrapper, SEL_P0_CODE, D_INT);
00058   createGate(&IDT, 0x0B, (long)int0Bh_wrapper, SEL_P0_CODE, D_INT);
00059   createGate(&IDT, 0x0C, (long)int0Ch_wrapper, SEL_P0_CODE, D_INT);
00060   createGate(&IDT, 0x0D, (long)int0Dh_wrapper, SEL_P0_CODE, D_INT);
00061   createGate(&IDT, 0x0E, (long)int0Eh_wrapper, SEL_P0_CODE, D_INT);
00062   createGate(&IDT, 0x0F, (long)int0Fh_wrapper, SEL_P0_CODE, D_INT);
00063   createGate(&IDT, 0x10, (long)int10h_wrapper, SEL_P0_CODE, D_INT);
00064   createGate(&IDT, 0x11, (long)int11h_wrapper, SEL_P0_CODE, D_INT);
00065   createGate(&IDT, 0x12, (long)int12h_wrapper, SEL_P0_CODE, D_INT);
00066   createGate(&IDT, 0x13, (long)int13h_wrapper, SEL_P0_CODE, D_INT);
00067   createGate(&IDT, 0x14, (long)int14h_wrapper, SEL_P0_CODE, D_INT);
00068   createGate(&IDT, 0x15, (long)int15h_wrapper, SEL_P0_CODE, D_INT);
00069   createGate(&IDT, 0x16, (long)int16h_wrapper, SEL_P0_CODE, D_INT);
00070   createGate(&IDT, 0x17, (long)int17h_wrapper, SEL_P0_CODE, D_INT);
00071   createGate(&IDT, 0x18, (long)int18h_wrapper, SEL_P0_CODE, D_INT);
00072   createGate(&IDT, 0x19, (long)int19h_wrapper, SEL_P0_CODE, D_INT);
00073   createGate(&IDT, 0x1A, (long)int1Ah_wrapper, SEL_P0_CODE, D_INT);
00074   createGate(&IDT, 0x1B, (long)int1Bh_wrapper, SEL_P0_CODE, D_INT);
00075   createGate(&IDT, 0x1C, (long)int1Ch_wrapper, SEL_P0_CODE, D_INT);
00076   createGate(&IDT, 0x1D, (long)int1Dh_wrapper, SEL_P0_CODE, D_INT);
00077   createGate(&IDT, 0x1E, (long)int1Eh_wrapper, SEL_P0_CODE, D_INT);
00078   createGate(&IDT, 0x1F, (long)int1Fh_wrapper, SEL_P0_CODE, D_INT);
00079   return;
00080 }
00081 
00082 void stdHandler (short exceptionNum,
00083                  short cs,
00084                   long ip,
00085                  short error,
00086                  short taskReg,
00087                   long eflags,
00088                   long edi,
00089                   long esi,
00090                   long ebp,
00091                   long esp,
00092                   long ebx,
00093                   long edx,
00094                   long ecx,
00095                   long eax,
00096                  short ss,
00097                  short gs,
00098                  short fs,
00099                  short es,
00100                  short ds) {
00101   if(exceptionNum < 19)
00102     consoleOut("%s Exception\n", exceptionNames[exceptionNum]);
00103   consoleOut("Exception num: 0x%2x\n", (long)exceptionNum);
00104   consoleOut("   at address: 0x%2x:0x%8x\n", (long)cs, ip);
00105   if (exceptionHasErrorCode[exceptionNum]) {
00106     consoleOut ("   Error Code: 0x%x [ Index: 0x%x, Type:%d ]\n",
00107             error, error >> 3, error & 7);
00108   }
00109   consoleOut("Task Register: 0x%x\n", (long)taskReg);
00110   consoleOut("       EFlags: 0x%8x\n\n", (long)eflags);
00111 
00112   consoleOut("ds: 0x%2x \teax: 0x%8x \tedi: 0x%8x\n", (long)ds, eax, edi);
00113   consoleOut("es: 0x%2x \tebx: 0x%8x \tesi: 0x%8x\n", (long)es, ebx, esi);
00114   consoleOut("fs: 0x%2x \tecx: 0x%8x \tebp: 0x%8x\n", (long)fs, ecx, ebp);
00115   consoleOut("gs: 0x%2x \tedx: 0x%8x \tesp: 0x%8x\n", (long)gs, edx, esp);
00116   consoleOut("ss: 0x%2x \n", (long)ss);
00117 
00118   asm("stopHere:\n hlt\n jmp stopHere\n");
00119   //exit (0);
00120 }

Generated on Sun Nov 21 18:26:11 2004 for ndk by doxygen 1.3.2