
Recompiler: Porting Xbox360 Executables to Windows - ingve
https://github.com/rexdex/recompiler#porting-xbox360-executables-to-windows
======
monocasa
Normally static recompilation of video games breaks down due to self modifying
code. If you're going to have to have go through the motions of JIT anyway
(and in places where, if they're going through the motions of self modifying
code, it's probably computationally expensive code at that), then you might as
well go whole hog. That way you only have to build one kind of compiler, and
you can take advantage of profile information for everything.

But the 360's security model specifically out rules self modifying code. And
this is enforced by the hypervisor; the system is W xor X, and the transition
of a page from W to X has to be accompanied by signatures signed by
Microsoft's private key. Nobody, including the kernel, can modify their code.

That might make this one of the first platforms where the static recompilation
scheme might make sense in the long term architecture of the emulator.

~~~
Scaevolus
Self modifying code hasn't been common in video games for 20 years. The main
problem is that static recompilation requires accurate alias analysis--
knowing what values a given pointer might have at a particular point of
execution. This is especially important for indirect calls through function
pointers (C++ virtual functions), where entire chunks of code might be missed.

~~~
tsomctl
But you can still have video games implement their own form of dynamically
loaded modules, which (to a jit) is the same problem as self modifying code. I
know several PS2 games do this.

~~~
a_t48
This still isn't really common. Code size typically pales in comparison to
data size.

~~~
tsomctl
But it's still something to be aware of, so that you don't have to make major
architectural changes to your jit so that one game will work. It's a million
and one little things like this that make emulators hard.

~~~
monocasa
Yeah, you'd probably want an indirect table for inter-page calls, with maybe a
soft TLB for this translation if the profiler gave you good results. You might
be able to bank on the idea that any processor you'd be running the generated
code on will have so much better branch prediction and speculative execution
than the 360, that you'll be able to fit in the cracks even with this extra
overhead.

------
RickSanchez2600
If they can emulate a PowerPC system then they can run AmigaOS and
MacOS/MacOSX for PowerMacs to run some legacy programs on Windows, Linux,
Modern MacOSX, iOS, etc.

There were rumors that Microsoft would port Windows 10 to the XBox One and
then convert XBox games to Windows 10 via the Windows Store, etc. Then you
could buy or rent XBox, XBox 360, and XBox One games.

Apple had a Rosetta software that ran PowerMac stuff on Intel Macs until 10.7
removed it IIRC. So Apple has the patents and IP for that.

There was also an old ARDI Executor program that ran old Mac 68K stuff in
Windows, Linux, BeOS, etc.

~~~
bluedino
Isn’t the challenge with Xbox in the obscure GPU emulation? I mean there’s no
Xbox emulator and it was designed with an Intel CPU.

~~~
monocasa
Yeah, although not any more obscure than the GC/Wii GPU really.

I'd argue that the fact that the OG Xbox's homebrew scene used the illegally
acquired official XDK for the mos part played a part. This meant that they
didn't get as deep into documenting the hardware at that early stage, and
instead relied on closed source libraries.

~~~
Grazester
The same could be argued about the Dreamcast where there SDK was concerned but
that has been emulated. Not perfectly but pretty well. I have read it was not
just interest in the console but the GPU.

~~~
monocasa
The GPU is way simpler on the Dreamcast since all T&L is done in software.
It's GPU is just a screen space rasterizer.

------
devbug
Xenia is a similar project that uses static recompilation (with fallbacks for
tricky parts).

[https://github.com/benvanik/xenia](https://github.com/benvanik/xenia)

------
4lch3m1st
This is amazing -- seems almost like a better way to play an Xbox 360 game on
PC, without an emulator. Could even be what Microsoft wanted, for better
retrocompatibility support. I wonder if it can also be done to other consoles?
Let's hope it gives good fruits.

~~~
Jasper_
Honestly, I think the emulator approach is a lot better -- you can do a lot
more with JIT than trying to translate instructions AOT 1:1.

~~~
bri3d
Yeah - as evidenced by the NES story the other day, the elegance of AOT blows
up completely as soon as there's any form of self-modifying code or even
memory arithmetic tricks or jump tables. It's all possible to work around, but
JIT is cleaner and more flexible in the long run.

~~~
reificator
I'm fairly sure that the 360 specifically did not allow self modifying code.
Makes it a good candidate for this approach.

------
tomyws
I've always wanted to find time looking at recompiling the Xbox Live Arcade
(XBLA) titles from the 360 to Windows. The games are just dotNET applications
which run against a variation of the standard libraries.

~~~
shinymark
I think you might be correct for Xbox Live Indie Games (XBLIG) but that’s not
correct for XBLA. Source: personally worked on native C++ XBLA games.

~~~
BillinghamJ
Yeah I think he might just be thinking about XNA? In which case, it can almost
directly be replaced by MonoGame.

------
h43k3r
How is it possible for one single person to figure all of these things ? I am
new to the industry ( 2 years ) and have only worked on Front End and Back End
( APIs) .

------
Jaruzel
Tangentially but related, does anyone know how to convert xbox360 XMV video
files back to WMV or better yet MP4?

Asking for a friend...

------
kyriakos
would it be easier to do the same for Xbox One games instead? no different
architecture complications

------
BackPropagate
There used to be a company called Hunter Systems in the late 80s that
recompiled DOS binaries for Unix workstations. I worked there.

