qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generate an LSB binary from my MSB binary (arm32)


From: Peter Maydell
Subject: Re: Generate an LSB binary from my MSB binary (arm32)
Date: Sun, 13 Feb 2022 20:39:17 +0000

On Sun, 13 Feb 2022 at 18:24, Frederick Virchanza Gotham
<cauldwell.thomas@gmail.com> wrote:
> I have written a program called 'Dynamo', and I have built it as a 32-Bit Big 
> Endian ARM executable binary. (The architecture codename for 32-Bit Big 
> Endian ARM is "armeb").
>
> When I run this 'armeb' binary on my x86_64 desktop PC, of course qemu 
> interprets the ARM machine code, converts it to x86_64 machine code and then 
> runs it on my x86_64 CPU.
>
> However if I were to run my 'armeb' program inside qemu running on a 32-Bit 
> Little Endian ARM computer, such as the Raspberry Pi, then the only 
> processing that qemu would have to do is:
> (1) At the very beginning of my program, execute the CPU instruction "setend 
> be" to switch the CPU to big endian for the current process.
> (2) Reverse bytes when my program interacts with the kernel (i.e. reverse the 
> bytes in the general purpose registers before and after each 'syscall' CPU 
> instruction).

This isn't the way QEMU works, I'm afraid. We don't make any
kind of optimizations or changes if the host and guest architectures
happen to be the same or similar. The process is always the same:
 * guest instructions are decoded
 * we generate an "intermediate representation" (TCG ops)
 * we do some optimizations on that intermediate representation
 * we generate instructions for the host

> Is it possible to get qemu to generate an LSB binary from a
> statically-linked MSB binary something like as follows?
>  qemu-convert-armeb-to-arm --input-file=dynamo_big --output-file=dynamo_little

The answer here is also 'no'. QEMU is a *runtime* translator
which dynamically does just-in-time emulation of executed
instructions. It doesn't do static conversion of a binary
to the host architecture (which is in general very tricky to
do correctly, given that the binary being run might for instance
have self-modifying code of various forms).

If you have the source code for this program, the simple thing
to do just to build it for the right endianness to match your
host in the first place :-)

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]