QEMU 适合学习 ARM 和 PowerPC 的汇编程序编程吗?
我想学习 PowerPC 和 ARM 的汇编程序编程,但我无法为此目的购买真正的硬件。我正在考虑使用 QEMU 来实现这一点。但是我不确定它是否足够好地模拟这两种架构,我是否会在本机汇编器中编译并运行我的程序?
I want to learn programming in assembler for PowerPC and ARM, but I'm unable to buy real hardware for this purpose. I'm thinking about using QEMU for that. However I'm not sure if it emulates both architectures enough well, that I'll compile and run my programs in native assembler on it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
QEMU 可以很好地测试程序校正(即代码是否可以在实际的 ARM 或 PowerPC 上正确运行),但它不适合测试程序效率:仿真不是周期准确,并且使用 QEMU 测量的速度无法可靠(甚至不可靠)地与真实硬件上的速度相关。
此外,QEMU 不会捕获未对齐的内存访问,这对于 PowerPC 仿真来说不是问题(PowerPC 容忍未对齐的访问),但对于 ARM 来说可能是问题(未对齐的访问,例如从 RAM 中不存在的地址读取 32 位字)。 4 的倍数,可以与 QEMU 一起正常工作,但会在真正的 ARM 处理器上触发异常)。
除了这些点之外,QEMU 非常适合 ARM 或 MIPS 上的汇编开发(还没有尝试过 PowerPC,因为我在 eBay 上找到了一本旧的 iBook);但我已经使用 QEMU 完成了 ARM 和 MIPS 汇编,然后在真正的硬件,并且这有效)。您可以模拟整个系统并在其中运行 Debian(在这种情况下,编译器、链接器、文本编辑器...也将在模拟中运行),或者使用运行 ARM/MIPS 可执行文件的“用户模式模拟”直接使用包装器将系统调用转换为主机 PC 的系统调用(假设主机是运行 Linux 的 PC)。后者更方便(您可以访问正常的主目录,编程工具是本机的......),但需要安装交叉开发工具。请参阅 buildroot (并与
-static
链接,这将避免许多麻烦)。QEMU works well for testing program correction (i.e. whether the code would properly run on an actual ARM or PowerPC) but it is not good for testing program efficiency: the emulation is not cycle accurate, and speed measured with QEMU cannot be reliably (or even unreliably) correlated with speed on true hardware.
Also, QEMU will not trap unaligned memory accesses, which is not a problem for PowerPC emulation (the PowerPC tolerates unaligned accesses) but may be for ARM (an unaligned access, e.g. reading a 32-bit word in RAM from an address which is not a multiple of 4, will work fine with QEMU but would trigger an exception on a true ARM processor).
Apart from these points, QEMU is fine for assembly development on ARM or MIPS (haven't tried PowerPC, because I found an old iBook on eBay for that; but I have done ARM and MIPS assembly with QEMU and then ran the resulting code on true hardware, and this worked). You can either emulate a whole system and run Debian in it (in which case the compiler, linker, text editor... will also run in emulation), or use the "user-mode emulation" where the ARM/MIPS executable is run directly, with a wrapper which converts system calls into those for the host PC (this assumes that the host is a PC running Linux). The latter is more convenient (you have access to your normal home directory, programming tools are native...) but requires installing cross-development tools. See buildroot for that (and link with
-static
, this will avoid many headaches).因为我发现 Debian 适用于 PowerPC 和 ARM 可以在 QEMU 上运行,我想这不会是问题。
Since I have found signs that Debian for PowerPC and for ARM can run on QEMU, I suppose this won't be a problem.