Skip to content

Commit ae0b866

Browse files
committed
Use constants for the addresses.
1 parent 0708270 commit ae0b866

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ use self::algo::*;
1010
fn find_func<T>(tag: [u8; 2]) -> T {
1111
let tag = u16::from_le_bytes(tag) as u32;
1212
type RomTableLookupFn = unsafe extern "C" fn(table: *const u16, code: u32) -> usize;
13+
/// This location in flash holds a 16-bit truncated pointer for the ROM lookup function
14+
const ROM_TABLE_LOOKUP_PTR: *const u16 = 0x0000_0018 as _;
15+
/// This location in flash holds a 16-bit truncated pointer for the ROM function table
16+
/// (there's also a ROM data table which we don't need)
17+
const FUNC_TABLE: *const u16 = 0x0000_0014 as _;
1318
unsafe {
14-
let lookup_func = core::ptr::read(0x0000_0018 as *const u16) as usize;
19+
let lookup_func = ROM_TABLE_LOOKUP_PTR.read() as usize;
1520
let lookup_func: RomTableLookupFn = core::mem::transmute(lookup_func);
16-
let table = core::ptr::read(0x0000_00014 as *const u16) as usize;
21+
let table = FUNC_TABLE.read() as usize;
1722
let result = lookup_func(table as *const u16, tag);
1823
if result == 0 {
1924
panic!("Function not found");

0 commit comments

Comments
 (0)