From aafdcb825d5e0a73e9747162e1c4ce23660ec437 Mon Sep 17 00:00:00 2001 From: acevest Date: Thu, 1 Jan 2026 11:34:15 +0800 Subject: [PATCH] =?utf8?q?=E7=A7=BB=E9=99=A4multiboot.S=E5=AF=B9=E5=AE=8F?= =?utf8?q?=E5=AE=9A=E4=B9=89KRNLADDR=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- boot/multiboot.S | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/boot/multiboot.S b/boot/multiboot.S index 839b2f3..98d2b53 100644 --- a/boot/multiboot.S +++ b/boot/multiboot.S @@ -14,8 +14,8 @@ *-------------------------------------------------------------------------- */ #define ASM + #include "boot.h" -#include "system.h" #include "task.h" .global kernel_entry @@ -25,6 +25,7 @@ .extern setup_kernel .extern root_task .extern root_task_entry +.extern kernel_virtual_addr_start #define MULTIBOOT_STACK_SIZE 0x4000 @@ -60,14 +61,11 @@ real_kernel_entry: # Save Multiboot Infomation... pushl %eax - addl $KRNLADDR,%ebx + addl $kernel_virtual_addr_start,%ebx pushl %ebx call boot_paging - #movl $init_pgd-KRNLADDR,%ebx - #movl %ebx,%cr3 - # enable PG WP movl %cr0,%eax orl $0x80010000,%eax @@ -76,9 +74,19 @@ real_kernel_entry: jmp 4f 4: # 准备切保护模式 + # 此时esp的地址还需要再调整一下 - addl $KRNLADDR, %esp - ljmp $0x08,$p_label+KRNLADDR + addl $kernel_virtual_addr_start, %esp + + + # 由于编译器不支持下面这种写法 + # ljmp $0x08, $p_label + kernel_virtual_addr_start + + # 所以采用下面的方法跳转 + leal p_label,%eax + addl $kernel_virtual_addr_start, %eax + movl %eax, p_label_far_ptr + ljmp *p_label_far_ptr p_label: leal check_kernel, %eax @@ -98,6 +106,12 @@ p_label: die: jmp die # Should never come to here. + +.align 4 +p_label_far_ptr: + .long 0x00 + .word 0x08, 0x00 + .align 32 boot_gdt: empty: .long 0x00000000, 0x00000000 @@ -108,4 +122,4 @@ boot_gdtr: boot_gdtr_limit: .word boot_gdt_end-boot_gdt boot_gdtr_base: .long boot_gdt - .comm stack, MULTIBOOT_STACK_SIZE +.comm stack, MULTIBOOT_STACK_SIZE -- 2.47.0