# src/script.ld OUTPUT_ARCH("riscv") ENTRY(_enter) MEMORY { ram (wxa) : ORIGIN = 0x80000000, LENGTH = 128M } PHDRS { text PT_LOAD; data PT_LOAD; bss PT_LOAD; } SECTIONS { . = ORIGIN(ram); # start at 0x8000_0000 (DRAM) .text : { # put code first PROVIDE(_text_start = .); *(.text.init) # start with anything in the .text.init section *(.text .text.*) # then put anything else in .text PROVIDE(_text_end = .); } >ram AT>ram :text # put this section into the text segment PROVIDE(_global_pointer = .); # this is magic, google "linker relaxation" .rodata : { # next, read-only data PROVIDE(_rodata_start = .); *(.rodata .rodata.*) PROVIDE(_rodata_end = .); } >ram AT>ram :text # goes into the text segment as well (since instructions are generally read-only) .data : { # and the data section . = ALIGN(4096); PROVIDE(_data_start = .); *(.sdata .sdata.*) *(.data .data.*) PROVIDE(_data_end = .); } >ram AT>ram :data # this will go into the data segment .bss :{ # finally, the BSS PROVIDE(_bss_start = .); # define a variable for the start of this section *(.sbss .sbss.*) *(.bss .bss.*) PROVIDE(_bss_end = .); # ... and one at the end } >ram AT>ram :bss # and this goes into the bss segment PROVIDE(_memory_start = ORIGIN(ram)); . = ALIGN(16); # stack is 16-byte aligned, per the C calling convention PROVIDE(_stack_start = .); PROVIDE(_stack_end = _stack_start + 0x80000); # reserve 0x80000 bytes for the stack PROVIDE(_memory_end = ORIGIN(ram) + LENGTH(ram)); /* TODO Redefine heap sections */ PROVIDE(_heap_start = _stack_end); # allocate heap to remaining physical memory PROVIDE(_heap_size = _memory_end - _heap_start); # capture size of heap }