From: acevest Date: Sat, 13 Apr 2024 09:35:30 +0000 (+0800) Subject: 将 multiboot2 的 header 在生成的二进制文件中的位置再往前放一点 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/mdoc.7.txt?a=commitdiff_plain;h=054efb994fdd39c6a5d5354737ddb32401241fc3;p=kernel.git 将 multiboot2 的 header 在生成的二进制文件中的位置再往前放一点 --- diff --git a/boot/multiboot.S b/boot/multiboot.S index da41886..0d43837 100644 --- a/boot/multiboot.S +++ b/boot/multiboot.S @@ -30,13 +30,20 @@ #define MULTIBOOT_STACK_SIZE 0x4000 -.text -.code32 -.align 32 +.section .kernel_entry_text kernel_entry: main: cli + jmp real_kernel_entry +# +# 这之间放multiboot2_header +# + +.text +.code32 +.align 4 +real_kernel_entry: # Load GDT's Information To GDTR lgdt GDTR-KRNLADDR @@ -155,8 +162,14 @@ GDTR: .section .multiboot2_header -# section align 64 bits boundary -.align 64 +# An OS image must contain an additional header called Multiboot2 header, +# besides the headers of the format used by the OS image. +# The Multiboot2 header must be contained completely within the first 32768 bytes of the OS image, +# and must be 64-bit aligned. +# In general, it should come as early as possible, +# and may be embedded in the beginning of the text segment after the real executable header. +# 64-bit 对齐 就是 8 字节对齐 +.align 8 multiboot2_header_bgn: # magic .long MULTIBOOT2_HEADER_MAGIC diff --git a/scripts/link.ld b/scripts/link.ld index 7d6272c..5736596 100644 --- a/scripts/link.ld +++ b/scripts/link.ld @@ -1,16 +1,16 @@ /* *-------------------------------------------------------------------------- * File Name: link.ld - * + * * Description: Link All Object Files to KERNEL ... - * - * + * + * * Author: Zhao Yanbai [zhaoyanbai@126.com] - * + * * Version: 1.1 * Create Date: Mon Mar 2 12:21:03 2009 * Last Update: Mon Mar 2 12:21:03 2009 - * + * *-------------------------------------------------------------------------- */ @@ -26,14 +26,16 @@ SECTIONS { code = .; phys_addr = . - kernel_virtual_addr_start; - boot/multiboot.S.o(.text) + *(.kernel_entry_text) *(.multiboot2_header) + /* 单独把 multiboot.S 的 .text 放在这个位置是为了便于调试,实际是可以不写这一句的 */ + boot/multiboot.S.o(.text) *(.text) *(.ring3.text); *(.sysexit) /* last */ } etext = .; - .data : AT(phys_addr) ALIGN(0x1000) + .data : AT(phys_addr) ALIGN(0x1000) { data = .; phys_addr = . - kernel_virtual_addr_start;