Skip to content

2. How to emulate a machine

Saku Kaarakainen edited this page Aug 20, 2016 · 1 revision

Note: This is only a sketch. The most likely this doesn't contain all the data you need to write an emulator.

Emulation techniques

Two ways: Low-level emulation (LLE) and High-level emulation (HLE)

LLE

  • Simulates the behavior of the hardware to be emulated
  • Requires fast processor
  • Can be achieved via hardware or software
  • First PS3 systems emulated PS2 this way.

HLE

  • Simulates functions of the hardware
  • Easier to program than LLE
  • Java Virtual Machine is an example of HLE
    • Java code doesn't complied and run on the host machine
    • Host runs a theoretical Java machine (where Java code is ran and compiled
  • Three methods to do this: Interpreting, Dynamic Recompiling and Lists interception.

Interpreting

  • Emulator executes the application line-by-line.
  • It's done by mimicking what each instruction is supposed to do.

Dynamic Recompiling

  • The emulator looks at chunks of the application's processors instructions.
    • looks if this can be optimized to run better on host machine.
  • This is opposed to running each instruction one by one.
    • Results in lookup overhead penalties.

List interception

  • Some hardware require the main processor to send command lists.
    • Co-processors, like GPU and audio chip.
  • These are a series of instructions that tell the co-processor what to do.
  • The emulator can intercept command list and turn it into something the host computer can process a similar co-processor.
  • For example:
    1. Command lists going to the emulated system's GPU
    2. Intercepted and turned into DirectX or OpenGL command for the hosts' video card to process.

Which one to use?

LLE

Pros:

  • Low-lever more accurate

Cons:

  • Hardware isn't always feasible as it adds cost to the system
  • Often limited to either
    • much older systems
    • prototype emulators that aregetting a handle on things, or
    • lesser of a system like an I/O controller.

HLE

Pros:

  • allows a system with complete hardware to be emulated on something only a bit more powerful.
  • It may also allow one without intimate knowledge of the hardware to emulate it.
  • It may not be able to emulate special features specific to the hardware etc.
    • that developers used to do something beyond the norm
    • However, nowadays developers use industry-standard API, which:
      • makes easier to emulate a system.
      • quite possible run the application with better performance than the original.
      • This is the approach most emulators of modern systems are taking.
  • modern emulators use HLE, (which makes better support). Cons:
  • Requires intimate knowledge of the system or its parts.
    • May not be possible if documentation is for its scarce
  • Requires much powerful system than the emulated machine.