diff options
| author | Tianhao Wang <shrik3@mailbox.org> | 2024-04-18 04:27:36 +0200 |
|---|---|---|
| committer | Tianhao Wang <shrik3@mailbox.org> | 2024-06-11 15:16:34 +0200 |
| commit | 18c798222a9a28f704a191e5e16b93c873a21ab2 (patch) | |
| tree | b736887eb11e5c915518b5360ab6d9ef9ecb1177 | |
| parent | 0de4e7d36430ea52b21e7b12d69605569bc986e7 (diff) | |
startup: define multiboot headers in linker script
| -rw-r--r-- | boot/startup-x86_64.s | 39 | ||||
| -rw-r--r-- | defs/x86_64-linker.ld | 24 |
2 files changed, 23 insertions, 40 deletions
diff --git a/boot/startup-x86_64.s b/boot/startup-x86_64.s index 3a8de41..4f34cc7 100644 --- a/boot/startup-x86_64.s +++ b/boot/startup-x86_64.s @@ -7,18 +7,6 @@ STACKSIZE: equ 65536 ; DON'T MODIFY THIS UNLESS YOU UPDATE THE setup_paging accordingly MAX_MEM: equ 512 -; Multiboot constants -MULTIBOOT_PAGE_ALIGN equ 1<<0 -MULTIBOOT_MEMORY_INFO equ 1<<1 - -; magic number for Multiboot -MULTIBOOT_HEADER_MAGIC equ 0x1badb002 - -; Multiboot flags (ELF specific!) -MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO -MULTIBOOT_HEADER_CHKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) -MULTIBOOT_EAX_MAGIC equ 0x2badb002 - ; exported symbols [GLOBAL startup] [GLOBAL pml4] @@ -37,33 +25,6 @@ MULTIBOOT_EAX_MAGIC equ 0x2badb002 [SECTION .text] [BITS 32] - - jmp startup ; jump over Multiboot header - align 4 ; 32-bit alignment for GRUB - -; -; Multiboot header for starting with GRUB or QEMU (w/o BIOS) -; - - dd MULTIBOOT_HEADER_MAGIC - dd MULTIBOOT_HEADER_FLAGS - dd MULTIBOOT_HEADER_CHKSUM - dd 0 ; header_addr (gets ignored) - dd 0 ; load_addr (gets ignored) - dd 0 ; load_end_addr (gets ignored) - dd 0 ; bss_end_addr (gets ignored) - dd 0 ; entry_addr (gets ignored) - dd 0 ; mode_type (gets ignored) - dd 0 ; width (gets ignored) - dd 0 ; height (gets ignored) - dd 0 ; depth (gets ignored) - -; -; system start, part 1 (in 32-bit Protected Mode) -; set up GDT, segmentation (dummy for long-mode, but requried). -; and pagetable. Prepare the system for long-mode -; - startup: cld ; GCC-compiled code expects the direction flag to be 0 cli ; disable interrupts diff --git a/defs/x86_64-linker.ld b/defs/x86_64-linker.ld index 3d54187..1f53bf8 100644 --- a/defs/x86_64-linker.ld +++ b/defs/x86_64-linker.ld @@ -1,8 +1,30 @@ +/* defs for Multiboot headers */ +MB_MAGIC = 0x1badb002; +MB_FLAGS = 0x3; +MB_CHKSUM = 0x100000000 - (MB_MAGIC + MB_FLAGS); + SECTIONS { - PROVIDE (___KERNEL_START__ = .); . = 0x100000; /* system's start address */ + .boot : + { + header_start = .; LONG(MB_MAGIC) + LONG(MB_FLAGS) + LONG(MB_CHKSUM) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + header_end = .; + } + + PROVIDE (___KERNEL_START__ = .); .text : { *(".text") |
