Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rv32i: add Display trait for PMPRegion/Config #1970

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 30 additions & 1 deletion arch/rv32i/src/pmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ pub struct PMPRegion {
cfg: tock_registers::registers::FieldValue<u32, pmpcfg::Register>,
}

impl fmt::Display for PMPRegion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn bit_str<'a>(reg: &PMPRegion, bit: u32, on_str: &'a str, off_str: &'a str) -> &'a str {
match reg.cfg.value & bit {
0 => off_str,
_ => on_str,
}
}

match self.location {
None => write!(f, "<unset>"),
Some((addr, size)) => write!(
f,
"addr={:p}, size={:#X}, cfg={:#X} ({}{}{})",
addr,
size,
u32::from(self.cfg),
bit_str(self, pmpcfg::r::SET.value, "r", "-"),
bit_str(self, pmpcfg::w::SET.value, "w", "-"),
bit_str(self, pmpcfg::x::SET.value, "x", "-"),
),
}
}
}

impl PMPRegion {
fn new(start: *const u8, size: usize, permissions: mpu::Permissions) -> PMPRegion {
// Determine access and execute permissions
Expand Down Expand Up @@ -136,7 +161,11 @@ impl Default for PMPConfig {
}

impl fmt::Display for PMPConfig {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "PMP regions:")?;
for n in 0..self.total_regions {
writeln!(f, " [{}]: {}", n, self.regions[n])?;
}
Ok(())
}
}
Expand Down