英文:
What is this arm assembly init code doing?
问题
这是某个 stm32f030 微控制器的下载固件的初始化代码的一部分。它是使用 radare2 反汇编的。
在时钟初始化后,但堆初始化之前,调用了以下代码:
0x0800335c 00f00bf8 bl fcn.08003376
0x08003360 0028 cmp r0, 0
0x08003362 01d0 beq 0x8003368
0x08003364 fff7d4ff bl INIT2
0x08003368 0020 movs r0, 0
[...]
0x08003376 0120 movs r0, 1
0x08003378 7047 bx lr
就我所知,r0 始终设置为 1,因此 INIT2 从不被跳过。我不明白它的目的。我漏掉了什么?
英文:
This is part of the init code of a downloaded firmware of some stm32f030 microcontroller. It was disassembled using radare2.
It is called after the clock has been initialized but before the heap is.
0x0800335c 00f00bf8 bl fcn.08003376
0x08003360 0028 cmp r0, 0
0x08003362 01d0 beq 0x8003368
0x08003364 fff7d4ff bl INIT2
0x08003368 0020 movs r0, 0
[...]
0x08003376 0120 movs r0, 1
0x08003378 7047 bx lr
As far as I can tell r0 gets always set to 1 so INIT2 is never skipped. I don't get the point. What am I missing?
答案1
得分: 3
我同意ElderBug在评论中的解释,第一个代码块来自一个支持多个构建的单元,而第二个函数来自一个已经配置为特定构建的单元。
除非您编辑问题以提供更多细节,否则我们只能猜测其目的,但这里有一个类似于我曾经处理过的代码的合理解释:
您希望在热启动时跳过INIT2中的堆初始化,其中RAM通过低功耗模式保留。 您所拥有的特定二进制文件不支持低功耗模式,因此其功能被硬编码为返回非零,但在另一个构建中,它可能会读取电源寄存器,并且如果RAM已保留,则可以返回零。
英文:
I agree with ElderBug's interpretation in the comments that the first block of code is from a unit that supports multiple builds, and the second function is from a unit that has been configured for a particular build.
Unless you edit the question to provide more detail, we can only guess at the purpose, but here is one plausible interpretation that is similar to code I have worked on:
You want to skip heap initialization in INIT2 on a warm-boot, where RAM has been retained through a low-power mode. The particular binary you have doesn't support low-power modes so its function is hard-coded to return non-zero, but in another build it might read the power registers and can return zero if the RAM was retained.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论