简体   繁体   English

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

[英]How to write Sparc assembly and run its binary in Qemu or Simics?

I am trying to start writing some Sparc assembly, but I can't figure out how to assemble and run the code. 我试图开始编写一些Sparc程序集,但我不知道如何组装和运行代码。 I have written arc with arcTools, but that's as far as I have gone with assembly. 我已经用arcTools编写了arc,但是就组装而言,这是我的努力。 I have downloaded both simics and qemu, but I don't know where to go from here. 我已经下载了simics和qemu,但是我不知道从这里去哪里。 Can anyone point me in the right direction? 谁能指出我正确的方向? Thanks. 谢谢。

You didn't say what operating system(s) you use. 您没有说要使用什么操作系统。 For this example, I will assume you have linux and want to write simple standalone sparc code (for educational purposes). 对于此示例,我假设您有linux并想编写简单的独立sparc代码(出于教育目的)。 You will need binutils and gdb compiled for sparc and qemu-sparc . 您将需要为sparc和qemu-sparc编译binutilsgdb Save this small sample code as test.s : 将这个小的示例代码保存为test.s

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

Use as to assemble and ld to link, as follows: 使用as汇编和ld链接,如下所示:

$ sparc-linux-as -g -o test.o test.s
$ sparc-linux-ld -g -o test test.o

Should produce the binary test : 应该产生二进制test

$ file test
test: ELF 32-bit MSB executable, SPARC, version 1 (SYSV), statically linked, not stripped

Now start qemu-sparc set up for gdb remote debugging (pick a port of your choice, I used 1234): 现在开始为gdb远程调试启动qemu-sparc设置(选择您选择的端口,我使用了1234):

$ qemu-sparc -g 1234 test

It will wait for gdb to connect. 它将等待gdb连接。 In another terminal, start gdb for the binary: 在另一个终端中,启动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)

Attach to the qemu instance: 附加到qemu实例:

(gdb) target remote :1234
Remote debugging using :1234
_start () at test.s:3
3           mov %o0, %g0

From here on, you can use gdb as usual to execute your code, examine registers and memory. 从这里开始,您可以照常使用gdb执行代码,检查寄存器和内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM