Skip to content

Commit 57a4983

Browse files
committed
Move rom_data_lookup code into rom_data_lookup_inline
Allows ROM data lookup from FLASH/RAM sensitive code
1 parent f0a1ff3 commit 57a4983

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/rp2_common/pico_bootrom/bootrom.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,9 @@ void *rom_func_lookup(uint32_t code) {
1414
return rom_func_lookup_inline(code);
1515
}
1616

17-
#pragma GCC diagnostic push
18-
// diagnostic: GCC thinks near-zero value is a null pointer member access, but it's not
19-
#pragma GCC diagnostic ignored "-Warray-bounds"
2017
void *rom_data_lookup(uint32_t code) {
21-
#if PICO_RP2040
22-
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(BOOTROM_TABLE_LOOKUP_OFFSET);
23-
uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(BOOTROM_DATA_TABLE_OFFSET);
24-
return rom_table_lookup(data_table, code);
25-
#else
26-
#ifdef __riscv
27-
uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
28-
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET + rom_offset_adjust);
29-
#else
30-
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET);
31-
#endif
32-
return rom_table_lookup(code, RT_FLAG_DATA);
33-
#endif
18+
return rom_data_lookup_inline(code);
3419
}
35-
#pragma GCC diagnostic pop
3620
/// \end::table_lookup[]
3721

3822
bool rom_funcs_lookup(uint32_t *table, unsigned int count) {

src/rp2_common/pico_bootrom/include/pico/bootrom.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,32 @@ static __force_inline void *rom_func_lookup_inline(uint32_t code) {
215215
}
216216
#pragma GCC diagnostic pop
217217

218+
/*!
219+
* \brief Lookup a bootrom data address by its code. This method is forcibly inlined into the caller for FLASH/RAM sensitive code usage
220+
* \ingroup pico_bootrom
221+
* \param code the code
222+
* \return a pointer to the data, or NULL if the code does not match any bootrom data
223+
*/
224+
#pragma GCC diagnostic push
225+
// diagnostic: GCC thinks near-zero value is a null pointer member access, but it's not
226+
#pragma GCC diagnostic ignored "-Warray-bounds"
227+
static __force_inline void *rom_data_lookup_inline(uint32_t code) {
228+
#if PICO_RP2040
229+
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(BOOTROM_TABLE_LOOKUP_OFFSET);
230+
uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(BOOTROM_DATA_TABLE_OFFSET);
231+
return rom_table_lookup(data_table, code);
232+
#else
233+
#ifdef __riscv
234+
uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
235+
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET + rom_offset_adjust);
236+
#else
237+
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET);
238+
#endif
239+
return rom_table_lookup(code, RT_FLAG_DATA);
240+
#endif
241+
}
242+
#pragma GCC diagnostic pop
243+
218244
/*!
219245
* \brief Reboot the device into BOOTSEL mode
220246
* \ingroup pico_bootrom

0 commit comments

Comments
 (0)