2 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
3 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by TooLs GmbH.
17 * 4. The name of TooLs GmbH may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * Copyright (C) 2001 Benno Rice
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
44 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
50 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
52 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
60 #include "opt_compat.h"
62 #include "opt_kstack_pages.h"
63 #include "opt_msgbuf.h"
65 #include <sys/param.h>
67 #include <sys/systm.h>
73 #include <sys/eventhandler.h>
75 #include <sys/imgact.h>
77 #include <sys/kernel.h>
79 #include <sys/linker.h>
81 #include <sys/malloc.h>
83 #include <sys/msgbuf.h>
84 #include <sys/mutex.h>
85 #include <sys/ptrace.h>
86 #include <sys/reboot.h>
87 #include <sys/signalvar.h>
88 #include <sys/sysctl.h>
89 #include <sys/sysent.h>
90 #include <sys/sysproto.h>
91 #include <sys/ucontext.h>
93 #include <sys/vmmeter.h>
94 #include <sys/vnode.h>
96 #include <net/netisr.h>
99 #include <vm/vm_extern.h>
100 #include <vm/vm_kern.h>
101 #include <vm/vm_page.h>
102 #include <vm/vm_map.h>
103 #include <vm/vm_object.h>
104 #include <vm/vm_pager.h>
106 #include <machine/bat.h>
107 #include <machine/cpu.h>
108 #include <machine/elf.h>
109 #include <machine/fpu.h>
110 #include <machine/md_var.h>
111 #include <machine/metadata.h>
112 #include <machine/mmuvar.h>
113 #include <machine/pcb.h>
114 #include <machine/powerpc.h>
115 #include <machine/reg.h>
116 #include <machine/sigframe.h>
117 #include <machine/trap.h>
118 #include <machine/vmparam.h>
122 #include <dev/ofw/openfirm.h>
125 extern vm_offset_t ksym_start, ksym_end;
130 struct pcpu __pcpu[MAXCPU];
131 struct trapframe frame0;
134 vm_offset_t kstack0_phys;
136 char machine[] = "powerpc";
137 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
139 static int cacheline_size = CACHELINESIZE;
140 SYSCTL_INT(_machdep, CPU_CACHELINE, cacheline_size,
141 CTLFLAG_RD, &cacheline_size, 0, "");
143 static void cpu_startup(void *);
144 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL)
146 void powerpc_init(u_int, u_int, u_int, void *);
148 int save_ofw_mapping(void);
149 int restore_ofw_mapping(void);
151 void install_extint(void (*)(void));
153 int setfault(faultbuf); /* defined in locore.S */
155 static int grab_mcontext(struct thread *, mcontext_t *, int);
157 void asm_panic(char *);
162 struct pmap ofw_pmap;
165 struct bat battable[16];
167 struct kva_md_info kmi;
169 void setPQL2(int *const size, int *const ways);
172 setPQL2(int *const size, int *const ways)
178 powerpc_ofw_shutdown(void *junk, int howto)
180 if (howto & RB_HALT) {
187 cpu_startup(void *dummy)
191 * Good {morning,afternoon,evening,night}.
193 cpu_setup(PCPU_GET(cpuid));
195 /* startrtclock(); */
199 printf("real memory = %ld (%ld MB)\n", ptoa(physmem),
200 ptoa(physmem) / 1048576);
204 * Display any holes after the first chunk of extended memory.
209 printf("Physical memory chunk(s):\n");
210 for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
211 int size1 = phys_avail[indx + 1] - phys_avail[indx];
213 printf("0x%08x - 0x%08x, %d bytes (%d pages)\n",
214 phys_avail[indx], phys_avail[indx + 1] - 1, size1,
219 vm_ksubmap_init(&kmi);
221 printf("avail memory = %ld (%ld MB)\n", ptoa(cnt.v_free_count),
222 ptoa(cnt.v_free_count) / 1048576);
225 * Set up buffers, so they can be used to read disk labels.
228 vm_pager_bufferinit();
230 EVENTHANDLER_REGISTER(shutdown_final, powerpc_ofw_shutdown, 0,
235 * OK, enough kmem_alloc/malloc state should be up, lets get on with it!
237 mp_start(); /* fire up the secondaries */
242 extern char kernel_text[], _end[];
244 extern void *trapcode, *trapsize;
245 extern void *alitrap, *alisize;
246 extern void *dsitrap, *dsisize;
247 extern void *decrint, *decrsize;
248 extern void *extint, *extsize;
249 extern void *dblow, *dbsize;
250 extern void *vectrap, *vectrapsize;
253 powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, void *mdp)
256 vm_offset_t end, off;
264 * Parse metadata if present and fetch parameters. Must be done
265 * before console is inited so cninit gets the right value of
269 preload_metadata = mdp;
270 kmdp = preload_search_by_type("elf kernel");
272 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
273 kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
274 end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
276 ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t);
277 ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t);
283 * Init params/tunables that can be overridden by the loader
288 * Start initializing proc0 and thread0.
290 proc_linkup(&proc0, &thread0);
291 thread0.td_frame = &frame0;
294 * Set up per-cpu data.
297 pcpu_init(pc, 0, sizeof(struct pcpu));
298 pc->pc_curthread = &thread0;
299 pc->pc_curpcb = thread0.td_pcb;
302 __asm __volatile("mtsprg 0, %0" :: "r"(pc));
307 * Initialize the console before printing anything.
312 * Complain if there is no metadata.
314 if (mdp == NULL || kmdp == NULL) {
315 printf("powerpc_init: no loader metadata.\n");
323 * XXX: Initialize the interrupt tables.
324 * Disable translation in case the vector area
325 * hasn't been mapped (G5)
327 mtmsr(mfmsr() & ~(PSL_IR | PSL_DR));
329 bcopy(&trapcode, (void *)EXC_RST, (size_t)&trapsize);
330 bcopy(&trapcode, (void *)EXC_MCHK, (size_t)&trapsize);
331 bcopy(&dsitrap, (void *)EXC_DSI, (size_t)&dsisize);
332 bcopy(&trapcode, (void *)EXC_ISI, (size_t)&trapsize);
333 bcopy(&trapcode, (void *)EXC_EXI, (size_t)&trapsize);
334 bcopy(&alitrap, (void *)EXC_ALI, (size_t)&alisize);
335 bcopy(&trapcode, (void *)EXC_PGM, (size_t)&trapsize);
336 bcopy(&trapcode, (void *)EXC_FPU, (size_t)&trapsize);
337 bcopy(&trapcode, (void *)EXC_DECR, (size_t)&trapsize);
338 bcopy(&trapcode, (void *)EXC_SC, (size_t)&trapsize);
339 bcopy(&trapcode, (void *)EXC_TRC, (size_t)&trapsize);
340 bcopy(&trapcode, (void *)EXC_FPA, (size_t)&trapsize);
341 bcopy(&vectrap, (void *)EXC_VEC, (size_t)&vectrapsize);
342 bcopy(&trapcode, (void *)EXC_VECAST, (size_t)&trapsize);
343 bcopy(&trapcode, (void *)EXC_THRM, (size_t)&trapsize);
344 bcopy(&trapcode, (void *)EXC_BPT, (size_t)&trapsize);
346 bcopy(&dblow, (void *)EXC_RST, (size_t)&dbsize);
347 bcopy(&dblow, (void *)EXC_MCHK, (size_t)&dbsize);
348 bcopy(&dblow, (void *)EXC_PGM, (size_t)&dbsize);
349 bcopy(&dblow, (void *)EXC_TRC, (size_t)&dbsize);
350 bcopy(&dblow, (void *)EXC_BPT, (size_t)&dbsize);
352 __syncicache(EXC_RSVD, EXC_LAST - EXC_RSVD);
355 * Make sure translation has been enabled
357 mtmsr(mfmsr() | PSL_IR|PSL_DR|PSL_ME|PSL_RI);
361 * Initialise virtual memory.
363 pmap_mmu_install(MMU_TYPE_OEA, 0); /* XXX temporary */
364 pmap_bootstrap(startkernel, endkernel);
367 * Initialize params/tunables that are derived from memsize
369 init_param2(physmem);
372 * Grab booted kernel's name
374 env = getenv("kernelname");
376 strlcpy(kernelname, env, sizeof(kernelname));
381 * Finish setting up thread0.
383 thread0.td_kstack = kstack0;
384 thread0.td_pcb = (struct pcb *)
385 (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
388 * Map and initialise the message buffer.
390 for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE)
391 pmap_kenter((vm_offset_t)msgbufp + off, msgbuf_phys + off);
392 msgbufinit(msgbufp, MSGBUF_SIZE);
395 if (boothowto & RB_KDB)
396 kdb_enter("Boot flags requested debugger");
401 bzero(void *buf, size_t len)
407 while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) {
412 while (len >= sizeof(u_long) * 8) {
414 *((u_long*) p + 1) = 0;
415 *((u_long*) p + 2) = 0;
416 *((u_long*) p + 3) = 0;
417 len -= sizeof(u_long) * 8;
418 *((u_long*) p + 4) = 0;
419 *((u_long*) p + 5) = 0;
420 *((u_long*) p + 6) = 0;
421 *((u_long*) p + 7) = 0;
422 p += sizeof(u_long) * 8;
425 while (len >= sizeof(u_long)) {
427 len -= sizeof(u_long);
438 sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
440 struct trapframe *tf;
441 struct sigframe *sfp;
446 int oonstack, rndfsize;
452 PROC_LOCK_ASSERT(p, MA_OWNED);
453 sig = ksi->ksi_signo;
454 code = ksi->ksi_code;
456 mtx_assert(&psp->ps_mtx, MA_OWNED);
458 oonstack = sigonstack(tf->fixreg[1]);
460 rndfsize = ((sizeof(sf) + 15) / 16) * 16;
462 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
468 memset(&sf, 0, sizeof(sf));
469 grab_mcontext(td, &sf.sf_uc.uc_mcontext, 0);
470 sf.sf_uc.uc_sigmask = *mask;
471 sf.sf_uc.uc_stack = td->td_sigstk;
472 sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
473 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
475 sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
478 * Allocate and validate space for the signal handler context.
480 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
481 SIGISMEMBER(psp->ps_sigonstack, sig)) {
482 sfp = (struct sigframe *)(td->td_sigstk.ss_sp +
483 td->td_sigstk.ss_size - rndfsize);
485 sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize);
489 * Translate the signal if appropriate (Linux emu ?)
491 if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
492 sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
495 * Save the floating-point state, if necessary, then copy it.
500 * Set up the registers to return to sigcode.
502 * r1/sp - sigframe ptr
503 * lr - sig function, dispatched to by blrl in trampoline
505 * r4 - SIGINFO ? &siginfo : exception code
507 * srr0 - trampoline function addr
509 tf->lr = (register_t)catcher;
510 tf->fixreg[1] = (register_t)sfp;
511 tf->fixreg[FIRSTARG] = sig;
512 tf->fixreg[FIRSTARG+2] = (register_t)&sfp->sf_uc;
513 if (SIGISMEMBER(psp->ps_siginfo, sig)) {
515 * Signal handler installed with SA_SIGINFO.
517 tf->fixreg[FIRSTARG+1] = (register_t)&sfp->sf_si;
520 * Fill siginfo structure.
522 sf.sf_si = ksi->ksi_info;
523 sf.sf_si.si_signo = sig;
524 sf.sf_si.si_addr = (void *) ((tf->exc == EXC_DSI) ?
527 /* Old FreeBSD-style arguments. */
528 tf->fixreg[FIRSTARG+1] = code;
529 tf->fixreg[FIRSTARG+3] = (tf->exc == EXC_DSI) ?
532 mtx_unlock(&psp->ps_mtx);
535 tf->srr0 = (register_t)(PS_STRINGS - *(p->p_sysent->sv_szsigcode));
538 * copy the frame out to userland.
540 if (copyout(&sf, sfp, sizeof(*sfp)) != 0) {
542 * Process has trashed its stack. Kill it.
544 CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
549 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td,
550 tf->srr0, tf->fixreg[1]);
553 mtx_lock(&psp->ps_mtx);
557 sigreturn(struct thread *td, struct sigreturn_args *uap)
563 CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp);
565 if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) {
566 CTR1(KTR_SIG, "sigreturn: efault td=%p", td);
570 error = set_mcontext(td, &uc.uc_mcontext);
576 td->td_sigmask = uc.uc_sigmask;
577 SIG_CANTMASK(td->td_sigmask);
581 CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x",
582 td, uc.uc_mcontext.mc_srr0, uc.uc_mcontext.mc_gpr[1]);
584 return (EJUSTRETURN);
587 #ifdef COMPAT_FREEBSD4
589 freebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
592 return sigreturn(td, (struct sigreturn_args *)uap);
597 * Construct a PCB from a trapframe. This is called from kdb_trap() where
598 * we want to start a backtrace from the function that caused us to enter
599 * the debugger. We have the context in the trapframe, but base the trace
600 * on the PCB. The PCB doesn't have to be perfect, as long as it contains
601 * enough for a backtrace.
604 makectx(struct trapframe *tf, struct pcb *pcb)
607 pcb->pcb_lr = tf->srr0;
608 pcb->pcb_sp = tf->fixreg[1];
612 * get_mcontext/sendsig helper routine that doesn't touch the
616 grab_mcontext(struct thread *td, mcontext_t *mcp, int flags)
622 memset(mcp, 0, sizeof(mcontext_t));
624 mcp->mc_vers = _MC_VERSION;
626 memcpy(&mcp->mc_frame, td->td_frame, sizeof(struct trapframe));
627 if (flags & GET_MC_CLEAR_RET) {
633 * This assumes that floating-point context is *not* lazy,
634 * so if the thread has used FP there would have been a
635 * FP-unavailable exception that would have set things up
638 if (pcb->pcb_flags & PCB_FPU) {
639 KASSERT(td == curthread,
640 ("get_mcontext: fp save not curthread"));
644 mcp->mc_flags |= _MC_FP_VALID;
645 memcpy(&mcp->mc_fpscr, &pcb->pcb_fpu.fpscr, sizeof(double));
646 memcpy(mcp->mc_fpreg, pcb->pcb_fpu.fpr, 32*sizeof(double));
649 /* XXX Altivec context ? */
651 mcp->mc_len = sizeof(*mcp);
657 get_mcontext(struct thread *td, mcontext_t *mcp, int flags)
661 error = grab_mcontext(td, mcp, flags);
663 PROC_LOCK(curthread->td_proc);
664 mcp->mc_onstack = sigonstack(td->td_frame->fixreg[1]);
665 PROC_UNLOCK(curthread->td_proc);
672 set_mcontext(struct thread *td, const mcontext_t *mcp)
675 struct trapframe *tf;
680 if (mcp->mc_vers != _MC_VERSION ||
681 mcp->mc_len != sizeof(*mcp))
685 * Don't let the user set privileged MSR bits
687 if ((mcp->mc_srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC)) {
691 memcpy(tf, mcp->mc_frame, sizeof(mcp->mc_frame));
693 if (mcp->mc_flags & _MC_FP_VALID) {
694 if ((pcb->pcb_flags & PCB_FPU) != PCB_FPU) {
699 memcpy(&pcb->pcb_fpu.fpscr, &mcp->mc_fpscr, sizeof(double));
700 memcpy(pcb->pcb_fpu.fpr, mcp->mc_fpreg, 32*sizeof(double));
703 /* XXX Altivec context? */
720 /* Get current clock frequency for the given cpu id. */
722 cpu_est_clockrate(int cpu_id, uint64_t *rate)
729 * Shutdown the CPU as much as possible.
741 /* TODO: Insert code to halt (until next interrupt) */
744 if ((mfmsr() & PSL_EE) != PSL_EE) {
745 struct thread *td = curthread;
746 printf("td msr %x\n", td->td_md.md_saved_msr);
747 panic("ints disabled in idleproc!");
753 * Set set up registers on exec.
756 exec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
758 struct trapframe *tf;
759 struct ps_strings arginfo;
762 bzero(tf, sizeof *tf);
763 tf->fixreg[1] = -roundup(-stack + 8, 16);
766 * XXX Machine-independent code has already copied arguments and
767 * XXX environment to userland. Get them back here.
769 (void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo));
772 * Set up arguments for _start():
773 * _start(argc, argv, envp, obj, cleanup, ps_strings);
776 * - obj and cleanup are the auxilliary and termination
777 * vectors. They are fixed up by ld.elf_so.
778 * - ps_strings is a NetBSD extention, and will be
779 * ignored by executables which are strictly
780 * compliant with the SVR4 ABI.
782 * XXX We have to set both regs and retval here due to different
783 * XXX calling convention in trap.c and init_main.c.
786 * XXX PG: these get overwritten in the syscall return code.
787 * execve() should return EJUSTRETURN, like it does on NetBSD.
788 * Emulate by setting the syscall return value cells. The
789 * registers still have to be set for init's fork trampoline.
791 td->td_retval[0] = arginfo.ps_nargvstr;
792 td->td_retval[1] = (register_t)arginfo.ps_argvstr;
793 tf->fixreg[3] = arginfo.ps_nargvstr;
794 tf->fixreg[4] = (register_t)arginfo.ps_argvstr;
795 tf->fixreg[5] = (register_t)arginfo.ps_envstr;
796 tf->fixreg[6] = 0; /* auxillary vector */
797 tf->fixreg[7] = 0; /* termination vector */
798 tf->fixreg[8] = (register_t)PS_STRINGS; /* NetBSD extension */
801 tf->srr1 = PSL_MBO | PSL_USERSET | PSL_FE_DFLT;
802 td->td_pcb->pcb_flags = 0;
806 fill_regs(struct thread *td, struct reg *regs)
808 struct trapframe *tf;
811 memcpy(regs, tf, sizeof(struct reg));
817 fill_dbregs(struct thread *td, struct dbreg *dbregs)
819 /* No debug registers on PowerPC */
824 fill_fpregs(struct thread *td, struct fpreg *fpregs)
830 if ((pcb->pcb_flags & PCB_FPU) == 0)
831 memset(fpregs, 0, sizeof(struct fpreg));
833 memcpy(fpregs, &pcb->pcb_fpu, sizeof(struct fpreg));
839 set_regs(struct thread *td, struct reg *regs)
841 struct trapframe *tf;
844 memcpy(tf, regs, sizeof(struct reg));
850 set_dbregs(struct thread *td, struct dbreg *dbregs)
852 /* No debug registers on PowerPC */
857 set_fpregs(struct thread *td, struct fpreg *fpregs)
862 if ((pcb->pcb_flags & PCB_FPU) == 0)
864 memcpy(&pcb->pcb_fpu, fpregs, sizeof(struct fpreg));
870 ptrace_set_pc(struct thread *td, unsigned long addr)
872 struct trapframe *tf;
875 tf->srr0 = (register_t)addr;
881 ptrace_single_step(struct thread *td)
883 struct trapframe *tf;
892 ptrace_clear_single_step(struct thread *td)
894 struct trapframe *tf;
903 * Initialise a struct pcpu.
906 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
917 if (td->td_md.md_spinlock_count == 0)
918 td->td_md.md_saved_msr = intr_disable();
919 td->td_md.md_spinlock_count++;
930 td->td_md.md_spinlock_count--;
931 if (td->td_md.md_spinlock_count == 0)
932 intr_restore(td->td_md.md_saved_msr);
936 * kcopy(const void *src, void *dst, size_t len);
938 * Copy len bytes from src to dst, aborting if we encounter a fatal
941 * kcopy() _must_ save and restore the old fault handler since it is
942 * called by uiomove(), which may be in the path of servicing a non-fatal
946 kcopy(const void *src, void *dst, size_t len)
949 faultbuf env, *oldfault;
952 td = PCPU_GET(curthread);
953 oldfault = td->td_pcb->pcb_onfault;
954 if ((rv = setfault(env)) != 0) {
955 td->td_pcb->pcb_onfault = oldfault;
959 memcpy(dst, src, len);
961 td->td_pcb->pcb_onfault = oldfault;
966 asm_panic(char *pstr)
971 int db_trap_glue(struct trapframe *); /* Called from trap_subr.S */
974 db_trap_glue(struct trapframe *frame)
976 if (!(frame->srr1 & PSL_PR)
977 && (frame->exc == EXC_TRC || frame->exc == EXC_RUNMODETRC
978 || (frame->exc == EXC_PGM
979 && (frame->srr1 & 0x20000))
980 || frame->exc == EXC_BPT
981 || frame->exc == EXC_DSI)) {
982 int type = frame->exc;
983 if (type == EXC_PGM && (frame->srr1 & 0x20000)) {
986 return (kdb_trap(type, 0, frame));