From 2f2f025a1fd1e82798481478d7caa5b390bdbf38 Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 5 Jan 2026 12:31:36 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8Dap=5Fboot.S=E9=87=8Cesp?= =?utf8?q?=E7=9A=84=E5=80=BC=E8=AE=BE=E7=BD=AE=E9=94=99=E8=AF=AF=E7=9A=84?= =?utf8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- boot/ap_boot.S | 19 ++++++++++++++----- qemu.sh | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/boot/ap_boot.S b/boot/ap_boot.S index 7c57109..1fc169f 100644 --- a/boot/ap_boot.S +++ b/boot/ap_boot.S @@ -43,10 +43,15 @@ ap_real_mode_entry: # 如果拿到锁, 则代表是第一个AP, 继续执行 1: # 算出ap_realmode_base的线性地址 + # 要把这个值传进保护模式 shl $4, %ebx - movl %ebx, %esp - addl $0x1000, %esp + # 将sp指向本页的末尾的位置 + # 这里不能写成 movl %ebx, %esp; addl $0x1000, %esp + # 因为目前sp还是搭配ss来用的 + movl $0x1000, %esp # ss:sp --> ss*16 + 0x1000 + #pushl $0x12345678 + #popl %eax lgdt ap_gdtr - ap_realmode_base @@ -78,6 +83,10 @@ ap_code32_entry: movw %ax, %fs movw %ax, %gs + + # 算出保护模式的esp值 + addl %ebx, %esp + # 加载一个跳板页目录, 为真正切换到内核地址空间做准备 .extern ap_pre_pgd leal ap_pre_pgd, %eax @@ -92,7 +101,7 @@ ap_code32_entry: jmp *%eax # 虽然下面的代码也会被复制到小于1MB的内存 -# 但是它不会在那里被执行, 而是会在大于1MB的物理内存, 并且是内核的地址空间执行 +# 但是它不会在那里被执行, 而是会在大于1MB的物理内存(也就是在它原来的位置), 并且是内核的地址空间执行 # 也就是说他们在内核的原来的地址执行 # 当然也可以把它搬到ap_boot_end之后, 这样它就不会被复制到小于1MB的内存里了 ap_code32_real_entry: @@ -124,14 +133,14 @@ ap_code32_real_entry: .align 32 .global ap_code32_entry_address -ap_code32_entry_address: .long ap_code32_entry - ap_realmode_base # 在BSP复制代码的时候会动态调整 +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复制代码的时候会动态调整 + ap_gdtr_base: .long ap_gdt - ap_realmode_base # 在BSP复制代码后会动态调整 .align 32 ap_gdt: diff --git a/qemu.sh b/qemu.sh index 9819af0..0efdfce 100755 --- a/qemu.sh +++ b/qemu.sh @@ -20,7 +20,7 @@ set -m qemu-system-i386 \ -boot d \ -m 3100\ - -smp 4 \ + -smp 2 \ -cpu qemu32,+x2apic \ -machine q35 \ -serial tcp::6666,server,nowait \ -- 2.47.0