kernel/src/script.ld

46 lines
1.5 KiB
Plaintext
Raw Normal View History

2024-05-13 18:31:37 -04:00
# src/script.ld
OUTPUT_ARCH("riscv")
ENTRY(_enter)
2024-05-13 18:31:37 -04:00
MEMORY {
ram (wxa) : ORIGIN = 0x80000000, LENGTH = 128M
}
PHDRS {
text PT_LOAD;
data PT_LOAD;
bss PT_LOAD;
}
SECTIONS {
2024-05-16 00:17:35 -04:00
. = ORIGIN(ram); # start at 0x8000_0000 (DRAM)
2024-05-13 18:31:37 -04:00
.text : { # put code first
*(.text.init) # start with anything in the .text.init section
*(.text .text.*) # then put anything else in .text
} >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
*(.rodata .rodata.*)
} >ram AT>ram :text # goes into the text segment as well (since instructions are generally read-only)
.data : { # and the data section
*(.sdata .sdata.*) *(.data .data.*)
} >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
2024-05-13 23:07:46 -04:00
. = ALIGN(16); # our stack needs to be 16-byte aligned, per the C calling convention
2024-05-16 12:21:27 -04:00
PROVIDE(_init_stack_top = . + 0x1000); # reserve 0x1000 bytes (4 kB) for the initialisation stack
2024-05-14 11:03:08 -04:00
PROVIDE(_kernel_heap_bottom = _init_stack_top); # allocate heap to remaining physical memory
PROVIDE(_kernel_heap_top = ORIGIN(ram) + LENGTH(ram)); # top of heap is end of ram
PROVIDE(_kernel_heap_size = _kernel_heap_top - _kernel_heap_bottom); # capture size of heap
2024-05-13 18:31:37 -04:00
}