Compare commits
No commits in common. "c70be3fe1f95ed931fb3bc009010cad8cfed0f02" and "aaf64d0a2d5b1c20845fb322f4a1548b86336b8a" have entirely different histories.
c70be3fe1f
...
aaf64d0a2d
13
src/main.rs
13
src/main.rs
|
@ -6,14 +6,12 @@
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
mod heap;
|
mod heap;
|
||||||
mod trap;
|
|
||||||
mod uart;
|
mod uart;
|
||||||
|
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[link_section = ".text.init"]
|
#[link_section = ".text.init"]
|
||||||
unsafe extern "C" fn _enter() -> ! {
|
unsafe extern "C" fn _enter() -> ! {
|
||||||
// TODO see if possible to replace this somehow...
|
|
||||||
use core::arch::asm;
|
use core::arch::asm;
|
||||||
asm!(
|
asm!(
|
||||||
// load hartid into t0; if t0 =/= 0, then jump to busy loop
|
// load hartid into t0; if t0 =/= 0, then jump to busy loop
|
||||||
|
@ -31,17 +29,9 @@ unsafe extern "C" fn _enter() -> ! {
|
||||||
"la gp, _global_pointer",
|
"la gp, _global_pointer",
|
||||||
".option pop", // pops the current option stack
|
".option pop", // pops the current option stack
|
||||||
|
|
||||||
// delegate all traps to S-mode trap handler
|
|
||||||
"li t5, 0xffff",
|
|
||||||
"csrw medeleg, t5", // delegate all machine exceptions
|
|
||||||
"csrw mideleg, t5", // delegate all machine interrupts
|
|
||||||
|
|
||||||
// set the stack pointer
|
// set the stack pointer
|
||||||
"la sp, _init_stack_top",
|
"la sp, _init_stack_top",
|
||||||
|
|
||||||
"la t2, {trap_vector}",
|
|
||||||
"csrw mtvec, t2",
|
|
||||||
|
|
||||||
// clear the BSS
|
// clear the BSS
|
||||||
"la t0, _bss_start",
|
"la t0, _bss_start",
|
||||||
"la t1, _bss_end",
|
"la t1, _bss_end",
|
||||||
|
@ -51,8 +41,8 @@ unsafe extern "C" fn _enter() -> ! {
|
||||||
"addi t0, t0, 1",
|
"addi t0, t0, 1",
|
||||||
"bne t0, t1, 1b",
|
"bne t0, t1, 1b",
|
||||||
"2:",
|
"2:",
|
||||||
"j 4f",
|
|
||||||
// BSS is clear!
|
// BSS is clear!
|
||||||
|
"j 4f",
|
||||||
|
|
||||||
// busy loop if hartid =/= 0
|
// busy loop if hartid =/= 0
|
||||||
"3:",
|
"3:",
|
||||||
|
@ -63,7 +53,6 @@ unsafe extern "C" fn _enter() -> ! {
|
||||||
// "tail-call" to {start} (call without saving a return address)
|
// "tail-call" to {start} (call without saving a return address)
|
||||||
"tail {start}",
|
"tail {start}",
|
||||||
start = sym start, // {start} refers to the function [start] below
|
start = sym start, // {start} refers to the function [start] below
|
||||||
trap_vector = sym trap::trap_handler, // {trap_vector} refers to function [trap::trap_handler]
|
|
||||||
options(noreturn) // we must handle "returning" from assembly
|
options(noreturn) // we must handle "returning" from assembly
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ SECTIONS {
|
||||||
} >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
|
. = 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(_init_stack_top = . + 0x1000); # reserve 0x1000 bytes for the initialisation stack
|
||||||
|
|
||||||
PROVIDE(_kernel_heap_bottom = _init_stack_top); # allocate heap to remaining physical memory
|
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_top = ORIGIN(ram) + LENGTH(ram)); # top of heap is end of ram
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#[naked]
|
|
||||||
pub unsafe extern "C" fn trap_handler() -> ! {
|
|
||||||
use core::arch::asm;
|
|
||||||
asm!(
|
|
||||||
"mret",
|
|
||||||
options(noreturn)
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in a new issue