Austin Schuh | 208337d | 2022-01-01 14:29:11 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include "pico/bootrom.h" |
| 8 | |
| 9 | /// \tag::table_lookup[] |
| 10 | |
| 11 | // Bootrom function: rom_table_lookup |
| 12 | // Returns the 32 bit pointer into the ROM if found or NULL otherwise. |
| 13 | typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code); |
| 14 | |
| 15 | // Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer |
| 16 | #define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address) |
| 17 | |
| 18 | void *rom_func_lookup(uint32_t code) { |
| 19 | return rom_func_lookup_inline(code); |
| 20 | } |
| 21 | |
| 22 | void *rom_data_lookup(uint32_t code) { |
| 23 | rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(0x18); |
| 24 | uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(0x16); |
| 25 | return rom_table_lookup(data_table, code); |
| 26 | } |
| 27 | /// \end::table_lookup[] |
| 28 | |
| 29 | bool rom_funcs_lookup(uint32_t *table, unsigned int count) { |
| 30 | bool ok = true; |
| 31 | for (unsigned int i = 0; i < count; i++) { |
| 32 | table[i] = (uintptr_t) rom_func_lookup(table[i]); |
| 33 | if (!table[i]) ok = false; |
| 34 | } |
| 35 | return ok; |
| 36 | } |