Series of examples outlining how to build a x64 JIT for a MIPS processor.
There is an accompanying series of blog articles here.
This repository comprises a series of exercises written while trying to learn about how one might go about trying to dynamically recompile MIPS instructions for the x64 architecture.
There are already some good tutorials online on how one might go and do this for languages like brainfuck and I encourage you to read them. The emphasis here is to provide and outline of you might evolve an interpreting emulator into a JIT.
This repository does not currently contain a fully working JIT for a MIPS processor.
Currently, the examples only work on architectures that conform to the System V AMD64 calling conventions. This means the examples should work on MacOS and Linux but not on Windows.
In this example we try and figure out how to call a free C++ function from our JIT.
This is so that if we haven't implemented a function in our JIT we can call the interpreted version.
We learn about the x64 16-byte stack alignment requirements.
The discussion here about direct vs indirect calls is also worth reading.
In this example we go a step further and pass arguments to our free C++ function.
In this example we introduce a simplified MIPS processor and introduce what is called a threaded interpreter. This is to say we do a single pass over the instructions and simply call the underlying interpreted function.
In this example we now attempt to re-implement one of the simpler instructions directly by reading and writing the guest registers to and from RAM.
In this example we reattempt the previous example using register relative indirect addressing.
In this example we attempt a trivial I-Type instruction.
In this example we attempt to deal with arithmetic overflow.
In this example we attempt to store a register in memory.
In this example we attempt to load a register from memory.
In this example we attempt to deal with branch instructions.
- Compiler explorer
- Calling conventions
- x64 instruction encoding
- x64 instruction reference
- Online Assembler & Disassembler