bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add multiboot2 header


From: Andrea G. Monaco
Subject: [PATCH] Add multiboot2 header
Date: Tue, 09 Feb 2021 01:11:11 +0100

Hello,


while trying to figure out uefi, I wrote a multiboot2 header. It's an
exercise, but I'll share it anyway.

I think that keeping both headers is ok, because they are very small and
have different magic numbers. You can choose which one to use at grub2,
since "multiboot" and "multiboot2" are different commands.

I checked that both headers get recognized by the boot loader, but
couldn't see if the boot completed because of console not working, as
usual. Please test if interested.

Warmly,
Andrea Monaco



diff --git a/i386/i386at/boothdr.S b/i386/i386at/boothdr.S
index 9339cb91..50a1f73b 100644
--- a/i386/i386at/boothdr.S
+++ b/i386/i386at/boothdr.S
@@ -14,15 +14,22 @@ start:
 _start:
        jmp     boot_entry
 
-       /* MultiBoot header - see multiboot.h.  */
+
+/* multiboot 1 and 2 headers - see multiboot.h.  */
+       
 #define        MULTIBOOT_MAGIC         0x1BADB002
+       
 #ifdef __ELF__
 #define MULTIBOOT_FLAGS                0x00000003
 #else  /* __ELF__ */
 #define MULTIBOOT_FLAGS                0x00010003
 #endif /* __ELF__ */
-       P2ALIGN(2)
-boot_hdr:
+       
+#define MULTIBOOT2_MAGIC        0xE85250D6
+#define MULTIBOOT2_ARCHITECTURE 0x00000000   /* protected mode of i386 */
+       
+       P2ALIGN(2)              
+multiboot_hdr:
        .long   MULTIBOOT_MAGIC
        .long   MULTIBOOT_FLAGS
                /*
@@ -31,13 +38,65 @@ boot_hdr:
                 */
        .long   - (MULTIBOOT_MAGIC+MULTIBOOT_FLAGS)
 #ifndef __ELF__        /* a.out kludge */
-       .long   boot_hdr        /* header_addr */
+       .long   multiboot_hdr   /* header_addr */
        .long   _start          /* load_addr */
        .long   _edata          /* load_end_addr */
        .long   _end            /* bss_end_addr */
        .long   boot_entry      /* entry */
 #endif /* __ELF__ */
+       
+       P2ALIGN(3)
+multiboot2_hdr:
+       .long   MULTIBOOT2_MAGIC
+       .long   MULTIBOOT2_ARCHITECTURE
+       .long   (boot_entry - multiboot2_hdr)    /* total header length, 
including magic */
+       .long   -(MULTIBOOT2_MAGIC + MULTIBOOT2_ARCHITECTURE + boot_entry - 
multiboot2_hdr)   /* checksum */
 
+       /* mb2 information request about memory */
+       P2ALIGN(3)
+       .short 0x1
+       .short 0x0   /* required */
+       .long  0xC   /* size */
+       .long  0x4
+       
+       /* flags tag */
+       P2ALIGN(3)
+       .short 0x4
+       .short 0x0   /* required */
+       .long  0xC   /* size */
+       .long  0x3   /* ega text support */
+
+       /* module alignment tag */
+       P2ALIGN(3)
+       .short 0x6
+       .short 0x0   /* required */
+       .long  0x8   /* size */
+       
+#ifndef __ELF__        /* a.out stuff */
+       /* address tag */
+       P2ALIGN(3)
+       .short 0x2
+       .short 0x0  /* required */
+       .long  0x18 /* size */
+       .long  multiboot2_hdr     /* header_addr */
+       .long  _start             /* load_addr */
+       .long  _edata             /* load_end_addr */
+       .long  _end               /* bss_end_addr */
+       
+       /* entry address tag */
+       P2ALIGN(3)
+       .short 0x3
+       .short 0x0  /* required */
+       .long  0xc  /* size */
+       .long  boot_entry
+#endif /* __ELF__ */
+       
+       /* closing tag */
+       P2ALIGN(3)
+       .short 0x0
+       .short 0x0
+       .long  0x8
+               
 boot_entry:
        /* use segmentation to offset ourself. */
        lgdt    boot_gdt_descr - KERNELBASE



reply via email to

[Prev in Thread] Current Thread [Next in Thread]