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

fix rom_table_lookup #20

Merged
merged 2 commits into from
Feb 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions rp2040-hal/src/rom_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ type RomTableLookupFn<T> = unsafe extern "C" fn(*const u16, u32) -> T;
const ROM_TABLE_LOOKUP_PTR: *const u16 = 0x18 as _;

/// Pointer to helper functions lookup table.
const FUNC_TABLE: *const *const u16 = 0x14 as _;
const FUNC_TABLE: *const u16 = 0x14 as _;

/// Pointer to the public data lookup table.
const DATA_TABLE: *const *const u16 = 0x16 as _;
const DATA_TABLE: *const u16 = 0x16 as _;

/// Retrive rom content from a table using a code.
fn rom_table_lookup<T>(table: *const *const u16, tag: RomFnTableCode) -> T {
fn rom_table_lookup<T>(table: *const u16, tag: RomFnTableCode) -> T {
unsafe {
let rom_table_lookup: RomTableLookupFn<T> = core::mem::transmute(ROM_TABLE_LOOKUP_PTR);
rom_table_lookup(*table, u16::from_le_bytes(tag) as u32)
let rom_table_lookup_ptr: *const u32 = rom_hword_as_ptr(ROM_TABLE_LOOKUP_PTR);
let rom_table_lookup: RomTableLookupFn<T> = core::mem::transmute(rom_table_lookup_ptr);
rom_table_lookup(rom_hword_as_ptr(table) as *const u16, u16::from_le_bytes(tag) as u32)
}
}

unsafe fn rom_hword_as_ptr(rom_address: *const u16) -> *const u32 {
let ptr: u16 = *rom_address;
ptr as *const u32
}

macro_rules! rom_funcs {
(
$(
Expand Down Expand Up @@ -138,9 +144,9 @@ pub fn copyright_string() -> &'static str {
}

/// The 8 most significant hex digits of the Bootrom git revision.
pub fn git_revision() -> &'static str {
let s: *const u8 = rom_table_lookup(DATA_TABLE, *b"GR");
unsafe { convert_str(s) }
pub fn git_revision() -> u32 {
let s: *const u32 = rom_table_lookup(DATA_TABLE, *b"GR");
unsafe { *s }
}

/// The start address of the floating point library code and data. This and fplib_end along with the individual
Expand Down