trap.c revision 1.13 1 1.13 ryo /* $NetBSD: trap.c,v 1.13 2018/12/12 18:11:00 ryo Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas of 3am Software Foundry.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt #include <sys/cdefs.h>
33 1.1 matt
34 1.13 ryo __KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.13 2018/12/12 18:11:00 ryo Exp $");
35 1.1 matt
36 1.4 ryo #include "opt_arm_intr_impl.h"
37 1.4 ryo #include "opt_compat_netbsd32.h"
38 1.4 ryo
39 1.1 matt #include <sys/param.h>
40 1.8 ryo #include <sys/kauth.h>
41 1.1 matt #include <sys/types.h>
42 1.4 ryo #include <sys/atomic.h>
43 1.1 matt #include <sys/cpu.h>
44 1.4 ryo #ifdef KDB
45 1.4 ryo #include <sys/kdb.h>
46 1.4 ryo #endif
47 1.3 nisimura #include <sys/proc.h>
48 1.3 nisimura #include <sys/systm.h>
49 1.3 nisimura #include <sys/signal.h>
50 1.3 nisimura #include <sys/signalvar.h>
51 1.3 nisimura #include <sys/siginfo.h>
52 1.1 matt
53 1.4 ryo #ifdef ARM_INTR_IMPL
54 1.4 ryo #include ARM_INTR_IMPL
55 1.4 ryo #else
56 1.4 ryo #error ARM_INTR_IMPL not defined
57 1.4 ryo #endif
58 1.4 ryo
59 1.4 ryo #ifndef ARM_IRQ_HANDLER
60 1.4 ryo #error ARM_IRQ_HANDLER not defined
61 1.4 ryo #endif
62 1.4 ryo
63 1.4 ryo #include <aarch64/userret.h>
64 1.4 ryo #include <aarch64/frame.h>
65 1.4 ryo #include <aarch64/machdep.h>
66 1.4 ryo #include <aarch64/armreg.h>
67 1.1 matt #include <aarch64/locore.h>
68 1.1 matt
69 1.4 ryo #ifdef KDB
70 1.4 ryo #include <machine/db_machdep.h>
71 1.4 ryo #endif
72 1.4 ryo #ifdef DDB
73 1.4 ryo #include <ddb/db_output.h>
74 1.4 ryo #include <machine/db_machdep.h>
75 1.4 ryo #endif
76 1.4 ryo
77 1.8 ryo #ifdef DDB
78 1.8 ryo int sigill_debug = 0;
79 1.8 ryo #endif
80 1.4 ryo
81 1.4 ryo const char * const trap_names[] = {
82 1.4 ryo [ESR_EC_UNKNOWN] = "Unknown Reason (Illegal Instruction)",
83 1.4 ryo [ESR_EC_SERROR] = "SError Interrupt",
84 1.4 ryo [ESR_EC_WFX] = "WFI or WFE instruction execution",
85 1.4 ryo [ESR_EC_ILL_STATE] = "Illegal Execution State",
86 1.4 ryo
87 1.4 ryo [ESR_EC_SYS_REG] = "MSR/MRS/SYS instruction",
88 1.4 ryo [ESR_EC_SVC_A64] = "SVC Instruction Execution",
89 1.4 ryo [ESR_EC_HVC_A64] = "HVC Instruction Execution",
90 1.4 ryo [ESR_EC_SMC_A64] = "SMC Instruction Execution",
91 1.4 ryo
92 1.4 ryo [ESR_EC_INSN_ABT_EL0] = "Instruction Abort (EL0)",
93 1.4 ryo [ESR_EC_INSN_ABT_EL1] = "Instruction Abort (EL1)",
94 1.4 ryo [ESR_EC_DATA_ABT_EL0] = "Data Abort (EL0)",
95 1.4 ryo [ESR_EC_DATA_ABT_EL1] = "Data Abort (EL1)",
96 1.4 ryo
97 1.4 ryo [ESR_EC_PC_ALIGNMENT] = "Misaligned PC",
98 1.4 ryo [ESR_EC_SP_ALIGNMENT] = "Misaligned SP",
99 1.4 ryo
100 1.4 ryo [ESR_EC_FP_ACCESS] = "Access to SIMD/FP Registers",
101 1.4 ryo [ESR_EC_FP_TRAP_A64] = "FP Exception",
102 1.4 ryo
103 1.4 ryo [ESR_EC_BRKPNT_EL0] = "Breakpoint Exception (EL0)",
104 1.4 ryo [ESR_EC_BRKPNT_EL1] = "Breakpoint Exception (EL1)",
105 1.4 ryo [ESR_EC_SW_STEP_EL0] = "Software Step (EL0)",
106 1.4 ryo [ESR_EC_SW_STEP_EL1] = "Software Step (EL1)",
107 1.4 ryo [ESR_EC_WTCHPNT_EL0] = "Watchpoint (EL0)",
108 1.4 ryo [ESR_EC_WTCHPNT_EL1] = "Watchpoint (EL1)",
109 1.4 ryo [ESR_EC_BKPT_INSN_A64] = "BKPT Instruction Execution",
110 1.4 ryo
111 1.4 ryo [ESR_EC_CP15_RT] = "A32: MCR/MRC access to CP15",
112 1.4 ryo [ESR_EC_CP15_RRT] = "A32: MCRR/MRRC access to CP15",
113 1.4 ryo [ESR_EC_CP14_RT] = "A32: MCR/MRC access to CP14",
114 1.4 ryo [ESR_EC_CP14_DT] = "A32: LDC/STC access to CP14",
115 1.4 ryo [ESR_EC_CP14_RRT] = "A32: MRRC access to CP14",
116 1.4 ryo [ESR_EC_SVC_A32] = "A32: SVC Instruction Execution",
117 1.4 ryo [ESR_EC_HVC_A32] = "A32: HVC Instruction Execution",
118 1.4 ryo [ESR_EC_SMC_A32] = "A32: SMC Instruction Execution",
119 1.4 ryo [ESR_EC_FPID] = "A32: MCR/MRC access to CP10",
120 1.4 ryo [ESR_EC_FP_TRAP_A32] = "A32: FP Exception",
121 1.4 ryo [ESR_EC_BKPT_INSN_A32] = "A32: BKPT Instruction Execution",
122 1.4 ryo [ESR_EC_VECTOR_CATCH] = "A32: Vector Catch Exception"
123 1.4 ryo };
124 1.4 ryo
125 1.6 christos const char *
126 1.4 ryo eclass_trapname(uint32_t eclass)
127 1.3 nisimura {
128 1.4 ryo static char trapnamebuf[sizeof("Unknown trap 0x????????")];
129 1.4 ryo
130 1.4 ryo if (eclass >= __arraycount(trap_names) || trap_names[eclass] == NULL) {
131 1.4 ryo snprintf(trapnamebuf, sizeof(trapnamebuf),
132 1.6 christos "Unknown trap %#02x", eclass);
133 1.4 ryo return trapnamebuf;
134 1.4 ryo }
135 1.4 ryo return trap_names[eclass];
136 1.3 nisimura }
137 1.3 nisimura
138 1.1 matt void
139 1.4 ryo userret(struct lwp *l)
140 1.1 matt {
141 1.1 matt mi_userret(l);
142 1.1 matt }
143 1.2 nisimura
144 1.3 nisimura void
145 1.4 ryo trap_doast(struct trapframe *tf)
146 1.3 nisimura {
147 1.3 nisimura struct lwp * const l = curlwp;
148 1.4 ryo
149 1.4 ryo /*
150 1.4 ryo * allow to have a chance of context switch just prior to user
151 1.4 ryo * exception return.
152 1.4 ryo */
153 1.4 ryo #ifdef __HAVE_PREEMPTION
154 1.4 ryo kpreempt_disable();
155 1.4 ryo #endif
156 1.4 ryo struct cpu_info * const ci = curcpu();
157 1.4 ryo
158 1.4 ryo ci->ci_data.cpu_ntrap++;
159 1.4 ryo
160 1.4 ryo KDASSERT(ci->ci_cpl == IPL_NONE);
161 1.4 ryo const int want_resched = ci->ci_want_resched;
162 1.4 ryo #ifdef __HAVE_PREEMPTION
163 1.4 ryo kpreempt_enable();
164 1.4 ryo #endif
165 1.4 ryo
166 1.4 ryo if (l->l_pflag & LP_OWEUPC) {
167 1.4 ryo l->l_pflag &= ~LP_OWEUPC;
168 1.4 ryo ADDUPROF(l);
169 1.3 nisimura }
170 1.4 ryo
171 1.4 ryo /* Allow a forced task switch. */
172 1.4 ryo if (want_resched)
173 1.4 ryo preempt();
174 1.4 ryo userret(l);
175 1.4 ryo }
176 1.4 ryo
177 1.4 ryo void
178 1.4 ryo trap_el1h_sync(struct trapframe *tf)
179 1.4 ryo {
180 1.4 ryo const uint32_t esr = tf->tf_esr;
181 1.4 ryo const uint32_t eclass = __SHIFTOUT(esr, ESR_EC); /* exception class */
182 1.4 ryo
183 1.4 ryo /* re-enable traps and interrupts */
184 1.4 ryo if (!(tf->tf_spsr & SPSR_I))
185 1.4 ryo daif_enable(DAIF_D|DAIF_A|DAIF_I|DAIF_F);
186 1.4 ryo else
187 1.4 ryo daif_enable(DAIF_D|DAIF_A);
188 1.4 ryo
189 1.4 ryo switch (eclass) {
190 1.4 ryo case ESR_EC_INSN_ABT_EL1:
191 1.4 ryo case ESR_EC_DATA_ABT_EL1:
192 1.6 christos data_abort_handler(tf, eclass);
193 1.4 ryo break;
194 1.4 ryo
195 1.4 ryo case ESR_EC_BRKPNT_EL1:
196 1.4 ryo case ESR_EC_SW_STEP_EL1:
197 1.4 ryo case ESR_EC_WTCHPNT_EL1:
198 1.4 ryo case ESR_EC_BKPT_INSN_A64:
199 1.4 ryo #ifdef DDB
200 1.4 ryo if (eclass == ESR_EC_BRKPNT_EL1)
201 1.4 ryo kdb_trap(DB_TRAP_BREAKPOINT, tf);
202 1.4 ryo else if (eclass == ESR_EC_BKPT_INSN_A64)
203 1.4 ryo kdb_trap(DB_TRAP_BKPT_INSN, tf);
204 1.4 ryo else if (eclass == ESR_EC_WTCHPNT_EL1)
205 1.4 ryo kdb_trap(DB_TRAP_WATCHPOINT, tf);
206 1.4 ryo else if (eclass == ESR_EC_SW_STEP_EL1)
207 1.4 ryo kdb_trap(DB_TRAP_SW_STEP, tf);
208 1.4 ryo else
209 1.4 ryo kdb_trap(DB_TRAP_UNKNOWN, tf);
210 1.4 ryo #else
211 1.4 ryo panic("No debugger in kernel");
212 1.4 ryo #endif
213 1.4 ryo break;
214 1.4 ryo
215 1.4 ryo case ESR_EC_FP_ACCESS:
216 1.4 ryo case ESR_EC_FP_TRAP_A64:
217 1.4 ryo case ESR_EC_PC_ALIGNMENT:
218 1.4 ryo case ESR_EC_SP_ALIGNMENT:
219 1.4 ryo case ESR_EC_ILL_STATE:
220 1.4 ryo default:
221 1.13 ryo panic("Trap: fatal %s: pc=%016" PRIx64 " sp=%016" PRIx64
222 1.13 ryo " esr=%08x", eclass_trapname(eclass), tf->tf_pc, tf->tf_sp,
223 1.6 christos esr);
224 1.4 ryo break;
225 1.3 nisimura }
226 1.3 nisimura }
227 1.3 nisimura
228 1.3 nisimura void
229 1.4 ryo trap_el0_sync(struct trapframe *tf)
230 1.3 nisimura {
231 1.4 ryo struct lwp * const l = curlwp;
232 1.4 ryo const uint32_t esr = tf->tf_esr;
233 1.4 ryo const uint32_t eclass = __SHIFTOUT(esr, ESR_EC); /* exception class */
234 1.4 ryo
235 1.4 ryo /* enable traps and interrupts */
236 1.4 ryo daif_enable(DAIF_D|DAIF_A|DAIF_I|DAIF_F);
237 1.4 ryo
238 1.4 ryo switch (eclass) {
239 1.4 ryo case ESR_EC_INSN_ABT_EL0:
240 1.4 ryo case ESR_EC_DATA_ABT_EL0:
241 1.6 christos data_abort_handler(tf, eclass);
242 1.4 ryo userret(l);
243 1.4 ryo break;
244 1.4 ryo
245 1.4 ryo case ESR_EC_SVC_A64:
246 1.4 ryo (*l->l_proc->p_md.md_syscall)(tf);
247 1.4 ryo break;
248 1.4 ryo case ESR_EC_FP_ACCESS:
249 1.4 ryo fpu_load(l);
250 1.4 ryo userret(l);
251 1.4 ryo break;
252 1.4 ryo case ESR_EC_FP_TRAP_A64:
253 1.4 ryo do_trapsignal(l, SIGFPE, FPE_FLTUND, NULL, esr); /* XXX */
254 1.4 ryo userret(l);
255 1.4 ryo break;
256 1.4 ryo
257 1.4 ryo case ESR_EC_PC_ALIGNMENT:
258 1.5 christos do_trapsignal(l, SIGBUS, BUS_ADRALN, (void *)tf->tf_pc, esr);
259 1.4 ryo userret(l);
260 1.4 ryo break;
261 1.4 ryo case ESR_EC_SP_ALIGNMENT:
262 1.5 christos do_trapsignal(l, SIGBUS, BUS_ADRALN, (void *)tf->tf_sp, esr);
263 1.4 ryo userret(l);
264 1.4 ryo break;
265 1.4 ryo
266 1.4 ryo case ESR_EC_BKPT_INSN_A64:
267 1.4 ryo case ESR_EC_BRKPNT_EL0:
268 1.4 ryo case ESR_EC_SW_STEP_EL0:
269 1.4 ryo case ESR_EC_WTCHPNT_EL0:
270 1.5 christos do_trapsignal(l, SIGTRAP, TRAP_BRKPT, (void *)tf->tf_pc, esr);
271 1.4 ryo userret(l);
272 1.4 ryo break;
273 1.4 ryo
274 1.4 ryo default:
275 1.4 ryo case ESR_EC_UNKNOWN:
276 1.8 ryo #ifdef DDB
277 1.8 ryo if (sigill_debug) {
278 1.8 ryo /* show illegal instruction */
279 1.11 ryo printf("TRAP: pid %d (%s), uid %d: %s:"
280 1.11 ryo " esr=0x%lx: pc=0x%lx: %s\n",
281 1.8 ryo curlwp->l_proc->p_pid, curlwp->l_proc->p_comm,
282 1.8 ryo l->l_cred ? kauth_cred_geteuid(l->l_cred) : -1,
283 1.11 ryo eclass_trapname(eclass), tf->tf_esr, tf->tf_pc,
284 1.11 ryo strdisasm(tf->tf_pc));
285 1.8 ryo }
286 1.8 ryo #endif
287 1.4 ryo /* illegal or not implemented instruction */
288 1.5 christos do_trapsignal(l, SIGILL, ILL_ILLTRP, (void *)tf->tf_pc, esr);
289 1.4 ryo userret(l);
290 1.4 ryo break;
291 1.4 ryo }
292 1.3 nisimura }
293 1.3 nisimura
294 1.4 ryo void
295 1.4 ryo interrupt(struct trapframe *tf)
296 1.4 ryo {
297 1.4 ryo struct cpu_info * const ci = curcpu();
298 1.2 nisimura
299 1.12 ryo #ifdef STACKCHECKS
300 1.12 ryo struct lwp *l = curlwp;
301 1.12 ryo void *sp = (void *)reg_sp_read();
302 1.12 ryo if (l->l_addr >= sp) {
303 1.12 ryo panic("lwp/interrupt stack overflow detected."
304 1.12 ryo " lwp=%p, sp=%p, l_addr=%p", l, sp, l->l_addr);
305 1.12 ryo }
306 1.12 ryo #endif
307 1.12 ryo
308 1.4 ryo /* enable traps */
309 1.4 ryo daif_enable(DAIF_D|DAIF_A);
310 1.2 nisimura
311 1.4 ryo ci->ci_intr_depth++;
312 1.4 ryo ARM_IRQ_HANDLER(tf);
313 1.4 ryo ci->ci_intr_depth--;
314 1.2 nisimura
315 1.4 ryo cpu_dosoftints();
316 1.4 ryo }
317 1.2 nisimura
318 1.2 nisimura void
319 1.4 ryo trap_el0_32sync(struct trapframe *tf)
320 1.2 nisimura {
321 1.4 ryo struct lwp * const l = curlwp;
322 1.4 ryo const uint32_t esr = tf->tf_esr;
323 1.4 ryo const uint32_t eclass = __SHIFTOUT(esr, ESR_EC); /* exception class */
324 1.4 ryo
325 1.4 ryo /* enable traps and interrupts */
326 1.4 ryo daif_enable(DAIF_D|DAIF_A|DAIF_I|DAIF_F);
327 1.4 ryo
328 1.4 ryo switch (eclass) {
329 1.11 ryo #ifdef COMPAT_NETBSD32
330 1.11 ryo case ESR_EC_INSN_ABT_EL0:
331 1.11 ryo case ESR_EC_DATA_ABT_EL0:
332 1.11 ryo data_abort_handler(tf, eclass);
333 1.11 ryo userret(l);
334 1.11 ryo break;
335 1.11 ryo
336 1.11 ryo case ESR_EC_SVC_A32:
337 1.11 ryo (*l->l_proc->p_md.md_syscall)(tf);
338 1.11 ryo break;
339 1.4 ryo case ESR_EC_FP_ACCESS:
340 1.4 ryo fpu_load(l);
341 1.4 ryo userret(l);
342 1.4 ryo break;
343 1.11 ryo case ESR_EC_FP_TRAP_A32:
344 1.11 ryo do_trapsignal(l, SIGFPE, FPE_FLTUND, NULL, esr); /* XXX */
345 1.4 ryo userret(l);
346 1.4 ryo
347 1.4 ryo case ESR_EC_PC_ALIGNMENT:
348 1.5 christos do_trapsignal(l, SIGBUS, BUS_ADRALN, (void *)tf->tf_pc, esr);
349 1.4 ryo userret(l);
350 1.4 ryo break;
351 1.4 ryo case ESR_EC_SP_ALIGNMENT:
352 1.11 ryo do_trapsignal(l, SIGBUS, BUS_ADRALN,
353 1.11 ryo (void *)tf->tf_reg[13], esr); /* sp is r13 on AArch32 */
354 1.4 ryo userret(l);
355 1.4 ryo break;
356 1.4 ryo
357 1.11 ryo case ESR_EC_BKPT_INSN_A32:
358 1.11 ryo do_trapsignal(l, SIGTRAP, TRAP_BRKPT, (void *)tf->tf_pc, esr);
359 1.11 ryo userret(l);
360 1.4 ryo break;
361 1.11 ryo
362 1.4 ryo case ESR_EC_CP15_RT:
363 1.4 ryo case ESR_EC_CP15_RRT:
364 1.4 ryo case ESR_EC_CP14_RT:
365 1.4 ryo case ESR_EC_CP14_DT:
366 1.4 ryo case ESR_EC_CP14_RRT:
367 1.4 ryo #endif /* COMPAT_NETBSD32 */
368 1.4 ryo default:
369 1.11 ryo #ifdef DDB
370 1.11 ryo if (sigill_debug) {
371 1.11 ryo /* show illegal instruction */
372 1.11 ryo printf("TRAP: pid %d (%s), uid %d: %s:"
373 1.11 ryo " esr=0x%lx: pc=0x%lx: %s\n",
374 1.11 ryo curlwp->l_proc->p_pid, curlwp->l_proc->p_comm,
375 1.11 ryo l->l_cred ? kauth_cred_geteuid(l->l_cred) : -1,
376 1.11 ryo eclass_trapname(eclass), tf->tf_esr, tf->tf_pc,
377 1.11 ryo strdisasm_aarch32(tf->tf_pc));
378 1.11 ryo }
379 1.11 ryo #endif
380 1.11 ryo /* illegal or not implemented instruction */
381 1.5 christos do_trapsignal(l, SIGILL, ILL_ILLTRP, (void *)tf->tf_pc, esr);
382 1.4 ryo userret(l);
383 1.4 ryo break;
384 1.4 ryo }
385 1.4 ryo }
386 1.4 ryo
387 1.4 ryo #define bad_trap_panic(trapfunc) \
388 1.4 ryo void \
389 1.4 ryo trapfunc(struct trapframe *tf) \
390 1.4 ryo { \
391 1.4 ryo panic("%s", __func__); \
392 1.4 ryo }
393 1.4 ryo bad_trap_panic(trap_el1t_sync)
394 1.4 ryo bad_trap_panic(trap_el1t_irq)
395 1.4 ryo bad_trap_panic(trap_el1t_fiq)
396 1.4 ryo bad_trap_panic(trap_el1t_error)
397 1.4 ryo bad_trap_panic(trap_el1h_fiq)
398 1.4 ryo bad_trap_panic(trap_el1h_error)
399 1.4 ryo bad_trap_panic(trap_el0_fiq)
400 1.4 ryo bad_trap_panic(trap_el0_error)
401 1.4 ryo bad_trap_panic(trap_el0_32fiq)
402 1.4 ryo bad_trap_panic(trap_el0_32error)
403 1.2 nisimura
404 1.4 ryo void
405 1.4 ryo cpu_jump_onfault(struct trapframe *tf, const struct faultbuf *fb, int val)
406 1.4 ryo {
407 1.2 nisimura tf->tf_reg[19] = fb->fb_reg[FB_X19];
408 1.2 nisimura tf->tf_reg[20] = fb->fb_reg[FB_X20];
409 1.2 nisimura tf->tf_reg[21] = fb->fb_reg[FB_X21];
410 1.2 nisimura tf->tf_reg[22] = fb->fb_reg[FB_X22];
411 1.2 nisimura tf->tf_reg[23] = fb->fb_reg[FB_X23];
412 1.2 nisimura tf->tf_reg[24] = fb->fb_reg[FB_X24];
413 1.2 nisimura tf->tf_reg[25] = fb->fb_reg[FB_X25];
414 1.2 nisimura tf->tf_reg[26] = fb->fb_reg[FB_X26];
415 1.2 nisimura tf->tf_reg[27] = fb->fb_reg[FB_X27];
416 1.2 nisimura tf->tf_reg[28] = fb->fb_reg[FB_X28];
417 1.2 nisimura tf->tf_reg[29] = fb->fb_reg[FB_X29];
418 1.2 nisimura tf->tf_sp = fb->fb_reg[FB_SP];
419 1.4 ryo tf->tf_pc = fb->fb_reg[FB_LR];
420 1.4 ryo tf->tf_reg[0] = val;
421 1.2 nisimura }
422 1.2 nisimura
423 1.2 nisimura void
424 1.4 ryo ucas_ras_check(struct trapframe *tf)
425 1.2 nisimura {
426 1.4 ryo #if 0 /* XXX notyet */
427 1.4 ryo extern char ucas_32_ras_start[];
428 1.4 ryo extern char ucas_32_ras_end[];
429 1.4 ryo extern char ucas_64_ras_start[];
430 1.4 ryo extern char ucas_64_ras_end[];
431 1.4 ryo
432 1.4 ryo if (tf->tf_pc > (vaddr_t)ucas_32_ras_start &&
433 1.4 ryo tf->tf_pc < (vaddr_t)ucas_32_ras_end) {
434 1.4 ryo tf->tf_pc = (vaddr_t)ucas_32_ras_start;
435 1.4 ryo } else if (tf->tf_pc > (vaddr_t)ucas_64_ras_start &&
436 1.4 ryo tf->tf_pc < (vaddr_t)ucas_64_ras_end) {
437 1.4 ryo tf->tf_pc = (vaddr_t)ucas_64_ras_start;
438 1.2 nisimura }
439 1.4 ryo #endif
440 1.2 nisimura }
441 1.2 nisimura
442 1.6 christos #ifdef TRAP_SIGDEBUG
443 1.6 christos static void
444 1.6 christos frame_dump(const struct trapframe *tf)
445 1.6 christos {
446 1.6 christos const struct reg *r = &tf->tf_regs;
447 1.6 christos
448 1.6 christos printf("trapframe %p\n", tf);
449 1.6 christos for (size_t i = 0; i < __arraycount(r->r_reg); i++) {
450 1.7 christos printf(" r%.2zu %#018" PRIx64 "%c", i, r->r_reg[i],
451 1.6 christos " \n"[i && (i & 1) == 0]);
452 1.6 christos }
453 1.6 christos
454 1.6 christos printf("\n");
455 1.6 christos printf(" sp %#018" PRIx64 " pc %#018" PRIx64 "\n",
456 1.6 christos r->r_sp, r->r_pc);
457 1.6 christos printf(" spsr %#018" PRIx64 " tpidr %#018" PRIx64 "\n",
458 1.6 christos r->r_spsr, r->r_tpidr);
459 1.6 christos printf(" esr %#018" PRIx64 " far %#018" PRIx64 "\n",
460 1.6 christos tf->tf_esr, tf->tf_far);
461 1.6 christos
462 1.6 christos printf("\n");
463 1.6 christos hexdump(printf, "Stack dump", tf, 256);
464 1.6 christos }
465 1.6 christos
466 1.6 christos static void
467 1.6 christos sigdebug(const struct trapframe *tf, const ksiginfo_t *ksi)
468 1.6 christos {
469 1.6 christos struct lwp *l = curlwp;
470 1.6 christos struct proc *p = l->l_proc;
471 1.6 christos const uint32_t eclass = __SHIFTOUT(ksi->ksi_trap, ESR_EC);
472 1.6 christos
473 1.6 christos printf("pid %d.%d (%s): signal %d (trap %#x) "
474 1.6 christos "@pc %#" PRIx64 ", addr %p, error=%s\n",
475 1.6 christos p->p_pid, l->l_lid, p->p_comm, ksi->ksi_signo, ksi->ksi_trap,
476 1.6 christos tf->tf_regs.r_pc, ksi->ksi_addr, eclass_trapname(eclass));
477 1.6 christos frame_dump(tf);
478 1.6 christos }
479 1.6 christos #endif
480 1.6 christos
481 1.6 christos void do_trapsignal1(
482 1.6 christos #ifdef TRAP_SIGDEBUG
483 1.6 christos const char *func,
484 1.6 christos size_t line,
485 1.6 christos struct trapframe *tf,
486 1.6 christos #endif
487 1.6 christos struct lwp *l, int signo, int code, void *addr, int trap)
488 1.6 christos {
489 1.6 christos ksiginfo_t ksi;
490 1.6 christos
491 1.6 christos KSI_INIT_TRAP(&ksi);
492 1.6 christos ksi.ksi_signo = signo;
493 1.6 christos ksi.ksi_code = code;
494 1.6 christos ksi.ksi_addr = addr;
495 1.6 christos ksi.ksi_trap = trap;
496 1.6 christos #ifdef TRAP_SIGDEBUG
497 1.6 christos printf("%s, %zu: ", func, line);
498 1.6 christos sigdebug(tf, &ksi);
499 1.6 christos #endif
500 1.6 christos (*l->l_proc->p_emul->e_trapsignal)(l, &ksi);
501 1.6 christos }
502