1 /* *********************************************************************
2 * SB1250 Board Support Package
4 * Exception Handler File: exception.S
6 * Author: Mitch Lichtenberg (mpl@broadcom.com)
8 *********************************************************************
10 * Copyright 2000,2001,2002,2003
11 * Broadcom Corporation. All rights reserved.
13 * This software is furnished under license and may be used and
14 * copied only in accordance with the following terms and
15 * conditions. Subject to these conditions, you may download,
16 * copy, install, use, modify and distribute modified or unmodified
17 * copies of this software in source and/or binary form. No title
18 * or ownership is transferred hereby.
20 * 1) Any source code used, modified or distributed must reproduce
21 * and retain this copyright notice and list of conditions
22 * as they appear in the source file.
24 * 2) No right is granted to use any trade name, trademark, or
25 * logo of Broadcom Corporation. The "Broadcom Corporation"
26 * name may not be used to endorse or promote products derived
27 * from this software without the prior written permission of
28 * Broadcom Corporation.
30 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
31 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
32 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
33 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
34 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
35 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
36 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
39 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
40 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
41 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
42 * THE POSSIBILITY OF SUCH DAMAGE.
43 ********************************************************************* */
47 #include "exception.h"
48 #include "mipsmacros.h"
49 #include "cpu_config.h" /* for definition of HAZARD and ERET */
50 #include "bsp_config.h"
52 /* *********************************************************************
54 ********************************************************************* */
69 /* *********************************************************************
71 ********************************************************************* */
76 _exc_vectab: _LONG_ 0 # XTYPE_RESET
77 _LONG_ 0 # XTYPE_TLBFILL (not used)
78 _LONG_ 0 # XTYPE_XTLBFILL
79 _LONG_ 0 # XTYPE_CACHEERR (not used)
80 _LONG_ 0 # XTYPE_EXCEPTION
81 _LONG_ 0 # XTYPE_INTERRUPT
82 _LONG_ 0 # XTYPE_EJTAG
84 /* *********************************************************************
86 ********************************************************************* */
91 /* *********************************************************************
93 ********************************************************************* */
97 #define R_EXC_CERR_TEMPLATE _TBLIDX(0)
98 #define R_EXC_CERR_TEMPLATE_END _TBLIDX(1)
100 .globl _exc_cerr_htable
102 _LONG_ _exc_cerr_template
103 _LONG_ _exc_cerr_template_end
106 /* *********************************************************************
109 * This is a template routine for our cache error handler.
110 * We save a couple of registers in our magic save area, then
111 * dispatch to code elsewhere in CFE.
113 * This code is copied right to the vector address, so it has
117 * nothing - running uncached, all registers trashed
120 * might return, might not
121 ********************************************************************* */
123 LEAF(_exc_cerr_template)
126 * Magic! When the cache error handler is running,
127 * we are in a very special state, running uncached
128 * and with translations turned off. We can use offsets
129 * from r0(zero) to store registers we need to use
130 * during the error handler.
133 .set push ; .set noreorder
135 SR k0,CFE_LOCORE_GLOBAL_K0TMP(zero)
136 SR k1,CFE_LOCORE_GLOBAL_K1TMP(zero)
137 SR ra,CFE_LOCORE_GLOBAL_RATMP(zero)
138 SR gp,CFE_LOCORE_GLOBAL_GPTMP(zero)
140 LR k0,CFE_LOCORE_GLOBAL_CERRH(zero)
144 LR k0,CFE_LOCORE_GLOBAL_K0TMP(zero)
145 LR k1,CFE_LOCORE_GLOBAL_K1TMP(zero)
146 LR ra,CFE_LOCORE_GLOBAL_RATMP(zero)
147 LR gp,CFE_LOCORE_GLOBAL_GPTMP(zero)
153 * Note: make sure this routine does not exceed 128 bytes
156 _exc_cerr_template_end:
158 END(_exc_cerr_template)
160 /* *********************************************************************
161 * _exc_setup_locore(cerrh)
163 * Set global data into the low-memory region. We do this in
164 * assembly language so it's easier to deal with the 32-bit/64-bit
165 * issues that arise in the "C" code.
168 * a0 - cache error handler
172 ********************************************************************* */
174 LEAF(_exc_setup_locore)
179 * Save GP for easy re-use, using uncached writes.
182 li t0,PHYS_TO_K1(CFE_LOCORE_GLOBAL_GP)
186 * Initialize cache error handler pointer. Make it
187 * uncached, since cache error handlers should not
192 and a0,a0,t1 # keep just physical part
194 or a0,a0,t1 # make into an uncached address
196 li t0,PHYS_TO_K1(CFE_LOCORE_GLOBAL_CERRH)
200 * Move the cache error handler into low RAM.
203 li t0,PHYS_TO_K1(MIPS_RAM_VEC_CACHEERR)
205 LOADREL(t1,_exc_cerr_htable)
206 LR t2,R_EXC_CERR_TEMPLATE_END(t1)
207 LR t1,R_EXC_CERR_TEMPLATE(t1)
209 1: lw t3,0(t1) # get a word
210 sw t3,0(t0) # write a word
211 ADD t0,4 # next word...
213 blt t1,t2,1b # till done
216 * Now do the whole thing again, but with cached writes.
217 * Writing uncached makes sure the data is actually in memory,
218 * and writing cached makes sure we write the same
219 * stuff again when the cache is evicted.
220 * This way we don't have to bother with cacheops,
221 * a bonus on the BCM1250 with its funky L2.
224 li t0,PHYS_TO_K0(CFE_LOCORE_GLOBAL_GP)
227 li t0,PHYS_TO_K0(CFE_LOCORE_GLOBAL_CERRH)
230 li t0,PHYS_TO_K0(MIPS_RAM_VEC_CACHEERR)
232 LOADREL(t1,_exc_cerr_htable)
233 LR t2,R_EXC_CERR_TEMPLATE_END(t1)
234 LR t1,R_EXC_CERR_TEMPLATE(t1)
236 1: lw t3,0(t1) # get a word
237 sw t3,0(t0) # write a word
238 ADD t0,4 # next word...
240 blt t1,t2,1b # till done
250 END(_exc_setup_locore)
255 /* *********************************************************************
256 * _exc_setvector(xtype,addr)
258 * Set an exception vector address
261 * xtype - exception vector type
262 * addr - routine address
266 ********************************************************************* */
271 srl a0,3 /* convert 8-byte index to array index */
272 sll a0,BPWSIZE /* convert back to index appropriate for word size */
280 /* *********************************************************************
283 * Crash the GDB simulator, causing it to exit.
289 * nothing - does not return
290 ********************************************************************* */
304 /* *********************************************************************
305 * _exc_cache_crash_sim()
307 * As _exc_crash_sim, but distinguish cache error exception.
313 * nothing - does not return
314 ********************************************************************* */
317 LEAF(_exc_cache_crash_sim)
325 END(_exc_cache_crash_sim)
328 /* *********************************************************************
331 * Restart the firmware at the boot address
338 ********************************************************************* */
342 li t0,0xBFC00000 # ROM restart vector
347 /* *********************************************************************
350 * Main exception entry point.
353 * k0 - exception type
357 ********************************************************************* */
364 subu k1,sp,EXCEPTION_SIZE
368 SREG zero,XGR_ZERO(k1)
412 SREG t0,XCP0_CAUSE(k1)
414 SREG t2,XCP0_VADDR(k1)
416 SREG t4,XCP0_PRID(k1)
421 la gp,PHYS_TO_K0(CFE_LOCORE_GLOBAL_GP)
422 LR gp,0(gp) # get our GP handle from low memory vector
424 la gp,_gp # Load up GP, not relocated so it's easy
427 move a0,k0 # Pass exception type
428 move a1,k1 # Pass frame to exception handler
429 la t0,_exc_vectab # get base of exception vectors
430 srl k0,3 # convert 8-byte index to array index
431 sll k0,BPWSIZE # convert back to index appropriate for word size
432 addu t0,k0 # get vector address
433 LR t0,(t0) # to call handler
435 move sp,k1 # "C" gets fresh stack area
437 jalr t0 # Call exception handler
479 /* do any CP0 cleanup here */
493 /* *********************************************************************
494 * _exc_clear_sr_exl()
496 * Clear SR(EXL) and return to caller.
503 ********************************************************************* */
505 LEAF(_exc_clear_sr_exl)
508 and t0,t0,~(0x02) # clear SR(EXL). Bit 1
515 END(_exc_clear_sr_exl)
517 /* *********************************************************************
518 * _exc_clear_sr_erl()
520 * Clear SR(ERL) and return to caller.
527 ********************************************************************* */
529 LEAF(_exc_clear_sr_erl)
532 and t0,t0,~(0x04) # clear SR(ERL). Bit 2
539 END(_exc_clear_sr_erl)
542 /* *********************************************************************
544 ********************************************************************* */