-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patherror.ref.S
More file actions
300 lines (280 loc) · 6.47 KB
/
Copy patherror.ref.S
File metadata and controls
300 lines (280 loc) · 6.47 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <max.h>
#include <asm_offsets.h>
#include <asm_std.h>
#include <max.h>
#include <vmdefs.h>
FUNC_START H2K_handle_error .text.vm.error .p2align 2
/* TBD: do double exception check as spec'd */
/*
* XXX: this is rather V3 oriented, we should probably macro
* the guest regs stuff to use guest regs in V4
*/
crswap(r0,sgp)
memd(r0+#CONTEXT_r3130) = r31:30
call H2K_context_save
/* r7 = me, r8 = ssr, r9 = htid */
r3 = r7
r1 = and(r8, #0xff)
#ifdef DO_EXT_SWITCH
p0 = cmp.eq(r1, #0x16) // XE exception?
if (!p0) jump 1f
p0 = tstbit(r8, #SSR_XE_BIT) // coprocessor error?
if (p0) jump 1f
// else XE == 0, so maybe restore ext context
r0 = memw(r7 + #CONTEXT_vmblock)
r10 = memw(r0 + #VMBLOCK_flags)
p0 = tstbit(r10, #H2K_VMBLOCK_FLAGS_DO_EXT_BIT) // VM doing ext switch?
if (!p0) jump 1f
jump H2K_ext_context_restore // continues to H2K_context_restore_return
#endif
.global H2K_error_nonxe
H2K_error_nonxe:
1:
r0 = badva
// r1 = cause
r2 = #ERROR_GEVB_OFFSET
// r3 = me
call H2K_vm_event
call H2K_preempt
jump H2K_context_restore_return
/* EJP: Dead Code! */
/* Set up KSP and jump to fatal_thread */
//#if ARCHV <= 3
// r29.h = #hi(H2K_stacks)
// r29.l = #lo(H2K_stacks)
// r28 = ssr
// r28 = extractu(r28,#3,#19)
// r2 = #KERNEL_STACK_SIZE
// r29 += mpyi(r28,r2)
//#else
// r28 = HTID
// r29 = #KERNEL_STACK_SIZE
// r29 = add(##H2K_stacks,mpyi(r28,r29))
//#endif
// r4 = r28
// r28.h = #hi(H2K_kg)
// r28.l = #lo(H2K_kg)
// r0 = #-3
// r1 = r24
// r3:2 = #0
// crswap(r24,sgp)
// jump H2K_fatal_thread
FUNC_END H2K_handle_error
/*
* User-specified soft crash. r0 is how to crash, r1 is me.
*/
#define WORK r16
#define ME r17
#define ME_WORK r17:16
FUNC_START H2K_fatal_crash .text.vm.error .p2align 2
{
ME_WORK = r1:0
allocframe(#0)
}
{
p0 = tstbit(WORK,#0)
if (!p0.new) jump:nt 9f
}
{
memw(H2K_GP+#KG_is_nmi_soft) = #1
}
// FIXME SOFT_BKL: crash path must NOT block on BKL if lock is already held
ASM_BKL_LOCK(r6, r7, r8, p0)
r2 = htid
r3 = #-1
r3 = togglebit(r3,r2)
nmi(r3)
/* EJP: probably should put stuff from ME into my hthread's crash context here?? */
.Lfatal_crash_hard_join:
.Lmodectl_wait:
r3 = #0
r2 = modectl
#if ARCHV >= 5
r1 = popcount(r3:2)
#else
r1 = #0
p0 = tstbit(r2,#0)
if (p0) r1 = add(r1,#1)
p0 = tstbit(r2,#1)
if (p0) r1 = add(r1,#1)
p0 = tstbit(r2,#2)
if (p0) r1 = add(r1,#1)
p0 = tstbit(r2,#3)
if (p0) r1 = add(r1,#1)
p0 = tstbit(r2,#4)
if (p0) r1 = add(r1,#1)
p0 = tstbit(r2,#5)
if (p0) r1 = add(r1,#1)
#endif
{
p0 = cmp.eq(r1,#1)
if (!p0.new) jump:nt .Lmodectl_wait
}
r1 = syscfg
r1 = clrbit(r1,#4) // clear GIE
syscfg = r1
// We should now be in "Single Thread Mode": only one thread active, and that's the one executing here
// Did we possibly nmi a thread holding a lock? We can fix it!
ASM_BKL_UNLOCK(r6, r7, r8, p0)
tlbunlock
// Bit 1: Save off TLB and flush caches
// EJP: for now, let's do this all the time.
9:
{
p0 = tstbit(WORK,#1)
//if (!p0.new) jump:nt 9f
}
#ifdef CRASH_DEBUG
// Save off TLB. FIXME: could be done in C...
r3:2 = combine(#0,##H2K_kg+KG_crash_tlb)
loop0(1f,#MAX_TLB_ENTRIES)
1:
r5:4 = tlbr(r3)
{
memd(r2++#8) = r5:4
r3 = add(r3,#1)
}:endloop0
nop
call H2K_intconfig_l2vic_crash
call H2K_tcm_crash_copy
#endif
call H2K_cache_d_cleaninv
call H2K_cache_l2_cleaninv
syncht
9:
// Bit 2: Die
{
p0 = tstbit(WORK,#2)
if (!p0.new) jump:nt 9f
}
syncht
nop
stop(r0)
nop
9:
dealloc_return
FUNC_END H2K_fatal_crash
/*
* Crash!
*
* This is an interesting place to be. NMI could be from internal or external.
*
* Serialization: k0lock and tlblock could have been interrupted, so might be bogus.
* ... so what good trick could we do?
* We want to preserve as much state as possible, but we don't know much about the
* registers... including, whether sgp0 has a thread context or something invalid
* because it might have been swapped and NMI'd in the middle of a context switch
*
* 0) Save registers as carefully as possible to crash area. will be reloaded by t32
* 1) Single thread mode
* 2) Save TLB entries
* 3) Clean caches
* 4) invoke SW routine. reuse fastint context?
*/
FUNC_START H2K_handle_nmi .text.vm.error .p2align 2
#ifdef NMI_STOP
r1=##0xe0f0beef
stop(r0)
#else
#ifdef CRASH_DEBUG
// Part 0: save off context. Kill cs1:0 registers, hopefully they're not important
c13:12 = r1:0 // CS1:0 registers
.Lhandle_nmi_soft_join:
r0 = ##H2K_kg+KG_crash_contexts
r1 = htid
r0 += mpyi(r1,##CONTEXT_SIZE)
memd(r0+#CONTEXT_r3130) = r31:30
call H2K_context_save
// r0 and sgp0 are swapped
// H2K_kg in r28
// SP set up
// lc0/sa0 saved
// usr/p30 saved
// ccrssr saved
// stuff from thread_switch not saved...
// r0/sgp0 swapped, context r0100 doesn't have the right values.
{
r3:2 = c13:12
}
{
memd(r7+#CONTEXT_r0100) = r3:2
memd(r7+#CONTEXT_r2322) = r23:22
r5:4 = c7:6 // m1:0
}
{
memd(r7+#CONTEXT_m1m0) = r5:4
memd(r7+#CONTEXT_r2120) = r21:20
r3:2 = c11:10
}
{
memd(r7+#CONTEXT_gpugp) = r3:2
memd(r7+#CONTEXT_r2524) = r25:24
r5:4 = g1:0
}
{
memd(r7+#CONTEXT_r2726) = r27:26
memd(r7+#CONTEXT_gssr_gelr) = r5:4
r3:2 = g3:2
}
{
memd(r7+#CONTEXT_gbadva_gosp) = r3:2
r1 = s1
}
{
r6 = ELR
}
{
memw(r7+#CONTEXT_elr) = r6
memd(r7+#CONTEXT_cs1cs0) = r1:0 // save sgp1:0 here
}
// EJP: do we want to save out global registers?
// EJP: If we have a soft NMI,
r0 = memw(##H2K_kg+KG_is_nmi_soft)
{
p0 = cmp.eq(r0,#0)
if (!p0.new) jump:t .Lstop
}
// Hard NMI, all threads are getting it. Only T0 will continue
r0 = HTID
{
p0 = cmp.eq(r0,#0)
if (!p0.new) jump:nt .Lstop
}
// Now we can join the common code for H2K_fatal_crash
// But we need to make sure that all steps are going to be taken.
ME_WORK = combine(#0,#-1)
jump .Lfatal_crash_hard_join
// All threads but one (unknown: which one...) should be getting NMI and shutting down.
// Wait for them here.
.Lstop:
stop(r0)
jump .Lstop
#else
crswap(r0,sgp)
memd(r0+#CONTEXT_r3130) = r31:30
call H2K_context_save
r0 = #-3
r1 = r7
r3:2 = #0
r4 = r9
jump H2K_fatal_thread
#endif
#endif
FUNC_END H2K_handle_nmi
FUNC_START H2K_handle_rsvd .text.vm.error .p2align 2
jump H2K_handle_nmi
FUNC_END H2K_handle_rsvd
FUNC_START H2K_handle_debug .text.vm.error .p2align 2
crswap(r0,sgp)
memd(r0+#CONTEXT_r3130) = r31:30
call H2K_context_save
r0 = #0
r1 = and(r8,#0xff)
r2 = #DEBUG_GEVB_OFFSET
r3 = r7
jump H2K_vm_event
FUNC_END H2K_handle_debug