interrupts.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2003
  4. * Texas Instruments <www.ti.com>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Marius Groeger <mgroeger@sysgo.de>
  9. *
  10. * (C) Copyright 2002
  11. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  12. * Alex Zuepke <azu@sysgo.de>
  13. *
  14. * (C) Copyright 2002-2004
  15. * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
  16. *
  17. * (C) Copyright 2004
  18. * Philippe Robin, ARM Ltd. <philippe.robin@arm.com>
  19. */
  20. #include <common.h>
  21. #include <cpu_func.h>
  22. #include <efi_loader.h>
  23. #include <irq_func.h>
  24. #include <asm/proc-armv/ptrace.h>
  25. #include <asm/ptrace.h>
  26. #include <asm/u-boot-arm.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. int interrupt_init(void)
  29. {
  30. /*
  31. * setup up stacks if necessary
  32. */
  33. IRQ_STACK_START_IN = gd->irq_sp + 8;
  34. enable_interrupts();
  35. return 0;
  36. }
  37. void enable_interrupts(void)
  38. {
  39. return;
  40. }
  41. int disable_interrupts(void)
  42. {
  43. return 0;
  44. }
  45. void bad_mode (void)
  46. {
  47. panic ("Resetting CPU ...\n");
  48. reset_cpu(0);
  49. }
  50. static void show_efi_loaded_images(struct pt_regs *regs)
  51. {
  52. efi_print_image_infos((void *)instruction_pointer(regs));
  53. }
  54. static void dump_instr(struct pt_regs *regs)
  55. {
  56. unsigned long addr = instruction_pointer(regs);
  57. const int thumb = thumb_mode(regs);
  58. const int width = thumb ? 4 : 8;
  59. int i;
  60. if (thumb)
  61. addr &= ~1L;
  62. else
  63. addr &= ~3L;
  64. printf("Code: ");
  65. for (i = -4; i < 1 + !!thumb; i++) {
  66. unsigned int val;
  67. if (thumb)
  68. val = ((u16 *)addr)[i];
  69. else
  70. val = ((u32 *)addr)[i];
  71. printf(i == 0 ? "(%0*x) " : "%0*x ", width, val);
  72. }
  73. printf("\n");
  74. }
  75. void show_regs (struct pt_regs *regs)
  76. {
  77. unsigned long __maybe_unused flags;
  78. const char __maybe_unused *processor_modes[] = {
  79. "USER_26", "FIQ_26", "IRQ_26", "SVC_26",
  80. "UK4_26", "UK5_26", "UK6_26", "UK7_26",
  81. "UK8_26", "UK9_26", "UK10_26", "UK11_26",
  82. "UK12_26", "UK13_26", "UK14_26", "UK15_26",
  83. "USER_32", "FIQ_32", "IRQ_32", "SVC_32",
  84. "UK4_32", "UK5_32", "UK6_32", "ABT_32",
  85. "UK8_32", "UK9_32", "HYP_32", "UND_32",
  86. "UK12_32", "UK13_32", "UK14_32", "SYS_32",
  87. };
  88. flags = condition_codes (regs);
  89. printf("pc : [<%08lx>] lr : [<%08lx>]\n",
  90. instruction_pointer(regs), regs->ARM_lr);
  91. if (gd->flags & GD_FLG_RELOC) {
  92. printf("reloc pc : [<%08lx>] lr : [<%08lx>]\n",
  93. instruction_pointer(regs) - gd->reloc_off,
  94. regs->ARM_lr - gd->reloc_off);
  95. }
  96. printf("sp : %08lx ip : %08lx fp : %08lx\n",
  97. regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
  98. printf ("r10: %08lx r9 : %08lx r8 : %08lx\n",
  99. regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
  100. printf ("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
  101. regs->ARM_r7, regs->ARM_r6, regs->ARM_r5, regs->ARM_r4);
  102. printf ("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
  103. regs->ARM_r3, regs->ARM_r2, regs->ARM_r1, regs->ARM_r0);
  104. printf ("Flags: %c%c%c%c",
  105. flags & CC_N_BIT ? 'N' : 'n',
  106. flags & CC_Z_BIT ? 'Z' : 'z',
  107. flags & CC_C_BIT ? 'C' : 'c', flags & CC_V_BIT ? 'V' : 'v');
  108. printf (" IRQs %s FIQs %s Mode %s%s\n",
  109. interrupts_enabled (regs) ? "on" : "off",
  110. fast_interrupts_enabled (regs) ? "on" : "off",
  111. processor_modes[processor_mode (regs)],
  112. thumb_mode (regs) ? " (T)" : "");
  113. dump_instr(regs);
  114. }
  115. /* fixup PC to point to the instruction leading to the exception */
  116. static inline void fixup_pc(struct pt_regs *regs, int offset)
  117. {
  118. uint32_t pc = instruction_pointer(regs) + offset;
  119. regs->ARM_pc = pc | (regs->ARM_pc & PCMASK);
  120. }
  121. void do_undefined_instruction (struct pt_regs *pt_regs)
  122. {
  123. efi_restore_gd();
  124. printf ("undefined instruction\n");
  125. fixup_pc(pt_regs, -4);
  126. show_regs (pt_regs);
  127. show_efi_loaded_images(pt_regs);
  128. bad_mode ();
  129. }
  130. void do_software_interrupt (struct pt_regs *pt_regs)
  131. {
  132. efi_restore_gd();
  133. printf ("software interrupt\n");
  134. fixup_pc(pt_regs, -4);
  135. show_regs (pt_regs);
  136. show_efi_loaded_images(pt_regs);
  137. bad_mode ();
  138. }
  139. void do_prefetch_abort (struct pt_regs *pt_regs)
  140. {
  141. efi_restore_gd();
  142. printf ("prefetch abort\n");
  143. fixup_pc(pt_regs, -8);
  144. show_regs (pt_regs);
  145. show_efi_loaded_images(pt_regs);
  146. bad_mode ();
  147. }
  148. void do_data_abort (struct pt_regs *pt_regs)
  149. {
  150. efi_restore_gd();
  151. printf ("data abort\n");
  152. fixup_pc(pt_regs, -8);
  153. show_regs (pt_regs);
  154. show_efi_loaded_images(pt_regs);
  155. bad_mode ();
  156. }
  157. void do_not_used (struct pt_regs *pt_regs)
  158. {
  159. efi_restore_gd();
  160. printf ("not used\n");
  161. fixup_pc(pt_regs, -8);
  162. show_regs (pt_regs);
  163. show_efi_loaded_images(pt_regs);
  164. bad_mode ();
  165. }
  166. void do_fiq (struct pt_regs *pt_regs)
  167. {
  168. efi_restore_gd();
  169. printf ("fast interrupt request\n");
  170. fixup_pc(pt_regs, -8);
  171. show_regs (pt_regs);
  172. show_efi_loaded_images(pt_regs);
  173. bad_mode ();
  174. }
  175. void do_irq (struct pt_regs *pt_regs)
  176. {
  177. efi_restore_gd();
  178. printf ("interrupt request\n");
  179. fixup_pc(pt_regs, -8);
  180. show_regs (pt_regs);
  181. show_efi_loaded_images(pt_regs);
  182. bad_mode ();
  183. }