简体   繁体   English

用qemu运行二进制文件

[英]Running binary file with qemu

I am learning arm assembly language in my one course. 我在一门课程中正在学习手臂汇编语言。 I am having little problem in getting started. 我入门没有什么问题。 I have written a simple c code: 我写了一个简单的C代码:

int main()
{
    int a = 10;
    int b = 20;
    int c = a+b;
}

And then I converted it to assembly code using gnu arm by giving the command: 然后通过使用以下命令,使用gnu arm将其转换为汇编代码:

arm-elf-gcc -S first.c

This generated a file first.s containing assembly code: 这首先生成一个包含汇编代码的文件:

    .file   "first.c"
    .text
    .align  2
    .global main
    .type   main, %function
main:
    @ args = 0, pretend = 0, frame = 12
    @ frame_needed = 1, uses_anonymous_args = 0
    mov ip, sp
    stmfd   sp!, {fp, ip, lr, pc}
    sub fp, ip, #4
    sub sp, sp, #12
    mov r3, #10
    str r3, [fp, #-16]
    mov r3, #20
    str r3, [fp, #-20]
    ldr r2, [fp, #-16]
    ldr r3, [fp, #-20]
    add r3, r2, r3
    str r3, [fp, #-24]
    mov r0, r3
    sub sp, fp, #12
    ldmfd   sp, {fp, sp, pc}
    .size   main, .-main
    .ident  "GCC: (GNU) 3.4.3"

Then I compiled the assembly code using following command: 然后,我使用以下命令编译了汇编代码:

arm-elf-gcc -g first.s

This generated a.out binary file. 这将生成一个.out二进制文件。 Then I tried to run a.out with qemu using command: 然后我尝试使用命令使用qemu运行a.out:

qemu-arm a.out

But this generates output 但这会产生输出

Segmentation fault

I can't find the mistake, what am I doing wrong? 我找不到错误,我在做什么错?

You are trying to run qemu in user mode. 您正在尝试在用户模式下运行qemu。 You also need to link the libraries which corresponds to arm. 您还需要链接与arm对应的库。

take a look at the script files in below pkg. 看看pkg下面的脚本文件。

http://wiki.qemu.org/download/linux-user-test-0.3.tar.gz http://wiki.qemu.org/download/linux-user-test-0.3.tar.gz

You will need to run qemu -L library_PATH_ARM ./a.out 您将需要运行qemu -L library_PATH_ARM ./a.out

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

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