From f761d0a4453186c4e3bce719b68280673190c8b6 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 26 Mar 2022 00:36:23 -0400 Subject: [PATCH] Jump to HULK from assembly --- src/hello/hello.d | 11 +++++++---- src/hulk/hulk.d | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/hello/hello.d b/src/hello/hello.d index d452125..7dd2f5c 100644 --- a/src/hello/hello.d +++ b/src/hello/hello.d @@ -11,6 +11,7 @@ import hulk.header : HulkHeader = Header; import hos.page_table; import hos.cpu; import hos.memory; +import ldc.llvmasm; __gshared EFI_SYSTEM_TABLE * st; private __gshared BootInfo bootinfo; @@ -376,10 +377,12 @@ private void build_page_tables(ulong max_physical_address, ulong bss_phys, ulong /** * Jump to HULK entry point. */ -private void jump_to_hulk() +private void jump_to_hulk(ulong stack_end) { - void function(BootInfo *) hulk_entry_fn = cast(void function(BootInfo *))hulk_header().entry; - hulk_entry_fn(&bootinfo); + __asm( + "jmpq *$0", + "r,{rdi},{rsp}", + hulk_header().entry, &bootinfo, stack_end); } /** @@ -431,7 +434,7 @@ extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st) bootinfo.bss_phys = bss_phys; bootinfo.stack_phys = stack_phys; - jump_to_hulk(); + jump_to_hulk(stack_phys + hulk_stack_size()); return EFI_SUCCESS; } diff --git a/src/hulk/hulk.d b/src/hulk/hulk.d index 13058bd..a63178f 100644 --- a/src/hulk/hulk.d +++ b/src/hulk/hulk.d @@ -26,7 +26,7 @@ private __gshared Header hulk_header = { * * @param bootinfo Pointer to HULK boot information structure. */ -extern(C) void hulk_start(ulong rdi, ulong rsi, ulong rdx, BootInfo * bootinfo) +void hulk_start(BootInfo * bootinfo) { fb.initialize(bootinfo.fb.buffer, bootinfo.fb.width, bootinfo.fb.height, bootinfo.fb.stride); console.initialize();