kernel/lds/kernel.lds

59 lines
1.7 KiB
Plaintext
Raw Normal View History

/* lds/kernel.lds */
2024-05-13 18:31:37 -04:00
OUTPUT_ARCH("riscv")
ENTRY(_entry)
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
2024-05-18 21:02:40 -04:00
PROVIDE(_text_start = .);
2024-05-13 18:31:37 -04:00
*(.text.init) # start with anything in the .text.init section
*(.text .text.*) # then put anything else in .text
2024-05-18 21:02:40 -04:00
PROVIDE(_text_end = .);
2024-05-13 18:31:37 -04:00
} >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
2024-05-18 21:02:40 -04:00
PROVIDE(_rodata_start = .);
2024-05-13 18:31:37 -04:00
*(.rodata .rodata.*)
2024-05-18 21:02:40 -04:00
PROVIDE(_rodata_end = .);
2024-05-13 18:31:37 -04:00
} >ram AT>ram :text # goes into the text segment as well (since instructions are generally read-only)
.data : { # and the data section
2024-05-18 21:02:40 -04:00
. = ALIGN(4096);
PROVIDE(_data_start = .);
2024-05-19 18:42:50 -04:00
*(.sdata .sdata.*)
*(.data .data.*)
2024-05-18 21:02:40 -04:00
PROVIDE(_data_end = .);
2024-05-13 18:31:37 -04:00
} >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
2024-05-19 18:42:50 -04:00
*(.sbss .sbss.*)
*(.bss .bss.*)
2024-05-13 18:31:37 -04:00
PROVIDE(_bss_end = .); # ... and one at the end
} >ram AT>ram :bss # and this goes into the bss segment
2024-05-18 21:02:40 -04:00
PROVIDE(_memory_start = ORIGIN(ram));
2024-05-14 11:03:08 -04:00
2024-05-18 21:02:40 -04:00
. = 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));
PROVIDE(_heap_start = _stack_end); # allocate heap to remaining physical memory
PROVIDE(_heap_size = _memory_end - _heap_start); # capture size of heap
2024-05-13 18:31:37 -04:00
}