diff --git a/src/rp2_common/pico_bootrom/bootrom.c b/src/rp2_common/pico_bootrom/bootrom.c index 84fbffd06..ff6e82bb4 100644 --- a/src/rp2_common/pico_bootrom/bootrom.c +++ b/src/rp2_common/pico_bootrom/bootrom.c @@ -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 } diff --git a/src/rp2_common/pico_bootrom/include/pico/bootrom.h b/src/rp2_common/pico_bootrom/include/pico/bootrom.h index 05bf1aa2f..180a4e54c 100644 --- a/src/rp2_common/pico_bootrom/include/pico/bootrom.h +++ b/src/rp2_common/pico_bootrom/include/pico/bootrom.h @@ -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