From f03986937db0b927da4b10554801e18e4dc7c43f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 29 Jan 2024 17:12:41 +0100 Subject: Kernel: Fix and unified NewBoot handover protocol. Signed-off-by: Amlal El Mahrouss --- Private/HALKit/AMD64/StartSequence.asm | 24 ++++++++++++---- Private/Linker/AMD64.ld | 50 --------------------------------- Private/Linker/Platforms/PC.lds | 51 ++++++++++++++++++++++++++++++++++ Private/NewBoot/BootKit/Protocol.hxx | 23 ++++++++++++++- Private/makefile | 2 +- 5 files changed, 92 insertions(+), 58 deletions(-) delete mode 100644 Private/Linker/AMD64.ld create mode 100644 Private/Linker/Platforms/PC.lds diff --git a/Private/HALKit/AMD64/StartSequence.asm b/Private/HALKit/AMD64/StartSequence.asm index 45bd1656..efb90843 100644 --- a/Private/HALKit/AMD64/StartSequence.asm +++ b/Private/HALKit/AMD64/StartSequence.asm @@ -8,18 +8,28 @@ ;; */ [bits 64] + +;; Global symbol of this unit [global Main] +[global MainUnsupported] + +;; External symbols needed by this unit. [extern RuntimeMain] [extern __SYSTEM_STACK_END] -section .text +%define kTypeKernel 100 +%define kArchAmd64 122 -NewBootMagic: dw 0x55FF66 -NewBootKernel: db "h-core", 0 -NewBootVersion: dw 1 +section .NewBoot +HandoverMagic: dq 0xBAD55 +HandoverType: dw kTypeKernel +HandoverArch: dw kArchAmd64 ;; This NewBootStart points to Main. -NewBootStart: +HandoverStart: dq Main + +section .text + ;; Just a simple setup, we'd also need to tell some before Main: mov rsp, __SYSTEM_STACK_END @@ -30,7 +40,9 @@ L0: hlt jmp $ -MainBIOS: +;; @brief this one is jumped on when an unsupported then gets through the boot stage. +;; @note: must be ISA compatible! +MainUnsupported: cli hlt jmp $ diff --git a/Private/Linker/AMD64.ld b/Private/Linker/AMD64.ld deleted file mode 100644 index 39cb0076..00000000 --- a/Private/Linker/AMD64.ld +++ /dev/null @@ -1,50 +0,0 @@ -OUTPUT_FORMAT("elf64-x86-64") - -ENTRY(Main) - -PHDRS { - null PT_NULL FLAGS(0) ; - text PT_LOAD FLAGS((1 << 0) | (1 << 2) | (1 << 3)); - rodata PT_LOAD FLAGS((1 << 2)) ; - data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; -} - -SECTIONS { - . = 0x10000000; - - .text : { - *(.text .text.*) - } :text - - . += CONSTANT(MAXPAGESIZE); - - .init : { - __SYSTEM_INIT = .; - *(.initl) - __SYSTEM_FINI = .; - } - - __SYSTEM_INIT_END = .; - - . += CONSTANT(MAXPAGESIZE); - - .rodata : { - *(.rodata .rodata.*) - } :rodata - - . += CONSTANT(MAXPAGESIZE); - - .data : { - *(.data .data.*) - } :data - - . += CONSTANT(MAXPAGESIZE); - - .bss : { - *(COMMON) - *(.bss .bss.*) - } :data - - __SYSTEM_STACK_PTR = .; - __SYSTEM_STACK_END = . + 0x4000; -} diff --git a/Private/Linker/Platforms/PC.lds b/Private/Linker/Platforms/PC.lds new file mode 100644 index 00000000..77d237e2 --- /dev/null +++ b/Private/Linker/Platforms/PC.lds @@ -0,0 +1,51 @@ +OUTPUT_FORMAT("elf64-x86-64") + +ENTRY(Main) + +PHDRS { + null PT_NULL FLAGS(0) ; + text PT_LOAD FLAGS((1 << 0) | (1 << 2) | (1 << 3)); + rodata PT_LOAD FLAGS((1 << 2)) ; + data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; +} + +SECTIONS { + . = 0x10000000; + + .text : { + *(.NewBoot) + *(.text .text.*) + } :text + + . += CONSTANT(MAXPAGESIZE); + + .init : { + __SYSTEM_INIT = .; + *(.initl) + __SYSTEM_FINI = .; + } + + __SYSTEM_INIT_END = .; + + . += CONSTANT(MAXPAGESIZE); + + .rodata : { + *(.rodata .rodata.*) + } :rodata + + . += CONSTANT(MAXPAGESIZE); + + .data : { + *(.data .data.*) + } :data + + . += CONSTANT(MAXPAGESIZE); + + .bss : { + *(COMMON) + *(.bss .bss.*) + } :data + + __SYSTEM_STACK_PTR = .; + __SYSTEM_STACK_END = . + 0x4000; +} diff --git a/Private/NewBoot/BootKit/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx index b33ab32e..c2dc1a9d 100644 --- a/Private/NewBoot/BootKit/Protocol.hxx +++ b/Private/NewBoot/BootKit/Protocol.hxx @@ -15,7 +15,28 @@ namespace HEL { using namespace hCore; -struct HandoverHeader final +/** + @brief the kind of executable we're loading. +*/ +enum +{ + kTypeKernel = 100, + kTypeKernelDriver = 101, + kTypeRsrc = 102, + kTypeCount = 3, +}; + +/** + @brief The executable architecture. +*/ + +enum +{ + kArchAmd64 = 122, + kArchCount = 2, +}; + +struct __attribute__((packed)) HandoverHeader final { Int32 targetMagic; Int32 targetType; diff --git a/Private/makefile b/Private/makefile index 4c3b8f5b..7e6a6639 100644 --- a/Private/makefile +++ b/Private/makefile @@ -13,7 +13,7 @@ ASMFLAGS = -f elf64 KERNEL = hKernel.efi # The kernel entrypoint -SCRIPT = --script=Linker/AMD64.ld +SCRIPT = --script=Linker/Platforms/PC.lds # we want a flat binary FMT = elf64 -- cgit v1.2.3