Update linker script
This commit is contained in:
parent
1ff52acc42
commit
c7ccdc371d
2
build.rs
2
build.rs
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Tell ld to use linker script.
|
// 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.
|
// Don't do any magic linker stuff.
|
||||||
println!("cargo::rustc-link-arg=--omagic");
|
println!("cargo::rustc-link-arg=--omagic");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::abort;
|
use crate::abort;
|
||||||
|
|
||||||
unsafe extern "C" fn _enter() {
|
unsafe extern "C" fn _enter() {
|
||||||
|
|
||||||
let id = riscv::register::mhartid::read();
|
let id = riscv::register::mhartid::read();
|
||||||
write_tp(&id);
|
write_tp(&id);
|
||||||
// TODO: set up stack for all harts
|
// TODO: set up stack for all harts
|
||||||
|
|
|
@ -40,7 +40,7 @@ unsafe extern "C" fn _enter() -> ! {
|
||||||
"csrw mideleg, t5", // delegate all machine interrupts
|
"csrw mideleg, t5", // delegate all machine interrupts
|
||||||
|
|
||||||
// set the stack pointer
|
// set the stack pointer
|
||||||
"la sp, _init_stack_top",
|
"la sp, _stack_end",
|
||||||
|
|
||||||
// Make sure machine mode is set, and enable coarse interrupts
|
// Make sure machine mode is set, and enable coarse interrupts
|
||||||
"li t0, (0b11 << 11) | (1 << 7) | (1 << 3)",
|
"li t0, (0b11 << 11) | (1 << 7) | (1 << 3)",
|
||||||
|
|
|
@ -17,18 +17,25 @@ SECTIONS {
|
||||||
. = ORIGIN(ram); # start at 0x8000_0000 (DRAM)
|
. = ORIGIN(ram); # start at 0x8000_0000 (DRAM)
|
||||||
|
|
||||||
.text : { # put code first
|
.text : { # put code first
|
||||||
|
PROVIDE(_text_start = .);
|
||||||
*(.text.init) # start with anything in the .text.init section
|
*(.text.init) # start with anything in the .text.init section
|
||||||
*(.text .text.*) # then put anything else in .text
|
*(.text .text.*) # then put anything else in .text
|
||||||
|
PROVIDE(_text_end = .);
|
||||||
} >ram AT>ram :text # put this section into the text segment
|
} >ram AT>ram :text # put this section into the text segment
|
||||||
|
|
||||||
PROVIDE(_global_pointer = .); # this is magic, google "linker relaxation"
|
PROVIDE(_global_pointer = .); # this is magic, google "linker relaxation"
|
||||||
|
|
||||||
.rodata : { # next, read-only data
|
.rodata : { # next, read-only data
|
||||||
|
PROVIDE(_rodata_start = .);
|
||||||
*(.rodata .rodata.*)
|
*(.rodata .rodata.*)
|
||||||
|
PROVIDE(_rodata_end = .);
|
||||||
} >ram AT>ram :text # goes into the text segment as well (since instructions are generally read-only)
|
} >ram AT>ram :text # goes into the text segment as well (since instructions are generally read-only)
|
||||||
|
|
||||||
.data : { # and the data section
|
.data : { # and the data section
|
||||||
|
. = ALIGN(4096);
|
||||||
|
PROVIDE(_data_start = .);
|
||||||
*(.sdata .sdata.*) *(.data .data.*)
|
*(.sdata .sdata.*) *(.data .data.*)
|
||||||
|
PROVIDE(_data_end = .);
|
||||||
} >ram AT>ram :data # this will go into the data segment
|
} >ram AT>ram :data # this will go into the data segment
|
||||||
|
|
||||||
.bss :{ # finally, the BSS
|
.bss :{ # finally, the BSS
|
||||||
|
@ -37,10 +44,15 @@ SECTIONS {
|
||||||
PROVIDE(_bss_end = .); # ... and one at the end
|
PROVIDE(_bss_end = .); # ... and one at the end
|
||||||
} >ram AT>ram :bss # and this goes into the bss segment
|
} >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(_memory_start = ORIGIN(ram));
|
||||||
PROVIDE(_init_stack_top = . + 0x1000); # reserve 0x1000 bytes (4 kB) for the initialisation stack
|
|
||||||
|
|
||||||
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_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
|
PROVIDE(_kernel_heap_size = _kernel_heap_top - _kernel_heap_bottom); # capture size of heap
|
||||||
}
|
}
|
Loading…
Reference in a new issue