Skip to content

Commit e6726f4

Browse files
committed
refactor is_pc_within_archive using PcResult
1 parent 220886a commit e6726f4

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

humility-core/src/hubris.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ impl HubrisArchive {
20972097
core.halt()?;
20982098
let result = self.is_pc_within_archive(core);
20992099
core.run()?;
2100-
if let Ok((false, pc)) = result {
2100+
if let Ok(PcResult::NotInArchive { pc }) = result {
21012101
bail!("image ID matches but PC at 0x{pc:x} is not part of any \
21022102
module. Maybe this is an incorrect A/B archive, or \
21032103
bootloader or ROM code is running?");
@@ -2182,12 +2182,12 @@ impl HubrisArchive {
21822182
pub fn is_pc_within_archive(
21832183
&self,
21842184
core: &mut dyn crate::core::Core,
2185-
) -> Result<(bool, u32)> {
2185+
) -> Result<PcResult> {
21862186
let pc = core.read_reg(ARMRegister::PC)?;
21872187
if self.instr_mod(pc).is_none() {
2188-
Ok((false, pc))
2188+
Ok(PcResult::NotInArchive { pc })
21892189
} else {
2190-
Ok((true, pc))
2190+
Ok(PcResult::InArchive)
21912191
}
21922192
}
21932193

@@ -6450,6 +6450,16 @@ pub enum HubrisValidate {
64506450
Booted,
64516451
}
64526452

6453+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6454+
pub enum PcResult {
6455+
/// The program counter is within the range of instruction addresses
6456+
/// defined by this archive
6457+
InArchive,
6458+
/// The program counter is NOT within the range of instruction addresses
6459+
/// defined by this archive, and is instead at the given address
6460+
NotInArchive { pc: u32 },
6461+
}
6462+
64536463
//
64546464
// We want to track our external regions because we want to be able to identify
64556465
// them, but this requires us knowing what addresses our external regions map

humility-flash/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use humility::{
99
core::Core,
10-
hubris::HubrisArchive,
10+
hubris::{HubrisArchive, PcResult},
1111
log::{Logger, info, warn},
1212
};
1313
use humility_auxflash::{AuxFlashHandler, AuxFlashWriter};
@@ -104,7 +104,8 @@ pub fn get_image_state(
104104
) -> Result<ImageStateResult, ImageStateError> {
105105
core.halt().map_err(ImageStateError::HaltFailed)?;
106106

107-
if let Ok((false, pc)) = hubris.is_pc_within_archive(core) {
107+
if let Ok(PcResult::NotInArchive { pc }) = hubris.is_pc_within_archive(core)
108+
{
108109
warn!(
109110
log,
110111
"PC at 0x{pc:x} is not part of any module. Maybe you're \

0 commit comments

Comments
 (0)