Tuesday, April 24, 2012
2:51 PM

Executing arm executable in x86 using qemu

QEMU is an emulator capable of emulating a number of processors, enabling the code written for one architecture to run on another. It works in two modes

1. Use mode : In which only applications written for one architecture can be executed on another. For e.g. an application written for ARM can be executed on an x86 machine.

2. System mode: In which a complete Operating system compiled for an architecture can be run on another. For e.g. a kernel compiled for ARM can be booted on an X86 machine.

In this post we will see how to work with the user mode of the QEMU by executing an ARM executable on an x86 machine (any normal desktop or laptop are x86 systmes).
Before starting to work with QEMU we will have to install it, which can be done from the package manager.
In Debian based systems :



Or we can download the source from qemu and compile it from source. While compiling make sure that the target "ARM" and "x86" both are selected.

To confirm if the installation has happened properly, open a terminal and execute the command



To generate an arm executable we will also need the cross compiler for arm, which can be downloaded from "gnuarm" or compiled using the script in this post script to download and compile gnuarm

Now let us write a simple program in c, to print hello world:

hello.c



compile this using the arm cross compiler



To verify the file type of executable generated you can use the command file



Now try running the "hello" executable directly on the x86 system.



The error indicates that the executable is not supported by the architecture of the system.

Now let us try running the same using qemu



qemu-arm is able to execute the ARM executable successfully on x86 machine.
This enables us to write and test code of any architecture on usual x86 systems and then port only the final code on to the real system.


0 comments:

Post a Comment