This repository was archived by the owner on Sep 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +22
-12
lines changed
Expand file tree Collapse file tree 3 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -7,21 +7,31 @@ pub(super) fn should_transfer_trap(ctx: &Context) -> bool {
77
88pub ( super ) fn do_transfer_trap ( ctx : & mut Context , cause : scause:: Trap ) {
99 unsafe {
10- // 填写陷入原因
10+ // 向 S 转发陷入
11+ mstatus:: set_mpp ( mstatus:: MPP :: Supervisor ) ;
12+ // 转发陷入源状态
13+ let spp = match ( ctx. mstatus >> 11 ) & 0b11 {
14+ // U
15+ 0b00 => mstatus:: SPP :: User ,
16+ // S
17+ 0b01 => mstatus:: SPP :: Supervisor ,
18+ // H/M
19+ mpp => unreachable ! ( "invalid mpp: {mpp:#x} to delegate" ) ,
20+ } ;
21+ mstatus:: set_spp ( spp) ;
22+ // 转发陷入原因
1123 scause:: set ( cause) ;
12- // 填写陷入附加信息
24+ // 转发陷入附加信息
1325 stval:: write ( mtval:: read ( ) ) ;
14- // 填写 S 态层需要返回到的地址
26+ // 转发陷入地址
1527 sepc:: write ( ctx. mepc ) ;
16- // 设置中断位
17- mstatus:: set_mpp ( mstatus:: MPP :: Supervisor ) ;
18- mstatus:: set_spp ( mstatus:: SPP :: Supervisor ) ;
28+ // 设置 S 中断状态
1929 if mstatus:: read ( ) . sie ( ) {
20- mstatus:: set_spie ( )
30+ mstatus:: set_spie ( ) ;
31+ mstatus:: clear_sie ( ) ;
2132 }
22- mstatus:: clear_sie ( ) ;
2333 core:: arch:: asm!( "csrr {}, mstatus" , out( reg) ctx. mstatus) ;
24- // 设置返回地址,返回到S层
34+ // 设置返回地址,返回到 S
2535 // TODO Vectored stvec?
2636 ctx. mepc = stvec:: read ( ) . address ( ) ;
2737 }
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ extern "C" fn primary_rust_main(hartid: usize, dtb_pa: usize) -> ! {
8989 unsafe { stvec:: write ( start_trap as usize , TrapMode :: Direct ) } ;
9090 test:: trap_delegate ( hartid) ;
9191
92- test:: start_stop_harts ( hartid, smp) ;
92+ test:: hsm ( hartid, smp) ;
9393
9494 sbi:: system_reset ( sbi:: RESET_TYPE_SHUTDOWN , sbi:: RESET_REASON_NO_REASON ) ;
9595 unreachable ! ( )
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ pub(crate) fn trap_delegate(hartid: usize) {
7979}
8080
8181/// 所有副核:启动 -> 不可恢复休眠 -> 唤醒 -> 可恢复休眠 -> 唤醒 -> 关闭。
82- pub ( crate ) fn start_stop_harts ( hartid : usize , smp : usize ) {
82+ pub ( crate ) fn hsm ( hartid : usize , smp : usize ) {
8383 const SUSPENDED : sbi:: SbiRet = sbi:: SbiRet {
8484 error : sbi:: RET_SUCCESS ,
8585 value : sbi:: HART_STATE_SUSPENDED ,
@@ -124,7 +124,7 @@ pub(crate) fn start_stop_harts(hartid: usize, smp: usize) {
124124
125125 println ! (
126126 "
127- [test-kernel] Testing start harts "
127+ [test-kernel] Testing hsm: start, stop, suspend and resume "
128128 ) ;
129129
130130 // 启动副核
You can’t perform that action at this time.
0 commit comments