aboutsummaryrefslogtreecommitdiff
path: root/i386
diff options
context:
space:
mode:
Diffstat (limited to 'i386')
-rw-r--r--i386/i386/apic.c11
-rw-r--r--i386/i386/cpu_number.h20
-rw-r--r--i386/i386/mp_desc.c3
3 files changed, 25 insertions, 9 deletions
diff --git a/i386/i386/apic.c b/i386/i386/apic.c
index 2bb8e3f1..3a51f506 100644
--- a/i386/i386/apic.c
+++ b/i386/i386/apic.c
@@ -185,7 +185,11 @@ apic_get_num_ioapics(void)
int
apic_get_current_cpu(void)
{
- return (lapic->apic_id.r >> 24) & 0xff;
+ unsigned int eax, ebx, ecx, edx;
+ eax = 1;
+ ecx = 0;
+ cpuid(eax, ebx, ecx, edx);
+ return (ebx >> 24);
}
@@ -295,11 +299,6 @@ lapic_enable(void)
cpu_intr_save(&flags);
apic_id = apic_get_current_cpu();
- if (apic_id < 0)
- {
- printf("apic_get_current_cpu() failed, assuming BSP\n");
- apic_id = 0;
- }
dummy = lapic->dest_format.r;
lapic->dest_format.r = 0xffffffff; /* flat model */
diff --git a/i386/i386/cpu_number.h b/i386/i386/cpu_number.h
index c00896e8..df086370 100644
--- a/i386/i386/cpu_number.h
+++ b/i386/i386/cpu_number.h
@@ -39,12 +39,30 @@
#define CX(addr, reg) addr(,reg,8)
#endif
-#define CPU_NUMBER(reg) \
+#define CPU_NUMBER_NO_STACK(reg) \
movl %cs:lapic, reg ;\
movl %cs:APIC_ID(reg), reg ;\
shrl $24, reg ;\
movl %cs:CX(cpu_id_lut, reg), reg ;\
+/* Never call CPU_NUMBER(%esi) */
+#define CPU_NUMBER(reg) \
+ pushl %esi ;\
+ pushl %eax ;\
+ pushl %ebx ;\
+ pushl %ecx ;\
+ pushl %edx ;\
+ movl $1, %eax ;\
+ cpuid ;\
+ shrl $24, %ebx ;\
+ movl %cs:CX(cpu_id_lut, %ebx), %esi ;\
+ popl %edx ;\
+ popl %ecx ;\
+ popl %ebx ;\
+ popl %eax ;\
+ movl %esi, reg ;\
+ popl %esi ;\
+
#ifndef __ASSEMBLER__
#include "kern/cpu_number.h"
int cpu_number(void);
diff --git a/i386/i386/mp_desc.c b/i386/i386/mp_desc.c
index 88fbb50a..f1a1f989 100644
--- a/i386/i386/mp_desc.c
+++ b/i386/i386/mp_desc.c
@@ -275,8 +275,7 @@ cpu_setup(int cpu)
void
cpu_ap_main()
{
- unsigned apic_id = (((ApicLocalUnit*)phystokv(lapic_addr))->apic_id.r >> 24) & 0xff;
- int cpu = apic_get_cpu_kernel_id(apic_id);
+ int cpu = cpu_number();
do {
cpu_pause();