Guest User

isr.c

a guest
Sep 5th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <kernel/idt.h>
  3. #include <kernel/isr.h>
  4. #include <stdio.h>
  5.  
  6. extern void isr0(); // All our ISRs
  7. extern void isr1();
  8. extern void isr2();
  9. extern void isr3();
  10. extern void isr4();
  11. extern void isr5();
  12. extern void isr6();
  13. extern void isr7();
  14. extern void isr8();
  15. extern void isr9();
  16. extern void isr10();
  17. extern void isr11();
  18. extern void isr12();
  19. extern void isr13();
  20. extern void isr14();
  21. extern void isr15();
  22. extern void isr16();
  23. extern void isr17();
  24. extern void isr18();
  25. extern void isr19();
  26. extern void isr20();
  27. extern void isr21();
  28. extern void isr22();
  29. extern void isr23();
  30. extern void isr24();
  31. extern void isr25();
  32. extern void isr26();
  33. extern void isr27();
  34. extern void isr28();
  35. extern void isr29();
  36. extern void isr30();
  37. extern void isr31();
  38.  
  39. void loadisr (void) {
  40.  
  41. idt_setgate(0, (uint32_t)isr0, 0x08, 0x8e); // Populate the IDT with addresses of ISR to call, with appropriate segment and flags
  42. idt_setgate(1, (uint32_t)isr1, 0x08, 0x8e);
  43. idt_setgate(2, (uint32_t)isr2, 0x08, 0x8e);
  44. idt_setgate(3, (uint32_t)isr3, 0x08, 0x8e);
  45. idt_setgate(4, (uint32_t)isr4, 0x08, 0x8e);
  46. idt_setgate(5, (uint32_t)isr5, 0x08, 0x8e);
  47. idt_setgate(6, (uint32_t)isr6, 0x08, 0x8e);
  48. idt_setgate(7, (uint32_t)isr7, 0x08, 0x8e);
  49. idt_setgate(8, (uint32_t)isr8, 0x08, 0x8e);
  50. idt_setgate(9, (uint32_t)isr9, 0x08, 0x8e);
  51. idt_setgate(10, (uint32_t)isr10, 0x08, 0x8e);
  52. idt_setgate(11, (uint32_t)isr11, 0x08, 0x8e);
  53. idt_setgate(12, (uint32_t)isr12, 0x08, 0x8e);
  54. idt_setgate(13, (uint32_t)isr13, 0x08, 0x8e);
  55. idt_setgate(14, (uint32_t)isr14, 0x08, 0x8e);
  56. idt_setgate(15, (uint32_t)isr15, 0x08, 0x8e);
  57. idt_setgate(16, (uint32_t)isr16, 0x08, 0x8e);
  58. idt_setgate(17, (uint32_t)isr17, 0x08, 0x8e);
  59. idt_setgate(18, (uint32_t)isr18, 0x08, 0x8e);
  60. idt_setgate(19, (uint32_t)isr19, 0x08, 0x8e);
  61. idt_setgate(20, (uint32_t)isr20, 0x08, 0x8e);
  62. idt_setgate(21, (uint32_t)isr21, 0x08, 0x8e);
  63. idt_setgate(22, (uint32_t)isr22, 0x08, 0x8e);
  64. idt_setgate(23, (uint32_t)isr23, 0x08, 0x8e);
  65. idt_setgate(24, (uint32_t)isr24, 0x08, 0x8e);
  66. idt_setgate(25, (uint32_t)isr25, 0x08, 0x8e);
  67. idt_setgate(26, (uint32_t)isr26, 0x08, 0x8e);
  68. idt_setgate(27, (uint32_t)isr27, 0x08, 0x8e);
  69. idt_setgate(28, (uint32_t)isr28, 0x08, 0x8e);
  70. idt_setgate(29, (uint32_t)isr29, 0x08, 0x8e);
  71. idt_setgate(30, (uint32_t)isr30, 0x08, 0x8e);
  72. idt_setgate(31, (uint32_t)isr31, 0x08, 0x8e);
  73. }
  74.  
  75. char *exceptionmsgs[] = { // Messages to print in case of specific exception.
  76.  
  77. "divide exception.",
  78. "debug error.",
  79. "non-maskable interrupt.",
  80. "breakpoint exception.",
  81. "overflow exception.",
  82. "BOUND range exceeded.",
  83. "invalid opcode.",
  84. "no Maths Coprocessor.",
  85. "double fault.",
  86. "coprocessor segment overun.",
  87. "invalid TSS exception.",
  88. "segment not present exception.",
  89. "stack segment fault.",
  90. "general protection fault.",
  91. "page fault.",
  92. "reserved exception.",
  93. "floating-point error.",
  94. "alignment check exception.",
  95. "machine check exception.",
  96. "SIMD floating point exeption.",
  97. "virtualisation exception.",
  98. "reserved exception.",
  99. "reserved exception.",
  100. "reserved exception.",
  101. "reserved exception.",
  102. "reserved exception.",
  103. "reserved exception.",
  104. "reserved exception.",
  105. "reserved exception.",
  106. "reserved exception.",
  107. "reserved exception.",
  108. "reserved exception."
  109. };
  110.  
  111. void isr_handle (struct regs *r) { // Function called from assembly (boot.S) to print out messages detailing exception and to halt.
  112.  
  113. if (r->int_no < 32) {
  114.  
  115. puts(exceptionmsgs[r->int_no]);
  116. puts("The system has been halted.");
  117.  
  118. for(;;);
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment