File tree Expand file tree Collapse file tree 3 files changed +45
-7
lines changed Expand file tree Collapse file tree 3 files changed +45
-7
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ impl Timer for Clint {
55
55
#[ inline]
56
56
fn set_timer ( & self , time_value : u64 ) {
57
57
unsafe {
58
+ riscv:: register:: mip:: clear_stimer ( ) ;
59
+ riscv:: register:: mie:: set_mtimer ( ) ;
58
60
( ( self . base as * mut u8 ) . offset ( 0x4000 ) as * mut u64 )
59
61
. add ( hart_id ( ) )
60
62
. write_volatile ( time_value) ;
Original file line number Diff line number Diff line change 6
6
7
7
use core:: arch:: asm;
8
8
use riscv:: register:: {
9
- scause:: Trap ,
9
+ scause:: { Interrupt , Trap } ,
10
10
sepc,
11
11
stvec:: { self , TrapMode } ,
12
12
} ;
@@ -84,7 +84,10 @@ extern "C" fn primary_rust_main(hartid: usize, dtb_pa: usize) -> ! {
84
84
test:: sbi_ins_emulation ( ) ;
85
85
86
86
unsafe { stvec:: write ( start_trap as usize , TrapMode :: Direct ) } ;
87
- test:: trap_delegate ( hartid) ;
87
+ test:: trap_execption_delegate ( hartid) ;
88
+
89
+ unsafe { riscv:: register:: sstatus:: set_sie ( ) } ;
90
+ test:: trap_interrupt_delegate ( hartid) ;
88
91
89
92
test:: hsm ( hartid, smp) ;
90
93
@@ -97,9 +100,16 @@ extern "C" fn rust_trap_exception(trap_frame: &mut TrapFrame) {
97
100
98
101
let cause = scause:: read ( ) . cause ( ) ;
99
102
let expected = unsafe { core:: mem:: take ( & mut EXPECTED [ trap_frame. tp ] ) } ;
100
-
101
103
if Some ( cause) == expected {
102
- sepc:: write ( sepc:: read ( ) . wrapping_add ( 4 ) ) ;
104
+ match cause {
105
+ Trap :: Exception ( _) => {
106
+ sepc:: write ( sepc:: read ( ) . wrapping_add ( 4 ) ) ;
107
+ }
108
+ Trap :: Interrupt ( Interrupt :: SupervisorTimer ) => {
109
+ sbi_rt:: set_timer ( u64:: MAX ) ;
110
+ }
111
+ _ => { }
112
+ }
103
113
} else {
104
114
panic ! ( "[test-kernel] SBI test FAILED due to unexpected trap {cause:?}" ) ;
105
115
}
Original file line number Diff line number Diff line change 1
- pub ( crate ) fn base_extension ( ) {
1
+ use crate :: EXPECTED ;
2
+
3
+ pub ( crate ) fn base_extension ( ) {
2
4
println ! (
3
5
"
4
6
[test-kernel] Testing base extension"
@@ -55,8 +57,7 @@ pub(crate) fn sbi_ins_emulation() {
55
57
}
56
58
}
57
59
58
- pub ( crate ) fn trap_delegate ( hartid : usize ) {
59
- use crate :: EXPECTED ;
60
+ pub ( crate ) fn trap_execption_delegate ( hartid : usize ) {
60
61
use core:: arch:: asm;
61
62
use riscv:: register:: scause:: { Exception , Trap } ;
62
63
@@ -78,6 +79,31 @@ pub(crate) fn trap_delegate(hartid: usize) {
78
79
) ;
79
80
}
80
81
82
+ pub ( crate ) fn trap_interrupt_delegate ( hartid : usize ) {
83
+ use core:: arch:: asm;
84
+ use riscv:: register:: {
85
+ scause:: { Interrupt , Trap } ,
86
+ sie, time,
87
+ } ;
88
+
89
+ println ! (
90
+ "
91
+ [test-kernel] Testing trap delegate
92
+ [test-kernel] Set timer +1s"
93
+ ) ;
94
+ unsafe {
95
+ sie:: set_stimer ( ) ;
96
+ EXPECTED [ hartid] = Some ( Trap :: Interrupt ( Interrupt :: SupervisorTimer ) ) ;
97
+ }
98
+ sbi_rt:: set_timer ( time:: read64 ( ) + ( 10 << 20 ) ) ;
99
+
100
+ unsafe { riscv:: asm:: wfi ( ) } ;
101
+ println ! (
102
+ "\
103
+ [test-kernel] Timer interrupt delegate success"
104
+ ) ;
105
+ }
106
+
81
107
/// 所有副核:启动 -> 不可恢复休眠 -> 唤醒 -> 可恢复休眠 -> 唤醒 -> 关闭。
82
108
pub ( crate ) fn hsm ( hartid : usize , smp : usize ) {
83
109
use sbi_rt:: SbiRet ;
You can’t perform that action at this time.
0 commit comments