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

Assembly 如何在Qemu或Simics中编写Sparc程序集并运行其二进制文件?,assembly,qemu,sparc,simics,Assembly,Qemu,Sparc,Simics,我正试图开始编写一些Sparc程序集,但我不知道如何组装和运行代码。我已经用arcTools编写了arc,但这只是我用assembly编写的。我已经下载了simics和qemu,但我不知道从这里可以走到哪里。谁能给我指出正确的方向吗?谢谢。您没有说您使用的是什么操作系统。 对于本例,我假设您有linux,并且希望编写简单的独立sparc代码(出于教育目的)。 您需要为sparc和qemu sparc编译binutils和gdb。 将此小样本代码另存为test.s: .globl _start _

我正试图开始编写一些Sparc程序集,但我不知道如何组装和运行代码。我已经用arcTools编写了arc,但这只是我用assembly编写的。我已经下载了simics和qemu,但我不知道从这里可以走到哪里。谁能给我指出正确的方向吗?谢谢。

您没有说您使用的是什么操作系统。 对于本例,我假设您有linux,并且希望编写简单的独立sparc代码(出于教育目的)。 您需要为sparc和qemu sparc编译
binutils
gdb
。 将此小样本代码另存为
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
应生成二进制
测试

$ file test
test: ELF 32-bit MSB executable, SPARC, version 1 (SYSV), statically linked, not stripped
现在开始
qemu-sparc
gdb
远程调试设置(选择您选择的端口,我使用了1234):

它将等待
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)

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

您是在SPARC上运行本机还是从其他体系结构交叉组装?
$ 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)
(gdb) target remote :1234
Remote debugging using :1234
_start () at test.s:3
3           mov %o0, %g0