1 // exc-unhandled.S - General Exception Handler for unhandled exceptions
3 // Copyright (c) 2002-2004, 2006, 2010 Tensilica Inc.
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be included
14 // in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include <xtensa/coreasm.h>
25 #include <xtensa/corebits.h>
26 #include <xtensa/config/specreg.h>
27 #include "xtos-internal.h"
29 #include <xtensa/simcall.h>
32 #if XCHAL_HAVE_EXCEPTIONS
35 * Assembly-level exception handler used when no handler was
36 * registered for the specific exception cause.
38 * The BREAK instruction is used to give control to the debugger,
39 * if one is present and active. (If none is present and active,
40 * the default debug exception handler will typically skip over
41 * this break instruction.)
42 * This code follows the convention documented in the ISA manual
43 * to use BREAK instructions to signal unhandled exceptions to the
44 * debugger. For the debugger to report or handle this condition
45 * in an OS-independent manner, all processor state (except PC)
46 * must be restored as it was when the unhandled exception just
47 * occurred (ie. as it was at the beginning of the vector).
48 * If execution continues after the BREAK instruction (in which
49 * case any register might have been modified by the debugger),
55 // If not pulled-in some other way, define it as unhandled:
56 .weak _xtos_cause3_handler
57 .global _xtos_cause3_handler
60 .global _xtos_unhandled_exception
61 _xtos_unhandled_exception:
62 #if XCHAL_HAVE_DEBUG || defined(SIMULATOR)
63 l32i a2, a1, UEXC_a2 // restore a2
64 l32i a3, a1, UEXC_a3 // restore a3
65 // Note: a4-a5 not clobbered, no need to restore.
66 addi a1, a1, ESF_TOTALSIZE // restore sp
68 break 1, 1 // give control to the debugger (if any present)
70 wsr a2, EXCSAVE1 // save a2 where simulator expects it
71 movi a2, SYS_unhandled_user_exc
72 simcall // let simulator/debugger report unhandled exception
73 rsr a2, EXCSAVE1 // restore a2
75 rfe_rfue // if sim/debug resume, just return
76 #else /* DEBUG or SIMULATOR */
77 j _xtos_unhandled_exception // just loop forever
78 #endif /* DEBUG or SIMULATOR */
80 .size _xtos_unhandled_exception, . - _xtos_unhandled_exception
83 #endif /* XCHAL_HAVE_EXCEPTIONS */