gpt4 book ai didi

assembly - 如何编写 Sparc 程序集并在 Qemu 或 Simics 中运行其二进制文件?

转载 作者:行者123 更新时间:2023-12-05 00:32:17 25 4
gpt4 key购买 nike

我正在尝试开始编写一些 Sparc 程序集,但我不知道如何组合和运行代码。我已经用 arcTools 编写了 arc,但这就是我对汇编程序的了解。我已经下载了simics和qemu,但我不知道从哪里开始。任何人都可以指出我正确的方向吗?谢谢。

最佳答案

你没有说你使用什么操作系统。
对于这个例子,我假设你有 linux 并且想要编写简单的独立 sparc 代码(用于教育目的)。
您将需要 binutilsgdb为 sparc 和 qemu-sparc 编译.
将此小示例代码另存为 test.s :

.globl _start
_start:
mov %o0, %g0
1:
inc %o0
cmp %o0, 100
bl 1b
nop
b .
nop

使用 as组装和 ld链接,如下:
$ sparc-linux-as -g -o test.o test.s
$ sparc-linux-ld -g -o test test.o

应该产生二进制 test :
$ file test
test: ELF 32-bit MSB executable, SPARC, version 1 (SYSV), statically linked, not stripped

现在开始 qemu-sparc设置为 gdb远程调试(选择您选择的端口,我使用 1234):
$ qemu-sparc -g 1234 test

它将等待 gdb连接。在另一个终端中,启动 gdb对于二进制:
$ sparc-linux-gdb test
GNU gdb (GDB) 7.3.50.20111117-cvs-debian
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=sparc-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /var/tmp/test...done.
(gdb)

附加到 qemu实例:
(gdb) target remote :1234
Remote debugging using :1234
_start () at test.s:3
3 mov %o0, %g0

从这里开始,您可以使用 gdb像往常一样执行你的代码,检查寄存器和内存。

关于assembly - 如何编写 Sparc 程序集并在 Qemu 或 Simics 中运行其二进制文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13706317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com