1 /* 2 * (C) Copyright 2013 3 * David Feng <fenghua@phytium.com.cn> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <linux/compiler.h> 10 #include <efi_loader.h> 11 12 DECLARE_GLOBAL_DATA_PTR; 13 #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_IRQ) 14 15 int interrupt_init(void) 16 { 17 return 0; 18 } 19 20 void enable_interrupts(void) 21 { 22 return; 23 } 24 25 int disable_interrupts(void) 26 { 27 return 0; 28 } 29 #endif 30 31 #if (!defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD)) 32 #define REG_BITS(val, shift, mask) (((val) >> (shift)) & (mask)) 33 34 void show_regs(struct pt_regs *regs) 35 { 36 int i; 37 int el = current_el(); 38 const char *h_scr_name[] = { 39 [2] = "HCR_EL2", 40 [3] = "SCR_EL3", 41 }; 42 const char *esr_bits_ec[] = { 43 [0] = "EC[31:26] == 000000, Exception with an unknown reason", 44 [1] = "EC[31:26] == 000001, Exception from a WFI or WFE instruction", 45 [3] = "EC[31:26] == 000011, Exception from an MCR or MRC access", 46 [4] = "EC[31:26] == 000100, Exception from an MCRR or MRRC access", 47 [5] = "EC[31:26] == 000101, Exception from an MCR or MRC access", 48 [6] = "EC[31:26] == 000110, Exception from an LDC or STC access to CP14", 49 [7] = "EC[31:26] == 000111, Exception from an access to an Advanced SIMD or floating-point register, resulting from CPACR_EL1.FPEN or CPTR_ELx.TFP", 50 [8] = "EC[31:26] == 001000, Exception from an MCR or MRC access", 51 [12] = "EC[31:26] == 001100, Exception from an MCRR or MRRC access", 52 [14] = "EC[31:26] == 001110, Exception from an Illegal execution state, or a PC or SP alignment fault", 53 [10] = "EC[31:26] == 010001, Exception from HVC or SVC instruction execution", 54 [18] = "EC[31:26] == 010010, Exception from HVC or SVC instruction execution", 55 [19] = "EC[31:26] == 010011, Exception from SMC instruction execution in AArch32 state", 56 [21] = "EC[31:26] == 010101, Exception from HVC or SVC instruction execution", 57 [22] = "EC[31:26] == 010110, Exception from HVC or SVC instruction execution", 58 [23] = "EC[31:26] == 010111, Exception from SMC instruction execution in AArch64 state", 59 [24] = "EC[31:26] == 011000, Exception from MSR, MRS, or System instruction execution in AArch64 state", 60 [31] = "EC[31:26] == 011111, IMPLEMENTATION DEFINED exception to EL3", 61 [32] = "EC[31:26] == 100000, Exception from an Instruction abort", 62 [33] = "EC[31:26] == 100001, Exception from an Instruction abort", 63 [34] = "EC[31:26] == 100010, Exception from an Illegal execution state, or a PC or SP alignment fault", 64 [36] = "EC[31:26] == 100100, Exception from a Data abort, from lower exception level", 65 [37] = "EC[31:26] == 100101, Exception from a Data abort, from current exception level", 66 [38] = "EC[31:26] == 100110, Exception from an Illegal execution state, or a PC or SP alignment fault", 67 [40] = "EC[31:26] == 101000, Exception from a trapped Floating-point exception", 68 [44] = "EC[31:26] == 101100, Exception from a trapped Floating-point exception", 69 [47] = "EC[31:26] == 101111, SError interrupt", 70 [48] = "EC[31:26] == 110000, Exception from a Breakpoint or Vector Catch debug event", 71 [49] = "EC[31:26] == 110001, Exception from a Breakpoint or Vector Catch debug event", 72 [50] = "EC[31:26] == 110010, Exception from a Software Step debug event", 73 [51] = "EC[31:26] == 110011, Exception from a Software Step debug event", 74 [52] = "EC[31:26] == 110100, Exception from a Watchpoint debug event", 75 [53] = "EC[31:26] == 110101, Exception from a Watchpoint debug event", 76 [56] = "EC[31:26] == 111000, Exception from execution of a Software Breakpoint instructio", 77 }; 78 const char *esr_bits_il[] = { 79 "IL[25] == 0, 16-bit instruction trapped", 80 "IL[25] == 1, 32-bit instruction trapped", 81 }; 82 const char *daif_bits_f[] = { 83 "F[6] == 0, FIQ not masked", 84 "F[6] == 1, FIQ masked", 85 }; 86 const char *daif_bits_i[] = { 87 "I[7] == 0, IRQ not masked", 88 "I[7] == 1, IRQ masked", 89 }; 90 const char *daif_bits_a[] = { 91 "A[8] == 0, ABORT not masked", 92 "A[8] == 1, ABORT masked", 93 }; 94 const char *daif_bits_d[] = { 95 "D[9] == 0, DBG not masked", 96 "D[9] == 1, DBG masked", 97 }; 98 const char *spsr_bits_m_aarch32[] = { 99 [0] = "M[3:0] == 0000, User", 100 [1] = "M[3:0] == 0001, FIQ", 101 [2] = "M[3:0] == 0010, IRQ", 102 [3] = "M[3:0] == 0011, Supervisor", 103 [6] = "M[3:0] == 0110, Monitor", 104 [7] = "M[3:0] == 0111, Abort", 105 [10] = "M[3:0] == 1010, Hyp", 106 [11] = "M[3:0] == 1011, Undefined", 107 [15] = "M[3:0] == 1111, System", 108 }; 109 const char *spsr_bits_m_aarch64[] = { 110 [0] = "M[3:0] == 0000, EL0t", 111 [4] = "M[3:0] == 0100, EL1t", 112 [5] = "M[3:0] == 0101, EL1h", 113 [8] = "M[3:0] == 1000, EL2t", 114 [9] = "M[3:0] == 1001, EL2h", 115 [10] = "M[3:0] == 1100, EL3t", 116 [11] = "M[3:0] == 1101, EL3h", 117 }; 118 const char *spsr_bits_m[] = { 119 "M[4] == 0, Exception taken from AArch64", 120 "M[4] == 1, Exception taken from AArch32", 121 }; 122 const char *spsr_bits_f[] = { 123 "F[6] == 0, FIQ not masked", 124 "F[6] == 1, FIQ masked", 125 }; 126 const char *spsr_bits_i[] = { 127 "I[7] == 0, IRQ not masked", 128 "I[7] == 1, IRQ masked", 129 }; 130 const char *spsr_bits_a[] = { 131 "A[8] == 0, ABORT not masked", 132 "A[8] == 1, ABORT masked", 133 }; 134 const char *spsr_bits_d[] = { 135 "D[9] == 0, DBG not masked", 136 "D[9] == 1, DBG masked", 137 }; 138 const char *sctlr_bits_i[] = { 139 "I[12] == 0, Icache disabled", 140 "I[12] == 1, Icaches enabled", 141 }; 142 const char *sctlr_bits_c[] = { 143 "C[2] == 0, Dcache disabled", 144 "C[2] == 1, Dcache enabled", 145 }; 146 const char *sctlr_bits_m[] = { 147 "M[0] == 0, MMU disabled", 148 "M[0] == 1, MMU enabled", 149 }; 150 151 printf("* Relocate offset = %016lx\n", gd->reloc_off); 152 153 if (gd->flags & GD_FLG_RELOC) { 154 printf("* ELR(PC) = %016lx\n", regs->elr - gd->reloc_off); 155 printf("* LR = %016lx\n", regs->regs[30] - gd->reloc_off); 156 } else { 157 printf("* ELR(PC) = %016lx\n", regs->elr); 158 printf("* LR = %016lx\n", regs->regs[30]); 159 } 160 161 printf("* SP = %016lx\n", regs->sp); 162 printf("\n"); 163 164 /* 165 * System registers 166 */ 167 /* ESR_EL2 */ 168 printf("* ESR_EL%d = %016lx\n", el, regs->esr); 169 printf("\t%s\n", esr_bits_ec[REG_BITS(regs->esr, 26, 0x3f)]); 170 printf("\t%s\n", esr_bits_il[REG_BITS(regs->esr, 25, 0x01)]); 171 printf("\n"); 172 /* DAIF */ 173 printf("* DAIF = %016lx\n", regs->daif); 174 printf("\t%s\n", daif_bits_d[REG_BITS(regs->daif, 9, 0x1)]); 175 printf("\t%s\n", daif_bits_a[REG_BITS(regs->daif, 8, 0x1)]); 176 printf("\t%s\n", daif_bits_i[REG_BITS(regs->daif, 7, 0x1)]); 177 printf("\t%s\n", daif_bits_f[REG_BITS(regs->daif, 6, 0x1)]); 178 printf("\n"); 179 /* SPSR_ELx */ 180 printf("* SPSR_EL%d = %016lx\n", el, regs->spsr); 181 printf("\t%s\n", spsr_bits_d[REG_BITS(regs->spsr, 9, 0x1)]); 182 printf("\t%s\n", spsr_bits_a[REG_BITS(regs->spsr, 8, 0x1)]); 183 printf("\t%s\n", spsr_bits_i[REG_BITS(regs->spsr, 7, 0x1)]); 184 printf("\t%s\n", spsr_bits_f[REG_BITS(regs->spsr, 6, 0x1)]); 185 printf("\t%s\n", spsr_bits_m[REG_BITS(regs->spsr, 4, 0x1)]); 186 if (REG_BITS(regs->spsr, 4, 0x1)) 187 printf("\t%s\n", spsr_bits_m_aarch32[REG_BITS(regs->spsr, 0, 0xf)]); 188 else 189 printf("\t%s\n", spsr_bits_m_aarch64[REG_BITS(regs->spsr, 0, 0xf)]); 190 printf("\n"); 191 /* SCTLR_EL2 */ 192 printf("* SCTLR_EL%d = %016lx\n", el, regs->sctlr); 193 printf("\t%s\n", sctlr_bits_i[REG_BITS(regs->sctlr, 12, 0x1)]); 194 printf("\t%s\n", sctlr_bits_c[REG_BITS(regs->sctlr, 2, 0x1)]); 195 printf("\t%s\n", sctlr_bits_m[REG_BITS(regs->sctlr, 0, 0x1)]); 196 printf("\n"); 197 198 /* Other */ 199 if (el >= 2) 200 printf("* %s = %016lx\n", h_scr_name[el], regs->hcr); 201 printf("* VBAR_EL%d = %016lx\n", el, regs->vbar); 202 printf("* TTBR0_EL%d = %016lx\n", el, regs->ttbr0); 203 printf("\n"); 204 205 for (i = 0; i < 29; i += 2) 206 printf("x%-2d: %016lx x%-2d: %016lx\n", 207 i, regs->regs[i], i+1, regs->regs[i+1]); 208 printf("\n"); 209 210 #ifdef CONFIG_ROCKCHIP_CRASH_DUMP 211 iomem_show_by_compatible("-cru", 0, 0x400); 212 iomem_show_by_compatible("-pmucru", 0, 0x400); 213 iomem_show_by_compatible("-grf", 0, 0x400); 214 iomem_show_by_compatible("-pmugrf", 0, 0x400); 215 /* tobe add here ... */ 216 #endif 217 } 218 219 #else 220 void show_regs(struct pt_regs *regs) 221 { 222 int i; 223 224 if (gd->flags & GD_FLG_RELOC) { 225 printf("ELR: %lx\n", regs->elr - gd->reloc_off); 226 printf("LR: %lx\n", regs->regs[30] - gd->reloc_off); 227 } else { 228 printf("ELR: %lx\n", regs->elr); 229 printf("LR: %lx\n", regs->regs[30]); 230 } 231 for (i = 0; i < 29; i += 2) 232 printf("x%-2d: %016lx x%-2d: %016lx\n", 233 i, regs->regs[i], i+1, regs->regs[i+1]); 234 printf("\n"); 235 } 236 #endif 237 238 /* 239 * do_bad_sync handles the impossible case in the Synchronous Abort vector. 240 */ 241 void do_bad_sync(struct pt_regs *pt_regs, unsigned int esr) 242 { 243 efi_restore_gd(); 244 printf("Bad mode in \"Synchronous Abort\" handler, esr 0x%08x\n", esr); 245 show_regs(pt_regs); 246 panic("Resetting CPU ...\n"); 247 } 248 249 /* 250 * do_bad_irq handles the impossible case in the Irq vector. 251 */ 252 void do_bad_irq(struct pt_regs *pt_regs, unsigned int esr) 253 { 254 efi_restore_gd(); 255 printf("Bad mode in \"Irq\" handler, esr 0x%08x\n", esr); 256 show_regs(pt_regs); 257 panic("Resetting CPU ...\n"); 258 } 259 260 /* 261 * do_bad_fiq handles the impossible case in the Fiq vector. 262 */ 263 void do_bad_fiq(struct pt_regs *pt_regs, unsigned int esr) 264 { 265 efi_restore_gd(); 266 printf("Bad mode in \"Fiq\" handler, esr 0x%08x\n", esr); 267 show_regs(pt_regs); 268 panic("Resetting CPU ...\n"); 269 } 270 271 /* 272 * do_bad_error handles the impossible case in the Error vector. 273 */ 274 void do_bad_error(struct pt_regs *pt_regs, unsigned int esr) 275 { 276 efi_restore_gd(); 277 printf("Bad mode in \"Error\" handler, esr 0x%08x\n", esr); 278 show_regs(pt_regs); 279 panic("Resetting CPU ...\n"); 280 } 281 282 /* 283 * do_sync handles the Synchronous Abort exception. 284 */ 285 void do_sync(struct pt_regs *pt_regs, unsigned int esr) 286 { 287 efi_restore_gd(); 288 printf("\"Synchronous Abort\" handler, esr 0x%08x\n", esr); 289 show_regs(pt_regs); 290 panic("Resetting CPU ...\n"); 291 } 292 293 #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_IRQ) 294 /* 295 * do_irq handles the Irq exception. 296 */ 297 void do_irq(struct pt_regs *pt_regs, unsigned int esr) 298 { 299 efi_restore_gd(); 300 printf("\"Irq\" handler, esr 0x%08x\n", esr); 301 show_regs(pt_regs); 302 panic("Resetting CPU ...\n"); 303 } 304 #endif 305 306 /* 307 * do_fiq handles the Fiq exception. 308 */ 309 void do_fiq(struct pt_regs *pt_regs, unsigned int esr) 310 { 311 efi_restore_gd(); 312 printf("\"Fiq\" handler, esr 0x%08x\n", esr); 313 show_regs(pt_regs); 314 panic("Resetting CPU ...\n"); 315 } 316 317 /* 318 * do_error handles the Error exception. 319 * Errors are more likely to be processor specific, 320 * it is defined with weak attribute and can be redefined 321 * in processor specific code. 322 */ 323 void __weak do_error(struct pt_regs *pt_regs, unsigned int esr) 324 { 325 efi_restore_gd(); 326 printf("\"Error\" handler, esr 0x%08x\n", esr); 327 show_regs(pt_regs); 328 panic("Resetting CPU ...\n"); 329 } 330