1 Bridging
Peter Mackay edited this page 2018-02-19 13:28:40 +00:00

Recommended reading

Background

HLE functions (in the src/emulator/modules directory) are written in C++, compiled to native machine code using the calling convention of the host machine.

The Vita, on the other hand, runs 32-bit ARM code, using the 32-bit ARM calling convention. Roughly speaking:

  • Before calling a function, the game stores the function parameters in registers and on the stack.
  • The game calls the function by jumping to the function address.
  • When the function returns, the game gets the function return values from registers or the stack.

Now keep in mind that the function being called doesn't really exist as ARM code. So instead of jumping to the function address, the emulator detects that a function is going to get called, interrupts the virtual CPU, calls an HLE function, and resumes the virtual CPU.

So what is bridging?

"Bridging" is the process of mapping between ARM registers and stack memory and C++ function arguments and return values. It's building of a bridge between the two worlds of ARM machine code and C++ functions.

Terminology

An export function, exported by the HLE module, is defined using the EXPORT macro, and looks very much like the functions declared in the vita-headers includes.

An import is a function, imported by the emulator, that takes only the host state and current thread ID, and uses bridging to take what it needs from the host in order to pass the correct values to the export and store its return value back to registers.

Type conversion

Because the host machine is 64-bit and the emulated machine is 32-bit, there are some data types that can't be used directly.

In particular, pointers to Vita memory are represented by the Ptr template type, which is essentially just a 32-bit address, with a type for easier development. You can't dereference a Ptr directly, as it's interpreted relative to a chunk of memory allocated to represent the Vita's 32-bit (4GB) address space.

Endianness

Currently it's assumed that the host machine is little-endian, like the Vita. There is no endian conversion.