exc.c 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2018 bzt (bztsrc@github)
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. */
  25. #include "uart.h"
  26. /**
  27. * common exception handler
  28. */
  29. void exc_handler(unsigned long type, unsigned long esr, unsigned long elr, unsigned long spsr, unsigned long far)
  30. {
  31. // print out interruption type
  32. switch(type) {
  33. case 0: uart_puts("Synchronous"); break;
  34. case 1: uart_puts("IRQ"); break;
  35. case 2: uart_puts("FIQ"); break;
  36. case 3: uart_puts("SError"); break;
  37. }
  38. uart_puts(": ");
  39. // decode exception type (some, not all. See ARM DDI0487B_b chapter D10.2.28)
  40. switch(esr>>26) {
  41. case 0b000000: uart_puts("Unknown"); break;
  42. case 0b000001: uart_puts("Trapped WFI/WFE"); break;
  43. case 0b001110: uart_puts("Illegal execution"); break;
  44. case 0b010101: uart_puts("System call"); break;
  45. case 0b100000: uart_puts("Instruction abort, lower EL"); break;
  46. case 0b100001: uart_puts("Instruction abort, same EL"); break;
  47. case 0b100010: uart_puts("Instruction alignment fault"); break;
  48. case 0b100100: uart_puts("Data abort, lower EL"); break;
  49. case 0b100101: uart_puts("Data abort, same EL"); break;
  50. case 0b100110: uart_puts("Stack alignment fault"); break;
  51. case 0b101100: uart_puts("Floating point"); break;
  52. default: uart_puts("Unknown"); break;
  53. }
  54. // decode data abort cause
  55. if(esr>>26==0b100100 || esr>>26==0b100101) {
  56. uart_puts(", ");
  57. switch((esr>>2)&0x3) {
  58. case 0: uart_puts("Address size fault"); break;
  59. case 1: uart_puts("Translation fault"); break;
  60. case 2: uart_puts("Access flag fault"); break;
  61. case 3: uart_puts("Permission fault"); break;
  62. }
  63. switch(esr&0x3) {
  64. case 0: uart_puts(" at level 0"); break;
  65. case 1: uart_puts(" at level 1"); break;
  66. case 2: uart_puts(" at level 2"); break;
  67. case 3: uart_puts(" at level 3"); break;
  68. }
  69. }
  70. // dump registers
  71. uart_puts(":\n ESR_EL1 ");
  72. uart_hex(esr>>32);
  73. uart_hex(esr);
  74. uart_puts(" ELR_EL1 ");
  75. uart_hex(elr>>32);
  76. uart_hex(elr);
  77. uart_puts("\n SPSR_EL1 ");
  78. uart_hex(spsr>>32);
  79. uart_hex(spsr);
  80. uart_puts(" FAR_EL1 ");
  81. uart_hex(far>>32);
  82. uart_hex(far);
  83. uart_puts("\n");
  84. // no return from exception for now
  85. while(1);
  86. }