我正在尝试开始编写一些Sparc程序集,但我无法弄清楚如何组装和运行代码.我用arcTools编写了弧形,但就我已经用装配而言.我已下载了simics和qemu,但我不知道从哪里开始.谁能指出我正确的方向?谢谢.
您没有说明您使用的操作系统.对于这个例子,我假设你有linux并且想要编写简单的独立sparc代码(用于教育目的).你将需要binutils
和gdb
编译sparc和qemu-sparc
.将此小样本代码保存为test.s
:
.globl _start
_start:
mov %o0, %g0
1:
inc %o0
cmp %o0, 100
bl 1b
nop
b .
nop
Run Code Online (Sandbox Code Playgroud)
使用as
组装和ld
链接,如下所示:
$ sparc-linux-as -g -o test.o test.s
$ sparc-linux-ld -g -o test test.o
Run Code Online (Sandbox Code Playgroud)
应该产生二进制文件test
:
$ file test
test: ELF 32-bit MSB executable, SPARC, version 1 (SYSV), statically linked, not stripped
Run Code Online (Sandbox Code Playgroud)
现在开始qemu-sparc
设置gdb
远程调试(选择一个你选择的端口,我使用1234):
$ qemu-sparc -g 1234 test
Run Code Online (Sandbox Code Playgroud)
它会等待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)
Run Code Online (Sandbox Code Playgroud)
附加到qemu
实例:
(gdb) target remote :1234
Remote debugging using :1234
_start () at test.s:3
3 mov %o0, %g0
Run Code Online (Sandbox Code Playgroud)
从这里开始,您可以gdb
像往常一样执行代码,检查寄存器和内存.