Skip to content

Commit 2b91200

Browse files
committed
noted
1 parent f8fb1da commit 2b91200

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

os/src/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl UserStack {
5151
struct AppManager {
5252
num_app: usize,
5353
current_app: usize,
54-
app_start: [usize; MAX_APP_NUM + 1],
54+
app_start: [usize; MAX_APP_NUM + 1],//参考下面的打印, 最后一个app也有一个结束地址,所以多留1
5555
}
5656

5757
impl AppManager {

os/src/boards/qemu.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ pub struct RISCV64 {
3030

3131
/// Encode the exit code using EXIT_FAILURE_FLAG.
3232
const fn exit_code_encode(code: u32) -> u32 {
33-
(code << 16) | EXIT_FAILURE_FLAG
33+
(code << 16) | EXIT_FAILURE_FLAG//按位或在这里等效于加(拼接), 取code的低16位拼接
3434
}
3535

3636
impl RISCV64 {
3737
/// Create an instance.
38-
pub const fn new(addr: u64) -> Self {
38+
pub const fn new(addr: u64) -> Self {//pub可外部调用,const作用似乎还有争议
3939
RISCV64 { addr }
4040
}
4141
}
42+
//let xxx = RISCV64::new(addr);
4243

4344
impl QEMUExit for RISCV64 {
44-
/// Exit qemu with specified exit code.
45+
/// Exit qemu with specified exit code.其实就是把错误码按规则解码后写进addr
4546
fn exit(&self, code: u32) -> ! {
4647
// If code is not a special value, we need to encode it with EXIT_FAILURE_FLAG.
4748
let code_new = match code {
@@ -52,20 +53,20 @@ impl QEMUExit for RISCV64 {
5253
unsafe {
5354
asm!(
5455
"sw {0}, 0({1})",
55-
in(reg)code_new, in(reg)self.addr
56+
in(reg)code_new, in(reg)self.addr//把解码后退出码写进指定位置
5657
);
5758

5859
// For the case that the QEMU exit attempt did not work, transition into an infinite
5960
// loop. Calling `panic!()` here is unfeasible, since there is a good chance
6061
// this function here is the last expression in the `panic!()` handler
6162
// itself. This prevents a possible infinite loop.
6263
loop {
63-
asm!("wfi", options(nomem, nostack));
64+
asm!("wfi", options(nomem, nostack));//wfi - wait for interrupt
6465
}
6566
}
6667
}
6768

68-
fn exit_success(&self) -> ! {
69+
fn exit_success(&self) -> ! {//欲表示退出成功直接调用?
6970
self.exit(EXIT_SUCCESS);
7071
}
7172

@@ -74,6 +75,7 @@ impl QEMUExit for RISCV64 {
7475
}
7576
}
7677

77-
const VIRT_TEST: u64 = 0x100000;
78+
const VIRT_TEST: u64 = 0x100000;//VT[20] = 1
7879

80+
//QEH在0X100000的地方写退出码
7981
pub const QEMU_EXIT_HANDLE: RISCV64 = RISCV64::new(VIRT_TEST);

0 commit comments

Comments
 (0)