Remove code bloat in public SDK for 64K roms (#2016)

This commit is contained in:
Graham Sanderson 2024-11-05 10:57:22 -06:00 committed by GitHub
parent 8905de509f
commit bd130eddff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 26 deletions

View file

@ -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
}

View file

@ -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