-
Notifications
You must be signed in to change notification settings - Fork 12
Bytecode
Please note that this documentation tends to lag behind the git repo and I only tend to update with releases. The most recent source of documentation is always either the VM itself in boot/interpeter.c
or the assembler.
Instructions are one byte and have a variable number of bytes afterwards.
Note that this file describes the instruction set AS THE VM INTERPRETS IT, e.g. not as you'd write it for the assembler. Notably, the size operand is normally automatically calculated, you should use labels rather than offsets for jump and you can specify strings/wstrings as data.
Any integers of greater than one byte are not re-ordered to fit endianness.
If you specify 0001 as a value, the vm will read this as: uint16_t val = *((uint16_t*){0x00, 0x01})
Be aware of this. That is interpreted as 0x0100 on a 3DS.
nop
- 1 byte
- Opcode 0x00
- Does nothing. Not actually treated as an instruction, rather just skipped over. This is mainly just for compatibility.
rel mode
- 2 bytes
- Opcode 0x01
- Chooses memory/patch relativity.
- mode : The location and size to operate in.
- Boot only:
- 0x0: NATIVE_FIRM (whole size)
- 0x1: AGB_FIRM (whole size)
- 0x2: TWL_FIRM (whole size)
- 0x3: Native Proc9 ExeFS (Default during boot)
- 0x4: AGB Proc9 ExeFS
- 0x5: TWL Proc9 ExeFS
- 0x6: Native Section 0
- 0x7: Native Section 1
- 0x8: Native Section 2
- 0x9: Native Section 3
- 0xA: AGB Section 0
- 0xB: AGB Section 1
- 0xC: AGB Section 2
- 0xD: AGB Section 3
- 0xE: TWL Section 0
- 0xF: TWL Section 1
- 0x10: TWL Section 2
- 0x11: TWL Section 3
- Loader only:
- 0x12: ExeFs .text segment (Default with loader)
- 0x13: ExeFs .data segment
- 0x14: ExeFs .ro segment
- Boot only:
find size pattern...
- 2 + size bytes
- opcode 0x02
- Finds a pattern in memory. On success, the offset pointer is moved to the beginning of the match and the
f
flag will be set. - size
- 1 byte
- How many bytes the pattern is.
- pattern
- size bytes
- The data to find
back count
- 2 bytes
- opcode 0x03
- Moves back count bytes from current position.
- count
- 1 byte
- How many bytes to move.
fwd
- 2 bytes
- opcode 0x04
- Moves forward count bytes from current position.
- count
- 1 byte
- How many bytes to move.
set size data...
- 2 + size bytes
- opcode 0x05
- Copies the bytes in
data
to the current location pointed to, and increments the current offset bysize
bytes copied. - size
- 1 byte
- How many bytes to copy.
- data
- size bytes
- Data to copy.
test size data...
- 2 + size bytes
- opcode 0x06
- Tests if the data at the current offset is equivalent to
data
, and sets flags accordingly. - size
- 1 byte
- Size of data to test against.
- data
- size bytes
- Pattern to test.
jmp[eq|ne|lt|gt|le|ge|f|nf] offset
- 3 bytes
- opcodes 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77, 0x87
- Jumps to absolute offset instruction within the bytecode, and resumes execution from there. A condition can be specified and a jump will only occur if the condition is true.
- offset
- 2 bytes
- Offset to jump to.
rewind
- 1 byte
- opcode 0x08
- Resets the current offset to the beginning.
and size data...
- 2 + size bytes
- opcode 0x09
- Performs an AND operation bitwise using data as a mask.
- size
- 1 byte
- Size of data
- data
- size bytes
- Data to bitwise and with relative data.
or size data...
- 2 + size bytes
- opcode 0x0A
- Performs an OR operation bitwise using data as a mask.
- size
- 1 byte
- Size of data
- data
- size bytes
- Data to bitwise or with relative data.
xor size data...
- 2 + size bytes
- opcode 0x0B
- Performs an XOR operation bitwise using data as a mask.
- size
- 1 byte
- Size of data
- data
- size bytes
- Data to bitwise xor with relative data.
not size
- 2 bytes
- opcode 0x0C
- Performs an NOT operation on data of size bytes.
- size
- 1 byte
- Size to perform bitwise not on
ver version
- 3 bytes
- opcode 0x0D
- Acts like test - compares the uint16_t version of a software title against input version. Sets flags accordingly.
- version
- 2 bytes
- uint16_t to test version against
clf
- 1 byte
- opcode 0x0E
- Clears flags set by test/ver/find.
n3ds
- 1 byte
- opcode 0x10
- Sets the eq flag if the console is an n3DS.
seek offset
- 5 bytes
- opcode 0x0F
- Seeks to an absolute offset in the data buffer.
- offset
- 4 bytes
- The absolute offset to seek to as uint32_t.
abort[eq|ne|lt|gt|f|nf]
- 1 byte
- opcodes 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78
- Aborts the VM, optionally specifying a condition.
next
- 1 byte
- Opcode 0xFF
- Resets state to default, and changes the base of code to the next instruction. This opcode is not meant to be used directly - it's emitted when generating caches to separate distinct patches.