Squashed 'third_party/pico-sdk/' content from commit 2062372d2

Change-Id: Ic20f199d3ed0ea8d3a6a1bbf513f875ec7500cc6
git-subtree-dir: third_party/pico-sdk
git-subtree-split: 2062372d203b372849d573f252cf7c6dc2800c0a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/src/rp2_common/pico_bootrom/bootrom.c b/src/rp2_common/pico_bootrom/bootrom.c
new file mode 100644
index 0000000..af7d091
--- /dev/null
+++ b/src/rp2_common/pico_bootrom/bootrom.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "pico/bootrom.h"
+
+/// \tag::table_lookup[]
+
+// Bootrom function: rom_table_lookup
+// Returns the 32 bit pointer into the ROM if found or NULL otherwise.
+typedef void *(*rom_table_lookup_fn)(uint16_t *table, uint32_t code);
+
+// Convert a 16 bit pointer stored at the given rom address into a 32 bit pointer
+#define rom_hword_as_ptr(rom_address) (void *)(uintptr_t)(*(uint16_t *)rom_address)
+
+void *rom_func_lookup(uint32_t code) {
+    return rom_func_lookup_inline(code);
+}
+
+void *rom_data_lookup(uint32_t code) {
+    rom_table_lookup_fn rom_table_lookup = (rom_table_lookup_fn) rom_hword_as_ptr(0x18);
+    uint16_t *data_table = (uint16_t *) rom_hword_as_ptr(0x16);
+    return rom_table_lookup(data_table, code);
+}
+/// \end::table_lookup[]
+
+bool rom_funcs_lookup(uint32_t *table, unsigned int count) {
+    bool ok = true;
+    for (unsigned int i = 0; i < count; i++) {
+        table[i] = (uintptr_t) rom_func_lookup(table[i]);
+        if (!table[i]) ok = false;
+    }
+    return ok;
+}