diff --git a/src/cortexm.rs b/src/cortexm.rs index 2cb2d51..8d27c11 100644 --- a/src/cortexm.rs +++ b/src/cortexm.rs @@ -46,8 +46,10 @@ pub fn subroutine_eq(addr1: u32, addr2: u32) -> bool { /// The contents of the vector table #[derive(Debug)] pub struct VectorTable { - // entry 0 + // entry 0: Initial SP pub initial_stack_pointer: u32, + // entry 1: Reset vector + pub reset: u32, // entry 3: HardFault handler pub hard_fault: u32, } diff --git a/src/elf.rs b/src/elf.rs index 10c1452..595236f 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -27,11 +27,7 @@ pub struct Elf<'file> { } impl<'file> Elf<'file> { - pub fn parse( - elf_bytes: &'file [u8], - elf_path: &'file Path, - reset_fn_address: u32, - ) -> Result { + pub fn parse(elf_bytes: &'file [u8], elf_path: &'file Path) -> Result { let elf = ObjectFile::parse(elf_bytes)?; let live_functions = extract_live_functions(&elf)?; @@ -42,7 +38,7 @@ impl<'file> Elf<'file> { let debug_frame = extract_debug_frame(&elf)?; - let symbols = extract_symbols(&elf, reset_fn_address)?; + let symbols = extract_symbols(&elf, vector_table.reset)?; Ok(Self { elf, @@ -149,11 +145,12 @@ fn extract_vector_table(elf: &ObjectFile) -> anyhow::Result any core.reset_and_halt(TIMEOUT)?; // gather information - let (stack_start, reset_fn_address) = analyze_vector_table(core)?; let elf_bytes = fs::read(elf_path)?; - let elf = &Elf::parse(&elf_bytes, elf_path, reset_fn_address)?; - let target_info = TargetInfo::new(elf, memory_map, probe_target, stack_start)?; + let elf = &Elf::parse(&elf_bytes, elf_path)?; + let target_info = TargetInfo::new(elf, memory_map, probe_target)?; // install stack canary let canary = Canary::install(core, &target_info, elf, opts.measure_stack)?; @@ -197,17 +196,6 @@ fn flashing_progress() -> flashing::FlashProgress { }) } -/// Read stack-pointer and reset-handler-address from the vector table. -/// -/// Assumes that the target was reset-halted. -/// -/// Returns `(stack_start: u32, reset_fn_address: u32)` -fn analyze_vector_table(core: &mut Core) -> anyhow::Result<(u32, u32)> { - let mut ivt = [0; 2]; - core.read_32(0, &mut ivt[..])?; - Ok((ivt[0], ivt[1])) -} - fn start_program(core: &mut Core, elf: &Elf) -> anyhow::Result<()> { log::debug!("starting device"); diff --git a/src/target_info.rs b/src/target_info.rs index 9a00a12..a4d245e 100644 --- a/src/target_info.rs +++ b/src/target_info.rs @@ -33,7 +33,6 @@ impl TargetInfo { elf: &Elf, memory_map: Vec, probe_target: probe_rs::Target, - stack_start: u32, ) -> anyhow::Result { let active_ram_region = extract_active_ram_region(&probe_target, elf.vector_table.initial_stack_pointer); @@ -46,7 +45,7 @@ impl TargetInfo { memory_map, probe_target, stack_info, - stack_start, + stack_start: elf.vector_table.initial_stack_pointer, }) } }