Initial binary object layout spec and matching impl (sans code)

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-01-28 18:12:31 -05:00
parent f98a53654e
commit 25f89bbc73
5 changed files with 330 additions and 0 deletions

68
vm.md
View File

@@ -195,6 +195,74 @@ wrapping around to 0.
* Pop
* More immediate stores?
# Binary format
The binary format is composed of a header followed by sections that make up the content of the blob.
## Header
The header is composed of:
* 64 bits - A magic number (0xDEAD_BEA7_BA5E_BA11).
* 16 bits - Version of the file
* 16 bits - The number of sections in the file
* 32 bits - Unused
* section descriptions detailed below
Total length: 128 bits
## Sections
The rest of the content is a list of sections. A section's layout is a section header, followed by
the section contents.
### Section header
* 8 bits - Section kind
* 0x00 - Data
* 0x10 - Code
* 0xFF - Meta
* 24 bits - Unused
* 32 bits - Checksum of the section
* 64 bits - Length of the section
Total length: 128 bits
### Data section
The data section contains static data that is initialized to some known value.
* 64 bits - load location - where in memory the contents of this section are put.
### Code section
The code section contains executable code.
* 64 bits - load location - where in memory the contents of this section are put.
The remaining length of the section is the code itself.
### Meta section
The meta section holds a table of metadata about the binary in a key-value format of strings mapping
to other strings. All strings are UTF-8 encoded.
* 64 bits - the number of key-value entries
The remaining length of the section are the key-value pairs.
The layout for a key-value pair is the key, followed immediately by the value. The key is always a
string, and the value may be any type of data. A key starts with the length of the string, followed
by the key string itself. A value starts with the length of the data, followed by the value data
itself.
The meta section should be used to place data that's readable by the VM, but is not used by the
executing program. Data in the meta section is not copied to the program memory.
A VM must provide support for the following meta-values:
* `entry` - a 64-bit address for where the VM should begin executing code.
# General TODO
* Interrupts