From 153a8d43f1452f7aa2fc45e4e2b5624865575875 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 26 Apr 2022 19:37:05 -0400 Subject: [PATCH] Add hulk.linker_addresses module --- src/hulk/hippo.d | 5 ++--- src/hulk/hulk.ld | 26 +++++++++++++++-------- src/hulk/linker_addresses.d | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 src/hulk/linker_addresses.d diff --git a/src/hulk/hippo.d b/src/hulk/hippo.d index e1ea2ee..cec3535 100644 --- a/src/hulk/hippo.d +++ b/src/hulk/hippo.d @@ -6,8 +6,7 @@ module hulk.hippo; import hulk.header; import hulk.bootinfo; import hulk.klog; - -extern extern(C) ubyte * _hulk_bss_size; +import hulk.linker_addresses; struct hippo { @@ -50,7 +49,7 @@ struct hippo size_t usable_memory; ulong[2][5] reserved = [ [header.bootinfo.hulk_phys, cast(ulong)header.total_size], - [header.bootinfo.bss_phys, cast(ulong)&_hulk_bss_size], + [header.bootinfo.bss_phys, LinkerAddresses.hulk_bss_size], [header.bootinfo.stack_phys, header.stack_size], [cast(ulong)header.bootinfo.fb.buffer, header.bootinfo.fb.height * header.bootinfo.fb.stride], [header.bootinfo.pt_phys, header.bootinfo.pt_size], diff --git a/src/hulk/hulk.ld b/src/hulk/hulk.ld index 8ea1054..c994277 100644 --- a/src/hulk/hulk.ld +++ b/src/hulk/hulk.ld @@ -3,37 +3,45 @@ SECTIONS . = 0xFFFF800000000000; _hulk_mem_start = .; - .hulk_header BLOCK(4K) : ALIGN(4K) + .hulk_header : { *(.hulk_header) } - _hulk_header_size = . - _hulk_mem_start; - .text BLOCK(4K) : ALIGN(4K) + . = ALIGN(4K); + _hulk_text_start = .; + + .text : { *(.text) } - .rodata BLOCK(4K) : ALIGN(4K) + . = ALIGN(4K); + _hulk_text_end = .; + + .rodata : { *(.rodata) } - .data BLOCK(4K) : ALIGN(4K) + . = ALIGN(4K); + + .data : { *(.data) } - .bss BLOCK(4K) : ALIGN(4K) + . = ALIGN(4K); + _hulk_bss_start = .; + + .bss : { - _hulk_bss_start = .; *(COMMON) *(.bss) } - _hulk_bss_size = . - _hulk_bss_start; . = ALIGN(4K); - + _hulk_bss_size = . - _hulk_bss_start; _hulk_mem_end = .; _hulk_total_size = _hulk_mem_end - _hulk_mem_start; } diff --git a/src/hulk/linker_addresses.d b/src/hulk/linker_addresses.d new file mode 100644 index 0000000..715b6fb --- /dev/null +++ b/src/hulk/linker_addresses.d @@ -0,0 +1,41 @@ +/** + * This module provides access to linker-defined symbols. + */ +module hulk.linker_addresses; + +private extern extern(C) __gshared ubyte _hulk_mem_start; +private extern extern(C) __gshared ubyte _hulk_bss_start; +private extern extern(C) __gshared ubyte _hulk_bss_size; +private extern extern(C) __gshared ubyte _hulk_mem_end; +private extern extern(C) __gshared ubyte _hulk_total_size; + +/** + * This struct provides access to linker-defined symbols. + */ +public struct LinkerAddresses +{ + public static @property ulong hulk_mem_start() + { + return cast(ulong)&_hulk_mem_start; + } + + public static @property ulong hulk_bss_start() + { + return cast(ulong)&_hulk_bss_start; + } + + public static @property ulong hulk_bss_size() + { + return cast(ulong)&_hulk_bss_size; + } + + public static @property ulong hulk_mem_end() + { + return cast(ulong)&_hulk_mem_end; + } + + public static @property ulong hulk_total_size() + { + return cast(ulong)&_hulk_total_size; + } +}