interrupts.c 4.7 KB

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