traps.c 2.6 KB

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