From 0a181faf2d930584dc29ea09d2458851a4818f61 Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 5 Jan 2026 09:46:11 +0800 Subject: [PATCH] =?utf8?q?=E5=90=AF=E5=8A=A8AP=E7=9A=84=E4=BB=A3=E7=A0=81?= =?utf8?q?=E9=87=8C=E5=85=B3=E4=BA=8Egdtr=5Fbase=E5=92=8Cap=5Fcode32=5Fent?= =?utf8?q?ry=5Faddress=E7=9A=84=E4=B8=8D=E5=86=8D=E5=9C=A8=E6=B1=87?= =?utf8?q?=E7=BC=96=E9=87=8C=E7=AE=97=E4=BA=86=EF=BC=8C=E5=9C=A8=E7=A7=BB?= =?utf8?q?=E5=8A=A8=E8=BF=99=E6=AE=B5=E4=BB=A3=E7=A0=81=E5=90=8E=E7=94=B1?= =?utf8?q?=E5=A4=8D=E5=88=B6=E7=A8=8B=E5=BA=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- boot/ap_boot.S | 29 +++++++++++------------------ kernel/apic.c | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/boot/ap_boot.S b/boot/ap_boot.S index 3ab0af3..7c57109 100644 --- a/boot/ap_boot.S +++ b/boot/ap_boot.S @@ -8,8 +8,6 @@ */ .code16 -#.text -#.section .ap_boot, "ax", @progbits .global ap_boot_bgn .global ap_boot_end .align 0x1000 @@ -50,18 +48,6 @@ ap_real_mode_entry: movl %ebx, %esp addl $0x1000, %esp - # 算出gdt的线性地址 - leal (ap_gdt - ap_realmode_base)(%ebx), %eax - # 把这个地址填入gdtr的base位置 - movl %eax, (ap_gdtr_base - ap_realmode_base) - - - # 算出ap_code32_entry的线性地址 - leal (ap_code32_entry - ap_realmode_base)(%ebx), %eax - # 把这个地址填入ap_code32_entry_address - mov %eax, (ap_code32_entry_address - ap_realmode_base) - - lgdt ap_gdtr - ap_realmode_base # enable PE @@ -137,17 +123,24 @@ ap_code32_real_entry: .align 32 -ap_code32_entry_address: .long 0x00000000 # 等待动态写入 +.global ap_code32_entry_address +ap_code32_entry_address: .long ap_code32_entry - ap_realmode_base # 在BSP复制代码的时候会动态调整 .word 0x0008, 0x0000 +.align 32 +.global ap_gdtr_base +ap_gdtr: + ap_gdtr_limit: .word ap_gdt_end-ap_gdt + ap_gdtr_base: .long ap_gdt - ap_realmode_base # 在BSP复制代码的时候会动态调整 + .align 32 ap_gdt: empty: .long 0x00000000, 0x00000000 code_desc: .long 0x0000FFFF, 0x00CF9B00 data_desc: .long 0x0000FFFF, 0x00CF9300 +pad0: .long 0x00000000, 0x00000000 +pad1: .long 0x00000000, 0x00000000 +pad2: .long 0x00000000, 0x00000000 ap_gdt_end: -ap_gdtr: - ap_gdtr_limit: .word ap_gdt_end-ap_gdt - ap_gdtr_base: .long 0 # 等待动态写入 ap_boot_end: diff --git a/kernel/apic.c b/kernel/apic.c index 3643db0..0c92c8e 100644 --- a/kernel/apic.c +++ b/kernel/apic.c @@ -372,10 +372,24 @@ void prepare_ap_code(paddr_t paddr) { extern char ap_boot_bgn; extern char ap_boot_end; uint32_t bytes = &ap_boot_end - &ap_boot_bgn; - // memcpy((void*)paddr, &ap_boot_bgn, bytes); + for(int i=0; i