mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
add ram zeorization to top of boot
this slows down boot a little bit but I think this is a good idea from a security perspective.
This commit is contained in:
parent
cafd760bf5
commit
36b1868fc4
1 changed files with 13 additions and 3 deletions
|
|
@ -7,6 +7,14 @@ pub extern "C" fn _start() {
|
||||||
unsafe {
|
unsafe {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
asm! (
|
asm! (
|
||||||
|
// zero memory
|
||||||
|
"mv t0, {ram_base}",
|
||||||
|
"mv t2, {ram_top}",
|
||||||
|
"100:",
|
||||||
|
"sw x0, 0(t0)",
|
||||||
|
"addi t0, t0, 4",
|
||||||
|
"bltu t0, t2, 100b",
|
||||||
|
|
||||||
// Place the stack pointer at the end of RAM
|
// Place the stack pointer at the end of RAM
|
||||||
"mv sp, {ram_top}",
|
"mv sp, {ram_top}",
|
||||||
// subtract four from sp to make room for a DMA "gutter"
|
// subtract four from sp to make room for a DMA "gutter"
|
||||||
|
|
@ -20,8 +28,8 @@ pub extern "C" fn _start() {
|
||||||
"sw t1, 0xc(t0)",
|
"sw t1, 0xc(t0)",
|
||||||
"li t1, 0x1",
|
"li t1, 0x1",
|
||||||
"sw t1, 0x4(t0)", // CR is 1
|
"sw t1, 0x4(t0)", // CR is 1
|
||||||
// print 8 instances of 'Z' (0x5A) (provided to help measure baud)
|
// print 4 instances of 'Z' (0x5A) (provided to help measure baud)
|
||||||
"li t2, 8",
|
"li t2, 4",
|
||||||
"li t1, 0x5A",
|
"li t1, 0x5A",
|
||||||
"10:",
|
"10:",
|
||||||
"sw t1, 0x0(t0)",
|
"sw t1, 0x0(t0)",
|
||||||
|
|
@ -30,7 +38,8 @@ pub extern "C" fn _start() {
|
||||||
"bne x0, t3, 11b", // wait for 0
|
"bne x0, t3, 11b", // wait for 0
|
||||||
"addi t2, t2, -1",
|
"addi t2, t2, -1",
|
||||||
"bne x0, t2, 10b",
|
"bne x0, t2, 10b",
|
||||||
"50:",
|
|
||||||
|
"50:",
|
||||||
// Install a machine mode trap handler
|
// Install a machine mode trap handler
|
||||||
"la t0, abort",
|
"la t0, abort",
|
||||||
"csrw mtvec, t0",
|
"csrw mtvec, t0",
|
||||||
|
|
@ -39,6 +48,7 @@ pub extern "C" fn _start() {
|
||||||
"j rust_entry",
|
"j rust_entry",
|
||||||
|
|
||||||
ram_top = in(reg) (platform::RAM_BASE + platform::RAM_SIZE),
|
ram_top = in(reg) (platform::RAM_BASE + platform::RAM_SIZE),
|
||||||
|
ram_base = in(reg) (platform::RAM_BASE),
|
||||||
options(noreturn)
|
options(noreturn)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue