Skip to contentSkip to conversation

Binary translation (of code)

Qemu-devel Tarmo Pikaro 5 participants 8 messages May 7, 2011 – May 8, 2011

lore
Share & tools
lore
#0 lore raw

Hi !

I've analyzed quite a lot of emulators source code, including qemu as well.

But I somehow would like to completely get rid of emulators, and simply convert application from one cpu/board to another cpu/board.

On wiki pages this is called "binary translation".

- Do you know some open source code projects related to binary translation ?

I'm searching for enthusiasts / gurus who want / could be involved in this excersise as well.

My intrest also goes beoynd one windows - linux - I would like to binary translate also
older console games - like nintendo/super nintendo rom (directly to .exe).

I was thinking about starting from qemu and cracking it into correct direction -

has anyone ever tried to:

- put qemu in visual studio (or other ide where it can be debugged)
- cross compiled qemu with cygwin ?
 --
Have a nice day!
Tarmo.

#1 lore raw

Hi...

Quoted 10 lines · Tarmo Pikaro

Hi !

I've analyzed quite a lot of emulators source code, including qemu as well.

But I somehow would like to completely get rid of emulators, and simply convert application from one cpu/board to another cpu/board.

On wiki pages this is called "binary translation".

- Do you know some open source code projects related to binary translation ?

Well, you end up in that kind of project, which is Qemu :) specifically the TCG (Tiny Code Generator) part....

Quoted 3 lines

has anyone ever tried to:

- put qemu in visual studio (or other ide where it can be debugged)

AFAIK, folks here use gdb or its interface such as ddd, but I might be wrong....

Quoted 1 line

- cross compiled qemu with cygwin ?

AFAIK too, folks uses mingw here...

Signature · 7 lines
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
#2 lore raw
In reply to Tarmo Pikaro
Quoted 9 lines · Tarmo Pikaro

Hi !

I've analyzed quite a lot of emulators source code, including qemu as well.

But I somehow would like to completely get rid of emulators, and simply convert application from one cpu/board to another cpu/board.

On wiki pages this is called "binary translation".

Quoted 8 lines

- Do you know some open source code projects related to binary translation ?

I'm searching for enthusiasts / gurus who want / could be involved in this excersise as well.

My intrest also goes beoynd one windows - linux - I would like to binary translate also
older console games - like nintendo/super nintendo rom (directly to .exe).

In general, this is not possible. Consider for example self-modifying or otherwise dynamically created code, or just code that examines itself.

In some specific trivial cases it could work, and QEMU could be made to abort if translation would be needed.

#3 lore raw
Quoted 7 lines

In general, this is not possible. Consider for example self-modifying or otherwise dynamically created code, or just code that examines itself.

In some specific trivial cases it could work, and QEMU could be made to abort if translation would be needed.

I think self-modifying code is kinda rare case - it's made typically for protection againt hackers , and typically on pc side. Nintendo roms probably don't use this kind of
protection.

Anyway - I think even to self-modifying code could be some tricks like dynamically generated code.

I would be probably intrest to re-compile only modules, like .dll - but this would

require to analyze when and how .dll being loaded. This is kinda self-modifying code as well ? (OS loads .DLL)

 --
Have a nice day!
Tarmo.

#4 lore raw
Quoted 5 lines · Tarmo Pikaro
Quoted 4 lines

In general, this is not possible. Consider for example self-modifying or otherwise dynamically created code, or just code that examines itself.

Quoted 7 lines
Quoted 2 lines

In some specific trivial cases it could work, and QEMU could be made to abort if translation would be needed.

I think self-modifying code is kinda rare case - it's made typically for protection againt hackers , and typically on pc side. Nintendo roms probably don't use this kind of
protection.

It doesn't have to be protection, for example GCC generates trampolines to stack when using nested functions.

Quoted 2 lines

Anyway - I think even to self-modifying code could be some tricks like dynamically generated code.

It would be possible to save the original executable (for read references or write references to code that change already generated code) and invoke translator when we detect untranslated instructions. This would amount to a full QEMU plus some kind of startup cache.

Quoted 5 lines

I would be probably intrest to re-compile only modules, like .dll - but this would

require to analyze when and how .dll being loaded. This is kinda self-modifying code as well ? (OS loads .DLL)

In general, a program can load anything and start executing them or even modify previously non-executable region to become executable.

#5 lore raw
Quoted 9 lines · Blue Swirl
Quoted 8 lines · Tarmo Pikaro
Quoted 7 lines

In general, this is not possible. Consider for example self-modifying or otherwise dynamically created code, or just code that examines itself.

In some specific trivial cases it could work, and QEMU could be made to abort if translation would be needed.

Quoted 7 lines
Quoted 4 lines

I think self-modifying code is kinda rare case - it's made typically for protection againt hackers , and typically on pc side. Nintendo roms probably don't use this kind of
protection.

It doesn't have to be protection, for example GCC generates trampolines to stack when using nested functions.

An example related to console games is that Gameboy games copy some routines into RAM and jump into them during one phase of the screen refresh because of hardware limitations. I forget the details but I think you cannot access ROM during some part of the screen refresh, even for code execution. This would break if you statically translated the ROM. Console games do whacky things.

Stefan

#6 lore raw
In reply to Blue Swirl

Hi !

Quoted 7 lines
Quoted 4 lines

I think self-modifying code is kinda rare case - it's made typically for protection againt hackers , and typically on pc side. Nintendo roms probably don't use this kind of
protection.

It doesn't have to be protection, for example GCC generates trampolines to stack when using nested functions.

Ok, so apparently we will have some challenges on the way.

I guess some sort of mutation - qemu + recompiler could be done as well...

Debugger: can gdb be used in windows as well ?
I think I have tried ddd in cygwin, it was kinda slow and diffucult to use.

#7 lore raw
Quoted 6 lines · Tarmo Pikaro

Hi !

Quoted 5 lines
Quoted 4 lines

I think self-modifying code is kinda rare case - it's made typically for protection againt hackers , and typically on pc side. Nintendo roms probably don't use this kind of
protection.

Quoted 6 lines
Quoted 2 lines

It doesn't have to be protection, for example GCC generates trampolines to stack when using nested functions.

Ok, so apparently we will have some challenges on the way.

I guess some sort of mutation - qemu + recompiler could be done as well...

It would be much easier to ship an executable containing both the guest application and qemu, so that executing it starts qemu with a pre-defined configuration and runs the guest binary.

Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth