Move bootinfo into HULK header

This commit is contained in:
Josh Holtrop 2022-03-27 16:14:54 -04:00
parent cf5956dcd3
commit d86745d91d
4 changed files with 47 additions and 36 deletions

View File

@ -14,7 +14,6 @@ import hos.memory;
import ldc.llvmasm; import ldc.llvmasm;
__gshared EFI_SYSTEM_TABLE * st; __gshared EFI_SYSTEM_TABLE * st;
private __gshared BootInfo bootinfo;
extern extern(C) __gshared ubyte _hulk_bin_start; extern extern(C) __gshared ubyte _hulk_bin_start;
extern extern(C) __gshared ubyte _hulk_bin_end; extern extern(C) __gshared ubyte _hulk_bin_end;
@ -23,6 +22,11 @@ private HulkHeader * hulk_header()
return cast(HulkHeader *)&_hulk_bin_start; return cast(HulkHeader *)&_hulk_bin_start;
} }
private BootInfo * bootinfo()
{
return &hulk_header().bootinfo;
}
private ulong hulk_bin_phys() private ulong hulk_bin_phys()
{ {
return cast(ulong)&_hulk_bin_start; return cast(ulong)&_hulk_bin_start;
@ -129,11 +133,11 @@ private bool set_graphics_mode()
console.writeln("SetMode: Error %x\n", status); console.writeln("SetMode: Error %x\n", status);
return false; return false;
} }
bootinfo.fb.buffer = cast(uint *)gop.Mode.FrameBufferBase; bootinfo().fb.buffer = cast(uint *)gop.Mode.FrameBufferBase;
bootinfo.fb.width = gop.Mode.Info.HorizontalResolution; bootinfo().fb.width = gop.Mode.Info.HorizontalResolution;
bootinfo.fb.height = gop.Mode.Info.VerticalResolution; bootinfo().fb.height = gop.Mode.Info.VerticalResolution;
bootinfo.fb.stride = gop.Mode.Info.PixelsPerScanLine; bootinfo().fb.stride = gop.Mode.Info.PixelsPerScanLine;
bootinfo.fb.format = gop.Mode.Info.PixelFormat; bootinfo().fb.format = gop.Mode.Info.PixelFormat;
return true; return true;
} }
@ -180,7 +184,7 @@ private void get_memory_map(ulong * bss_phys, ulong * stack_phys, ulong * max_ph
bool found_stack; bool found_stack;
for (count = 0u; count < n_entries; count++) for (count = 0u; count < n_entries; count++)
{ {
if (count > bootinfo.memory_map.length) if (count > bootinfo().memory_map.length)
{ {
console.writeln("Memory map too large"); console.writeln("Memory map too large");
for (;;) {} for (;;) {}
@ -202,29 +206,29 @@ private void get_memory_map(ulong * bss_phys, ulong * stack_phys, ulong * max_ph
{ {
continue; continue;
} }
bootinfo.memory_map[count].base = descriptor.PhysicalStart; bootinfo().memory_map[count].base = descriptor.PhysicalStart;
bootinfo.memory_map[count].size = descriptor.NumberOfPages * 4096u; bootinfo().memory_map[count].size = descriptor.NumberOfPages * 4096u;
bootinfo.memory_map[count].type = efi_to_hulk_memory_map_type[descriptor.Type]; bootinfo().memory_map[count].type = efi_to_hulk_memory_map_type[descriptor.Type];
if ((!found_bss) && if ((!found_bss) &&
(descriptor.Type == EfiConventionalMemory) && (descriptor.Type == EfiConventionalMemory) &&
(bootinfo.memory_map[count].size >= hulk_bss_size())) (bootinfo().memory_map[count].size >= hulk_bss_size()))
{ {
*bss_phys = bootinfo.memory_map[count].base; *bss_phys = bootinfo().memory_map[count].base;
bootinfo.memory_map[count].base += hulk_bss_size(); bootinfo().memory_map[count].base += hulk_bss_size();
bootinfo.memory_map[count].size -= hulk_bss_size(); bootinfo().memory_map[count].size -= hulk_bss_size();
found_bss = true; found_bss = true;
} }
if ((!found_stack) && if ((!found_stack) &&
(descriptor.Type == EfiConventionalMemory) && (descriptor.Type == EfiConventionalMemory) &&
(bootinfo.memory_map[count].size >= hulk_stack_size())) (bootinfo().memory_map[count].size >= hulk_stack_size()))
{ {
*stack_phys = bootinfo.memory_map[count].base; *stack_phys = bootinfo().memory_map[count].base;
bootinfo.memory_map[count].base += hulk_stack_size(); bootinfo().memory_map[count].base += hulk_stack_size();
bootinfo.memory_map[count].size -= hulk_stack_size(); bootinfo().memory_map[count].size -= hulk_stack_size();
found_stack = true; found_stack = true;
} }
} }
bootinfo.memory_map_count = count; bootinfo().memory_map_count = count;
if ((!found_bss) && (!found_stack)) if ((!found_bss) && (!found_stack))
{ {
for (;;) {} for (;;) {}
@ -365,17 +369,17 @@ private void build_page_tables(ulong max_physical_address, ulong bss_phys, ulong
map2m(addr, addr, pt_base); map2m(addr, addr, pt_base);
} }
/* Map any memory regions that are outside physical RAM. */ /* Map any memory regions that are outside physical RAM. */
for (size_t i = 0u; i < bootinfo.memory_map_count; i++) for (size_t i = 0u; i < bootinfo().memory_map_count; i++)
{ {
ulong addr = bootinfo.memory_map[i].base; ulong addr = bootinfo().memory_map[i].base;
if (addr >= max_physical_address) if (addr >= max_physical_address)
{ {
map4kregion(addr, addr, bootinfo.memory_map[i].size, pt_base); map4kregion(addr, addr, bootinfo().memory_map[i].size, pt_base);
} }
} }
/* Map graphics framebuffer. */ /* Map graphics framebuffer. */
ulong framebuffer_size = bootinfo.fb.height * bootinfo.fb.stride * 4u; ulong framebuffer_size = bootinfo().fb.height * bootinfo().fb.stride * 4u;
ulong fb_phys = cast(ulong)bootinfo.fb.buffer; ulong fb_phys = cast(ulong)bootinfo().fb.buffer;
ulong fb_virt = hulk_virt_framebuffer_address(); ulong fb_virt = hulk_virt_framebuffer_address();
map4kregion(fb_virt, fb_phys, framebuffer_size, pt_base); map4kregion(fb_virt, fb_phys, framebuffer_size, pt_base);
/* Map HULK regions. */ /* Map HULK regions. */
@ -391,8 +395,8 @@ private void jump_to_hulk()
{ {
__asm( __asm(
"jmpq *$0", "jmpq *$0",
"r,{rdi},{rsp}", "r,{rsp}",
hulk_header().entry, &bootinfo, hulk_virt_stack_top()); hulk_header().entry, hulk_virt_stack_top());
} }
/** /**
@ -440,9 +444,9 @@ extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st)
build_page_tables(max_physical_address, bss_phys, stack_phys); build_page_tables(max_physical_address, bss_phys, stack_phys);
bootinfo.hulk_phys = hulk_bin_phys(); bootinfo().hulk_phys = hulk_bin_phys();
bootinfo.bss_phys = bss_phys; bootinfo().bss_phys = bss_phys;
bootinfo.stack_phys = stack_phys; bootinfo().stack_phys = stack_phys;
jump_to_hulk(); jump_to_hulk();

View File

@ -3,6 +3,8 @@
*/ */
module hulk.header; module hulk.header;
import hulk.bootinfo;
/** /**
* Header describing the HULK image. * Header describing the HULK image.
*/ */
@ -32,4 +34,7 @@ struct HulkHeader
/** Framebuffer virtual address. */ /** Framebuffer virtual address. */
ulong virt_fb_buffer; ulong virt_fb_buffer;
/** HULK boot information. */
BootInfo bootinfo;
} }

View File

@ -4,7 +4,6 @@
module hulk.hulk; module hulk.hulk;
import hulk.header; import hulk.header;
import hulk.bootinfo;
import hulk.fb; import hulk.fb;
import hulk.console; import hulk.console;
import hos.memory; import hos.memory;
@ -27,12 +26,10 @@ private __gshared HulkHeader hulk_header = {
/** /**
* HULK entry point. * HULK entry point.
*
* @param bootinfo Pointer to HULK boot information structure.
*/ */
void hulk_start(BootInfo * bootinfo) void hulk_start()
{ {
fb.initialize(cast(uint *)HULK_VIRTUAL_FRAMEBUFFER_ADDRESS, bootinfo.fb.width, bootinfo.fb.height, bootinfo.fb.stride); fb.initialize(cast(uint *)HULK_VIRTUAL_FRAMEBUFFER_ADDRESS, hulk_header.bootinfo.fb.width, hulk_header.bootinfo.fb.height, hulk_header.bootinfo.fb.stride);
console.initialize(); console.initialize();
console.clear(); console.clear();
klog.initialize(); klog.initialize();

View File

@ -3,17 +3,22 @@ SECTIONS
. = 0xFFFF800000000000; . = 0xFFFF800000000000;
_hulk_mem_start = .; _hulk_mem_start = .;
.rodata BLOCK(4K) : ALIGN(4K) .hulk_header BLOCK(4K) : ALIGN(4K)
{ {
*(.hulk_header) *(.hulk_header)
*(.rodata)
} }
_hulk_header_size = . - _hulk_mem_start;
.text BLOCK(4K) : ALIGN(4K) .text BLOCK(4K) : ALIGN(4K)
{ {
*(.text) *(.text)
} }
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
.data BLOCK(4K) : ALIGN(4K) .data BLOCK(4K) : ALIGN(4K)
{ {
*(.data) *(.data)