summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTobias Weingartner <weingart@cvs.openbsd.org>2007-05-26 22:09:18 +0000
committerTobias Weingartner <weingart@cvs.openbsd.org>2007-05-26 22:09:18 +0000
commit1bcfbbfdb34c25a28af67ebf5994768517f7b9b9 (patch)
treeb438d54990fba309fd16566f45bae3e1fe818289 /sys
parentc3228f5d60740159839a6c80297911c64ca64343 (diff)
Move cpu_info/curcpu to be mapped by the %fs segment. Extra input and
debugging by tom@, art@, kettenis@, and others. Testing by many others. ok art@, kettenis@, tom@
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/i386/i386/cpu.c8
-rw-r--r--sys/arch/i386/i386/locore.s11
-rw-r--r--sys/arch/i386/i386/machdep.c3
-rw-r--r--sys/arch/i386/include/cpu.h18
-rw-r--r--sys/arch/i386/include/i82489var.h4
5 files changed, 31 insertions, 13 deletions
diff --git a/sys/arch/i386/i386/cpu.c b/sys/arch/i386/i386/cpu.c
index b2cb29e15b0..55661e9e738 100644
--- a/sys/arch/i386/i386/cpu.c
+++ b/sys/arch/i386/i386/cpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.c,v 1.23 2007/05/08 18:51:59 deraadt Exp $ */
+/* $OpenBSD: cpu.c,v 1.24 2007/05/26 22:09:17 weingart Exp $ */
/* $NetBSD: cpu.c,v 1.1.2.7 2000/06/26 02:04:05 sommerfeld Exp $ */
/*-
@@ -151,7 +151,7 @@ void cpu_copy_trampoline(void);
void
cpu_init_first()
{
- int cpunum = cpu_number();
+ int cpunum = lapic_cpu_number();
if (cpunum != 0) {
cpu_info[0] = NULL;
@@ -193,10 +193,10 @@ cpu_attach(struct device *parent, struct device *self, void *aux)
struct pcb *pcb;
if (caa->cpu_role != CPU_ROLE_AP) {
- if (cpunum != cpu_number()) {
+ if (cpunum != lapic_cpu_number()) {
panic("%s: running cpu is at apic %d"
" instead of at expected %d",
- self->dv_xname, cpu_number(), cpunum);
+ self->dv_xname, lapic_cpu_number(), cpunum);
}
ci = &cpu_info_primary;
diff --git a/sys/arch/i386/i386/locore.s b/sys/arch/i386/i386/locore.s
index 0a2736bce97..9b964169984 100644
--- a/sys/arch/i386/i386/locore.s
+++ b/sys/arch/i386/i386/locore.s
@@ -1,4 +1,4 @@
-/* $OpenBSD: locore.s,v 1.109 2007/05/25 20:32:29 krw Exp $ */
+/* $OpenBSD: locore.s,v 1.110 2007/05/26 22:09:17 weingart Exp $ */
/* $NetBSD: locore.s,v 1.145 1996/05/03 19:41:19 christos Exp $ */
/*-
@@ -297,7 +297,7 @@ start: movw $0x1234,0x472 # warm boot
pushl $PSL_MBO
popfl
- /* Clear segment registers; always null in proc0. */
+ /* Clear segment registers; null until proc0 setup */
xorl %eax,%eax
movw %ax,%fs
movw %ax,%gs
@@ -1897,9 +1897,12 @@ ENTRY(switch_exit)
/* Clear segment registers; always null in proc0. */
xorl %ecx,%ecx
- movw %cx,%fs
movw %cx,%gs
+ /* Point to cpu_info */
+ movl $GSEL(GCPU_SEL, SEL_KPL),%ecx
+ movw %cx,%fs
+
/* Restore cr0 (including FPU state). */
movl PCB_CR0(%esi),%ecx
movl %ecx,%cr0
@@ -2083,7 +2086,7 @@ NENTRY(resume_pop_es)
movw %ax,%gs
NENTRY(resume_pop_gs)
pushl %fs
- movl $GSEL(GDATA_SEL, SEL_KPL),%eax
+ movl $GSEL(GCPU_SEL, SEL_KPL),%eax
movw %ax,%fs
NENTRY(resume_pop_fs)
movl $T_PROTFLT,TF_TRAPNO(%esp)
diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c
index a6fb19dbb84..1bbdc48fba8 100644
--- a/sys/arch/i386/i386/machdep.c
+++ b/sys/arch/i386/i386/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.391 2007/05/26 20:26:50 pedro Exp $ */
+/* $OpenBSD: machdep.c,v 1.392 2007/05/26 22:09:17 weingart Exp $ */
/* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */
/*-
@@ -2785,6 +2785,7 @@ init386(paddr_t first_avail)
bios_memmap_t *im;
proc0.p_addr = proc0paddr;
+ cpu_info_primary.ci_self = &cpu_info_primary;
cpu_info_primary.ci_curpcb = &proc0.p_addr->u_pcb;
/*
diff --git a/sys/arch/i386/include/cpu.h b/sys/arch/i386/include/cpu.h
index b69f1f78dd3..e74c7ace152 100644
--- a/sys/arch/i386/include/cpu.h
+++ b/sys/arch/i386/include/cpu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.92 2007/04/21 21:06:15 gwk Exp $ */
+/* $OpenBSD: cpu.h,v 1.93 2007/05/26 22:09:17 weingart Exp $ */
/* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos Exp $ */
/*-
@@ -182,8 +182,20 @@ extern struct cpu_info *cpu_info_list;
#define CPU_STOP(_ci) ((_ci)->ci_func->stop(_ci))
#define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci))
-#define cpu_number() (i82489_readreg(LAPIC_ID)>>LAPIC_ID_SHIFT)
-#define curcpu() (cpu_info[cpu_number()])
+static struct cpu_info *curcpu(void);
+
+__inline static struct cpu_info *
+curcpu(void)
+{
+ struct cpu_info *ci;
+
+ /* Can't include sys/param.h for offsetof() since it includes us */
+ __asm __volatile("movl %%fs:%1, %0" :
+ "=r" (ci) : "m"
+ (*(struct cpu_info * const *)&((struct cpu_info *)0)->ci_self));
+ return ci;
+}
+#define cpu_number() (curcpu()->ci_cpuid)
#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY)
diff --git a/sys/arch/i386/include/i82489var.h b/sys/arch/i386/include/i82489var.h
index 0fe445e41fe..3fac16e9011 100644
--- a/sys/arch/i386/include/i82489var.h
+++ b/sys/arch/i386/include/i82489var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: i82489var.h,v 1.5 2007/05/25 15:55:27 art Exp $ */
+/* $OpenBSD: i82489var.h,v 1.6 2007/05/26 22:09:17 weingart Exp $ */
/* $NetBSD: i82489var.h,v 1.1.2.2 2000/02/21 18:46:14 sommerfeld Exp $ */
/*-
@@ -134,4 +134,6 @@ extern void lapic_set_softvectors(void);
extern void lapic_enable(void);
extern void lapic_calibrate_timer(struct cpu_info *);
+#define lapic_cpu_number() (i82489_readreg(LAPIC_ID)>>LAPIC_ID_SHIFT)
+
#endif