From 054efb994fdd39c6a5d5354737ddb32401241fc3 Mon Sep 17 00:00:00 2001 From: acevest Date: Sat, 13 Apr 2024 17:35:30 +0800 Subject: [PATCH] =?utf8?q?=E5=B0=86=20multiboot2=20=E7=9A=84=20header=20?= =?utf8?q?=E5=9C=A8=E7=94=9F=E6=88=90=E7=9A=84=E4=BA=8C=E8=BF=9B=E5=88=B6?= =?utf8?q?=E6=96=87=E4=BB=B6=E4=B8=AD=E7=9A=84=E4=BD=8D=E7=BD=AE=E5=86=8D?= =?utf8?q?=E5=BE=80=E5=89=8D=E6=94=BE=E4=B8=80=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- boot/multiboot.S | 23 ++++++++++++++++++----- scripts/link.ld | 16 +++++++++------- 2 files changed, 27 insertions(+), 12 deletions(-) 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; -- 2.44.0