March 6, 2026

Adventures with memcpy and the RP2040 - Datasheet

We have a 636 page datasheet on the RP2040. Pages 130-152 are devoted to the bootrom.

This section mentions "fast memory fill/copy routines".

Table 163 details some items in fixed locations at the start of the ROM, in particular offset 0x14 has a 16 bit pointer that is a "public function" lookup table (rom_func_table). It tells us that these are highly optimized functions that would otherwise take up space in user binaries.

You should ensure that the 3 bytes at address 0x10 are 'M', 'U', 0x01 then you can rely on the pointers at offset 0x14.

The source

The datasheet gives only some of the details. For the rest, you need to look at the source code. In particular, the file bootrom_rt0.S

The table itself has a 2 byte "tag", followed by a halfword pointer to the function in the ROM. In particular, _memcpy has the tag 'M', 'C'.
The table looks like this:

function_table:
.byte 'M', 'S'
.hword __memset + 1
.byte 'S', '4'
.hword __memset_4 + 1
.byte 'M', 'C'
.hword __memcpy + 1
.byte 'C', '4'
.hword __memcpy_44 + 1
# end of function table marker
.hword 0
Offset 0x18 in the ROM is a halfword pointer to a "helper function" called rom_table_lookup() -- you could call this function with a 2 byte code (such as "MC") and let it return the halfword pointer to the rom function for you. This is clearly the intent.

But that is not what is going on in the code we are looking at that started this whole thing.


Have any comments? Questions? Drop me a line!

Tom's software pages / tom@mmto.org