blob: 7a682f256a65cdc4e49673ed2b9d631f9b354cbf [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Daniel Schwierzecke8d31552016-01-09 18:34:14 +01002/*
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 Schwierzecke8d31552016-01-09 18:34:14 +010011 */
12
13#include <common.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Simon Glass6b9f0102020-05-10 11:40:06 -060015#include <asm/ptrace.h>
Simon Glass63334482019-11-14 12:57:39 -070016#include <cpu_func.h>
Simon Glassf11478f2019-12-28 10:45:07 -070017#include <hang.h>
Simon Glass537ecc92019-11-14 12:57:48 -070018#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Daniel Schwierzecke8d31552016-01-09 18:34:14 +010020#include <asm/mipsregs.h>
21#include <asm/addrspace.h>
22#include <asm/system.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
developer5cbbd712020-04-21 09:28:25 +020026static unsigned long saved_ebase;
27
Daniel Schwierzecke8d31552016-01-09 18:34:14 +010028static void show_regs(const struct pt_regs *regs)
29{
30 const int field = 2 * sizeof(unsigned long);
31 unsigned int cause = regs->cp0_cause;
32 unsigned int exccode;
33 int i;
34
35 /*
36 * Saved main processor registers
37 */
38 for (i = 0; i < 32; ) {
39 if ((i % 4) == 0)
40 printf("$%2d :", i);
41 if (i == 0)
42 printf(" %0*lx", field, 0UL);
43 else if (i == 26 || i == 27)
44 printf(" %*s", field, "");
45 else
46 printf(" %0*lx", field, regs->regs[i]);
47
48 i++;
49 if ((i % 4) == 0)
50 puts("\n");
51 }
52
53 printf("Hi : %0*lx\n", field, regs->hi);
54 printf("Lo : %0*lx\n", field, regs->lo);
55
56 /*
57 * Saved cp0 registers
58 */
59 printf("epc : %0*lx (text %0*lx)\n", field, regs->cp0_epc,
60 field, regs->cp0_epc - gd->reloc_off);
61 printf("ra : %0*lx (text %0*lx)\n", field, regs->regs[31],
62 field, regs->regs[31] - gd->reloc_off);
63
64 printf("Status: %08x\n", (uint32_t) regs->cp0_status);
65
66 exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
67 printf("Cause : %08x (ExcCode %02x)\n", cause, exccode);
68
69 if (1 <= exccode && exccode <= 5)
70 printf("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
71
72 printf("PrId : %08x\n", read_c0_prid());
73}
74
75void do_reserved(const struct pt_regs *regs)
76{
77 puts("\nOoops:\n");
78 show_regs(regs);
79 hang();
80}
81
82void do_ejtag_debug(const struct pt_regs *regs)
83{
84 const int field = 2 * sizeof(unsigned long);
85 unsigned long depc;
86 unsigned int debug;
87
88 depc = read_c0_depc();
89 debug = read_c0_debug();
90
91 printf("SDBBP EJTAG debug exception: c0_depc = %0*lx, DEBUG = %08x\n",
92 field, depc, debug);
93}
94
95static void set_handler(unsigned long offset, void *addr, unsigned long size)
96{
97 unsigned long ebase = gd->irq_sp;
98
99 memcpy((void *)(ebase + offset), addr, size);
100 flush_cache(ebase + offset, size);
101}
102
Ovidiu Panait2c823912020-11-28 10:43:18 +0200103static void trap_init(ulong reloc_addr)
Daniel Schwierzecke8d31552016-01-09 18:34:14 +0100104{
105 unsigned long ebase = gd->irq_sp;
106
107 set_handler(0x180, &except_vec3_generic, 0x80);
108 set_handler(0x280, &except_vec_ejtag_debug, 0x80);
109
developer5cbbd712020-04-21 09:28:25 +0200110 saved_ebase = read_c0_ebase() & 0xfffff000;
111
Stefan Roesefb79cbd2020-05-14 11:59:06 +0200112 /* Set WG bit on Octeon to enable writing to bits 63:30 */
113 if (IS_ENABLED(CONFIG_ARCH_OCTEON))
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200114 ebase |= MIPS_EBASE_WG;
Stefan Roesefb79cbd2020-05-14 11:59:06 +0200115
Daniel Schwierzecke8d31552016-01-09 18:34:14 +0100116 write_c0_ebase(ebase);
117 clear_c0_status(ST0_BEV);
118 execution_hazard_barrier();
119}
developer5cbbd712020-04-21 09:28:25 +0200120
121void trap_restore(void)
122{
123 set_c0_status(ST0_BEV);
124 execution_hazard_barrier();
125
126#ifdef CONFIG_OVERRIDE_EXCEPTION_VECTOR_BASE
127 write_c0_ebase(CONFIG_NEW_EXCEPTION_VECTOR_BASE & 0xfffff000);
128#else
129 write_c0_ebase(saved_ebase);
130#endif
131
132 clear_c0_status(ST0_BEV);
133 execution_hazard_barrier();
134}
Ovidiu Panait2c823912020-11-28 10:43:18 +0200135
136int arch_initr_trap(void)
137{
Tom Rinibb4dd962022-11-16 13:10:37 -0500138 trap_init(CFG_SYS_SDRAM_BASE);
Ovidiu Panait2c823912020-11-28 10:43:18 +0200139
140 return 0;
141}