xref: /openbmc/u-boot/arch/mips/lib/traps.c (revision fc47cf9d)
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 
14 #include <common.h>
15 #include <asm/mipsregs.h>
16 #include <asm/addrspace.h>
17 #include <asm/system.h>
18 
19 DECLARE_GLOBAL_DATA_PTR;
20 
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 	/*
29 	 * Saved main processor registers
30 	 */
31 	for (i = 0; i < 32; ) {
32 		if ((i % 4) == 0)
33 			printf("$%2d   :", i);
34 		if (i == 0)
35 			printf(" %0*lx", field, 0UL);
36 		else if (i == 26 || i == 27)
37 			printf(" %*s", field, "");
38 		else
39 			printf(" %0*lx", field, regs->regs[i]);
40 
41 		i++;
42 		if ((i % 4) == 0)
43 			puts("\n");
44 	}
45 
46 	printf("Hi    : %0*lx\n", field, regs->hi);
47 	printf("Lo    : %0*lx\n", field, regs->lo);
48 
49 	/*
50 	 * Saved cp0 registers
51 	 */
52 	printf("epc   : %0*lx (text %0*lx)\n", field, regs->cp0_epc,
53 	       field, regs->cp0_epc - gd->reloc_off);
54 	printf("ra    : %0*lx (text %0*lx)\n", field, regs->regs[31],
55 	       field, regs->regs[31] - gd->reloc_off);
56 
57 	printf("Status: %08x\n", (uint32_t) regs->cp0_status);
58 
59 	exccode = (cause & CAUSEF_EXCCODE) >> CAUSEB_EXCCODE;
60 	printf("Cause : %08x (ExcCode %02x)\n", cause, exccode);
61 
62 	if (1 <= exccode && exccode <= 5)
63 		printf("BadVA : %0*lx\n", field, regs->cp0_badvaddr);
64 
65 	printf("PrId  : %08x\n", read_c0_prid());
66 }
67 
68 void do_reserved(const struct pt_regs *regs)
69 {
70 	puts("\nOoops:\n");
71 	show_regs(regs);
72 	hang();
73 }
74 
75 void do_ejtag_debug(const struct pt_regs *regs)
76 {
77 	const int field = 2 * sizeof(unsigned long);
78 	unsigned long depc;
79 	unsigned int debug;
80 
81 	depc = read_c0_depc();
82 	debug = read_c0_debug();
83 
84 	printf("SDBBP EJTAG debug exception: c0_depc = %0*lx, DEBUG = %08x\n",
85 	       field, depc, debug);
86 }
87 
88 static void set_handler(unsigned long offset, void *addr, unsigned long size)
89 {
90 	unsigned long ebase = gd->irq_sp;
91 
92 	memcpy((void *)(ebase + offset), addr, size);
93 	flush_cache(ebase + offset, size);
94 }
95 
96 void trap_init(ulong reloc_addr)
97 {
98 	unsigned long ebase = gd->irq_sp;
99 
100 	set_handler(0x180, &except_vec3_generic, 0x80);
101 	set_handler(0x280, &except_vec_ejtag_debug, 0x80);
102 
103 	write_c0_ebase(ebase);
104 	clear_c0_status(ST0_BEV);
105 	execution_hazard_barrier();
106 }
107