]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm64/arm64/exec_machdep.c
Merge bmake-20220330
[FreeBSD/FreeBSD.git] / sys / arm64 / arm64 / exec_machdep.c
1 /*-
2  * Copyright (c) 2014 Andrew Turner
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/exec.h>
34 #include <sys/imgact.h>
35 #include <sys/kdb.h>
36 #include <sys/kernel.h>
37 #include <sys/ktr.h>
38 #include <sys/limits.h>
39 #include <sys/lock.h>
40 #include <sys/mutex.h>
41 #include <sys/proc.h>
42 #include <sys/ptrace.h>
43 #include <sys/reg.h>
44 #include <sys/rwlock.h>
45 #include <sys/signalvar.h>
46 #include <sys/syscallsubr.h>
47 #include <sys/sysent.h>
48 #include <sys/sysproto.h>
49 #include <sys/ucontext.h>
50
51 #include <vm/vm.h>
52 #include <vm/vm_param.h>
53
54 #include <machine/armreg.h>
55 #include <machine/kdb.h>
56 #include <machine/md_var.h>
57 #include <machine/pcb.h>
58
59 #ifdef VFP
60 #include <machine/vfp.h>
61 #endif
62
63 _Static_assert(sizeof(mcontext_t) == 880, "mcontext_t size incorrect");
64 _Static_assert(sizeof(ucontext_t) == 960, "ucontext_t size incorrect");
65 _Static_assert(sizeof(siginfo_t) == 80, "siginfo_t size incorrect");
66
67 static void get_fpcontext(struct thread *td, mcontext_t *mcp);
68 static void set_fpcontext(struct thread *td, mcontext_t *mcp);
69
70 int
71 fill_regs(struct thread *td, struct reg *regs)
72 {
73         struct trapframe *frame;
74
75         frame = td->td_frame;
76         regs->sp = frame->tf_sp;
77         regs->lr = frame->tf_lr;
78         regs->elr = frame->tf_elr;
79         regs->spsr = frame->tf_spsr;
80
81         memcpy(regs->x, frame->tf_x, sizeof(regs->x));
82
83 #ifdef COMPAT_FREEBSD32
84         /*
85          * We may be called here for a 32bits process, if we're using a
86          * 64bits debugger. If so, put PC and SPSR where it expects it.
87          */
88         if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
89                 regs->x[15] = frame->tf_elr;
90                 regs->x[16] = frame->tf_spsr;
91         }
92 #endif
93         return (0);
94 }
95
96 int
97 set_regs(struct thread *td, struct reg *regs)
98 {
99         struct trapframe *frame;
100
101         frame = td->td_frame;
102         frame->tf_sp = regs->sp;
103         frame->tf_lr = regs->lr;
104
105         memcpy(frame->tf_x, regs->x, sizeof(frame->tf_x));
106
107 #ifdef COMPAT_FREEBSD32
108         if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
109                 /*
110                  * We may be called for a 32bits process if we're using
111                  * a 64bits debugger. If so, get PC and SPSR from where
112                  * it put it.
113                  */
114                 frame->tf_elr = regs->x[15];
115                 frame->tf_spsr &= ~PSR_SETTABLE_32;
116                 frame->tf_spsr |= regs->x[16] & PSR_SETTABLE_32;
117                 /* Don't allow userspace to ask to continue single stepping.
118                  * The SPSR.SS field doesn't exist when the EL1 is AArch32.
119                  * As the SPSR.DIT field has moved in its place don't
120                  * allow userspace to set the SPSR.SS field.
121                  */
122         } else
123 #endif
124         {
125                 frame->tf_elr = regs->elr;
126                 frame->tf_spsr &= ~PSR_SETTABLE_64;
127                 frame->tf_spsr |= regs->spsr & PSR_SETTABLE_64;
128                 /* Enable single stepping if userspace asked fot it */
129                 if ((frame->tf_spsr & PSR_SS) != 0) {
130                         td->td_pcb->pcb_flags |= PCB_SINGLE_STEP;
131
132                         WRITE_SPECIALREG(mdscr_el1,
133                             READ_SPECIALREG(mdscr_el1) | MDSCR_SS);
134                         isb();
135                 }
136         }
137         return (0);
138 }
139
140 int
141 fill_fpregs(struct thread *td, struct fpreg *regs)
142 {
143 #ifdef VFP
144         struct pcb *pcb;
145
146         pcb = td->td_pcb;
147         if ((pcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
148                 /*
149                  * If we have just been running VFP instructions we will
150                  * need to save the state to memcpy it below.
151                  */
152                 if (td == curthread)
153                         vfp_save_state(td, pcb);
154
155                 KASSERT(pcb->pcb_fpusaved == &pcb->pcb_fpustate,
156                     ("Called fill_fpregs while the kernel is using the VFP"));
157                 memcpy(regs->fp_q, pcb->pcb_fpustate.vfp_regs,
158                     sizeof(regs->fp_q));
159                 regs->fp_cr = pcb->pcb_fpustate.vfp_fpcr;
160                 regs->fp_sr = pcb->pcb_fpustate.vfp_fpsr;
161         } else
162 #endif
163                 memset(regs, 0, sizeof(*regs));
164         return (0);
165 }
166
167 int
168 set_fpregs(struct thread *td, struct fpreg *regs)
169 {
170 #ifdef VFP
171         struct pcb *pcb;
172
173         pcb = td->td_pcb;
174         KASSERT(pcb->pcb_fpusaved == &pcb->pcb_fpustate,
175             ("Called set_fpregs while the kernel is using the VFP"));
176         memcpy(pcb->pcb_fpustate.vfp_regs, regs->fp_q, sizeof(regs->fp_q));
177         pcb->pcb_fpustate.vfp_fpcr = regs->fp_cr;
178         pcb->pcb_fpustate.vfp_fpsr = regs->fp_sr;
179 #endif
180         return (0);
181 }
182
183 int
184 fill_dbregs(struct thread *td, struct dbreg *regs)
185 {
186         struct debug_monitor_state *monitor;
187         int i;
188         uint8_t debug_ver, nbkpts, nwtpts;
189
190         memset(regs, 0, sizeof(*regs));
191
192         extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_DebugVer_SHIFT,
193             &debug_ver);
194         extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_BRPs_SHIFT,
195             &nbkpts);
196         extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_WRPs_SHIFT,
197             &nwtpts);
198
199         /*
200          * The BRPs field contains the number of breakpoints - 1. Armv8-A
201          * allows the hardware to provide 2-16 breakpoints so this won't
202          * overflow an 8 bit value. The same applies to the WRPs field.
203          */
204         nbkpts++;
205         nwtpts++;
206
207         regs->db_debug_ver = debug_ver;
208         regs->db_nbkpts = nbkpts;
209         regs->db_nwtpts = nwtpts;
210
211         monitor = &td->td_pcb->pcb_dbg_regs;
212         if ((monitor->dbg_flags & DBGMON_ENABLED) != 0) {
213                 for (i = 0; i < nbkpts; i++) {
214                         regs->db_breakregs[i].dbr_addr = monitor->dbg_bvr[i];
215                         regs->db_breakregs[i].dbr_ctrl = monitor->dbg_bcr[i];
216                 }
217                 for (i = 0; i < nwtpts; i++) {
218                         regs->db_watchregs[i].dbw_addr = monitor->dbg_wvr[i];
219                         regs->db_watchregs[i].dbw_ctrl = monitor->dbg_wcr[i];
220                 }
221         }
222
223         return (0);
224 }
225
226 int
227 set_dbregs(struct thread *td, struct dbreg *regs)
228 {
229         struct debug_monitor_state *monitor;
230         uint64_t addr;
231         uint32_t ctrl;
232         int i;
233
234         monitor = &td->td_pcb->pcb_dbg_regs;
235         monitor->dbg_enable_count = 0;
236
237         for (i = 0; i < DBG_BRP_MAX; i++) {
238                 addr = regs->db_breakregs[i].dbr_addr;
239                 ctrl = regs->db_breakregs[i].dbr_ctrl;
240
241                 /*
242                  * Don't let the user set a breakpoint on a kernel or
243                  * non-canonical user address.
244                  */
245                 if (addr >= VM_MAXUSER_ADDRESS)
246                         return (EINVAL);
247
248                 /*
249                  * The lowest 2 bits are ignored, so record the effective
250                  * address.
251                  */
252                 addr = rounddown2(addr, 4);
253
254                 /*
255                  * Some control fields are ignored, and other bits reserved.
256                  * Only unlinked, address-matching breakpoints are supported.
257                  *
258                  * XXX: fields that appear unvalidated, such as BAS, have
259                  * constrained undefined behaviour. If the user mis-programs
260                  * these, there is no risk to the system.
261                  */
262                 ctrl &= DBGBCR_EN | DBGBCR_PMC | DBGBCR_BAS;
263                 if ((ctrl & DBGBCR_EN) != 0) {
264                         /* Only target EL0. */
265                         if ((ctrl & DBGBCR_PMC) != DBGBCR_PMC_EL0)
266                                 return (EINVAL);
267
268                         monitor->dbg_enable_count++;
269                 }
270
271                 monitor->dbg_bvr[i] = addr;
272                 monitor->dbg_bcr[i] = ctrl;
273         }
274
275         for (i = 0; i < DBG_WRP_MAX; i++) {
276                 addr = regs->db_watchregs[i].dbw_addr;
277                 ctrl = regs->db_watchregs[i].dbw_ctrl;
278
279                 /*
280                  * Don't let the user set a watchpoint on a kernel or
281                  * non-canonical user address.
282                  */
283                 if (addr >= VM_MAXUSER_ADDRESS)
284                         return (EINVAL);
285
286                 /*
287                  * Some control fields are ignored, and other bits reserved.
288                  * Only unlinked watchpoints are supported.
289                  */
290                 ctrl &= DBGWCR_EN | DBGWCR_PAC | DBGWCR_LSC | DBGWCR_BAS |
291                     DBGWCR_MASK;
292
293                 if ((ctrl & DBGWCR_EN) != 0) {
294                         /* Only target EL0. */
295                         if ((ctrl & DBGWCR_PAC) != DBGWCR_PAC_EL0)
296                                 return (EINVAL);
297
298                         /* Must set at least one of the load/store bits. */
299                         if ((ctrl & DBGWCR_LSC) == 0)
300                                 return (EINVAL);
301
302                         /*
303                          * When specifying the address range with BAS, the MASK
304                          * field must be zero.
305                          */
306                         if ((ctrl & DBGWCR_BAS) != DBGWCR_BAS &&
307                             (ctrl & DBGWCR_MASK) != 0)
308                                 return (EINVAL);
309
310                         monitor->dbg_enable_count++;
311                 }
312                 monitor->dbg_wvr[i] = addr;
313                 monitor->dbg_wcr[i] = ctrl;
314         }
315
316         if (monitor->dbg_enable_count > 0)
317                 monitor->dbg_flags |= DBGMON_ENABLED;
318
319         return (0);
320 }
321
322 #ifdef COMPAT_FREEBSD32
323 int
324 fill_regs32(struct thread *td, struct reg32 *regs)
325 {
326         int i;
327         struct trapframe *tf;
328
329         tf = td->td_frame;
330         for (i = 0; i < 13; i++)
331                 regs->r[i] = tf->tf_x[i];
332         /* For arm32, SP is r13 and LR is r14 */
333         regs->r_sp = tf->tf_x[13];
334         regs->r_lr = tf->tf_x[14];
335         regs->r_pc = tf->tf_elr;
336         regs->r_cpsr = tf->tf_spsr;
337
338         return (0);
339 }
340
341 int
342 set_regs32(struct thread *td, struct reg32 *regs)
343 {
344         int i;
345         struct trapframe *tf;
346
347         tf = td->td_frame;
348         for (i = 0; i < 13; i++)
349                 tf->tf_x[i] = regs->r[i];
350         /* For arm 32, SP is r13 an LR is r14 */
351         tf->tf_x[13] = regs->r_sp;
352         tf->tf_x[14] = regs->r_lr;
353         tf->tf_elr = regs->r_pc;
354         tf->tf_spsr &= ~PSR_SETTABLE_32;
355         tf->tf_spsr |= regs->r_cpsr & PSR_SETTABLE_32;
356
357         return (0);
358 }
359
360 /* XXX fill/set dbregs/fpregs are stubbed on 32-bit arm. */
361 int
362 fill_fpregs32(struct thread *td, struct fpreg32 *regs)
363 {
364
365         memset(regs, 0, sizeof(*regs));
366         return (0);
367 }
368
369 int
370 set_fpregs32(struct thread *td, struct fpreg32 *regs)
371 {
372
373         return (0);
374 }
375
376 int
377 fill_dbregs32(struct thread *td, struct dbreg32 *regs)
378 {
379
380         memset(regs, 0, sizeof(*regs));
381         return (0);
382 }
383
384 int
385 set_dbregs32(struct thread *td, struct dbreg32 *regs)
386 {
387
388         return (0);
389 }
390 #endif
391
392 void
393 exec_setregs(struct thread *td, struct image_params *imgp, uintptr_t stack)
394 {
395         struct trapframe *tf = td->td_frame;
396         struct pcb *pcb = td->td_pcb;
397
398         memset(tf, 0, sizeof(struct trapframe));
399
400         tf->tf_x[0] = stack;
401         tf->tf_sp = STACKALIGN(stack);
402         tf->tf_lr = imgp->entry_addr;
403         tf->tf_elr = imgp->entry_addr;
404
405         td->td_pcb->pcb_tpidr_el0 = 0;
406         td->td_pcb->pcb_tpidrro_el0 = 0;
407         WRITE_SPECIALREG(tpidrro_el0, 0);
408         WRITE_SPECIALREG(tpidr_el0, 0);
409
410 #ifdef VFP
411         vfp_reset_state(td, pcb);
412 #endif
413
414         /*
415          * Clear debug register state. It is not applicable to the new process.
416          */
417         bzero(&pcb->pcb_dbg_regs, sizeof(pcb->pcb_dbg_regs));
418
419         /* Generate new pointer authentication keys */
420         ptrauth_exec(td);
421 }
422
423 /* Sanity check these are the same size, they will be memcpy'd to and from */
424 CTASSERT(sizeof(((struct trapframe *)0)->tf_x) ==
425     sizeof((struct gpregs *)0)->gp_x);
426 CTASSERT(sizeof(((struct trapframe *)0)->tf_x) ==
427     sizeof((struct reg *)0)->x);
428
429 int
430 get_mcontext(struct thread *td, mcontext_t *mcp, int clear_ret)
431 {
432         struct trapframe *tf = td->td_frame;
433
434         if (clear_ret & GET_MC_CLEAR_RET) {
435                 mcp->mc_gpregs.gp_x[0] = 0;
436                 mcp->mc_gpregs.gp_spsr = tf->tf_spsr & ~PSR_C;
437         } else {
438                 mcp->mc_gpregs.gp_x[0] = tf->tf_x[0];
439                 mcp->mc_gpregs.gp_spsr = tf->tf_spsr;
440         }
441
442         memcpy(&mcp->mc_gpregs.gp_x[1], &tf->tf_x[1],
443             sizeof(mcp->mc_gpregs.gp_x[1]) * (nitems(mcp->mc_gpregs.gp_x) - 1));
444
445         mcp->mc_gpregs.gp_sp = tf->tf_sp;
446         mcp->mc_gpregs.gp_lr = tf->tf_lr;
447         mcp->mc_gpregs.gp_elr = tf->tf_elr;
448         get_fpcontext(td, mcp);
449
450         return (0);
451 }
452
453 int
454 set_mcontext(struct thread *td, mcontext_t *mcp)
455 {
456         struct trapframe *tf = td->td_frame;
457         uint32_t spsr;
458
459         spsr = mcp->mc_gpregs.gp_spsr;
460         if ((spsr & PSR_M_MASK) != PSR_M_EL0t ||
461             (spsr & PSR_AARCH32) != 0 ||
462             (spsr & PSR_DAIF) != (td->td_frame->tf_spsr & PSR_DAIF))
463                 return (EINVAL); 
464
465         memcpy(tf->tf_x, mcp->mc_gpregs.gp_x, sizeof(tf->tf_x));
466
467         tf->tf_sp = mcp->mc_gpregs.gp_sp;
468         tf->tf_lr = mcp->mc_gpregs.gp_lr;
469         tf->tf_elr = mcp->mc_gpregs.gp_elr;
470         tf->tf_spsr = mcp->mc_gpregs.gp_spsr;
471         if ((tf->tf_spsr & PSR_SS) != 0) {
472                 td->td_pcb->pcb_flags |= PCB_SINGLE_STEP;
473
474                 WRITE_SPECIALREG(mdscr_el1,
475                     READ_SPECIALREG(mdscr_el1) | MDSCR_SS);
476                 isb();
477         }
478         set_fpcontext(td, mcp);
479
480         return (0);
481 }
482
483 static void
484 get_fpcontext(struct thread *td, mcontext_t *mcp)
485 {
486 #ifdef VFP
487         struct pcb *curpcb;
488
489         critical_enter();
490
491         curpcb = curthread->td_pcb;
492
493         if ((curpcb->pcb_fpflags & PCB_FP_STARTED) != 0) {
494                 /*
495                  * If we have just been running VFP instructions we will
496                  * need to save the state to memcpy it below.
497                  */
498                 vfp_save_state(td, curpcb);
499
500                 KASSERT(curpcb->pcb_fpusaved == &curpcb->pcb_fpustate,
501                     ("Called get_fpcontext while the kernel is using the VFP"));
502                 KASSERT((curpcb->pcb_fpflags & ~PCB_FP_USERMASK) == 0,
503                     ("Non-userspace FPU flags set in get_fpcontext"));
504                 memcpy(mcp->mc_fpregs.fp_q, curpcb->pcb_fpustate.vfp_regs,
505                     sizeof(mcp->mc_fpregs.fp_q));
506                 mcp->mc_fpregs.fp_cr = curpcb->pcb_fpustate.vfp_fpcr;
507                 mcp->mc_fpregs.fp_sr = curpcb->pcb_fpustate.vfp_fpsr;
508                 mcp->mc_fpregs.fp_flags = curpcb->pcb_fpflags;
509                 mcp->mc_flags |= _MC_FP_VALID;
510         }
511
512         critical_exit();
513 #endif
514 }
515
516 static void
517 set_fpcontext(struct thread *td, mcontext_t *mcp)
518 {
519 #ifdef VFP
520         struct pcb *curpcb;
521
522         critical_enter();
523
524         if ((mcp->mc_flags & _MC_FP_VALID) != 0) {
525                 curpcb = curthread->td_pcb;
526
527                 /*
528                  * Discard any vfp state for the current thread, we
529                  * are about to override it.
530                  */
531                 vfp_discard(td);
532
533                 KASSERT(curpcb->pcb_fpusaved == &curpcb->pcb_fpustate,
534                     ("Called set_fpcontext while the kernel is using the VFP"));
535                 memcpy(curpcb->pcb_fpustate.vfp_regs, mcp->mc_fpregs.fp_q,
536                     sizeof(mcp->mc_fpregs.fp_q));
537                 curpcb->pcb_fpustate.vfp_fpcr = mcp->mc_fpregs.fp_cr;
538                 curpcb->pcb_fpustate.vfp_fpsr = mcp->mc_fpregs.fp_sr;
539                 curpcb->pcb_fpflags = mcp->mc_fpregs.fp_flags & PCB_FP_USERMASK;
540         }
541
542         critical_exit();
543 #endif
544 }
545
546 int
547 sys_sigreturn(struct thread *td, struct sigreturn_args *uap)
548 {
549         ucontext_t uc;
550         int error;
551
552         if (copyin(uap->sigcntxp, &uc, sizeof(uc)))
553                 return (EFAULT);
554
555         error = set_mcontext(td, &uc.uc_mcontext);
556         if (error != 0)
557                 return (error);
558
559         /* Restore signal mask. */
560         kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
561
562         return (EJUSTRETURN);
563 }
564
565 void
566 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
567 {
568         struct thread *td;
569         struct proc *p;
570         struct trapframe *tf;
571         struct sigframe *fp, frame;
572         struct sigacts *psp;
573         int onstack, sig;
574
575         td = curthread;
576         p = td->td_proc;
577         PROC_LOCK_ASSERT(p, MA_OWNED);
578
579         sig = ksi->ksi_signo;
580         psp = p->p_sigacts;
581         mtx_assert(&psp->ps_mtx, MA_OWNED);
582
583         tf = td->td_frame;
584         onstack = sigonstack(tf->tf_sp);
585
586         CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
587             catcher, sig);
588
589         /* Allocate and validate space for the signal handler context. */
590         if ((td->td_pflags & TDP_ALTSTACK) != 0 && !onstack &&
591             SIGISMEMBER(psp->ps_sigonstack, sig)) {
592                 fp = (struct sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
593                     td->td_sigstk.ss_size);
594 #if defined(COMPAT_43)
595                 td->td_sigstk.ss_flags |= SS_ONSTACK;
596 #endif
597         } else {
598                 fp = (struct sigframe *)td->td_frame->tf_sp;
599         }
600
601         /* Make room, keeping the stack aligned */
602         fp--;
603         fp = (struct sigframe *)STACKALIGN(fp);
604
605         /* Fill in the frame to copy out */
606         bzero(&frame, sizeof(frame));
607         get_mcontext(td, &frame.sf_uc.uc_mcontext, 0);
608         frame.sf_si = ksi->ksi_info;
609         frame.sf_uc.uc_sigmask = *mask;
610         frame.sf_uc.uc_stack = td->td_sigstk;
611         frame.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) != 0 ?
612             (onstack ? SS_ONSTACK : 0) : SS_DISABLE;
613         mtx_unlock(&psp->ps_mtx);
614         PROC_UNLOCK(td->td_proc);
615
616         /* Copy the sigframe out to the user's stack. */
617         if (copyout(&frame, fp, sizeof(*fp)) != 0) {
618                 /* Process has trashed its stack. Kill it. */
619                 CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp);
620                 PROC_LOCK(p);
621                 sigexit(td, SIGILL);
622         }
623
624         tf->tf_x[0] = sig;
625         tf->tf_x[1] = (register_t)&fp->sf_si;
626         tf->tf_x[2] = (register_t)&fp->sf_uc;
627         tf->tf_x[8] = (register_t)catcher;
628         tf->tf_sp = (register_t)fp;
629         tf->tf_elr = (register_t)p->p_sysent->sv_sigcode_base;
630
631         /* Clear the single step flag while in the signal handler */
632         if ((td->td_pcb->pcb_flags & PCB_SINGLE_STEP) != 0) {
633                 td->td_pcb->pcb_flags &= ~PCB_SINGLE_STEP;
634                 WRITE_SPECIALREG(mdscr_el1,
635                     READ_SPECIALREG(mdscr_el1) & ~MDSCR_SS);
636                 isb();
637         }
638
639         CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_elr,
640             tf->tf_sp);
641
642         PROC_LOCK(p);
643         mtx_lock(&psp->ps_mtx);
644 }