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