TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Raspberry Pi Pico: What is this code doing in its boot ROM, line 442?

217 pointsby nynyny7about 3 years ago

12 comments

nynyny7about 3 years ago
Okay. I have an idea. Let’s see what happens if we treat…<p><pre><code> 06: 00 B5 push {lr} </code></pre> … as the start of this weird code(?) sequence. It pushes the link register (i.e., the return address to the caller).<p><pre><code> 08: 42 40 eors r2, r0 0a: 00 2A cmp r2, #0 </code></pre> This XORs R2 and R0 and compares the result against zero. But that’s just a decoy, as we’ll see.<p><pre><code> 0c: 00 F0 02 F8 bl #0x14 </code></pre> This calls into…<p><pre><code> 14: 70 46 mov r0, lr 16: 00 47 bx r0 </code></pre> … which moves the return address to R0, and then returns. Using the addresses in this disassembly (not in the actual boot ROM), the return address is 0x10; but LR and, therefore, R0 will actually contain 0x11 because the LSB signifies Thumb mode.<p>None of the previous three instructions modifies the flags. (I checked in the ARM reference manual.) Thus, “BHS” (branch unsigned higher or same) uses the flags from the “CMP R2,#0” above. _Every_ value of R2 is higher (in the unsigned sense) or same as 0. Hence, the following branch is always taken:<p><pre><code> 10: F6 D2 bhs #0 </code></pre> … to…<p><pre><code> 00: 11 38 subs r0, #0x11 </code></pre> R0 contained 0x11 relative to the start of this code sequence. (The absolute address in boot ROM is of course different.) Now, R0 points to the start of the code sequence.<p><pre><code> 02: C0 7A ldrb r0, [r0, #0xb] </code></pre> This loads the byte at offset 0xB in this code sequence. Look above, it is 0x2A.<p><pre><code> 04: 00 BD pop {pc} </code></pre> This returns to the caller, using the LR pushed at the beginning. The return value in R0 is 0x2A.<p>0x2A is 42 (decimal)! Could this be an Easter egg; a very obfuscated way of returning 42, the Answer to the Ultimate Question of Life, the Universe, and Everything? (Remember that the Raspberry design team is from Britain, same as Douglas Adams.)
评论 #30981724 未加载
评论 #30971316 未加载
评论 #30971132 未加载
评论 #30971543 未加载
评论 #30971753 未加载
评论 #30971791 未加载
评论 #30971148 未加载
评论 #30971175 未加载
Retr0idabout 3 years ago
ARM thumb disassembly:<p><pre><code> 00: 11 38 subs r0, #0x11 02: C0 7A ldrb r0, [r0, #0xb] 04: 00 BD pop {pc} 06: 00 B5 push {lr} 08: 42 40 eors r2, r0 0a: 00 2A cmp r2, #0 0c: 00 F0 02 F8 bl #0x14 10: F6 D2 bhs #0 12: 8E 46 mov lr, r1 14: 70 46 mov r0, lr 16: 00 47 bx r0 </code></pre> Edit: I agree with the other commenters that this doesn&#x27;t really look like a valid disassembly, it is perhaps data rather than code.<p>Edit2: I take that back - it&#x27;s just very &quot;creatively&quot; written.
评论 #30970763 未加载
评论 #30970967 未加载
评论 #30970783 未加载
0x456about 3 years ago
Worthwhile reading on Easter Eggs<p>&quot;Why No Easter Eggs&quot;<p><a href="https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;archive&#x2F;blogs&#x2F;larryosterman&#x2F;why-no-easter-eggs" rel="nofollow">https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;archive&#x2F;blogs&#x2F;larryosterman...</a><p><a href="https:&#x2F;&#x2F;hn.algolia.com&#x2F;?query=Why%20no%20Easter%20Eggs" rel="nofollow">https:&#x2F;&#x2F;hn.algolia.com&#x2F;?query=Why%20no%20Easter%20Eggs</a><p>... and<p><a href="https:&#x2F;&#x2F;unix.stackexchange.com&#x2F;a&#x2F;405874" rel="nofollow">https:&#x2F;&#x2F;unix.stackexchange.com&#x2F;a&#x2F;405874</a><p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27994194" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27994194</a>
评论 #30972982 未加载
评论 #30972082 未加载
评论 #30972734 未加载
rahimialiabout 3 years ago
Direct link to the line in question:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;raspberrypi&#x2F;pico-bootrom&#x2F;blob&#x2F;ef22cd8ede5bc007f81d7f2416b48db90f313434&#x2F;bootrom&#x2F;bootrom_rt0.S#L442" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;raspberrypi&#x2F;pico-bootrom&#x2F;blob&#x2F;ef22cd8ede5...</a><p>(@dang, worth updating the link?)
kzrdudeabout 3 years ago
It kind of looks like zphd is the label of the end of those bytes, right? I mean, that they are referred to somewhere else by using that as an end pointer.
评论 #30970852 未加载
josuahabout 3 years ago
Crosslinking the two posts: <a href="https:&#x2F;&#x2F;github.com&#x2F;raspberrypi&#x2F;pico-bootrom&#x2F;issues&#x2F;17" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;raspberrypi&#x2F;pico-bootrom&#x2F;issues&#x2F;17</a>
mmastracabout 3 years ago
[deleted, thought it was possibly some pre-compiled code related to the trampoline but I don&#x27;t think so]<p>EDIT: I spoke too quickly, looking at the disassembly in the sibling comment.<p>EDIT 2: That disassembly looks like data, TBH.
评论 #30970683 未加载
peter_retiefabout 3 years ago
What happens if you remove it?
评论 #30975187 未加载
drpixieabout 3 years ago
Hmmm. Looks like 441 would be a great place for a helpful comment block.
throwaway81523about 3 years ago
Even if it&#x27;s not obfuscated, what is this decompilation doing in the pico source repo? Are they claiming that is the real source code that someone wrote?
评论 #30971204 未加载
nynyny7about 3 years ago
Lines 442-445, but apparently line numbers are stripped from GitHub URLs posted to HN: <a href="https:&#x2F;&#x2F;github.com&#x2F;raspberrypi&#x2F;pico-bootrom&#x2F;blob&#x2F;ef22cd8ede5bc007f81d7f2416b48db90f313434&#x2F;bootrom&#x2F;bootrom_rt0.S#L441-L445" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;raspberrypi&#x2F;pico-bootrom&#x2F;blob&#x2F;ef22cd8ede5...</a>
评论 #30970854 未加载
评论 #30971492 未加载
mannanjabout 3 years ago
NSA hidden code?
评论 #30971214 未加载