Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Daniel Schwierzeck | 6c59363 | 2016-01-09 18:34:14 +0100 | [diff] [blame] | 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. |
Daniel Schwierzeck | 6c59363 | 2016-01-09 18:34:14 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 14 | #include <cpu_func.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 15 | #include <hang.h> |
Simon Glass | d67bdaa | 2019-11-14 12:57:48 -0700 | [diff] [blame] | 16 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame^] | 17 | #include <log.h> |
Daniel Schwierzeck | 6c59363 | 2016-01-09 18:34:14 +0100 | [diff] [blame] | 18 | #include <asm/mipsregs.h> |
| 19 | #include <asm/addrspace.h> |
| 20 | #include <asm/system.h> |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Weijie Gao | 7105973 | 2020-04-21 09:28:25 +0200 | [diff] [blame] | 24 | static unsigned long saved_ebase; |
| 25 | |
Daniel Schwierzeck | 6c59363 | 2016-01-09 18:34:14 +0100 | [diff] [blame] | 26 | static void show_regs(const struct pt_regs *regs) |
| 27 | { |
| 28 | const int field = 2 * sizeof(unsigned long); |
| 29 | unsigned int cause = regs->cp0_cause; |
| 30 | unsigned int exccode; |
| 31 | int i; |
| 32 | |
| 33 | /* |
| 34 | * Saved main processor registers |
| 35 | */ |
| 36 | for (i = 0; i < 32; ) { |
| 37 | if ((i % 4) == 0) |
| 38 | printf("$%2d :", i); |
| 39 | if (i == 0) |
| 40 | printf(" %0*lx", field, 0UL); |
| 41 | else if (i == 26 || i == 27) |
| 42 | printf(" %*s", field, ""); |
| 43 | else |
| 44 | printf(" %0*lx", field, regs->regs[i]); |
| 45 | |
| 46 | i++; |
| 47 | if ((i % 4) == 0) |
| 48 | puts("\n"); |
| 49 | } |
| 50 | |
| 51 | printf("Hi : %0*lx\n", field, regs->hi); |
| 52 | printf("Lo : %0*lx\n", field, regs->lo); |
| 53 | |
| 54 | /* |
| 55 | * Saved cp0 registers |
| 56 | */ |
| 57 | printf("epc : %0*lx (text %0*lx)\n", field, regs->cp0_epc, |
| 58 | field, regs->cp0_epc - gd->reloc_off); |
| 59 | printf("ra : %0*lx (text %0*lx)\n", field, regs->regs[31], |
| 60 | field, regs->regs[31] - gd->reloc_off); |
| 61 | |
| 62 | printf("Status: %08x\n", (uint32_t) regs->cp0_status); |
| 63 | |
| 64 | exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE; |
| 65 | printf("Cause : %08x (ExcCode %02x)\n", cause, exccode); |
| 66 | |
| 67 | if (1 <= exccode && exccode <= 5) |
| 68 | printf("BadVA : %0*lx\n", field, regs->cp0_badvaddr); |
| 69 | |
| 70 | printf("PrId : %08x\n", read_c0_prid()); |
| 71 | } |
| 72 | |
| 73 | void do_reserved(const struct pt_regs *regs) |
| 74 | { |
| 75 | puts("\nOoops:\n"); |
| 76 | show_regs(regs); |
| 77 | hang(); |
| 78 | } |
| 79 | |
| 80 | void do_ejtag_debug(const struct pt_regs *regs) |
| 81 | { |
| 82 | const int field = 2 * sizeof(unsigned long); |
| 83 | unsigned long depc; |
| 84 | unsigned int debug; |
| 85 | |
| 86 | depc = read_c0_depc(); |
| 87 | debug = read_c0_debug(); |
| 88 | |
| 89 | printf("SDBBP EJTAG debug exception: c0_depc = %0*lx, DEBUG = %08x\n", |
| 90 | field, depc, debug); |
| 91 | } |
| 92 | |
| 93 | static void set_handler(unsigned long offset, void *addr, unsigned long size) |
| 94 | { |
| 95 | unsigned long ebase = gd->irq_sp; |
| 96 | |
| 97 | memcpy((void *)(ebase + offset), addr, size); |
| 98 | flush_cache(ebase + offset, size); |
| 99 | } |
| 100 | |
| 101 | void trap_init(ulong reloc_addr) |
| 102 | { |
| 103 | unsigned long ebase = gd->irq_sp; |
| 104 | |
| 105 | set_handler(0x180, &except_vec3_generic, 0x80); |
| 106 | set_handler(0x280, &except_vec_ejtag_debug, 0x80); |
| 107 | |
Weijie Gao | 7105973 | 2020-04-21 09:28:25 +0200 | [diff] [blame] | 108 | saved_ebase = read_c0_ebase() & 0xfffff000; |
| 109 | |
Daniel Schwierzeck | 6c59363 | 2016-01-09 18:34:14 +0100 | [diff] [blame] | 110 | write_c0_ebase(ebase); |
| 111 | clear_c0_status(ST0_BEV); |
| 112 | execution_hazard_barrier(); |
| 113 | } |
Weijie Gao | 7105973 | 2020-04-21 09:28:25 +0200 | [diff] [blame] | 114 | |
| 115 | void trap_restore(void) |
| 116 | { |
| 117 | set_c0_status(ST0_BEV); |
| 118 | execution_hazard_barrier(); |
| 119 | |
| 120 | #ifdef CONFIG_OVERRIDE_EXCEPTION_VECTOR_BASE |
| 121 | write_c0_ebase(CONFIG_NEW_EXCEPTION_VECTOR_BASE & 0xfffff000); |
| 122 | #else |
| 123 | write_c0_ebase(saved_ebase); |
| 124 | #endif |
| 125 | |
| 126 | clear_c0_status(ST0_BEV); |
| 127 | execution_hazard_barrier(); |
| 128 | } |