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"
45 #include <sys/param.h>
46 #include <sys/malloc.h>
48 #include <sys/systm.h>
54 #include <sys/eventhandler.h>
56 #include <sys/imgact.h>
57 #include <sys/interrupt.h>
59 #include <sys/kernel.h>
61 #include <sys/linker.h>
63 #include <sys/msgbuf.h>
64 #include <sys/mutex.h>
66 #include <sys/ptrace.h>
67 #include <sys/reboot.h>
68 #include <sys/signalvar.h>
70 #include <sys/syscallsubr.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/cache.h>
91 #include <machine/cmt.h>
92 #include <machine/cpu.h>
93 #include <machine/fireplane.h>
94 #include <machine/fp.h>
95 #include <machine/fsr.h>
96 #include <machine/intr_machdep.h>
97 #include <machine/jbus.h>
98 #include <machine/md_var.h>
99 #include <machine/metadata.h>
100 #include <machine/ofw_machdep.h>
101 #include <machine/ofw_mem.h>
102 #include <machine/pcb.h>
103 #include <machine/pmap.h>
104 #include <machine/pstate.h>
105 #include <machine/reg.h>
106 #include <machine/sigframe.h>
107 #include <machine/smp.h>
108 #include <machine/tick.h>
109 #include <machine/tlb.h>
110 #include <machine/tstate.h>
111 #include <machine/upa.h>
112 #include <machine/ver.h>
114 typedef int ofw_vec_t(void *);
117 extern vm_offset_t ksym_start, ksym_end;
122 struct tlb_entry *kernel_tlbs;
123 int kernel_tlb_slots;
130 char pcpu0[PCPU_PAGES * PAGE_SIZE];
131 struct trapframe frame0;
134 vm_paddr_t kstack0_phys;
136 struct kva_md_info kmi;
140 u_int tba_taken_over;
142 char sparc64_model[32];
144 static int cpu_use_vis = 1;
146 cpu_block_copy_t *cpu_block_copy;
147 cpu_block_zero_t *cpu_block_zero;
149 static phandle_t find_bsp(phandle_t node, uint32_t bspid, u_int cpu_impl);
150 void sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3,
152 static void sparc64_shutdown_final(void *dummy, int howto);
154 static void cpu_startup(void *arg);
155 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
157 CTASSERT((1 << INT_SHIFT) == sizeof(int));
158 CTASSERT((1 << PTR_SHIFT) == sizeof(char *));
160 CTASSERT(sizeof(struct reg) == 256);
161 CTASSERT(sizeof(struct fpreg) == 272);
162 CTASSERT(sizeof(struct __mcontext) == 512);
164 CTASSERT((sizeof(struct pcb) & (64 - 1)) == 0);
165 CTASSERT((offsetof(struct pcb, pcb_kfp) & (64 - 1)) == 0);
166 CTASSERT((offsetof(struct pcb, pcb_ufp) & (64 - 1)) == 0);
167 CTASSERT(sizeof(struct pcb) <= ((KSTACK_PAGES * PAGE_SIZE) / 8));
169 CTASSERT(sizeof(struct pcpu) <= ((PCPU_PAGES * PAGE_SIZE) / 2));
172 cpu_startup(void *arg)
178 for (i = 0; i < sparc64_nmemreg; i++)
179 physsz += sparc64_memreg[i].mr_size;
180 printf("real memory = %lu (%lu MB)\n", physsz,
181 physsz / (1024 * 1024));
182 realmem = (long)physsz / PAGE_SIZE;
184 vm_ksubmap_init(&kmi);
187 vm_pager_bufferinit();
189 EVENTHANDLER_REGISTER(shutdown_final, sparc64_shutdown_final, NULL,
192 printf("avail memory = %lu (%lu MB)\n", cnt.v_free_count * PAGE_SIZE,
193 cnt.v_free_count / ((1024 * 1024) / PAGE_SIZE));
196 printf("machine: %s\n", sparc64_model);
198 cpu_identify(rdpr(ver), PCPU_GET(clock), curcpu);
201 * Add BSP as an interrupt target.
207 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
209 struct intr_request *ir;
212 pcpu->pc_irtail = &pcpu->pc_irhead;
213 for (i = 0; i < IR_FREE; i++) {
214 ir = &pcpu->pc_irpool[i];
215 ir->ir_next = pcpu->pc_irfree;
216 pcpu->pc_irfree = ir;
227 if (td->td_md.md_spinlock_count == 0) {
229 wrpr(pil, 0, PIL_TICK);
230 td->td_md.md_spinlock_count = 1;
231 td->td_md.md_saved_pil = pil;
233 td->td_md.md_spinlock_count++;
245 pil = td->td_md.md_saved_pil;
246 td->td_md.md_spinlock_count--;
247 if (td->td_md.md_spinlock_count == 0)
252 find_bsp(phandle_t node, uint32_t bspid, u_int cpu_impl)
254 char type[sizeof("cpu")];
258 for (; node != 0; node = OF_peer(node)) {
259 child = OF_child(node);
261 child = find_bsp(child, bspid, cpu_impl);
265 if (OF_getprop(node, "device_type", type,
268 if (strcmp(type, "cpu") != 0)
270 if (OF_getprop(node, cpu_cpuid_prop(cpu_impl), &cpuid,
281 cpu_cpuid_prop(u_int cpu_impl)
285 case CPU_IMPL_SPARC64:
286 case CPU_IMPL_SPARC64V:
287 case CPU_IMPL_ULTRASPARCI:
288 case CPU_IMPL_ULTRASPARCII:
289 case CPU_IMPL_ULTRASPARCIIi:
290 case CPU_IMPL_ULTRASPARCIIe:
291 return ("upa-portid");
292 case CPU_IMPL_ULTRASPARCIII:
293 case CPU_IMPL_ULTRASPARCIIIp:
294 case CPU_IMPL_ULTRASPARCIIIi:
295 case CPU_IMPL_ULTRASPARCIIIip:
297 case CPU_IMPL_ULTRASPARCIV:
298 case CPU_IMPL_ULTRASPARCIVp:
306 cpu_get_mid(u_int cpu_impl)
310 case CPU_IMPL_SPARC64:
311 case CPU_IMPL_SPARC64V:
312 case CPU_IMPL_ULTRASPARCI:
313 case CPU_IMPL_ULTRASPARCII:
314 case CPU_IMPL_ULTRASPARCIIi:
315 case CPU_IMPL_ULTRASPARCIIe:
316 return (UPA_CR_GET_MID(ldxa(0, ASI_UPA_CONFIG_REG)));
317 case CPU_IMPL_ULTRASPARCIII:
318 case CPU_IMPL_ULTRASPARCIIIp:
319 return (FIREPLANE_CR_GET_AID(ldxa(AA_FIREPLANE_CONFIG,
320 ASI_FIREPLANE_CONFIG_REG)));
321 case CPU_IMPL_ULTRASPARCIIIi:
322 case CPU_IMPL_ULTRASPARCIIIip:
323 return (JBUS_CR_GET_JID(ldxa(0, ASI_JBUS_CONFIG_REG)));
324 case CPU_IMPL_ULTRASPARCIV:
325 case CPU_IMPL_ULTRASPARCIVp:
326 return (INTR_ID_GET_ID(ldxa(AA_INTR_ID, ASI_INTR_ID)));
333 sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
347 * Find out what kind of CPU we have first, for anything that changes
350 cpu_impl = VER_IMPL(rdpr(ver));
353 * Do CPU-specific initialization.
355 if (cpu_impl >= CPU_IMPL_ULTRASPARCIII)
356 cheetah_init(cpu_impl);
357 else if (cpu_impl == CPU_IMPL_SPARC64V)
361 * Clear (S)TICK timer (including NPT).
363 tick_clear(cpu_impl);
366 * UltraSparc II[e,i] based systems come up with the tick interrupt
367 * enabled and a handler that resets the tick counter, causing DELAY()
368 * to not work properly when used early in boot.
369 * UltraSPARC III based systems come up with the system tick interrupt
370 * enabled, causing an interrupt storm on startup since they are not
376 * Set up Open Firmware entry points.
379 ofw_vec = (u_long)vec;
382 * Parse metadata if present and fetch parameters. Must be before the
383 * console is inited so cninit() gets the right value of boothowto.
386 preload_metadata = mdp;
387 kmdp = preload_search_by_type("elf kernel");
389 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
390 kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
391 end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
392 kernel_tlb_slots = MD_FETCH(kmdp, MODINFOMD_DTLB_SLOTS,
394 kernel_tlbs = (void *)preload_search_info(kmdp,
395 MODINFO_METADATA | MODINFOMD_DTLB);
402 * Initialize Open Firmware (needed for console).
404 OF_install(OFW_STD_DIRECT, 0);
408 * Prime our per-CPU data page for use. Note, we are using it for
409 * our stack, so don't pass the real size (PAGE_SIZE) to pcpu_init
410 * or it'll zero it out from under us.
412 pc = (struct pcpu *)(pcpu0 + (PCPU_PAGES * PAGE_SIZE)) - 1;
413 pcpu_init(pc, 0, sizeof(struct pcpu));
414 pc->pc_addr = (vm_offset_t)pcpu0;
415 pc->pc_impl = cpu_impl;
416 pc->pc_mid = cpu_get_mid(cpu_impl);
417 pc->pc_tlb_ctx = TLB_CTX_USER_MIN;
418 pc->pc_tlb_ctx_min = TLB_CTX_USER_MIN;
419 pc->pc_tlb_ctx_max = TLB_CTX_USER_MAX;
422 * Determine the OFW node and frequency of the BSP (and ensure the
423 * BSP is in the device tree in the first place).
426 pc->pc_node = find_bsp(root, pc->pc_mid, cpu_impl);
427 if (pc->pc_node == 0)
428 OF_panic("%s: cannot find boot CPU node", __func__);
429 if (OF_getprop(pc->pc_node, "clock-frequency", &pc->pc_clock,
430 sizeof(pc->pc_clock)) <= 0)
431 OF_panic("%s: cannot determine boot CPU clock", __func__);
434 * Panic if there is no metadata. Most likely the kernel was booted
435 * directly, instead of through loader(8).
437 if (mdp == NULL || kmdp == NULL || end == 0 ||
438 kernel_tlb_slots == 0 || kernel_tlbs == NULL)
439 OF_panic("%s: missing loader metadata.\nThis probably means "
440 "you are not using loader(8).", __func__);
443 * Work around the broken loader behavior of not demapping no
444 * longer used kernel TLB slots when unloading the kernel or
447 for (va = KERNBASE + (kernel_tlb_slots - 1) * PAGE_SIZE_4M;
448 va >= roundup2(end, PAGE_SIZE_4M); va -= PAGE_SIZE_4M) {
450 OF_printf("demapping unused kernel TLB slot "
451 "(va %#lx - %#lx)\n", va, va + PAGE_SIZE_4M - 1);
452 stxa(TLB_DEMAP_VA(va) | TLB_DEMAP_PRIMARY | TLB_DEMAP_PAGE,
454 stxa(TLB_DEMAP_VA(va) | TLB_DEMAP_PRIMARY | TLB_DEMAP_PAGE,
461 * Determine the TLB slot maxima, which are expected to be
462 * equal across all CPUs.
463 * NB: for cheetah-class CPUs, these properties only refer
466 if (OF_getprop(pc->pc_node, "#dtlb-entries", &dtlb_slots,
467 sizeof(dtlb_slots)) == -1)
468 OF_panic("%s: cannot determine number of dTLB slots",
470 if (OF_getprop(pc->pc_node, "#itlb-entries", &itlb_slots,
471 sizeof(itlb_slots)) == -1)
472 OF_panic("%s: cannot determine number of iTLB slots",
476 * Initialize and enable the caches. Note that this may include
477 * applying workarounds.
480 cache_enable(cpu_impl);
481 uma_set_align(pc->pc_cache.dc_linesize - 1);
483 cpu_block_copy = bcopy;
484 cpu_block_zero = bzero;
485 getenv_int("machdep.use_vis", &cpu_use_vis);
488 case CPU_IMPL_SPARC64:
489 case CPU_IMPL_ULTRASPARCI:
490 case CPU_IMPL_ULTRASPARCII:
491 case CPU_IMPL_ULTRASPARCIIi:
492 case CPU_IMPL_ULTRASPARCIIe:
493 case CPU_IMPL_ULTRASPARCIII: /* NB: we've disabled P$. */
494 case CPU_IMPL_ULTRASPARCIIIp:
495 case CPU_IMPL_ULTRASPARCIIIi:
496 case CPU_IMPL_ULTRASPARCIV:
497 case CPU_IMPL_ULTRASPARCIVp:
498 case CPU_IMPL_ULTRASPARCIIIip:
499 cpu_block_copy = spitfire_block_copy;
500 cpu_block_zero = spitfire_block_zero;
502 case CPU_IMPL_SPARC64V:
503 cpu_block_copy = zeus_block_copy;
504 cpu_block_zero = zeus_block_zero;
514 * Initialize virtual memory and calculate physmem.
516 pmap_bootstrap(cpu_impl);
519 * Initialize tunables.
521 init_param2(physmem);
522 env = getenv("kernelname");
524 strlcpy(kernelname, env, sizeof(kernelname));
529 * Initialize the interrupt tables.
534 * Initialize proc0, set kstack0, frame0, curthread and curpcb.
536 proc_linkup0(&proc0, &thread0);
537 proc0.p_md.md_sigtramp = NULL;
538 proc0.p_md.md_utrap = NULL;
539 thread0.td_kstack = kstack0;
540 thread0.td_kstack_pages = KSTACK_PAGES;
541 thread0.td_pcb = (struct pcb *)
542 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
543 frame0.tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_PRIV;
544 thread0.td_frame = &frame0;
545 pc->pc_curthread = &thread0;
546 pc->pc_curpcb = thread0.td_pcb;
549 * Initialize global registers.
554 * Take over the trap table via the PROM. Using the PROM for this
555 * is necessary in order to set obp-control-relinquished to true
556 * within the PROM so obtaining /virtual-memory/translations doesn't
557 * trigger a fatal reset error or worse things further down the road.
558 * XXX it should be possible to use this solely instead of writing
559 * %tba in cpu_setregs(). Doing so causes a hang however.
561 * NB: the low-level console drivers require a working DELAY() and
562 * some compiler optimizations may cause the curthread accesses of
563 * mutex(9) to be factored out even if the latter aren't actually
564 * called. Both of these require PCPU_REG to be set. However, we
565 * can't set PCPU_REG without also taking over the trap table or the
566 * firmware will overwrite it.
568 sun4u_set_traptable(tl0_base);
571 * Initialize the dynamic per-CPU area for the BSP and the message
572 * buffer (after setting the trap table).
574 dpcpu_init(dpcpu0, 0);
575 msgbufinit(msgbufp, msgbufsize);
578 * Initialize mutexes.
583 * Initialize console now that we have a reasonable set of system
589 * Finish the interrupt initialization now that mutexes work and
594 wrpr(pstate, 0, PSTATE_KERNEL);
596 OF_getprop(root, "name", sparc64_model, sizeof(sparc64_model) - 1);
601 if (boothowto & RB_KDB)
602 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
607 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
609 struct trapframe *tf;
610 struct sigframe *sfp;
623 PROC_LOCK_ASSERT(p, MA_OWNED);
624 sig = ksi->ksi_signo;
626 mtx_assert(&psp->ps_mtx, MA_OWNED);
628 sp = tf->tf_sp + SPOFF;
629 oonstack = sigonstack(sp);
631 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
634 /* Make sure we have a signal trampoline to return to. */
635 if (p->p_md.md_sigtramp == NULL) {
637 * No signal trampoline... kill the process.
639 CTR0(KTR_SIG, "sendsig: no sigtramp");
640 printf("sendsig: %s is too old, rebuild it\n", p->p_comm);
645 /* Save user context. */
646 bzero(&sf, sizeof(sf));
647 get_mcontext(td, &sf.sf_uc.uc_mcontext, 0);
648 sf.sf_uc.uc_sigmask = *mask;
649 sf.sf_uc.uc_stack = td->td_sigstk;
650 sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) ?
651 ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
653 /* Allocate and validate space for the signal handler context. */
654 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
655 SIGISMEMBER(psp->ps_sigonstack, sig)) {
656 sfp = (struct sigframe *)(td->td_sigstk.ss_sp +
657 td->td_sigstk.ss_size - sizeof(struct sigframe));
659 sfp = (struct sigframe *)sp - 1;
660 mtx_unlock(&psp->ps_mtx);
663 fp = (struct frame *)sfp - 1;
665 /* Translate the signal if appropriate. */
666 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
667 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
669 /* Build the argument list for the signal handler. */
671 tf->tf_out[2] = (register_t)&sfp->sf_uc;
672 tf->tf_out[4] = (register_t)catcher;
673 if (SIGISMEMBER(psp->ps_siginfo, sig)) {
674 /* Signal handler installed with SA_SIGINFO. */
675 tf->tf_out[1] = (register_t)&sfp->sf_si;
677 /* Fill in POSIX parts. */
678 sf.sf_si = ksi->ksi_info;
679 sf.sf_si.si_signo = sig; /* maybe a translated signal */
681 /* Old FreeBSD-style arguments. */
682 tf->tf_out[1] = ksi->ksi_code;
683 tf->tf_out[3] = (register_t)ksi->ksi_addr;
686 /* Copy the sigframe out to the user's stack. */
687 if (rwindow_save(td) != 0 || copyout(&sf, sfp, sizeof(*sfp)) != 0 ||
688 suword(&fp->fr_in[6], tf->tf_out[6]) != 0) {
690 * Something is wrong with the stack pointer.
691 * ...Kill the process.
693 CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
699 tf->tf_tpc = (u_long)p->p_md.md_sigtramp;
700 tf->tf_tnpc = tf->tf_tpc + 4;
701 tf->tf_sp = (u_long)fp - SPOFF;
703 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#lx sp=%#lx", td, tf->tf_tpc,
707 mtx_lock(&psp->ps_mtx);
710 #ifndef _SYS_SYSPROTO_H_
711 struct sigreturn_args {
720 sys_sigreturn(struct thread *td, struct sigreturn_args *uap)
728 if (rwindow_save(td)) {
733 CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp);
734 if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) {
735 CTR1(KTR_SIG, "sigreturn: efault td=%p", td);
739 mc = &uc.uc_mcontext;
740 error = set_mcontext(td, mc);
744 kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0);
746 CTR4(KTR_SIG, "sigreturn: return td=%p pc=%#lx sp=%#lx tstate=%#lx",
747 td, mc->_mc_tpc, mc->_mc_sp, mc->_mc_tstate);
748 return (EJUSTRETURN);
752 * Construct a PCB from a trapframe. This is called from kdb_trap() where
753 * we want to start a backtrace from the function that caused us to enter
754 * the debugger. We have the context in the trapframe, but base the trace
755 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
756 * enough for a backtrace.
759 makectx(struct trapframe *tf, struct pcb *pcb)
762 pcb->pcb_pc = tf->tf_tpc;
763 pcb->pcb_sp = tf->tf_sp;
767 get_mcontext(struct thread *td, mcontext_t *mc, int flags)
769 struct trapframe *tf;
775 * Copy the registers which will be restored by tl0_ret() from the
777 * Note that we skip %g7 which is used as the userland TLS register
780 mc->_mc_flags = _MC_VERSION;
781 mc->mc_global[1] = tf->tf_global[1];
782 mc->mc_global[2] = tf->tf_global[2];
783 mc->mc_global[3] = tf->tf_global[3];
784 mc->mc_global[4] = tf->tf_global[4];
785 mc->mc_global[5] = tf->tf_global[5];
786 mc->mc_global[6] = tf->tf_global[6];
787 if (flags & GET_MC_CLEAR_RET) {
791 mc->mc_out[0] = tf->tf_out[0];
792 mc->mc_out[1] = tf->tf_out[1];
794 mc->mc_out[2] = tf->tf_out[2];
795 mc->mc_out[3] = tf->tf_out[3];
796 mc->mc_out[4] = tf->tf_out[4];
797 mc->mc_out[5] = tf->tf_out[5];
798 mc->mc_out[6] = tf->tf_out[6];
799 mc->mc_out[7] = tf->tf_out[7];
800 mc->_mc_fprs = tf->tf_fprs;
801 mc->_mc_fsr = tf->tf_fsr;
802 mc->_mc_gsr = tf->tf_gsr;
803 mc->_mc_tnpc = tf->tf_tnpc;
804 mc->_mc_tpc = tf->tf_tpc;
805 mc->_mc_tstate = tf->tf_tstate;
806 mc->_mc_y = tf->tf_y;
808 if ((tf->tf_fprs & FPRS_FEF) != 0) {
809 savefpctx(pcb->pcb_ufp);
810 tf->tf_fprs &= ~FPRS_FEF;
811 pcb->pcb_flags |= PCB_FEF;
813 if ((pcb->pcb_flags & PCB_FEF) != 0) {
814 bcopy(pcb->pcb_ufp, mc->mc_fp, sizeof(mc->mc_fp));
815 mc->_mc_fprs |= FPRS_FEF;
822 set_mcontext(struct thread *td, const mcontext_t *mc)
824 struct trapframe *tf;
827 if (!TSTATE_SECURE(mc->_mc_tstate) ||
828 (mc->_mc_flags & ((1L << _MC_VERSION_BITS) - 1)) != _MC_VERSION)
832 /* Make sure the windows are spilled first. */
835 * Copy the registers which will be restored by tl0_ret() to the
837 * Note that we skip %g7 which is used as the userland TLS register
840 tf->tf_global[1] = mc->mc_global[1];
841 tf->tf_global[2] = mc->mc_global[2];
842 tf->tf_global[3] = mc->mc_global[3];
843 tf->tf_global[4] = mc->mc_global[4];
844 tf->tf_global[5] = mc->mc_global[5];
845 tf->tf_global[6] = mc->mc_global[6];
846 tf->tf_out[0] = mc->mc_out[0];
847 tf->tf_out[1] = mc->mc_out[1];
848 tf->tf_out[2] = mc->mc_out[2];
849 tf->tf_out[3] = mc->mc_out[3];
850 tf->tf_out[4] = mc->mc_out[4];
851 tf->tf_out[5] = mc->mc_out[5];
852 tf->tf_out[6] = mc->mc_out[6];
853 tf->tf_out[7] = mc->mc_out[7];
854 tf->tf_fprs = mc->_mc_fprs;
855 tf->tf_fsr = mc->_mc_fsr;
856 tf->tf_gsr = mc->_mc_gsr;
857 tf->tf_tnpc = mc->_mc_tnpc;
858 tf->tf_tpc = mc->_mc_tpc;
859 tf->tf_tstate = mc->_mc_tstate;
860 tf->tf_y = mc->_mc_y;
861 if ((mc->_mc_fprs & FPRS_FEF) != 0) {
863 bcopy(mc->mc_fp, pcb->pcb_ufp, sizeof(pcb->pcb_ufp));
864 pcb->pcb_flags |= PCB_FEF;
870 * Exit the kernel and execute a firmware call that will not return, as
871 * specified by the arguments.
874 cpu_shutdown(void *args)
884 * Flush the D-cache for non-DMA I/O so that the I-cache can
885 * be made coherent later.
888 cpu_flush_dcache(void *ptr, size_t len)
894 /* Get current clock frequency for the given CPU ID. */
896 cpu_est_clockrate(int cpu_id, uint64_t *rate)
900 pc = pcpu_find(cpu_id);
901 if (pc == NULL || rate == NULL)
903 *rate = pc->pc_clock;
908 * Duplicate OF_exit() with a different firmware call function that restores
909 * the trap table, otherwise a RED state exception is triggered in at least
910 * some firmware versions.
929 sparc64_shutdown_final(void *dummy, int howto)
936 (cell_t)"SUNW,power-off",
941 /* Turn the power off? */
942 if ((howto & RB_POWEROFF) != 0)
944 /* In case of halt, return to the firmware. */
945 if ((howto & RB_HALT) != 0)
953 /* Insert code to halt (until next interrupt) for the idle loop. */
957 cpu_idle_wakeup(int cpu)
964 ptrace_set_pc(struct thread *td, u_long addr)
967 td->td_frame->tf_tpc = addr;
968 td->td_frame->tf_tnpc = addr + 4;
973 ptrace_single_step(struct thread *td)
981 ptrace_clear_single_step(struct thread *td)
989 exec_setregs(struct thread *td, struct image_params *imgp, u_long stack)
991 struct trapframe *tf;
996 /* XXX no cpu_exec */
998 p->p_md.md_sigtramp = NULL;
999 if (p->p_md.md_utrap != NULL) {
1000 utrap_free(p->p_md.md_utrap);
1001 p->p_md.md_utrap = NULL;
1006 sp = rounddown(stack, 16);
1007 bzero(pcb, sizeof(*pcb));
1008 bzero(tf, sizeof(*tf));
1009 tf->tf_out[0] = stack;
1010 tf->tf_out[3] = p->p_sysent->sv_psstrings;
1011 tf->tf_out[6] = sp - SPOFF - sizeof(struct frame);
1012 tf->tf_tnpc = imgp->entry_addr + 4;
1013 tf->tf_tpc = imgp->entry_addr;
1015 * While we could adhere to the memory model indicated in the ELF
1016 * header, it turns out that just always using TSO performs best.
1018 tf->tf_tstate = TSTATE_IE | TSTATE_PEF | TSTATE_MM_TSO;
1020 td->td_retval[0] = tf->tf_out[0];
1021 td->td_retval[1] = tf->tf_out[1];
1025 fill_regs(struct thread *td, struct reg *regs)
1028 bcopy(td->td_frame, regs, sizeof(*regs));
1033 set_regs(struct thread *td, struct reg *regs)
1035 struct trapframe *tf;
1037 if (!TSTATE_SECURE(regs->r_tstate))
1040 regs->r_wstate = tf->tf_wstate;
1041 bcopy(regs, tf, sizeof(*regs));
1046 fill_dbregs(struct thread *td, struct dbreg *dbregs)
1053 set_dbregs(struct thread *td, struct dbreg *dbregs)
1060 fill_fpregs(struct thread *td, struct fpreg *fpregs)
1062 struct trapframe *tf;
1067 bcopy(pcb->pcb_ufp, fpregs->fr_regs, sizeof(fpregs->fr_regs));
1068 fpregs->fr_fsr = tf->tf_fsr;
1069 fpregs->fr_gsr = tf->tf_gsr;
1074 set_fpregs(struct thread *td, struct fpreg *fpregs)
1076 struct trapframe *tf;
1081 tf->tf_fprs &= ~FPRS_FEF;
1082 bcopy(fpregs->fr_regs, pcb->pcb_ufp, sizeof(pcb->pcb_ufp));
1083 tf->tf_fsr = fpregs->fr_fsr;
1084 tf->tf_gsr = fpregs->fr_gsr;
1091 struct md_utrap *ut;
1093 ut = malloc(sizeof(struct md_utrap), M_SUBPROC, M_WAITOK | M_ZERO);
1099 utrap_free(struct md_utrap *ut)
1105 mtx_pool_lock(mtxpool_sleep, ut);
1107 refcnt = ut->ut_refcnt;
1108 mtx_pool_unlock(mtxpool_sleep, ut);
1110 free(ut, M_SUBPROC);
1114 utrap_hold(struct md_utrap *ut)
1119 mtx_pool_lock(mtxpool_sleep, ut);
1121 mtx_pool_unlock(mtxpool_sleep, ut);