ARM Linux:为什么linux期望寄存器r0设置为零

发布于 2024-12-10 03:37:06 字数 404 浏览 0 评论 0原文

ARM Linux 启动手册说寄存器 r0 应该为零。为什么寄存器r0应该是zer0?

http://www.arm.linux.org.uk/developer/booting.php

CPU register settings
    r0 = 0.
    r1 = machine type number discovered in (3) above.
    r2 = physical address of tagged list in system RAM. 

我浏览了 arch/arm/kernel/head.S 但找不到原因。

ARM Linux booting manual says that the register r0 should be zero. Why should the register r0 be zer0?

http://www.arm.linux.org.uk/developer/booting.php

CPU register settings
    r0 = 0.
    r1 = machine type number discovered in (3) above.
    r2 = physical address of tagged list in system RAM. 

I browsed through the arch/arm/kernel/head.S but could not find the reason for that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

止于盛夏 2024-12-17 03:37:06

尽管我在 Linux 内核邮件列表或 Linux 源中找不到任何参考资料来证实这一点,但我推测该值正被用作 ABI 版本,以保证 ABI 的未来发展。

内核的未来版本可能希望修改从引导加载程序传入的参数:也许某些新的 CPU 功能需要一个新参数,或者需要稍微调整现有参数之一。

当从旧的引导加载程序引导新内核时,这会带来一个严重的问题:内核如何知道传入的参数是什么?我们可以尝试强制新内核只能使用新的引导加载程序来引导,但这会在过渡期间引起相当多的麻烦。 (引导加载程序是由 Linux 内核团队之外的人员编写的;并且经常会深入硬件,从而在某些情况下阻止它们轻松升级。)

更好的解决方案是保留寄存器 r0为 ABI 版本。目前,我们坚持 r0 始终为 0。如果 ABI 发生变化,r0 可以增加 1。然后,未来的内核可以检查 r0 以确定它正在启动的 ABI 版本,以及如何解释其他寄存器中的值。

Though I can't find any references in the Linux kernel mailing lists or the Linux sources confirming this, I would speculate that the value is being used as an ABI version for future-proofing the ABI.

Future versions of the kernel may wish to modify what arguments are passed in from the boot-loader: perhaps a new argument is needed for some new CPU feature, or one of the existing arguments needs to be slightly tweaked.

This presents a serious problem when a new kernel is booted from an older boot-loader: how does the kernel know what arguments are being passed in? We could try and enforce that new kernels are only ever booted with new boot-loaders, but this would cause quite a few head-aches during the transition period. (Boot-loaders are written by people outside the Linux kernel team; and are also frequently flashed deep into hardware, preventing them from being easily upgraded in some circumstances.)

A better solution is to reserve the register r0 to be the ABI version. For now, we insist that r0 is always 0. If the ABI ever changes, r0 can be bumped up by one. Future kernels could then inspect r0 to determine what version ABI it is being booted with, and hence how to interpret the values in the other registers.

燕归巢 2024-12-17 03:37:06

一致性和效率。由于将寄存器设置为零是常见操作,并且 ARM 通常在受限环境中使用,因此代码密度可能会有所提高。将寄存器设置为立即值的指令编码比将寄存器设置为另一个寄存器的值的指令编码长。这在实践中是否会产生很大的影响是另一个问题。

Consistency and efficiency. Since setting a register to zero is a common operation, and ARM is typically used in constrained environments, there may be an improvement in code density. The instruction encoding for setting a register to an immediate value is longer than setting a register to the value of another register. Whether this makes much of a difference in practice is another question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文