Skip to content

Commit d37e360

Browse files
committed
feat(x86_64): add control registers dump cmds (#546)
This adds kernel shell `dump arch` commands for CR0, CR2, CR3, and CR4, which seemed nice to have. For example: <img width="1332" height="914" alt="image" src="https://github.com/user-attachments/assets/59798c62-9301-4a1a-9724-a281e7540284" />
1 parent 3b63fbd commit d37e360

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/arch/x86_64/shell.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::shell::{Command, NumberFormat};
2+
use hal_x86_64::control_regs;
23
use mycelium_util::fmt;
34

45
pub const DUMP_ARCH: Command = Command::new("arch")
@@ -88,4 +89,41 @@ pub const DUMP_ARCH: Command = Command::new("arch")
8889
}
8990
Ok(())
9091
}),
92+
Command::new("cr0")
93+
.with_help("print the value of control register CR0")
94+
.with_fn(|_| {
95+
tracing::info!(
96+
target: "shell",
97+
"CR0:\n{}",
98+
control_regs::Cr0::read(),
99+
);
100+
Ok(())
101+
}),
102+
Command::new("cr2")
103+
.with_help("print the value of control register CR2")
104+
.with_fn(|_| {
105+
tracing::info!(
106+
target: "shell",
107+
cr2 = ?control_regs::Cr2::read(),
108+
"CR2",
109+
);
110+
Ok(())
111+
}),
112+
Command::new("cr3")
113+
.with_help("print the value of control register CR3")
114+
.with_fn(|_| {
115+
let (page, flags) = control_regs::cr3::read();
116+
tracing::info!(target: "shell", ?page, ?flags, "CR3");
117+
Ok(())
118+
}),
119+
Command::new("cr4")
120+
.with_help("print the value of control register CR4")
121+
.with_fn(|_| {
122+
tracing::info!(
123+
target: "shell",
124+
"CR4\n{}",
125+
control_regs::Cr4::read(),
126+
);
127+
Ok(())
128+
}),
91129
]);

0 commit comments

Comments
 (0)