Skip to content

Commit b8637e1

Browse files
committed
temp: 增加一些启动逻辑
Signed-off-by: YdrMaster <[email protected]>
1 parent 0c82b09 commit b8637e1

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustsbi-qemu/src/main.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use execute::Operation;
3434
use fast_trap::{
3535
reuse_stack_for_trap, FastContext, FastResult, FlowContext, FreeTrapStack, TrapStackBlock,
3636
};
37+
use riscv::register::*;
3738
use rustsbi::RustSBI;
3839
use spin::{Mutex, Once};
3940
use uart_16550::MmioSerialPort;
@@ -194,9 +195,6 @@ fn hart_id() -> usize {
194195

195196
/// 设置 PMP。
196197
fn set_pmp(board_info: &BoardInfo) {
197-
use riscv::register::{
198-
pmpaddr0, pmpaddr1, pmpaddr2, pmpaddr3, pmpaddr4, pmpcfg0, Permission, Range,
199-
};
200198
let mem = &board_info.mem;
201199
unsafe {
202200
pmpcfg0::set_pmp(0, Range::OFF, Permission::NONE, false);
@@ -216,8 +214,12 @@ fn set_pmp(board_info: &BoardInfo) {
216214
}
217215
}
218216

217+
mod cause {
218+
pub(crate) const BOOT: usize = 24;
219+
}
220+
219221
extern "C" fn fast_handler(
220-
mut _ctx: FastContext,
222+
ctx: FastContext,
221223
_a1: usize,
222224
_a2: usize,
223225
_a3: usize,
@@ -226,7 +228,19 @@ extern "C" fn fast_handler(
226228
_a6: usize,
227229
_a7: usize,
228230
) -> FastResult {
229-
todo!()
231+
use mcause::{Exception as E, Trap as T};
232+
233+
let cause = mcause::read();
234+
match cause.cause() {
235+
T::Exception(E::Unknown) => match cause.bits() {
236+
cause::BOOT => {
237+
// TODO 检查状态,设置启动参数
238+
ctx.call(2)
239+
}
240+
_ => todo!(),
241+
},
242+
T::Exception(_) | T::Interrupt(_) => todo!(),
243+
}
230244
}
231245

232246
#[panic_handler]

0 commit comments

Comments
 (0)