exceptions.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engström, Omicron Ceti AB, daniel@omicron.se.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/interrupt.h>
  25. asm (".globl exp_return\n"
  26. "exp_return:\n"
  27. " addl $12, %esp\n"
  28. " pop %esp\n"
  29. " popa\n"
  30. " iret\n");
  31. char exception_stack[4096];
  32. /*
  33. * For detailed description of each exception, refer to:
  34. * Intel® 64 and IA-32 Architectures Software Developer's Manual
  35. * Volume 1: Basic Architecture
  36. * Order Number: 253665-029US, November 2008
  37. * Table 6-1. Exceptions and Interrupts
  38. */
  39. DECLARE_EXCEPTION(0, divide_error_entry);
  40. DECLARE_EXCEPTION(1, debug_entry);
  41. DECLARE_EXCEPTION(2, nmi_interrupt_entry);
  42. DECLARE_EXCEPTION(3, breakpoint_entry);
  43. DECLARE_EXCEPTION(4, overflow_entry);
  44. DECLARE_EXCEPTION(5, bound_range_exceeded_entry);
  45. DECLARE_EXCEPTION(6, invalid_opcode_entry);
  46. DECLARE_EXCEPTION(7, device_not_available_entry);
  47. DECLARE_EXCEPTION(8, double_fault_entry);
  48. DECLARE_EXCEPTION(9, coprocessor_segment_overrun_entry);
  49. DECLARE_EXCEPTION(10, invalid_tss_entry);
  50. DECLARE_EXCEPTION(11, segment_not_present_entry);
  51. DECLARE_EXCEPTION(12, stack_segment_fault_entry);
  52. DECLARE_EXCEPTION(13, general_protection_entry);
  53. DECLARE_EXCEPTION(14, page_fault_entry);
  54. DECLARE_EXCEPTION(15, reserved_exception_entry);
  55. DECLARE_EXCEPTION(16, floating_point_error_entry);
  56. DECLARE_EXCEPTION(17, alignment_check_entry);
  57. DECLARE_EXCEPTION(18, machine_check_entry);
  58. DECLARE_EXCEPTION(19, simd_floating_point_exception_entry);
  59. DECLARE_EXCEPTION(20, reserved_exception_entry);
  60. DECLARE_EXCEPTION(21, reserved_exception_entry);
  61. DECLARE_EXCEPTION(22, reserved_exception_entry);
  62. DECLARE_EXCEPTION(23, reserved_exception_entry);
  63. DECLARE_EXCEPTION(24, reserved_exception_entry);
  64. DECLARE_EXCEPTION(25, reserved_exception_entry);
  65. DECLARE_EXCEPTION(26, reserved_exception_entry);
  66. DECLARE_EXCEPTION(27, reserved_exception_entry);
  67. DECLARE_EXCEPTION(28, reserved_exception_entry);
  68. DECLARE_EXCEPTION(29, reserved_exception_entry);
  69. DECLARE_EXCEPTION(30, reserved_exception_entry);
  70. DECLARE_EXCEPTION(31, reserved_exception_entry);
  71. __isr__ reserved_exception_entry(int cause, int ip, int seg)
  72. {
  73. printf("Reserved Exception %d at %04x:%08x\n", cause, seg, ip);
  74. }
  75. __isr__ divide_error_entry(int cause, int ip, int seg)
  76. {
  77. printf("Divide Error (Division by zero) at %04x:%08x\n", seg, ip);
  78. while(1);
  79. }
  80. __isr__ debug_entry(int cause, int ip, int seg)
  81. {
  82. printf("Debug Interrupt (Single step) at %04x:%08x\n", seg, ip);
  83. }
  84. __isr__ nmi_interrupt_entry(int cause, int ip, int seg)
  85. {
  86. printf("NMI Interrupt at %04x:%08x\n", seg, ip);
  87. }
  88. __isr__ breakpoint_entry(int cause, int ip, int seg)
  89. {
  90. printf("Breakpoint at %04x:%08x\n", seg, ip);
  91. }
  92. __isr__ overflow_entry(int cause, int ip, int seg)
  93. {
  94. printf("Overflow at %04x:%08x\n", seg, ip);
  95. while(1);
  96. }
  97. __isr__ bound_range_exceeded_entry(int cause, int ip, int seg)
  98. {
  99. printf("BOUND Range Exceeded at %04x:%08x\n", seg, ip);
  100. while(1);
  101. }
  102. __isr__ invalid_opcode_entry(int cause, int ip, int seg)
  103. {
  104. printf("Invalid Opcode (UnDefined Opcode) at %04x:%08x\n", seg, ip);
  105. while(1);
  106. }
  107. __isr__ device_not_available_entry(int cause, int ip, int seg)
  108. {
  109. printf("Device Not Available (No Math Coprocessor) at %04x:%08x\n", seg, ip);
  110. while(1);
  111. }
  112. __isr__ double_fault_entry(int cause, int ip, int seg)
  113. {
  114. printf("Double fault at %04x:%08x\n", seg, ip);
  115. while(1);
  116. }
  117. __isr__ coprocessor_segment_overrun_entry(int cause, int ip, int seg)
  118. {
  119. printf("Co-processor segment overrun at %04x:%08x\n", seg, ip);
  120. while(1);
  121. }
  122. __isr__ invalid_tss_entry(int cause, int ip, int seg)
  123. {
  124. printf("Invalid TSS at %04x:%08x\n", seg, ip);
  125. }
  126. __isr__ segment_not_present_entry(int cause, int ip, int seg)
  127. {
  128. printf("Segment Not Present at %04x:%08x\n", seg, ip);
  129. while(1);
  130. }
  131. __isr__ stack_segment_fault_entry(int cause, int ip, int seg)
  132. {
  133. printf("Stack Segment Fault at %04x:%08x\n", seg, ip);
  134. while(1);
  135. }
  136. __isr__ general_protection_entry(int cause, int ip, int seg)
  137. {
  138. printf("General Protection at %04x:%08x\n", seg, ip);
  139. }
  140. __isr__ page_fault_entry(int cause, int ip, int seg)
  141. {
  142. printf("Page fault at %04x:%08x\n", seg, ip);
  143. while(1);
  144. }
  145. __isr__ floating_point_error_entry(int cause, int ip, int seg)
  146. {
  147. printf("Floating-Point Error (Math Fault) at %04x:%08x\n", seg, ip);
  148. }
  149. __isr__ alignment_check_entry(int cause, int ip, int seg)
  150. {
  151. printf("Alignment check at %04x:%08x\n", seg, ip);
  152. }
  153. __isr__ machine_check_entry(int cause, int ip, int seg)
  154. {
  155. printf("Machine Check at %04x:%08x\n", seg, ip);
  156. }
  157. __isr__ simd_floating_point_exception_entry(int cause, int ip, int seg)
  158. {
  159. printf("SIMD Floating-Point Exception at %04x:%08x\n", seg, ip);
  160. }
  161. int cpu_init_exceptions(void)
  162. {
  163. /* Just in case... */
  164. disable_interrupts();
  165. /* Setup exceptions */
  166. set_vector(0x00, exp_0);
  167. set_vector(0x01, exp_1);
  168. set_vector(0x02, exp_2);
  169. set_vector(0x03, exp_3);
  170. set_vector(0x04, exp_4);
  171. set_vector(0x05, exp_5);
  172. set_vector(0x06, exp_6);
  173. set_vector(0x07, exp_7);
  174. set_vector(0x08, exp_8);
  175. set_vector(0x09, exp_9);
  176. set_vector(0x0a, exp_10);
  177. set_vector(0x0b, exp_11);
  178. set_vector(0x0c, exp_12);
  179. set_vector(0x0d, exp_13);
  180. set_vector(0x0e, exp_14);
  181. set_vector(0x0f, exp_15);
  182. set_vector(0x10, exp_16);
  183. set_vector(0x11, exp_17);
  184. set_vector(0x12, exp_18);
  185. set_vector(0x13, exp_19);
  186. set_vector(0x14, exp_20);
  187. set_vector(0x15, exp_21);
  188. set_vector(0x16, exp_22);
  189. set_vector(0x17, exp_23);
  190. set_vector(0x18, exp_24);
  191. set_vector(0x19, exp_25);
  192. set_vector(0x1a, exp_26);
  193. set_vector(0x1b, exp_27);
  194. set_vector(0x1c, exp_28);
  195. set_vector(0x1d, exp_29);
  196. set_vector(0x1e, exp_30);
  197. set_vector(0x1f, exp_31);
  198. /* It is now safe to enable interrupts */
  199. enable_interrupts();
  200. return 0;
  201. }