summaryrefslogtreecommitdiff
path: root/sys/arch/powerpc
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2007-03-20 20:59:55 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2007-03-20 20:59:55 +0000
commitedb06578c73fe05fb3c9ab52a47e1d0a34eca656 (patch)
tree0c292f80e38cc053d22638c7a85f354f2a842154 /sys/arch/powerpc
parentc0b399741b60996c0b30aaa0dc02061dc731634c (diff)
Move macppc to __HAVE_CPUINFO, and make locore.S and trap.c suitable for
MULTIPROCESSOR. From now on sprg0 holds a pointer to struct cpuinfo, which is used to spill registers to during trap instead of the globals we used to use for that purpose. Bits and pieces from NetBSD. Help from drahn@ and art@. Tested by xsa@, thib@, miod@, gwk@, deraadt@. ok drahn@, gwk@
Diffstat (limited to 'sys/arch/powerpc')
-rw-r--r--sys/arch/powerpc/include/_types.h5
-rw-r--r--sys/arch/powerpc/include/cpu.h101
-rw-r--r--sys/arch/powerpc/include/intr.h26
-rw-r--r--sys/arch/powerpc/include/lock.h112
-rw-r--r--sys/arch/powerpc/include/pcb.h4
-rw-r--r--sys/arch/powerpc/powerpc/fpu.c16
-rw-r--r--sys/arch/powerpc/powerpc/process_machdep.c22
-rw-r--r--sys/arch/powerpc/powerpc/trap.c69
-rw-r--r--sys/arch/powerpc/powerpc/vm_machdep.c20
9 files changed, 312 insertions, 63 deletions
diff --git a/sys/arch/powerpc/include/_types.h b/sys/arch/powerpc/include/_types.h
index 1529aa9cdfb..d8cc81d4506 100644
--- a/sys/arch/powerpc/include/_types.h
+++ b/sys/arch/powerpc/include/_types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: _types.h,v 1.2 2006/01/13 17:50:06 millert Exp $ */
+/* $OpenBSD: _types.h,v 1.3 2007/03/20 20:59:53 kettenis Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -115,4 +115,7 @@ typedef int __rune_t;
typedef void * __wctrans_t;
typedef void * __wctype_t;
+/* Feature test macros */
+#define __HAVE_CPUINFO
+
#endif /* _POWERPC__TYPES_H_ */
diff --git a/sys/arch/powerpc/include/cpu.h b/sys/arch/powerpc/include/cpu.h
index d89ed88c158..fe4151fa6be 100644
--- a/sys/arch/powerpc/include/cpu.h
+++ b/sys/arch/powerpc/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.29 2007/03/15 10:22:29 art Exp $ */
+/* $OpenBSD: cpu.h,v 1.30 2007/03/20 20:59:53 kettenis Exp $ */
/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */
/*
@@ -36,7 +36,85 @@
#include <machine/frame.h>
-#include <machine/psl.h>
+#include <sys/device.h>
+#include <sys/lock.h>
+#include <sys/sched.h>
+
+struct cpu_info {
+ struct device *ci_dev; /* our device */
+ struct schedstate_percpu ci_schedstate; /* scheduler state */
+
+ struct proc *ci_curproc;
+
+ struct pcb *ci_curpcb;
+ struct pmap *ci_curpm;
+ struct proc *ci_fpuproc;
+ struct proc *ci_vecproc;
+ struct pcb *ci_idle_pcb; /* PA of our idle pcb */
+ int ci_cpuid;
+
+ volatile int ci_astpending;
+ volatile int ci_want_resched;
+ volatile int ci_cpl;
+ volatile int ci_iactive;
+ volatile int ci_ipending;
+ int ci_intrdepth;
+ char *ci_intstk;
+#define CPUSAVE_LEN 8
+ register_t ci_tempsave[CPUSAVE_LEN];
+ register_t ci_ddbsave[CPUSAVE_LEN];
+#define DISISAVE_LEN 4
+ register_t ci_disisave[DISISAVE_LEN];
+};
+
+static __inline struct cpu_info *
+curcpu(void)
+{
+ struct cpu_info *ci;
+
+ __asm volatile ("mfsprg %0,0" : "=r"(ci));
+ return ci;
+}
+
+#define curpcb (curcpu()->ci_curpcb)
+#define curpm (curcpu()->ci_curpm)
+
+#define CPU_INFO_UNIT(ci) ((ci)->ci_dev->dv_unit)
+
+#ifdef MULTIPROCESSOR
+
+#define PPC_MAXPROCS 4
+
+static __inline int
+cpu_number(void)
+{
+ int pir;
+
+ __asm ("mfspr %0,1023" : "=r"(pir));
+ return pir;
+}
+
+void cpu_boot_secondary_processors(void);
+
+#define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0)
+#define CPU_INFO_ITERATOR int
+#define CPU_INFO_FOREACH(cii, ci) \
+ for (cii = 0, ci = &cpu_info[0]; cii < PPC_MAXPROCS; cii++, ci++)
+
+#else
+
+#define PPC_MAXPROCS 1
+
+#define cpu_number() 0
+
+#define CPU_IS_PRIMARY(ci) 1
+#define CPU_INFO_ITERATOR int
+#define CPU_INFO_FOREACH(cii, ci) \
+ for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL)
+
+#endif
+
+extern struct cpu_info cpu_info[PPC_MAXPROCS];
#define CLKF_USERMODE(frame) (((frame)->srr1 & PSL_PR) != 0)
#define CLKF_PC(frame) ((frame)->srr0)
@@ -47,12 +125,9 @@
void delay(unsigned);
#define DELAY(n) delay(n)
-extern volatile int want_resched;
-extern volatile int astpending;
-
-#define need_resched(ci) (want_resched = 1, astpending = 1)
-#define need_proftick(p) do { astpending = 1; } while (0)
-#define signotify(p) (astpending = 1)
+#define need_resched(ci) (ci->ci_want_resched = 1, ci->ci_astpending = 1)
+#define need_proftick(p) do { curcpu()->ci_astpending = 1; } while (0)
+#define signotify(p) (curcpu()->ci_astpending = 1)
extern char *bootpath;
@@ -200,6 +275,8 @@ void ppc64_mtscomc(u_int64_t);
u_int64_t ppc64_mfscomd(void);
void ppc_mtscomd(u_int32_t);
+#include <machine/psl.h>
+
/*
* General functions to enable and disable interrupts
* without having inlined assembly code in many functions.
@@ -250,4 +327,12 @@ extern int ppc_proc_is_64b;
#define PPC_CPU_MPC7455 0x8001
#define PPC_CPU_MPC7457 0x8002
+/*
+ * This needs to be included late since it relies on definitions higher
+ * up in this file.
+ */
+#if defined(MULTIPROCESSOR) && defined(_KERNEL)
+#include <sys/mplock.h>
+#endif
+
#endif /* _POWERPC_CPU_H_ */
diff --git a/sys/arch/powerpc/include/intr.h b/sys/arch/powerpc/include/intr.h
index fc328c7d342..aad653eeb87 100644
--- a/sys/arch/powerpc/include/intr.h
+++ b/sys/arch/powerpc/include/intr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: intr.h,v 1.31 2006/03/12 02:55:58 brad Exp $ */
+/* $OpenBSD: intr.h,v 1.32 2007/03/20 20:59:53 kettenis Exp $ */
/*
* Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA.
@@ -68,7 +68,6 @@ int splsoftnet(void);
void do_pending_int(void);
-volatile extern int cpl, ipending, astpending;
extern int imask[IPL_NUM];
/* SPL asserts */
@@ -82,11 +81,12 @@ extern int imask[IPL_NUM];
volatile static __inline int
splraise(int newcpl)
{
+ struct cpu_info *ci = curcpu();
int oldcpl;
__asm__ volatile("":::"memory"); /* don't reorder.... */
- oldcpl = cpl;
- cpl = oldcpl | newcpl;
+ oldcpl = ci->ci_cpl;
+ ci->ci_cpl = oldcpl | newcpl;
__asm__ volatile("":::"memory"); /* don't reorder.... */
return(oldcpl);
}
@@ -94,9 +94,11 @@ splraise(int newcpl)
volatile static __inline void
splx(int newcpl)
{
+ struct cpu_info *ci = curcpu();
+
__asm__ volatile("":::"memory"); /* reorder protect */
- cpl = newcpl;
- if(ipending & ~newcpl)
+ ci->ci_cpl = newcpl;
+ if(ci->ci_ipending & ~newcpl)
do_pending_int();
__asm__ volatile("":::"memory"); /* reorder protect */
}
@@ -104,12 +106,13 @@ splx(int newcpl)
volatile static __inline int
spllower(int newcpl)
{
+ struct cpu_info *ci = curcpu();
int oldcpl;
__asm__ volatile("":::"memory"); /* reorder protect */
- oldcpl = cpl;
- cpl = newcpl;
- if(ipending & ~newcpl)
+ oldcpl = ci->ci_cpl;
+ ci->ci_cpl = newcpl;
+ if(ci->ci_ipending & ~newcpl)
do_pending_int();
__asm__ volatile("":::"memory"); /* reorder protect */
return(oldcpl);
@@ -120,11 +123,12 @@ spllower(int newcpl)
static __inline void
set_sint(int pending)
{
+ struct cpu_info *ci = curcpu();
int msrsave;
__asm__ ("mfmsr %0" : "=r"(msrsave));
__asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
- ipending |= pending;
+ ci->ci_ipending |= pending;
__asm__ volatile ("mtmsr %0" :: "r"(msrsave));
}
@@ -140,6 +144,8 @@ set_sint(int pending)
#define splaudio() splraise(imask[IPL_AUDIO])
#define splclock() splraise(imask[IPL_CLOCK])
#define splvm() splraise(imask[IPL_VM])
+#define splsched() splhigh()
+#define spllock() splhigh()
#define splstatclock() splhigh()
#define splsoftclock() splraise(SINT_CLOCK)
#define splsoftnet() splraise(SINT_NET|SINT_CLOCK)
diff --git a/sys/arch/powerpc/include/lock.h b/sys/arch/powerpc/include/lock.h
new file mode 100644
index 00000000000..a9b64118c5d
--- /dev/null
+++ b/sys/arch/powerpc/include/lock.h
@@ -0,0 +1,112 @@
+/* $OpenBSD: lock.h,v 1.1 2007/03/20 20:59:53 kettenis Exp $ */
+/* $NetBSD: lock.h,v 1.8 2005/12/28 19:09:29 perry Exp $ */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Machine-dependent spin lock operations.
+ */
+
+#ifndef _POWERPC_LOCK_H_
+#define _POWERPC_LOCK_H_
+
+typedef __volatile int __cpu_simple_lock_t;
+
+#define __SIMPLELOCK_LOCKED 1
+#define __SIMPLELOCK_UNLOCKED 0
+
+static __inline void
+__cpu_simple_lock_init(__cpu_simple_lock_t *alp)
+{
+ *alp = __SIMPLELOCK_UNLOCKED;
+ __asm volatile ("sync");
+}
+
+static __inline void
+__cpu_simple_lock(__cpu_simple_lock_t *alp)
+{
+ int old;
+
+ __asm volatile (" \
+ \n\
+1: lwarx %0,0,%1 \n\
+ cmpwi %0,%2 \n\
+ beq+ 3f \n\
+2: lwzx %0,0,%1 \n\
+ cmpwi %0,%2 \n\
+ beq+ 1b \n\
+ b 2b \n\
+3: stwcx. %3,0,%1 \n\
+ bne- 1b \n\
+ isync \n\
+ \n"
+ : "=&r"(old)
+ : "r"(alp), "I"(__SIMPLELOCK_UNLOCKED), "r"(__SIMPLELOCK_LOCKED)
+ : "memory");
+}
+
+static __inline int
+__cpu_simple_lock_try(__cpu_simple_lock_t *alp)
+{
+ int old, dummy;
+
+ __asm volatile (" \
+ \n\
+1: lwarx %0,0,%1 \n\
+ cmpwi %0,%2 \n\
+ bne 2f \n\
+ stwcx. %3,0,%1 \n\
+ bne- 1b \n\
+2: stwcx. %3,0,%4 \n\
+ isync \n\
+ \n"
+ : "=&r"(old)
+ : "r"(alp), "I"(__SIMPLELOCK_UNLOCKED), "r"(__SIMPLELOCK_LOCKED),
+ "r"(&dummy)
+ : "memory");
+
+ return (old == __SIMPLELOCK_UNLOCKED);
+}
+
+static __inline void
+__cpu_simple_unlock(__cpu_simple_lock_t *alp)
+{
+ __asm volatile ("sync");
+ *alp = __SIMPLELOCK_UNLOCKED;
+}
+
+#endif /* _POWERPC_LOCK_H_ */
diff --git a/sys/arch/powerpc/include/pcb.h b/sys/arch/powerpc/include/pcb.h
index bd356bd1891..a49d03f1488 100644
--- a/sys/arch/powerpc/include/pcb.h
+++ b/sys/arch/powerpc/include/pcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcb.h,v 1.9 2003/02/26 21:54:44 drahn Exp $ */
+/* $OpenBSD: pcb.h,v 1.10 2007/03/20 20:59:53 kettenis Exp $ */
/* $NetBSD: pcb.h,v 1.1 1996/09/30 16:34:29 ws Exp $ */
/*-
@@ -65,8 +65,6 @@ struct md_coredump {
};
#ifdef _KERNEL
-extern struct pcb *curpcb;
-extern struct pmap *curpm;
extern struct proc *fpuproc;
int setfault(faultbuf *env);
#endif
diff --git a/sys/arch/powerpc/powerpc/fpu.c b/sys/arch/powerpc/powerpc/fpu.c
index c5672584c62..7b40ea97df6 100644
--- a/sys/arch/powerpc/powerpc/fpu.c
+++ b/sys/arch/powerpc/powerpc/fpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fpu.c,v 1.9 2005/10/09 14:52:12 drahn Exp $ */
+/* $OpenBSD: fpu.c,v 1.10 2007/03/20 20:59:53 kettenis Exp $ */
/* $NetBSD: fpu.c,v 1.1 1996/09/30 16:34:44 ws Exp $ */
/*
@@ -41,9 +41,10 @@
void
enable_fpu(struct proc *p)
{
- int msr;
+ struct cpu_info *ci = curcpu();
struct pcb *pcb = &p->p_addr->u_pcb;
struct trapframe *tf = trapframe(p);
+ int msr;
if (!(pcb->pcb_flags & PCB_FPU)) {
bzero(&pcb->pcb_fpu, sizeof pcb->pcb_fpu);
@@ -86,7 +87,7 @@ enable_fpu(struct proc *p)
"lfd 29,232(%0);"
"lfd 30,240(%0);"
"lfd 31,248(%0)" :: "b"(&pcb->pcb_fpu.fpr[0]));
- fpuproc = p;
+ ci->ci_fpuproc = p;
tf->srr1 |= PSL_FP;
ppc_mtmsr(msr);
__asm volatile("isync");
@@ -95,15 +96,16 @@ enable_fpu(struct proc *p)
void
save_fpu()
{
- int msr;
+ struct cpu_info *ci = curcpu();
struct pcb *pcb;
struct proc *p;
struct trapframe *tf;
+ int msr;
msr = ppc_mfmsr();
ppc_mtmsr((msr & ~PSL_EE) | PSL_FP);
- p = fpuproc;
+ p = ci->ci_fpuproc;
if (p == NULL) {
ppc_mtmsr(msr);
@@ -149,9 +151,9 @@ save_fpu()
asm volatile ("mffs 0; stfd 0,0(%0)" :: "b"(&pcb->pcb_fpu.fpcsr));
asm ("lfd 0,0(%0);" :: "b"(&pcb->pcb_fpu.fpr[0]));
- tf = trapframe(fpuproc);
+ tf = trapframe(ci->ci_fpuproc);
tf->srr1 &= ~PSL_FP;
- fpuproc = NULL;
+ ci->ci_fpuproc = NULL;
ppc_mtmsr(msr);
__asm volatile("isync");
diff --git a/sys/arch/powerpc/powerpc/process_machdep.c b/sys/arch/powerpc/powerpc/process_machdep.c
index bdba319e20f..4004c4dd9cf 100644
--- a/sys/arch/powerpc/powerpc/process_machdep.c
+++ b/sys/arch/powerpc/powerpc/process_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process_machdep.c,v 1.11 2006/05/15 21:02:44 kettenis Exp $ */
+/* $OpenBSD: process_machdep.c,v 1.12 2007/03/20 20:59:53 kettenis Exp $ */
/* $NetBSD: process_machdep.c,v 1.1 1996/09/30 16:34:53 ws Exp $ */
/*
@@ -45,6 +45,7 @@
int
process_read_regs(struct proc *p, struct reg *regs)
{
+ struct cpu_info *ci = curcpu();
struct trapframe *tf = trapframe(p);
struct pcb *pcb = &p->p_addr->u_pcb;
@@ -53,7 +54,8 @@ process_read_regs(struct proc *p, struct reg *regs)
if (!(pcb->pcb_flags & PCB_FPU)) {
bzero(regs->fpr, sizeof(regs->fpr));
} else {
- if (p == fpuproc)
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc)
save_fpu();
bcopy(pcb->pcb_fpu.fpr, regs->fpr, sizeof(regs->fpr));
}
@@ -72,13 +74,15 @@ process_read_regs(struct proc *p, struct reg *regs)
int
process_read_fpregs(struct proc *p, struct fpreg *regs)
{
+ struct cpu_info *ci = curcpu();
struct pcb *pcb = &p->p_addr->u_pcb;
if (!(pcb->pcb_flags & PCB_FPU)) {
bzero(regs->fpr, sizeof(regs->fpr));
regs->fpscr = 0;
} else {
- if (p == fpuproc)
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc)
save_fpu();
bcopy(pcb->pcb_fpu.fpr, regs->fpr, sizeof(regs->fpr));
regs->fpscr = *(u_int64_t *)&pcb->pcb_fpu.fpcsr;
@@ -116,14 +120,16 @@ process_sstep(struct proc *p, int sstep)
int
process_write_regs(struct proc *p, struct reg *regs)
{
+ struct cpu_info *ci = curcpu();
struct trapframe *tf = trapframe(p);
struct pcb *pcb = &p->p_addr->u_pcb;
bcopy(regs->gpr, tf->fixreg, sizeof(regs->gpr));
- if (p == fpuproc) { /* release the fpu */
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc) { /* release the fpu */
save_fpu();
- fpuproc = NULL;
+ ci->ci_fpuproc = NULL;
}
bcopy(regs->fpr, pcb->pcb_fpu.fpr, sizeof(regs->fpr));
@@ -146,12 +152,14 @@ process_write_regs(struct proc *p, struct reg *regs)
int
process_write_fpregs(struct proc *p, struct fpreg *regs)
{
+ struct cpu_info *ci = curcpu();
struct pcb *pcb = &p->p_addr->u_pcb;
u_int64_t fpscr = regs->fpscr;
- if (p == fpuproc) { /* release the fpu */
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc) { /* release the fpu */
save_fpu();
- fpuproc = NULL;
+ ci->ci_fpuproc = NULL;
}
bcopy(regs->fpr, pcb->pcb_fpu.fpr, sizeof(regs->fpr));
diff --git a/sys/arch/powerpc/powerpc/trap.c b/sys/arch/powerpc/powerpc/trap.c
index c5c67b3f456..378730ba6ae 100644
--- a/sys/arch/powerpc/powerpc/trap.c
+++ b/sys/arch/powerpc/powerpc/trap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: trap.c,v 1.74 2007/03/15 10:22:29 art Exp $ */
+/* $OpenBSD: trap.c,v 1.75 2007/03/20 20:59:53 kettenis Exp $ */
/* $NetBSD: trap.c,v 1.3 1996/10/13 03:31:37 christos Exp $ */
/*
@@ -71,10 +71,6 @@ void trap(struct trapframe *frame);
#define NARGREG 8 /* 8 args are in registers */
#define MOREARGS(sp) ((caddr_t)((int)(sp) + 8)) /* more args go here */
-volatile int want_resched;
-struct proc *ppc_vecproc;
-struct proc *fpuproc;
-
#ifdef DDB
void ppc_dumpbt(struct trapframe *frame);
@@ -261,12 +257,13 @@ userret(struct proc *p, int pc, u_quad_t oticks)
addupc_task(p, pc, (int)(p->p_sticks - oticks) * psratio);
}
- curpriority = p->p_priority;
+ curcpu()->ci_schedstate.spc_curpriority = p->p_priority;
}
void
trap(struct trapframe *frame)
{
+ struct cpu_info *ci = curcpu();
struct proc *p = curproc;
int type = frame->exc;
u_quad_t sticks;
@@ -283,7 +280,9 @@ trap(struct trapframe *frame)
case EXC_TRC|EXC_USER:
{
sv.sival_int = frame->srr0;
+ KERNEL_PROC_LOCK(p);
trapsignal(p, SIGTRAP, type, TRAP_TRACE, sv);
+ KERNEL_PROC_UNLOCK(p);
}
break;
@@ -353,6 +352,7 @@ printf("kern dsi on addr %x iar %x\n", frame->dar, frame->srr0);
frame->dar, frame->dsisr, 0))
break;
+ KERNEL_PROC_LOCK(p);
if (frame->dsisr & DSISR_STORE) {
ftype = VM_PROT_READ | VM_PROT_WRITE;
vftype = VM_PROT_WRITE;
@@ -361,6 +361,7 @@ printf("kern dsi on addr %x iar %x\n", frame->dar, frame->srr0);
if (uvm_fault(&p->p_vmspace->vm_map,
trunc_page(frame->dar), 0, ftype) == 0) {
uvm_grow(p, trunc_page(frame->dar));
+ KERNEL_PROC_UNLOCK(p);
break;
}
@@ -372,6 +373,7 @@ printf("dsi on addr %x iar %x lr %x\n", frame->dar, frame->srr0,frame->lr);
*/
sv.sival_int = frame->dar;
trapsignal(p, SIGSEGV, vftype, SEGV_MAPERR, sv);
+ KERNEL_PROC_UNLOCK(p);
}
break;
case EXC_ISI|EXC_USER:
@@ -383,12 +385,15 @@ printf("dsi on addr %x iar %x lr %x\n", frame->dar, frame->srr0,frame->lr);
frame->srr0, 0, 1))
break;
+ KERNEL_PROC_LOCK(p);
ftype = VM_PROT_READ | VM_PROT_EXECUTE;
if (uvm_fault(&p->p_vmspace->vm_map,
trunc_page(frame->srr0), 0, ftype) == 0) {
uvm_grow(p, trunc_page(frame->srr0));
+ KERNEL_PROC_UNLOCK(p);
break;
}
+ KERNEL_PROC_UNLOCK(p);
}
#if 0
printf("isi iar %x lr %x\n", frame->srr0, frame->lr);
@@ -398,7 +403,9 @@ printf("isi iar %x lr %x\n", frame->srr0, frame->lr);
/* XXX Likely that returning from this trap is bogus... */
/* XXX Have to make sure that sigreturn does the right thing. */
sv.sival_int = frame->srr0;
+ KERNEL_PROC_LOCK(p);
trapsignal(p, SIGSEGV, VM_PROT_EXECUTE, SEGV_MAPERR, sv);
+ KERNEL_PROC_UNLOCK(p);
break;
case EXC_SC|EXC_USER:
{
@@ -461,6 +468,8 @@ printf("isi iar %x lr %x\n", frame->srr0, frame->lr);
}
params = args;
}
+
+ KERNEL_PROC_LOCK(p);
#ifdef KTRACE
if (KTRPOINT(p, KTR_SYSCALL))
ktrsyscall(p, code, argsize, params);
@@ -480,6 +489,7 @@ printf("isi iar %x lr %x\n", frame->srr0, frame->lr);
else
#endif
error = (*callp->sy_call)(p, params, rval);
+ KERNEL_PROC_UNLOCK(p);
switch (error) {
case 0:
frame->fixreg[0] = error;
@@ -507,17 +517,22 @@ syscall_bad:
break;
}
#ifdef SYSCALL_DEBUG
- scdebug_ret(p, code, error, rval);
+ KERNEL_PROC_LOCK(p);
+ scdebug_ret(p, code, error, rval);
+ KERNEL_PROC_UNLOCK(p);
#endif
#ifdef KTRACE
- if (KTRPOINT(p, KTR_SYSRET))
+ if (KTRPOINT(p, KTR_SYSRET)) {
+ KERNEL_PROC_LOCK(p);
ktrsysret(p, code, error, rval[0]);
+ KERNEL_PROC_UNLOCK(p);
+ }
#endif
}
break;
case EXC_FPU|EXC_USER:
- if (fpuproc)
+ if (ci->ci_fpuproc)
save_fpu();
uvmexp.fpswtch++;
enable_fpu(p);
@@ -533,8 +548,10 @@ syscall_bad:
frame->srr0 += 4;
else {
sv.sival_int = frame->srr0;
+ KERNEL_PROC_LOCK(p);
trapsignal(p, SIGSEGV, VM_PROT_EXECUTE, SEGV_MAPERR,
sv);
+ KERNEL_PROC_UNLOCK(p);
}
break;
@@ -588,7 +605,9 @@ mpc_print_pci_stat();
errnum++;
#endif
sv.sival_int = frame->srr0;
+ KERNEL_PROC_LOCK(p);
trapsignal(p, SIGTRAP, type, TRAP_BRKPT, sv);
+ KERNEL_PROC_UNLOCK(p);
break;
}
#if 0
@@ -607,7 +626,9 @@ for (i = 0; i < errnum; i++) {
}
#endif
sv.sival_int = frame->srr0;
+ KERNEL_PROC_LOCK(p);
trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv);
+ KERNEL_PROC_UNLOCK(p);
break;
}
case EXC_PGM:
@@ -628,25 +649,29 @@ for (i = 0; i < errnum; i++) {
case EXC_PERF|EXC_USER:
#ifdef ALTIVEC
case EXC_VEC|EXC_USER:
- if (ppc_vecproc)
- save_vec(ppc_vecproc);
+ if (ci->ci_vecproc)
+ save_vec(ci->ci_vecproc);
- ppc_vecproc = p;
+ ci->ci_vecproc = p;
enable_vec(p);
break;
#else /* ALTIVEC */
sv.sival_int = frame->srr0;
+ KERNEL_PROC_LOCK(p);
trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv);
+ KERNEL_PROC_UNLOCK(p);
break;
#endif
case EXC_AST|EXC_USER:
uvmexp.softs++;
- astpending = 0; /* we are about to do it */
+ ci->ci_astpending = 0; /* we are about to do it */
if (p->p_flag & P_OWEUPC) {
+ KERNEL_PROC_LOCK(p);
ADDUPROF(p);
+ KERNEL_PROC_UNLOCK(p);
}
- if (want_resched)
+ if (ci->ci_want_resched)
preempt(NULL);
break;
}
@@ -656,7 +681,7 @@ for (i = 0; i < errnum; i++) {
/*
* If someone stole the fpu while we were away, disable it
*/
- if (p != fpuproc)
+ if (p != ci->ci_fpuproc)
frame->srr1 &= ~PSL_FP;
else if (p->p_addr->u_pcb.pcb_flags & PCB_FPU)
frame->srr1 |= PSL_FP;
@@ -665,7 +690,7 @@ for (i = 0; i < errnum; i++) {
/*
* If someone stole the vector unit while we were away, disable it
*/
- if (p == ppc_vecproc)
+ if (p == ci->ci_vecproc)
frame->srr1 |= PSL_VEC;
else
frame->srr1 &= ~PSL_VEC;
@@ -685,12 +710,17 @@ child_return(void *arg)
/* Disable FPU, VECT, as we can't be fpuproc */
tf->srr1 &= ~(PSL_FP|PSL_VEC);
+ KERNEL_PROC_UNLOCK(p);
+
userret(p, tf->srr0, 0);
#ifdef KTRACE
- if (KTRPOINT(p, KTR_SYSRET))
+ if (KTRPOINT(p, KTR_SYSRET)) {
+ KERNEL_PROC_LOCK(p);
ktrsysret(p,
(p->p_flag & P_PPWAIT) ? SYS_vfork : SYS_fork, 0, 0);
+ KERNEL_PROC_UNLOCK(p);
+ }
#endif
}
@@ -733,6 +763,7 @@ static int
fix_unaligned(struct proc *p, struct trapframe *frame)
{
int indicator = EXC_ALI_OPCODE_INDICATOR(frame->dsisr);
+ struct cpu_info *ci = curcpu();
switch (indicator) {
case EXC_ALI_LFD:
@@ -745,8 +776,8 @@ fix_unaligned(struct proc *p, struct trapframe *frame)
* the FPRs, and that their current state is in
* the PCB.
*/
- if (fpuproc != p) {
- if (fpuproc)
+ if (ci->ci_fpuproc != p) {
+ if (ci->ci_fpuproc)
save_fpu();
enable_fpu(p);
}
diff --git a/sys/arch/powerpc/powerpc/vm_machdep.c b/sys/arch/powerpc/powerpc/vm_machdep.c
index d21d46bd283..78cf2d0c1e0 100644
--- a/sys/arch/powerpc/powerpc/vm_machdep.c
+++ b/sys/arch/powerpc/powerpc/vm_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vm_machdep.c,v 1.41 2006/11/29 12:26:14 miod Exp $ */
+/* $OpenBSD: vm_machdep.c,v 1.42 2007/03/20 20:59:53 kettenis Exp $ */
/* $NetBSD: vm_machdep.c,v 1.1 1996/09/30 16:34:57 ws Exp $ */
/*
@@ -59,14 +59,15 @@ cpu_fork(struct proc *p1, struct proc *p2, void *stack, size_t stacksize,
caddr_t stktop1, stktop2;
extern void fork_trampoline(void);
struct pcb *pcb = &p2->p_addr->u_pcb;
+ struct cpu_info *ci = curcpu();
- if (p1 == fpuproc)
+ if (p1 == ci->ci_fpuproc)
save_fpu();
*pcb = p1->p_addr->u_pcb;
#ifdef ALTIVEC
if (p1->p_addr->u_pcb.pcb_vr != NULL) {
- if (p1 == ppc_vecproc)
+ if (p1 == ci->ci_vecproc)
save_vec(p1);
pcb->pcb_vr = pool_get(&ppc_vecpl, PR_WAITOK);
*pcb->pcb_vr = *p1->p_addr->u_pcb.pcb_vr;
@@ -157,21 +158,24 @@ pagemove(caddr_t from, caddr_t to, size_t size)
void
cpu_exit(struct proc *p)
{
+ struct cpu_info *ci = curcpu();
#ifdef ALTIVEC
struct pcb *pcb = &p->p_addr->u_pcb;
#endif /* ALTIVEC */
- if (p == fpuproc) /* release the fpu */
- fpuproc = NULL;
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc) /* release the fpu */
+ ci->ci_fpuproc = NULL;
#ifdef ALTIVEC
- if (p == ppc_vecproc)
- ppc_vecproc = NULL; /* release the Altivec Unit */
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_vecproc)
+ ci->ci_vecproc = NULL; /* release the Altivec Unit */
if (pcb->pcb_vr != NULL)
pool_put(&ppc_vecpl, pcb->pcb_vr);
#endif /* ALTIVEC */
- (void)splhigh();
+ (void)splsched();
switchexit(p);
}