traps.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 1994 - 1999, 2000, 01, 06 Ralf Baechle
  4. * Copyright (C) 1995, 1996 Paul M. Antoine
  5. * Copyright (C) 1998 Ulf Carlsson
  6. * Copyright (C) 1999 Silicon Graphics, Inc.
  7. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  8. * Copyright (C) 2002, 2003, 2004, 2005, 2007 Maciej W. Rozycki
  9. * Copyright (C) 2000, 2001, 2012 MIPS Technologies, Inc. All rights reserved.
  10. * Copyright (C) 2014, Imagination Technologies Ltd.
  11. */
  12. #include <common.h>
  13. #include <cpu_func.h>
  14. #include <hang.h>
  15. #include <init.h>
  16. #include <asm/mipsregs.h>
  17. #include <asm/addrspace.h>
  18. #include <asm/system.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. static unsigned long saved_ebase;
  21. static void show_regs(const struct pt_regs *regs)
  22. {
  23. const int field = 2 * sizeof(unsigned long);
  24. unsigned int cause = regs->cp0_cause;
  25. unsigned int exccode;
  26. int i;
  27. /*
  28. * Saved main processor registers
  29. */
  30. for (i = 0; i < 32; ) {
  31. if ((i % 4) == 0)
  32. printf("$%2d :", i);
  33. if (i == 0)
  34. printf(" %0*lx", field, 0UL);
  35. else if (i == 26 || i == 27)
  36. printf(" %*s", field, "");
  37. else
  38. printf(" %0*lx", field, regs->regs[i]);
  39. i++;
  40. if ((i % 4) == 0)
  41. puts("\n");
  42. }
  43. printf("Hi : %0*lx\n", field, regs->hi);
  44. printf("Lo : %0*lx\n", field, regs->lo);
  45. /*
  46. * Saved cp0 registers
  47. */
  48. printf("epc : %0*lx (text %0*lx)\n", field, regs->cp0_epc,
  49. field, regs->cp0_epc - gd->reloc_off);
  50. printf("ra : %0*lx (text %0*lx)\n", field, regs->regs[31],
  51. field, regs->regs[31] - gd->reloc_off);
  52. printf("Status: %08x\n", (uint32_t) regs->cp0_status);
  53. exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
  54. printf("Cause : %08x (ExcCode %02x)\n", cause, exccode);
  55. if (1 <= exccode && exccode <= 5)
  56. printf("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
  57. printf("PrId : %08x\n", read_c0_prid());
  58. }
  59. void do_reserved(const struct pt_regs *regs)
  60. {
  61. puts("\nOoops:\n");
  62. show_regs(regs);
  63. hang();
  64. }
  65. void do_ejtag_debug(const struct pt_regs *regs)
  66. {
  67. const int field = 2 * sizeof(unsigned long);
  68. unsigned long depc;
  69. unsigned int debug;
  70. depc = read_c0_depc();
  71. debug = read_c0_debug();
  72. printf("SDBBP EJTAG debug exception: c0_depc = %0*lx, DEBUG = %08x\n",
  73. field, depc, debug);
  74. }
  75. static void set_handler(unsigned long offset, void *addr, unsigned long size)
  76. {
  77. unsigned long ebase = gd->irq_sp;
  78. memcpy((void *)(ebase + offset), addr, size);
  79. flush_cache(ebase + offset, size);
  80. }
  81. void trap_init(ulong reloc_addr)
  82. {
  83. unsigned long ebase = gd->irq_sp;
  84. set_handler(0x180, &except_vec3_generic, 0x80);
  85. set_handler(0x280, &except_vec_ejtag_debug, 0x80);
  86. saved_ebase = read_c0_ebase() & 0xfffff000;
  87. write_c0_ebase(ebase);
  88. clear_c0_status(ST0_BEV);
  89. execution_hazard_barrier();
  90. }
  91. void trap_restore(void)
  92. {
  93. set_c0_status(ST0_BEV);
  94. execution_hazard_barrier();
  95. #ifdef CONFIG_OVERRIDE_EXCEPTION_VECTOR_BASE
  96. write_c0_ebase(CONFIG_NEW_EXCEPTION_VECTOR_BASE & 0xfffff000);
  97. #else
  98. write_c0_ebase(saved_ebase);
  99. #endif
  100. clear_c0_status(ST0_BEV);
  101. execution_hazard_barrier();
  102. }