Guest User

ISRs C code

a guest
Sep 26th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.68 KB | None | 0 0
  1. #include <stdint.h>
  2. #include "isrs.h"
  3.  
  4. extern int printf(char *fmt, ...);
  5.  
  6. void isrs_install()
  7. {
  8.     idt_set_gate(0, (uint32_t) isr0, 0x08, 0x8E);
  9.     idt_set_gate(1, (uint32_t) isr1, 0x08, 0x8E);
  10.     idt_set_gate(2, (uint32_t) isr2, 0x08, 0x8E);
  11.     idt_set_gate(3, (uint32_t) isr3, 0x08, 0x8E);
  12.     idt_set_gate(4, (uint32_t) isr4, 0x08, 0x8E);
  13.     idt_set_gate(5, (uint32_t) isr5, 0x08, 0x8E);
  14.     idt_set_gate(6, (uint32_t) isr6, 0x08, 0x8E);
  15.     idt_set_gate(7, (uint32_t) isr7, 0x08, 0x8E);
  16.     idt_set_gate(8, (uint32_t) isr8, 0x08, 0x8E);
  17.     idt_set_gate(9, (uint32_t) isr9, 0x08, 0x8E);
  18.     idt_set_gate(10, (uint32_t) isr10, 0x08, 0x8E);
  19.     idt_set_gate(11, (uint32_t) isr11, 0x08, 0x8E);
  20.     idt_set_gate(12, (uint32_t) isr12, 0x08, 0x8E);
  21.     idt_set_gate(13, (uint32_t) isr13, 0x08, 0x8E);
  22.     idt_set_gate(14, (uint32_t) isr14, 0x08, 0x8E);
  23.     idt_set_gate(15, (uint32_t) isr15, 0x08, 0x8E);
  24.     idt_set_gate(16, (uint32_t) isr16, 0x08, 0x8E);
  25.     idt_set_gate(17, (uint32_t) isr17, 0x08, 0x8E);
  26.     idt_set_gate(18, (uint32_t) isr18, 0x08, 0x8E);
  27.     idt_set_gate(19, (uint32_t) isr19, 0x08, 0x8E);
  28.     idt_set_gate(20, (uint32_t) isr20, 0x08, 0x8E);
  29.     idt_set_gate(21, (uint32_t) isr21, 0x08, 0x8E);
  30.     idt_set_gate(22, (uint32_t) isr22, 0x08, 0x8E);
  31.     idt_set_gate(23, (uint32_t) isr23, 0x08, 0x8E);
  32.     idt_set_gate(24, (uint32_t) isr24, 0x08, 0x8E);
  33.     idt_set_gate(25, (uint32_t) isr25, 0x08, 0x8E);
  34.     idt_set_gate(26, (uint32_t) isr26, 0x08, 0x8E);
  35.     idt_set_gate(27, (uint32_t) isr27, 0x08, 0x8E);
  36.     idt_set_gate(28, (uint32_t) isr28, 0x08, 0x8E);
  37.     idt_set_gate(29, (uint32_t) isr29, 0x08, 0x8E);
  38.     idt_set_gate(30, (uint32_t) isr30, 0x08, 0x8E);
  39.     idt_set_gate(31, (uint32_t) isr31, 0x08, 0x8E);
  40. }
  41.  
  42. unsigned char *exception_message[] =
  43. {
  44.     "Division By Zero",
  45.     "Debug Exception",
  46.     "Non Maskable Interrupt Exception",
  47.     "Breakpoint Exception",
  48.     "Into Detected Overflow Exception",
  49.     "Out of Bounds Exception",
  50.     "Invalid Opcode Exception",
  51.     "No Coprocessor Exception",
  52.     "Double Fault Exception",
  53.     "Coprocessor Segment Overrun Exception",
  54.     "Bad TSS Exception",
  55.     "Segment Not Present Exception",
  56.     "Stack Fault Exception",
  57.     "General Protection Fault Exception",
  58.     "Page Fault Exception",
  59.     "Unknown Interrupt Exception",
  60.     "Coprocessor Fault Exception",
  61.     "Alignment Check Exception",
  62.     "Machine Check Exception",
  63.     "Reserved",
  64.     "Reserved",
  65.     "Reserved",
  66.     "Reserved",
  67.     "Reserved",
  68.     "Reserved",
  69.     "Reserved",
  70.     "Reserved",
  71.     "Reserved",
  72.     "Reserved",
  73.     "Reserved",
  74.     "Reserved",
  75.     "Reserved",
  76. };
  77.  
  78. void fault_handler(struct regs *r)
  79. {
  80.     if (r->int_no < 32)
  81.     {
  82.         /* display description of exception that has occured */
  83.        
  84.         printf("%s\n", exception_message[r->int_no]);
  85.         printf("Exception caught. System halted");
  86.        
  87.         for(;;);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment