2 * Copyright (c) 2001 Jake Burkholder.
3 * Copyright (c) 1992 Terrence R. Lambert.
4 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
35 * from: FreeBSD: src/sys/i386/i386/machdep.c,v 1.477 2001/08/27
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include "opt_compat.h"
43 #include "opt_kstack_pages.h"
44 #include "opt_msgbuf.h"
46 #include <sys/param.h>
47 #include <sys/malloc.h>
49 #include <sys/systm.h>
55 #include <sys/eventhandler.h>
57 #include <sys/imgact.h>
58 #include <sys/interrupt.h>
60 #include <sys/kernel.h>
62 #include <sys/linker.h>
64 #include <sys/msgbuf.h>
65 #include <sys/mutex.h>
67 #include <sys/ptrace.h>
68 #include <sys/reboot.h>
69 #include <sys/signalvar.h>
71 #include <sys/sysent.h>
72 #include <sys/sysproto.h>
73 #include <sys/timetc.h>
74 #include <sys/ucontext.h>
76 #include <dev/ofw/openfirm.h>
79 #include <vm/vm_extern.h>
80 #include <vm/vm_kern.h>
81 #include <vm/vm_page.h>
82 #include <vm/vm_map.h>
83 #include <vm/vm_object.h>
84 #include <vm/vm_pager.h>
85 #include <vm/vm_param.h>
89 #include <machine/bus.h>
90 #include <machine/clock.h>
91 #include <machine/cpu.h>
92 #include <machine/fp.h>
93 #include <machine/fsr.h>
94 #include <machine/intr_machdep.h>
95 #include <machine/md_var.h>
96 #include <machine/metadata.h>
97 #include <machine/ofw_machdep.h>
98 #include <machine/ofw_mem.h>
99 #include <machine/pcb.h>
100 #include <machine/pmap.h>
101 #include <machine/pstate.h>
102 #include <machine/reg.h>
103 #include <machine/sigframe.h>
104 #include <machine/smp.h>
105 #include <machine/tick.h>
106 #include <machine/tlb.h>
107 #include <machine/tstate.h>
108 #include <machine/asm.h>
109 #include <machine/hv_api.h>
110 #include <machine/wstate.h>
112 #include <machine/md_var.h>
113 #include <machine/hypervisorvar.h>
114 #include <dev/ofw/openfirm.h>
116 /* XXX move this to a header */
117 extern void mdesc_init(void);
119 typedef int ofw_vec_t(void *);
122 extern vm_offset_t ksym_start, ksym_end;
125 struct tlb_entry *kernel_tlbs;
126 int kernel_tlb_slots;
133 char pcpu0[PCPU_PAGES * PAGE_SIZE];
134 struct trapframe frame0;
135 int trap_conversion[256];
136 vm_paddr_t mmu_fault_status_area;
139 vm_paddr_t kstack0_phys;
141 struct kva_md_info kmi;
147 * Note: timer quality for CPU's is set low to try and prevent them from
148 * being chosen as the primary timecounter. The CPU counters are not
149 * synchronized among the CPU's so in MP machines this causes problems
150 * when calculating the time. With this value the CPU's should only be
151 * chosen as the primary timecounter as a last resort.
154 #define UP_TICK_QUALITY 1000
156 #define MP_TICK_QUALITY 1000
158 #define MP_TICK_QUALITY -100
165 static struct timecounter tick_tc;
167 char sparc64_model[32];
169 cpu_block_copy_t *cpu_block_copy;
170 cpu_block_zero_t *cpu_block_zero;
172 static timecounter_get_t tick_get_timecount;
173 void sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3,
175 void sparc64_shutdown_final(void *dummy, int howto);
177 static void cpu_startup(void *);
178 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
180 CTASSERT((1 << INT_SHIFT) == sizeof(int));
181 CTASSERT((1 << PTR_SHIFT) == sizeof(char *));
183 CTASSERT(sizeof(struct reg) == 256);
184 CTASSERT(sizeof(struct fpreg) == 272);
185 CTASSERT(sizeof(struct __mcontext) == 512);
187 CTASSERT((sizeof(struct pcb) & (64 - 1)) == 0);
188 CTASSERT((offsetof(struct pcb, pcb_kfp) & (64 - 1)) == 0);
189 CTASSERT((offsetof(struct pcb, pcb_ufp) & (64 - 1)) == 0);
190 CTASSERT(sizeof(struct pcb) <= ((KSTACK_PAGES * PAGE_SIZE) / 8));
192 CTASSERT(sizeof(struct pcpu) <= ((PCPU_PAGES * PAGE_SIZE) / 2));
193 CTASSERT((sizeof(struct pcpu) & ((1<<6)-1)) == 0);
196 #define BVPRINTF(x) \
201 cpu_startup(void *arg)
206 tick_tc.tc_get_timecount = tick_get_timecount;
207 tick_tc.tc_poll_pps = NULL;
208 tick_tc.tc_counter_mask = ~0u;
209 tick_tc.tc_frequency = tick_freq;
210 tick_tc.tc_name = "tick";
211 tick_tc.tc_quality = UP_TICK_QUALITY;
214 * We do not know if each CPU's tick counter is synchronized.
217 tick_tc.tc_quality = MP_TICK_QUALITY;
223 for (i = 0; i < sparc64_nmemreg; i++)
224 physsz += sparc64_memreg[i].mr_size;
225 printf("real memory = %lu (%lu MB)\n", physsz,
226 physsz / (1024 * 1024));
227 realmem = (long)physsz;
229 vm_ksubmap_init(&kmi);
232 vm_pager_bufferinit();
234 EVENTHANDLER_REGISTER(shutdown_final, sparc64_shutdown_final, NULL,
237 printf("avail memory = %lu (%lu MB)\n", cnt.v_free_count * PAGE_SIZE,
238 cnt.v_free_count / ((1024 * 1024) / PAGE_SIZE));
241 printf("machine: %s\n", sparc64_model);
244 cpu_identify(rdpr(ver), tick_freq, PCPU_GET(cpuid));
249 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
251 struct intr_request *ir;
254 pcpu->pc_irtail = &pcpu->pc_irhead;
255 for (i = 0; i < IR_FREE; i++) {
256 ir = &pcpu->pc_irpool[i];
257 ir->ir_next = pcpu->pc_irfree;
258 pcpu->pc_irfree = ir;
269 if (td->td_md.md_spinlock_count == 0) {
270 pil = intr_disable();
271 td->td_md.md_saved_pil = pil;
273 td->td_md.md_spinlock_count++;
284 td->td_md.md_spinlock_count--;
285 if (td->td_md.md_spinlock_count == 0) {
286 intr_restore(td->td_md.md_saved_pil);
292 tick_get_timecount(struct timecounter *tc)
294 return ((unsigned)rd(tick));
298 sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
320 * Set up Open Firmware entry points
323 ofw_vec = (u_long)vec;
326 * Parse metadata if present and fetch parameters. Must be before the
327 * console is inited so cninit gets the right value of boothowto.
330 preload_metadata = mdp;
331 kmdp = preload_search_by_type("elf kernel");
333 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
334 kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
335 end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
336 kernel_tlb_slots = MD_FETCH(kmdp, MODINFOMD_DTLB_SLOTS,
338 kernel_tlbs = (void *)preload_search_info(kmdp,
339 MODINFO_METADATA | MODINFOMD_DTLB);
343 if (boothowto & RB_VERBOSE)
349 * Initialize Open Firmware (needed for console).
351 OF_install(OFW_STD_DIRECT, 0);
355 for (child = OF_child(root); child != 0; child = OF_peer(child)) {
356 OF_getprop(child, "device_type", type, sizeof(type));
357 if (strcmp(type, "cpu") == 0)
361 OF_getprop(child, "clock-frequency", &clock, sizeof(clock));
364 * Initialize the console before printing anything.
365 * console uses the pcpu area for serialization
367 pc = (struct pcpu *)(pcpu0 + (PCPU_PAGES * PAGE_SIZE)) - 1;
371 * Initialize proc0 stuff (p_contested needs to be done early).
374 proc_linkup0(&proc0, &thread0);
375 proc0.p_md.md_sigtramp = NULL;
376 proc0.p_md.md_utrap = NULL;
377 frame0.tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_PRIV;
378 thread0.td_frame = &frame0;
379 if ((u_long)thread0.td_frame & 0x3f) {
380 panic("unaligned frame0");
384 * Prime our per-cpu data page for use. Note, we are using it for our
385 * stack, so don't pass the real size (PAGE_SIZE) to pcpu_init or
386 * it'll zero it out from under us.
388 pc = (struct pcpu *)(pcpu0 + (PCPU_PAGES * PAGE_SIZE)) - 1;
389 pcpu_init(pc, 0, sizeof(struct pcpu));
390 pc->pc_curthread = &thread0;
391 pc->pc_addr = (vm_offset_t)pcpu0;
396 printf("cpu0: UltraSparc T1 Processor (%d.%02d MHz CPU)\n",
397 (clock + 4999) / 1000000, ((clock + 4999) / 10000) % 100);
400 * Panic is there is no metadata. Most likely the kernel was booted
401 * directly, instead of through loader(8).
403 if (mdp == NULL || kmdp == NULL) {
404 printf("sparc64_init: no loader metadata.\n"
405 "This probably means you are not using loader(8).\n");
406 panic("sparc64_init");
410 * Sanity check the kernel end, which is important.
413 printf("sparc64_init: warning, kernel end not specified.\n"
414 "Attempting to continue anyway.\n");
415 end = (vm_offset_t)_end;
418 cpu_block_copy = bcopy;
419 cpu_block_zero = bzero;
422 mp_tramp = mp_tramp_alloc();
425 env = getenv("kernelname");
427 strlcpy(kernelname, env, sizeof(kernelname));
432 * Initialize global registers.
433 * needed for curthread to work
438 * Initialize virtual memory and calculate physmem.
442 thread0.td_kstack = kstack0;
443 thread0.td_md.md_saved_pil = 0;
444 thread0.td_pcb = (struct pcb *)
445 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
446 thread0.td_pcb->pcb_kstack = (uint64_t)(((char *)thread0.td_pcb) - (CCFSZ + SPOFF));
447 thread0.td_pcb = (struct pcb *)TLB_PHYS_TO_DIRECT(vtophys((vm_offset_t)thread0.td_pcb));
448 pc->pc_curpcb = thread0.td_pcb;
450 if (((thread0.td_pcb->pcb_kstack + SPOFF) & 0x3f) != 0) {
451 printf("unaligned stack pcb_kstack & 0x3f == 0x%lx\n",
452 ((thread0.td_pcb->pcb_kstack + SPOFF) & 0x3f));
456 * Update PCPU_REG to point to direct address
457 * to support easy phys <-> virt translation in trap handler
459 pc = (struct pcpu *)TLB_PHYS_TO_DIRECT(vtophys(pc));
461 BVPRINTF("initializing cpu regs\n");
465 * Initialize tunables.
467 BVPRINTF("initialize tunables\n");
468 init_param2(physmem);
471 * setup trap table and fault status area
473 BVPRINTF("initialize trap tables\n");
475 mmfsa = mmu_fault_status_area + MMFSA_SIZE;
476 BVPRINTF("setwstate\n");
477 set_wstate(WSTATE_KERN);
478 BVPRINTF("set_mmfsa_scratchpad\n");
479 set_mmfsa_scratchpad(mmfsa);
481 BVPRINTF("init_mondo_queue\n");
483 BVPRINTF("set_mmfsa_traptable\n");
484 set_mmfsa_traptable(&tl0_base, mmfsa);
485 BVPRINTF("trap conversion\n");
486 for (i = 0; i < 256; i++)
487 trap_conversion[i] = 0;
488 trap_conversion[TT_INSTRUCTION_EXCEPTION] = T_INSTRUCTION_EXCEPTION;
489 trap_conversion[TT_INSTRUCTION_MISS] = T_INSTRUCTION_MISS;
490 trap_conversion[TT_ILLEGAL_INSTRUCTION] = T_ILLEGAL_INSTRUCTION;
491 trap_conversion[TT_PRIVILEGED_OPCODE] = T_PRIVILEGED_OPCODE;
492 trap_conversion[TT_FP_EXCEPTION_IEEE_754] = T_FP_EXCEPTION_IEEE_754;
493 trap_conversion[TT_TAG_OVERFLOW] = T_TAG_OVERFLOW;
494 trap_conversion[TT_DIVISION_BY_ZERO] = T_DIVISION_BY_ZERO;
495 trap_conversion[TT_DATA_EXCEPTION] = T_DATA_EXCEPTION;
496 trap_conversion[TT_DATA_MISS] = T_DATA_MISS;
497 trap_conversion[TT_ALIGNMENT] = T_ALIGNMENT;
498 trap_conversion[TT_DATA_PROTECTION] = T_DATA_PROTECTION;
501 * Initialize the message buffer (after setting trap table).
503 BVPRINTF("initialize msgbuf\n");
504 dpcpu_init(dpcpu0, 0);
505 msgbufinit(msgbufp, MSGBUF_SIZE);
507 BVPRINTF("initialize mutexes\n");
510 BVPRINTF("initialize machine descriptor table\n");
513 BVPRINTF("initialize get model name\n");
514 OF_getprop(root, "name", sparc64_model, sizeof(sparc64_model) - 1);
516 BVPRINTF("initialize kdb\n");
520 if (boothowto & RB_KDB)
521 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
523 BVPRINTF("sparc64_init done\n");
527 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
529 struct trapframe *tf;
530 struct sigframe *sfp;
544 PROC_LOCK_ASSERT(p, MA_OWNED);
545 sig = ksi->ksi_signo;
546 code = ksi->ksi_code;
548 mtx_assert(&psp->ps_mtx, MA_OWNED);
550 sp = tf->tf_sp + SPOFF;
551 oonstack = sigonstack(sp);
553 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
556 /* Make sure we have a signal trampoline to return to. */
557 if (p->p_md.md_sigtramp == NULL) {
559 * No signal tramoline... kill the process.
561 CTR0(KTR_SIG, "sendsig: no sigtramp");
562 printf("sendsig: %s is too old, rebuild it\n", p->p_comm);
567 /* Save user context. */
568 bzero(&sf, sizeof(sf));
569 get_mcontext(td, &sf.sf_uc.uc_mcontext, 0);
570 sf.sf_uc.uc_sigmask = *mask;
571 sf.sf_uc.uc_stack = td->td_sigstk;
572 sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
573 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
575 /* Allocate and validate space for the signal handler context. */
576 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
577 SIGISMEMBER(psp->ps_sigonstack, sig)) {
578 sfp = (struct sigframe *)(td->td_sigstk.ss_sp +
579 td->td_sigstk.ss_size - sizeof(struct sigframe));
581 sfp = (struct sigframe *)sp - 1;
582 mtx_unlock(&psp->ps_mtx);
585 fp = (struct frame *)sfp - 1;
587 /* Translate the signal if appropriate. */
588 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
589 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
591 /* Build the argument list for the signal handler. */
593 tf->tf_out[2] = (register_t)&sfp->sf_uc;
594 tf->tf_out[4] = (register_t)catcher;
596 /* Fill siginfo structure. */
597 sf.sf_si = ksi->ksi_info;
598 sf.sf_si.si_addr = (void *)tf->tf_tpc;
599 if (SIGISMEMBER(psp->ps_siginfo, sig)) {
600 /* Signal handler installed with SA_SIGINFO. */
601 tf->tf_out[1] = (register_t)&sfp->sf_si;
603 /* Fill in POSIX parts. */
604 sf.sf_si = ksi->ksi_info;
605 sf.sf_si.si_signo = sig; /* maybe a translated signal */
607 /* Old FreeBSD-style arguments. */
608 tf->tf_out[1] = ksi->ksi_code;
609 tf->tf_out[3] = (register_t)ksi->ksi_addr;
612 /* Copy the sigframe out to the user's stack. */
613 if (rwindow_save(td) != 0 || copyout(&sf, sfp, sizeof(*sfp)) != 0 ||
614 suword(&fp->fr_in[6], tf->tf_out[6]) != 0) {
616 * Something is wrong with the stack pointer.
617 * ...Kill the process.
619 CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
625 tf->tf_tpc = (u_long)p->p_md.md_sigtramp;
626 tf->tf_tnpc = tf->tf_tpc + 4;
627 tf->tf_sp = (u_long)fp - SPOFF;
629 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#lx sp=%#lx", td, tf->tf_tpc,
633 mtx_lock(&psp->ps_mtx);
636 #ifndef _SYS_SYSPROTO_H_
637 struct sigreturn_args {
646 sigreturn(struct thread *td, struct sigreturn_args *uap)
654 if (rwindow_save(td)) {
659 CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp);
660 if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) {
661 CTR1(KTR_SIG, "sigreturn: efault td=%p", td);
665 mc = &uc.uc_mcontext;
666 error = set_mcontext(td, mc);
670 kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
672 CTR4(KTR_SIG, "sigreturn: return td=%p pc=%#lx sp=%#lx tstate=%#lx",
673 td, mc->mc_tpc, mc->mc_sp, mc->mc_tstate);
674 return (EJUSTRETURN);
677 #ifdef COMPAT_FREEBSD4
679 freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
682 return sigreturn(td, (struct sigreturn_args *)uap);
687 * Construct a PCB from a trapframe. This is called from kdb_trap() where
688 * we want to start a backtrace from the function that caused us to enter
689 * the debugger. We have the context in the trapframe, but base the trace
690 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
691 * enough for a backtrace.
694 makectx(struct trapframe *tf, struct pcb *pcb)
697 pcb->pcb_pc = tf->tf_tpc;
698 pcb->pcb_sp = tf->tf_sp;
702 get_mcontext(struct thread *td, mcontext_t *mc, int flags)
704 struct trapframe *tf;
709 bcopy(tf, mc, sizeof(*tf));
710 if (flags & GET_MC_CLEAR_RET) {
714 mc->mc_flags = _MC_VERSION;
716 if ((tf->tf_fprs & FPRS_FEF) != 0) {
717 savefpctx(pcb->pcb_ufp);
718 pcb->pcb_flags |= PCB_FEF;
719 tf->tf_fprs &= ~FPRS_FEF;
721 if ((pcb->pcb_flags & PCB_FEF) != 0) {
722 bcopy(pcb->pcb_ufp, mc->mc_fp, sizeof(mc->mc_fp));
723 mc->mc_fprs |= FPRS_FEF;
730 set_mcontext(struct thread *td, const mcontext_t *mc)
732 struct trapframe *tf;
736 if (!TSTATE_SECURE(mc->mc_tstate) ||
737 (mc->mc_flags & ((1L << _MC_VERSION_BITS) - 1)) != _MC_VERSION)
741 /* Make sure the windows are spilled first. */
743 wstate = tf->tf_wstate;
744 bcopy(mc, tf, sizeof(*tf));
745 tf->tf_wstate = wstate;
746 if ((mc->mc_fprs & FPRS_FEF) != 0) {
748 bcopy(mc->mc_fp, pcb->pcb_ufp, sizeof(pcb->pcb_ufp));
749 pcb->pcb_flags |= PCB_FEF;
755 * Exit the kernel and execute a firmware call that will not return, as
756 * specified by the arguments.
759 cpu_shutdown(void *args)
769 * Flush the D-cache for non-DMA I/O so that the I-cache can
770 * be made coherent later.
773 cpu_flush_dcache(void *ptr, size_t len)
778 /* Get current clock frequency for the given cpu id. */
780 cpu_est_clockrate(int cpu_id, uint64_t *rate)
787 * Duplicate OF_exit() with a different firmware call function that restores
788 * the trap table, otherwise a RED state exception is triggered in at least
789 * some firmware versions.
808 sparc64_shutdown_final(void *dummy, int howto)
815 (cell_t)"SUNW,power-off",
820 /* Turn the power off? */
821 if ((howto & RB_POWEROFF) != 0)
823 /* In case of halt, return to the firmware */
824 if ((howto & RB_HALT) != 0)
833 panic("pil in cpu_idle not 0 - %ld", rdpr(pil));
834 if (rdpr(pstate) != 0x16)
835 panic("interrupts disabled in cpu_idle 0x%lx", rdpr(pstate));
836 /* XXX heinous hack begin*/
842 cpu_idle_wakeup(int cpu)
849 ptrace_set_pc(struct thread *td, u_long addr)
852 td->td_frame->tf_tpc = addr;
853 td->td_frame->tf_tnpc = addr + 4;
858 ptrace_single_step(struct thread *td)
865 ptrace_clear_single_step(struct thread *td)
872 exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
874 struct trapframe *tf;
880 /* XXX no cpu_exec */
883 p->p_md.md_sigtramp = NULL;
884 if (p->p_md.md_utrap != NULL) {
885 utrap_free(p->p_md.md_utrap);
886 p->p_md.md_utrap = NULL;
889 kstack = pcb->pcb_kstack;
891 sp = rounddown(stack, 16);
892 bzero(pcb, sizeof(*pcb));
893 bzero(tf, sizeof(*tf));
894 pcb->pcb_kstack = kstack;
896 tf->tf_out[0] = stack;
897 tf->tf_out[3] = p->p_sysent->sv_psstrings;
898 tf->tf_out[6] = sp - SPOFF - sizeof(struct frame);
900 tf->tf_tnpc = entry + 4;
902 tf->tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_MM_TSO;
904 td->td_retval[0] = tf->tf_out[0];
905 td->td_retval[1] = tf->tf_out[1];
909 fill_regs(struct thread *td, struct reg *regs)
912 bcopy(td->td_frame, regs, sizeof(*regs));
917 set_regs(struct thread *td, struct reg *regs)
919 struct trapframe *tf;
921 if (!TSTATE_SECURE(regs->r_tstate))
924 regs->r_wstate = tf->tf_wstate;
925 bcopy(regs, tf, sizeof(*regs));
930 fill_dbregs(struct thread *td, struct dbreg *dbregs)
937 set_dbregs(struct thread *td, struct dbreg *dbregs)
944 fill_fpregs(struct thread *td, struct fpreg *fpregs)
946 struct trapframe *tf;
951 tf->tf_fprs = ~FPRS_FEF;
952 bcopy(pcb->pcb_ufp, fpregs->fr_regs, sizeof(fpregs->fr_regs));
953 fpregs->fr_fsr = tf->tf_fsr;
954 fpregs->fr_gsr = tf->tf_gsr;
959 set_fpregs(struct thread *td, struct fpreg *fpregs)
961 struct trapframe *tf;
966 tf->tf_fprs &= ~FPRS_FEF;
967 bcopy(fpregs->fr_regs, pcb->pcb_ufp, sizeof(pcb->pcb_ufp));
968 tf->tf_fsr = fpregs->fr_fsr;
969 tf->tf_gsr = fpregs->fr_gsr;
978 ut = malloc(sizeof(struct md_utrap), M_SUBPROC, M_WAITOK | M_ZERO);
984 utrap_free(struct md_utrap *ut)
990 mtx_pool_lock(mtxpool_sleep, ut);
992 refcnt = ut->ut_refcnt;
993 mtx_pool_unlock(mtxpool_sleep, ut);
999 utrap_hold(struct md_utrap *ut)
1004 mtx_pool_lock(mtxpool_sleep, ut);
1006 mtx_pool_unlock(mtxpool_sleep, ut);
1013 if (rdpr(pil) < PIL_TICK)