From: acevest Date: Mon, 5 Jan 2026 01:46:11 +0000 (+0800) Subject: 启动AP的代码里关于gdtr_base和ap_code32_entry_address的不再在汇编里算了,在移动这段代码后由复制程序调整 X-Git-Url: http://repos.zhaoyanbai.com/Mou_128.png?a=commitdiff_plain;h=refs%2Fheads%2Fioapic;p=kernel.git 启动AP的代码里关于gdtr_base和ap_code32_entry_address的不再在汇编里算了,在移动这段代码后由复制程序调整 --- 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