Since the gdt for apboot is located at a shared location
in memory, we cannot patch the gdt values per cpu during
parallel smp init, or havoc entails.
---
 i386/i386/cpuboot.S | 75 +++++----------------------------------------
 i386/i386/mp_desc.c |  6 ++--
 2 files changed, 11 insertions(+), 70 deletions(-)

diff --git a/i386/i386/cpuboot.S b/i386/i386/cpuboot.S
index f93e0387..e1b63c5c 100644
--- a/i386/i386/cpuboot.S
+++ b/i386/i386/cpuboot.S
@@ -39,7 +39,7 @@ apboot_idt_ptr:
 .align 16
        .word 0
 apboot_gdt_descr:
-       .word 14*8-1
+       .word 3*8-1
        .long apboot_gdt - KERNELBASE
 .align 16
 apboot_gdt:
@@ -62,45 +62,6 @@ apboot_gdt:
        .byte ((SZ_32 | SZ_G) << 4) | 0xf /* High 4 bits */
        .byte ((-KERNELBASE) >> 24) & 0xff /*Base 24-31 bits */
 
-       /* LDT = 0x18 */
-       .quad 0
-
-       /* TSS = 0x20 */
-       .quad 0
-
-       /* USER_LDT = 0x28 */
-       .quad 0
-
-       /* USER_TSS = 0x30 */
-       .quad 0
-
-       /* LINEAR = 0x38 */
-       .quad 0
-
-       /* FPREGS = 0x40 */
-       .quad 0
-
-       /* USER_GDT = 0x48 and 0x50 */
-       .quad 0
-       .quad 0
-
-       /* USER_TSS64 = 0x58 */
-       .quad 0
-
-       /* USER_TSS64 = 0x60 */
-       .quad 0
-
-       /* boot GS = 0x68 */
-       .word 0xffff
-apboot_percpu_low:
-       .word 0
-apboot_percpu_med:
-       .byte 0
-       .byte ACC_PL_K | ACC_DATA_W | ACC_P
-       .byte ((SZ_32 | SZ_G) << 4) | 0xf
-apboot_percpu_high:
-       .byte 0
-
 .globl apboot, apbootend, gdt_descr_tmp, apboot_jmp_offset
 .align 16
 .code16
@@ -159,32 +120,6 @@ apboot_jmp_offset:
        movw    %ax, %gs
        movw    %ax, %ss
 
-       /* Get CPU number */
-       movl    $1, %eax
-       cpuid
-       shrl    $24, %ebx
-       movl    %cs:CX(cpu_id_lut, %ebx), %ecx
-
-       /* Access per_cpu area */
-       movl    %ecx,%eax
-       movl    $PC_SIZE,%ebx
-       mul     %ebx
-       addl    $percpu_array, %eax
-
-       /* Record our cpu number */
-       movl    %ecx, (PERCPU_CPU_ID)(%eax)
-
-       /* Set up temporary percpu descriptor */
-       addl    $(-KERNELBASE), %eax
-       movw    %ax, apboot_percpu_low
-       shr     $16, %eax
-       movb    %al, apboot_percpu_med
-       shr     $8, %ax
-       movb    %al, apboot_percpu_high
-
-       movw    $PERCPU_DS, %ax
-       movw    %ax, %gs
-
        /* Load null Interrupt descriptor table */
        mov     apboot_idt_ptr, %ebx
        lidt    (%ebx)
@@ -199,8 +134,14 @@ apboot_jmp_offset:
        movl    $APIC_MSR, %ecx
        wrmsr
 
+       /* Get CPU number */
+       xorl    %ecx, %ecx
+       movl    $1, %eax
+       cpuid
+       shrl    $24, %ebx
+       movl    %cs:CX(cpu_id_lut, %ebx), %edx
+
        /* Load int_stack_top[cpu] -> esp */
-       CPU_NUMBER(%edx)
        movl    CX(EXT(int_stack_top), %edx), %esp
 
        /* Ensure stack alignment */
diff --git a/i386/i386/mp_desc.c b/i386/i386/mp_desc.c
index f13a391a..16b1c865 100644
--- a/i386/i386/mp_desc.c
+++ b/i386/i386/mp_desc.c
@@ -241,7 +241,6 @@ cpu_setup(int cpu)
     flush_instr_queue();
     printf("AP=(%u) paging done\n", cpu);
 
-    init_percpu(cpu);
     mp_desc_init(cpu);
     printf("AP=(%u) mpdesc done\n", cpu);
 
@@ -271,6 +270,7 @@ cpu_setup(int cpu)
     machine_slot[cpu].cpu_subtype = CPU_SUBTYPE_AT386;
     machine_slot[cpu].cpu_type = machine_slot[0].cpu_type;
 
+    init_percpu(cpu);
     init_fpu();
     lapic_setup();
     lapic_enable();
@@ -278,9 +278,9 @@ cpu_setup(int cpu)
 }
 
 void
-cpu_ap_main()
+cpu_ap_main(void)
 {
-    int cpu = cpu_number();
+    int cpu = cpu_number_slow();
 
     assert(cpu > 0);
 
-- 
2.45.2



Reply via email to