Skip to content

Commit

Permalink
Merge #1970
Browse files Browse the repository at this point in the history
1970: rv32i: add Display trait for PMPRegion/Config r=a-pronin a=a-pronin

### Pull Request Overview

This patch implements Display trait for PMPregion and PMPconfig, and that adds PMP regions information for a process to the standard panic printout.

### Testing Strategy

This pull request was tested by triggering a panic on a RISC-V board and monitoring output.


Co-authored-by: Andrey Pronin <apronin@google.com>
  • Loading branch information
bors[bot] and a-pronin committed Jun 23, 2020
2 parents e70e93e + 179a309 commit 957a890
Showing 1 changed file with 30 additions and 1 deletion.
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

0 comments on commit 957a890

Please sign in to comment.