1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*******************************************************************************
* Copyright (C) 2018 Cadence Design Systems, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to use this Software with Cadence processor cores only and
* not with any other processors and platforms, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#include "xtensa-defs.h"
.macro SAVE_ reg, loc
rsr a1, \reg
s32i a1, a3, \loc * 4
.endm
.macro SAVE reg
SAVE_ \reg, \reg
.endm
.macro LOAD_ reg, loc
l32i a1, a3, \loc * 4
wsr a1, \reg
.endm
.macro LOAD reg
LOAD_ \reg, \reg
.endm
.section ".DebugExceptionVector.text", "ax"
.global DebugExceptionVector
DebugExceptionVector:
j 1f
.align 4
.literal_position
1:
xsr a2, DEBUG_EXCSAVE
jx a2
.text
.global DebugExceptionEntry
.align 4
DebugExceptionEntry:
j 1f
.align 4
.literal_position
1:
movi a2, aregs
s32i a0, a2, 0
s32i a1, a2, 4
rsr a1, DEBUG_EXCSAVE
s32i a1, a2, 8
s32i a3, a2, 12
movi a3, sregs
SAVE LBEG
SAVE LEND
SAVE LCOUNT
SAVE SAR
SAVE WINDOWBASE
SAVE WINDOWSTART
rsr a1, DEBUG_PC
movi a2, initial_breakpoint
bne a1, a2, 1f
addi a1, a1, 3
1:
s32i a1, a3, DEBUG_PC * 4
SAVE EXCSAVE_1
SAVE_ DEBUG_PS, PS
SAVE EXCCAUSE
SAVE DEBUGCAUSE
SAVE EXCVADDR
movi a1, XCHAL_NUM_AREGS / 4 - 1
movi a2, aregs
1:
s32i a4, a2, 16
s32i a5, a2, 20
s32i a6, a2, 24
s32i a7, a2, 28
addi a6, a2, 16
addi a5, a1, -1
rotw 1
bnez a1, 1b
movi a1, 1
wsr a1, windowstart
movi a0, 0
wsr a0, windowbase
rsync
movi a0, 0
movi a1, stack + STACK_SIZE - 20
rsr a2, ps
addi a2, a2, -PS_EXCM_MASK
wsr a2, ps
rsync
movi a4, handle_exception
callx4 a4
DebugExceptionExit:
movi a2, DebugExceptionEntry
wsr a2, DEBUG_EXCSAVE
rsr a2, ps
addi a2, a2, PS_EXCM_MASK
wsr a2, ps
rsync
movi a3, sregs
LOAD LBEG
LOAD LEND
LOAD LCOUNT
/* TODO: handle unlikely return-to-lend case */
LOAD SAR
LOAD WINDOWBASE
rsync
movi a3, sregs
LOAD WINDOWSTART
LOAD DEBUG_PC
LOAD EXCSAVE_1
LOAD_ DEBUG_PS, PS
LOAD EXCCAUSE
LOAD EXCVADDR
movi a6, aregs
movi a5, XCHAL_NUM_AREGS / 4 - 2
1:
l32i a0, a6, 0
l32i a1, a6, 4
l32i a2, a6, 8
l32i a3, a6, 12
beqz a5, 2f
addi a10, a6, 16
addi a9, a5, -1
rotw 1
j 1b
2:
l32i a4, a6, 16
l32i a5, a6, 20
l32i a7, a6, 28
l32i a6, a6, 24
rotw 2
rfi XCHAL_DEBUGLEVEL
#ifdef LIBC_LEVEL1_HANDLER
.global fault_handler
.align 4
fault_handler:
rsr a2, epc1
addi a2, a2, 3
wsr a2, epc1
rsync
movi a2, mem_err
s32i a2, a2, 0
l32i a2, a1, 16
l32i a3, a1, 20
addi a1, a1, 256
rfe
#endif
.global init_debug_entry
.align 4
init_debug_entry:
entry a1, 16
movi a2, DebugExceptionEntry
wsr a2, DEBUG_EXCSAVE
isync
retw
.global breakpoint
.align 4
breakpoint:
entry a1, 16
initial_breakpoint:
_break 0, 0
retw
|