-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
783 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
use core::arch::global_asm; | ||
use core::arch::{asm, global_asm}; | ||
|
||
global_asm!(include_str!("boot.S")); | ||
global_asm!(include_str!("trap.S")); | ||
use crate::{cpu, sbi::extensions::timer_extension}; | ||
|
||
global_asm!(include_str!("boot.S"), KERNEL_PAGE_TABLES_SATP_OFFSET = const cpu::KERNEL_PAGE_TABLES_SATP_OFFSET); | ||
global_asm!(include_str!("trap.S"), TRAP_FRAME_OFFSET = const cpu::TRAP_FRAME_OFFSET, KERNEL_PAGE_TABLES_SATP_OFFSET = const cpu::KERNEL_PAGE_TABLES_SATP_OFFSET); | ||
global_asm!(include_str!("powersave.S"), EID = const timer_extension::EID, FID_SET_TIMER = const timer_extension::FID_SET_TIMER); | ||
global_asm!(include_str!("panic.S")); | ||
|
||
#[unsafe(no_mangle)] | ||
pub fn asm_panic_rust() { | ||
let ra: usize; | ||
unsafe { | ||
asm!("mv {}, ra", out(reg)ra); | ||
} | ||
panic!("Panic from asm code (ra={ra:#x})"); | ||
} | ||
|
||
#[unsafe(no_mangle)] | ||
#[naked] | ||
pub extern "C" fn wfi_loop() -> ! { | ||
unsafe { | ||
core::arch::naked_asm!( | ||
" | ||
0: | ||
wfi | ||
j 0 | ||
" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.section .text | ||
.global powersave | ||
.align 4 | ||
asm_panic: | ||
# Disable interrupts. | ||
csrw sie, zero | ||
|
||
# Load emergency stack | ||
la sp, __stop_kernel_stack | ||
|
||
# Jump to asm_panic_rust such that we still now | ||
# where we came from via the ra register | ||
j asm_panic_rust | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.section .text | ||
.global powersave | ||
.align 4 | ||
powersave: | ||
# Disable timer interrupt | ||
li t0, (1 << 5) | ||
csrc sie, t0 | ||
|
||
# Set next timer interrupt to -2 | ||
li a7, {EID} | ||
li a6, {FID_SET_TIMER} | ||
|
||
# arg | ||
li a0, 0 | ||
# Somehow u64::MAX triggers timer interrupt indefinitely | ||
# u64::MAX - 1 works as intended. | ||
addi a0, a0, -2 | ||
|
||
ecall | ||
|
||
# a0 should be 0 to indicate success | ||
bne a0, x0, powersave_error | ||
|
||
wfi | ||
j powersave | ||
|
||
powersave_error: | ||
call asm_panic | ||
powersave_error_sleep: | ||
wfi | ||
j powersave_error_sleep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.