Skip to content

Commit

Permalink
Remove code bloat in public SDK for 64K roms
Browse files Browse the repository at this point in the history
  • Loading branch information
kilograham committed Nov 4, 2024
1 parent 3708588 commit 432192e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
5 changes: 5 additions & 0 deletions src/rp2_common/pico_bootrom/bootrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ void *rom_data_lookup(uint32_t code) {
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(BOOTROM_TABLE_LOOKUP_OFFSET);
uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(BOOTROM_DATA_TABLE_OFFSET);
return rom_table_lookup(data_table, code);
#else
#ifdef __riscv
uint32_t rom_offset_adjust = rom_size_is_64k() ? 32 * 1024 : 0;
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET + rom_offset_adjust);
#else
rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) (uintptr_t)*(uint16_t*)(BOOTROM_TABLE_LOOKUP_OFFSET);
#endif
return rom_table_lookup(code, RT_FLAG_DATA);
#endif
}
Expand Down
27 changes: 1 addition & 26 deletions src/rp2_common/pico_bootrom/include/pico/bootrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,32 +174,7 @@ __force_inline static void *rom_hword_as_ptr(uint16_t rom_address) {
#ifdef __riscv
static __force_inline bool rom_size_is_64k(void) {
#ifdef RASPBERRYPI_AMETHYST_FPGA
// Detect ROM size by testing for bus fault at +32k
uint result;
pico_default_asm_volatile (
"li %0, 0\n"
// Save and disable IRQs before touching trap vector
"csrr t2, mstatus\n"
"csrci mstatus, 0x8\n"
// Set up trap vector to skip the instruction which sets the %0 flag
"la t0, 1f\n"
"csrrw t0, mtvec, t0\n"
// This load will fault if the bootrom is no larger than 32k:
"li t1, 32 * 1024\n"
"lw t1, (t1)\n"
// No fault, so set return to true
"li %0, 1\n"
".p2align 2\n"
// Always end up back here, restore the trap table
"1:\n"
"csrw mtvec, t0\n"
// Now safe to restore interrupts
"csrw mstatus, t2\n"
: "=r" (result)
:
: "t0", "t1", "t2"
);
return result;
return *(uint16_t*)0x14 >= 0x8000;
#else
return false;
#endif
Expand Down

0 comments on commit 432192e

Please sign in to comment.