HELLO: Zero out HULK bss section
This commit is contained in:
parent
37d5621e41
commit
0568a813f2
@ -16,6 +16,7 @@ __gshared EFI_SYSTEM_TABLE * st;
|
|||||||
private __gshared BootInfo bootinfo;
|
private __gshared BootInfo bootinfo;
|
||||||
private __gshared UINTN memory_map_key;
|
private __gshared UINTN memory_map_key;
|
||||||
extern extern(C) __gshared ubyte hulk_bin_start;
|
extern extern(C) __gshared ubyte hulk_bin_start;
|
||||||
|
extern extern(C) __gshared ubyte hulk_bin_end;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect if we're running in QEMU.
|
* Detect if we're running in QEMU.
|
||||||
@ -229,6 +230,31 @@ private void map2m(ulong source_page, ulong dest_page, PageTableEntry * pt_base)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate a memory region for the HULK bss section.
|
||||||
|
*
|
||||||
|
* @param bss_size Size of the HULK bss section.
|
||||||
|
*
|
||||||
|
* @return Physical memory address.
|
||||||
|
*/
|
||||||
|
private ulong alloc_hulk_bss(size_t bss_size)
|
||||||
|
{
|
||||||
|
for (size_t i = 0u; i < bootinfo.memory_map_count; i++)
|
||||||
|
{
|
||||||
|
if ((bootinfo.memory_map[i].type == EfiConventionalMemory) &&
|
||||||
|
(bootinfo.memory_map[i].size >= bss_size))
|
||||||
|
{
|
||||||
|
memset64(cast(void *)bootinfo.memory_map[i].base, 0u, bss_size / 8u);
|
||||||
|
return bootinfo.memory_map[i].base;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We failed to find free memory. */
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map HULK virtual addresses to physical kernel location.
|
* Map HULK virtual addresses to physical kernel location.
|
||||||
*
|
*
|
||||||
@ -237,14 +263,27 @@ private void map2m(ulong source_page, ulong dest_page, PageTableEntry * pt_base)
|
|||||||
private void map_hulk(PageTableEntry * pt_base)
|
private void map_hulk(PageTableEntry * pt_base)
|
||||||
{
|
{
|
||||||
ulong virt = HULK_VIRTUAL_START;
|
ulong virt = HULK_VIRTUAL_START;
|
||||||
ulong phys = cast(ulong)&hulk_bin_start;
|
ulong hulk_bin_phys_start = cast(ulong)&hulk_bin_start;
|
||||||
HulkHeader * hulk_header = cast(HulkHeader *)&hulk_bin_start;
|
ulong hulk_bin_phys_end = cast(ulong)&hulk_bin_end;
|
||||||
size_t end_phys = phys + cast(size_t)hulk_header.total_size;
|
ulong phys_iter = hulk_bin_phys_start;
|
||||||
while (phys < end_phys)
|
while (phys_iter < hulk_bin_phys_end)
|
||||||
{
|
{
|
||||||
map4k(virt, phys, pt_base);
|
map4k(virt, phys_iter, pt_base);
|
||||||
virt += 4096u;
|
virt += 4096u;
|
||||||
phys += 4096u;
|
phys_iter += 4096u;
|
||||||
|
}
|
||||||
|
/* Now the binary has been mapped, but the bss section still needs to be
|
||||||
|
* allocated, zeroed and mapped. */
|
||||||
|
HulkHeader * hulk_header = cast(HulkHeader *)&hulk_bin_start;
|
||||||
|
size_t hulk_bin_phys_size = hulk_bin_phys_end - hulk_bin_phys_end;
|
||||||
|
size_t bss_size = cast(size_t)hulk_header.total_size - hulk_bin_phys_size;
|
||||||
|
ulong bss_phys = alloc_hulk_bss(bss_size);
|
||||||
|
ulong bss_phys_end = bss_phys + bss_size;
|
||||||
|
while (bss_phys < bss_phys_end)
|
||||||
|
{
|
||||||
|
map4k(virt, bss_phys, pt_base);
|
||||||
|
virt += 4096u;
|
||||||
|
bss_phys += 4096u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user