blob: 5def61a09c6039112ccd34944a1f056b7fd098a8 [file] [log] [blame]
Austin Schuh208337d2022-01-01 14:29:11 -08001/*
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.
13typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code);
14
Austin Schuh208337d2022-01-01 14:29:11 -080015void *rom_func_lookup(uint32_t code) {
16 return rom_func_lookup_inline(code);
17}
18
19void *rom_data_lookup(uint32_t code) {
20 rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(0x18);
21 uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(0x16);
22 return rom_table_lookup(data_table, code);
23}
24/// \end::table_lookup[]
25
26bool rom_funcs_lookup(uint32_t *table, unsigned int count) {
27 bool ok = true;
28 for (unsigned int i = 0; i < count; i++) {
29 table[i] = (uintptr_t) rom_func_lookup(table[i]);
30 if (!table[i]) ok = false;
31 }
32 return ok;
33}