objvm - Bytecode file format
The header
The header is a 16 byte segment containing the following fields:
- Field 1: 2 byte magic number - 0xAC 0xAC
- Field 2: 2 bytes for file subtype
- Raw - 0x00 0x00
- …
- Field 3: 2 bytes of code size between 0x0000 0xFFFF
- Unused: 10 bytes of unused padding to be used later
The only file subtype is raw, which signifies a raw code+data segment
Raw File Format
The raw file format contains one segment, the code segment. It starts at byte 16 and follows through to the end of the file. In memory, the code sits at the beginning of a buffer where the size of the buffer is specified by header field 3 (Code Size).
The code specifies both “code” and “data” and it is the responsibility of the code to know which is which.
You can optional segment data and code with a JMP header:
; position of the code we want to jump
; to is the size of our data region plus
; the size of this header, which is 0x0a
PUSH CONSTANT size-of-data ; size=3 cp=0
PUSH CONSTANT 0x0a ; size=3 cp=3
ADD ; size=1 cp=6
JMP SPECIAL STACK ; size=3 cp=7
; cp=10
; data region
0xaa 0xaf 0xcc ...
; code region
POP ; start of code, empty the stack , cp=0x0a+size-of-data
...