4

我正在尝试开始编写一些 Sparc 程序集,但我不知道如何组装和运行代码。我已经用 arcTools 编写了 arc,但这就是我在组装方面所做的。我已经下载了simics和qemu,但我不知道从哪里开始。谁能指出我正确的方向?谢谢。

4

1 回答 1

6

你没有说你使用什么操作系统。对于这个例子,我假设你有 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照常使用来执行代码、检查寄存器和内存。

于 2012-12-04T18:43:53.400 回答