Update linker script

This commit is contained in:
gil 2024-05-18 20:02:40 -05:00
parent 1ff52acc42
commit c7ccdc371d
4 changed files with 18 additions and 5 deletions

View file

@ -2,7 +2,7 @@
fn main() {
// Tell ld to use linker script.
println!("cargo::rustc-link-arg=-Tsrc/script.ld");
println!("cargo::rustc-link-arg=-Tsrc/script.lds");
// Don't do any magic linker stuff.
println!("cargo::rustc-link-arg=--omagic");
}

View file

@ -1,6 +1,7 @@
use crate::abort;
unsafe extern "C" fn _enter() {
let id = riscv::register::mhartid::read();
write_tp(&id);
// TODO: set up stack for all harts

View file

@ -40,7 +40,7 @@ unsafe extern "C" fn _enter() -> ! {
"csrw mideleg, t5", // delegate all machine interrupts
// set the stack pointer
"la sp, _init_stack_top",
"la sp, _stack_end",
// Make sure machine mode is set, and enable coarse interrupts
"li t0, (0b11 << 11) | (1 << 7) | (1 << 3)",

View file

@ -17,18 +17,25 @@ 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
@ -37,10 +44,15 @@ SECTIONS {
PROVIDE(_bss_end = .); # ... and one at the end
} >ram AT>ram :bss # and this goes into the bss segment
. = ALIGN(16); # our stack needs to be 16-byte aligned, per the C calling convention
PROVIDE(_init_stack_top = . + 0x1000); # reserve 0x1000 bytes (4 kB) for the initialisation stack
PROVIDE(_memory_start = ORIGIN(ram));
PROVIDE(_kernel_heap_bottom = _init_stack_top); # allocate heap to remaining physical memory
. = 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(_kernel_heap_bottom = _stack_end); # 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
}