The Register With No Name
The verdict is the AUIPC semantic from the unprivileged ISA: the 20-bit immediate with 12 zero bits appended is added to the address of the auipc instruction itself. The QEMU run confirmed it twice: the auipc at 0x800001d2 returned 0x800001d2, and the auipc with immediate 0x12345 at 0x800001f4 returned 0x923451f4, which is 0x800001f4 plus 0x12345000.
No claim depends on how any core implements the addition. The three values came from one run on QEMU's virt board, and the post asserts nothing about pipelines, caches, or timing.
The test runs on bare metal without calling any firmware service, and the verdict asserts nothing about firmware behavior. The auipc semantic is defined by the instruction itself, independent of privilege level.
The verdict concerns one user-level instruction and its register result. No trap, no system call, and no operating system data structure takes part in any of the three checks.
The claim is one instruction semantic checked against three observed register values, not a computation proved against an independent oracle. No invariant is proved beyond the observed output.
The program counter has no register number. RISC-V names 32 integer registers, x0 through x31, and the PC is not one of them: no instruction takes it as a source operand, and there is no mv t0, pc. The one instruction that looks at it does so sideways: [1]
auipc s0, 0 # s0 = the address of this very instruction
On the QEMU virt board that auipc sat at 0x800001d2, and it put 0x800001d2 into s0: its own address, read off the UART. The mechanism is one addition. auipc takes the 20-bit immediate, appends 12 zero bits, and adds the result to the address of the auipc instruction itself. With an immediate of zero the offset is zero, so the PC comes back unchanged. [1]
With auipc s0, 0x12345 sitting at 0x800001f4, the UART printed 0x923451f4, and 0x800001f4 + 0x12345000 = 0x923451f4 exactly. The immediate is the upper 20 bits; the low 12 are always zero. [1]
This is how code that does not know where it was loaded still reaches its own data. The pair auipc t0, %pcrel_hi(table) / ld t1, %pcrel_lo(1b)(t0) adds the link-time distance from the auipc to the symbol onto the live PC. In the test it fetched the constant 0x123456789abcdef0 through that pair, and the same two instructions work wherever the image lands, because the distance never changes and the PC is always true. [1]
Diagram: hand-built by Chris Dillinger for this post
The bench habit: when a bare-metal image misbehaves after moving to a new load address, the first suspect is an absolute address baked in somewhere. PC-relative access through auipc has no absolute address to go stale, which is why the toolchain reaches for it whenever code must address data without knowing where it will live.
Sources
- 01src/auipc-pcread: auipc PC-read checks, plus the firsthand runChris Dillinger
Three checks built from src/boot.S and src/uart.c, run on QEMU 8.2.2 with the image at 0x80000000: auipc s0,0 at 0x800001d2 printed 0x800001d2; auipc s0,0x12345 at 0x800001f4 printed 0x923451f4, equal to 0x800001f4 plus 0x12345000; the auipc t0,%pcrel_hi(marker) and ld s0,%pcrel_lo(1b)(t0) pair loaded 0x123456789abcdef0 from marker at 0x80000350. The AUIPC semantic (20-bit immediate, 12 zero bits appended, added to the address of the auipc itself) follows the RISC-V User-Level ISA description of AUIPC.