|
| 1 | +# ASMMod file format |
| 2 | +ASMMod is a file format used by the Callisto compiler for compiled modules. It contains |
| 3 | +function defintions and top level code with their generated assembly |
| 4 | + |
| 5 | +It is made up of sections, each one has a byte describing what kind of section it is: |
| 6 | + |
| 7 | +| Byte | Meaning | |
| 8 | +| ---- | -------------------- | |
| 9 | +| 0x00 | Top-level code | |
| 10 | +| 0x01 | Function definition | |
| 11 | +| 0x02 | Import | |
| 12 | +| 0x03 | Enable statement | |
| 13 | +| 0x04 | Const statement | |
| 14 | +| 0x05 | Enum statement | |
| 15 | +| 0x06 | Restrict statement | |
| 16 | +| 0x07 | Union statement | |
| 17 | +| 0x08 | Alias statement | |
| 18 | +| 0x09 | Implement statement | |
| 19 | +| 0x0A | Let statement | |
| 20 | +| 0x0B | Structure | |
| 21 | +| 0x0C | BSS section assembly | |
| 22 | +| 0x0D | Data section | |
| 23 | +| 0x0E | Extern function | |
| 24 | + |
| 25 | +Integers are little endian. Strings are null-terminated. |
| 26 | + |
| 27 | +## Header |
| 28 | +| Offset (bytes) | Size (bytes) | Description | |
| 29 | +| -------------- | ------------ | ------------------------------------------------------- | |
| 30 | +| 0 | 3 | ASCII magic bytes containing "MOD" | |
| 31 | +| 3 | 1 | Flags | |
| 32 | +| 4 | 8 | Version number, currently 0x0000 | |
| 33 | +| 12 | 8 | CPU architecture ID (see below) | |
| 34 | +| 20 | 8 | Operating system ID (see below) | |
| 35 | +| 28 | 8 | Number of sections | |
| 36 | +| 36 | 8 | String containing full path of the original source file | |
| 37 | + |
| 38 | +#### Flags |
| 39 | +| Bit | Value | |
| 40 | +| --- | ---------------------------------------------------------- | |
| 41 | +| 0 | 1 - this module is a stub, 0 - this is a full module | |
| 42 | +| 1 | 1 - this is the main module, 0 - it is not the main module | |
| 43 | + |
| 44 | +### CPU architectures |
| 45 | +"None" is used for transpiled languages (like when Callisto compiles to Lua) |
| 46 | +| ID | Name | |
| 47 | +| ------ | --------------- | |
| 48 | +| 0x0000 | None | |
| 49 | +| 0x0001 | x86_64 | |
| 50 | +| 0x0002 | x86 real mode | |
| 51 | +| 0x0003 | ARM64 | |
| 52 | +| 0x0004 | Uxn | |
| 53 | +| 0x0005 | Fox32 | |
| 54 | +| 0x0006 | Motorola 68000 | |
| 55 | +| 0x0007 | RISC-V | |
| 56 | + |
| 57 | +### Operating systems |
| 58 | +| ID | Name | |
| 59 | +| ------ | --------------- | |
| 60 | +| 0x0000 | None | |
| 61 | +| 0x0001 | Linux | |
| 62 | +| 0x0002 | macOS | |
| 63 | +| 0x0003 | Windows | |
| 64 | +| 0x0004 | MS-DOS | |
| 65 | +| 0x0005 | FreeBSD | |
| 66 | +| 0x0006 | Varvara | |
| 67 | +| 0x0007 | Fox32OS | |
| 68 | + |
| 69 | +# Sections |
| 70 | +The following tables will include the type byte mentioned before |
| 71 | + |
| 72 | +## Top level code |
| 73 | +| Offset (bytes) | Size (bytes) | Description | |
| 74 | +| -------------- | ------------ | -------------------------------------------------- | |
| 75 | +| 0 | 1 | Type - set to 0x00 | |
| 76 | +| 1 | 8 | Number of called functions | |
| 77 | +| 9 | ? | Array of strings containing called functions | |
| 78 | +| ? | ? | Assembly of top level code | |
| 79 | + |
| 80 | +## Function definition |
| 81 | +| Offset (bytes) | Size (bytes) | Description | |
| 82 | +| -------------- | ------------ | -------------------------------------------------- | |
| 83 | +| 0 | 1 | Type - set to 0x01 | |
| 84 | +| 1 | 2 | Flags - see below | |
| 85 | +| 3 | 8 | Number of called functions | |
| 86 | +| 11 | ? | Array of strings containing called functions | |
| 87 | +| ? | ? | Assembly of function (includes label) | |
| 88 | +| ? | ? | Function name | |
| 89 | +| ? | 8 | Number of parameters | |
| 90 | +| ? | 8 | Number of return values | |
| 91 | + |
| 92 | +### Flags |
| 93 | +Flags are OR'd together |
| 94 | +| Number | Description | |
| 95 | +| ------- | -------------------------------------- | |
| 96 | +| 1 | Public | |
| 97 | +| 2 | Inline (the assembly is callisto code) | |
| 98 | +| 4 | Throws errors | |
| 99 | + |
| 100 | +# Import |
| 101 | +| Offset (bytes) | Size (bytes) | Description | |
| 102 | +| -------------- | ------------ | -------------------------------------------------- | |
| 103 | +| 0 | 1 | Type - set to 0x02 | |
| 104 | +| 1 | 1 | Boolean - public? |
| 105 | +| 2 | ? | String containing name of module | |
| 106 | + |
| 107 | +## Enable statement |
| 108 | +| Offset (bytes) | Size (bytes) | Description | |
| 109 | +| -------------- | ------------ | -------------------------------------------------- | |
| 110 | +| 0 | 1 | Type - set to 0x03 | |
| 111 | +| 1 | ? | String containing version to enable | |
| 112 | + |
| 113 | +## Const statement |
| 114 | +| Offset (bytes) | Size (bytes) | Description | |
| 115 | +| -------------- | ------------ | -------------------------------------------------- | |
| 116 | +| 0 | 1 | Type - set to 0x04 | |
| 117 | +| 1 | 8 | Const value | |
| 118 | +| 9 | ? | String containing const name | |
| 119 | + |
| 120 | +## Enum statement |
| 121 | +### Enum header |
| 122 | +| Offset (bytes) | Size (bytes) | Description | |
| 123 | +| -------------- | ------------ | -------------------------------------------------- | |
| 124 | +| 0 | 1 | Type - set to 0x05 | |
| 125 | +| 1 | 8 | Number of enum values | |
| 126 | +| 9 | ? | Enum name | |
| 127 | +| ? | ? | String - enum type | |
| 128 | + |
| 129 | +Enum entries follow this header. |
| 130 | + |
| 131 | +### Enum entry |
| 132 | +| Offset (bytes) | Size (bytes) | Description | |
| 133 | +| -------------- | ------------ | -------------------------------------------------- | |
| 134 | +| 0 | 8 | Enum value | |
| 135 | +| 8 | ? | Enum name | |
| 136 | + |
| 137 | +## Restrict statement |
| 138 | +| Offset (bytes) | Size (bytes) | Description | |
| 139 | +| -------------- | ------------ | -------------------------------------------------- | |
| 140 | +| 0 | 1 | Type - set to 0x06 | |
| 141 | +| 1 | ? | String containing version to restrict | |
| 142 | + |
| 143 | +## Union staement |
| 144 | +| Offset (bytes) | Size (bytes) | Description | |
| 145 | +| -------------- | ------------ | -------------------------------------------------- | |
| 146 | +| 0 | 1 | Type - set to 0x07 | |
| 147 | +| 1 | ? | Union name | |
| 148 | +| ? | 8 | Number of types in union | |
| 149 | +| ? | ? | String array with type names | |
| 150 | + |
| 151 | +## Alias statement |
| 152 | +| Offset (bytes) | Size (bytes) | Description | |
| 153 | +| -------------- | ------------ | -------------------------------------------------- | |
| 154 | +| 0 | 1 | Type - set to 0x08 | |
| 155 | +| 1 | ? | Original type name | |
| 156 | +| ? | ? | New type name | |
| 157 | + |
| 158 | +## Implement statement |
| 159 | +| Offset (bytes) | Size (bytes) | Description | |
| 160 | +| -------------- | ------------ | -------------------------------------------------- | |
| 161 | +| 0 | 1 | Type - set to 0x09 | |
| 162 | +| 1 | ? | Type name | |
| 163 | +| ? | ? | Method name | |
| 164 | +| ? | 8 | Number of called functions | |
| 165 | +| ? | ? | Array of strings containing called functions | |
| 166 | +| ? | ? | Assembly of compiled implement statement | |
| 167 | + |
| 168 | +## Let statement |
| 169 | +| Offset (bytes) | Size (bytes) | Description | |
| 170 | +| -------------- | ------------ | -------------------------------------------------- | |
| 171 | +| 0 | 1 | Type - set to 0x0A | |
| 172 | +| 1 | 1 | Boolean - is this an array? | |
| 173 | +| 2 | 8 | Array size | |
| 174 | +| 10 | 1 | Boolean - is this a pointer? | |
| 175 | +| 10 | ? | Type | |
| 176 | +| ? | ? | Variable name | |
| 177 | + |
| 178 | +## Struct |
| 179 | +| Offset (bytes) | Size (bytes) | Description | |
| 180 | +| -------------- | ------------ | -------------------------------------------------- | |
| 181 | +| 0 | 1 | Type - set to 0x0B | |
| 182 | +| 1 | ? | Structure name | |
| 183 | +| ? | ? | String - parent structure, empty if none | |
| 184 | +| ? | 8 | Number of structure entries | |
| 185 | +| ? | ? | Structure entries | |
| 186 | + |
| 187 | +### Structure entries |
| 188 | +| Offset (bytes) | Size (bytes) | Description | |
| 189 | +| -------------- | ------------ | -------------------------------------------------- | |
| 190 | +| 0 | 1 | Bool - is pointer? | |
| 191 | +| 1 | ? | Type name | |
| 192 | +| ? | 1 | Bool - is array? | |
| 193 | +| ? | 8 | Array length, if applicable | |
| 194 | +| ? | 8 | Offset in structure | |
| 195 | +| ? | ? | Member name | |
| 196 | + |
| 197 | +## BSS Section assembly |
| 198 | +| Offset (bytes) | Size (bytes) | Description | |
| 199 | +| -------------- | ------------ | -------------------------------------------------- | |
| 200 | +| 0 | 1 | Type - set to 0x0C | |
| 201 | +| 1 | ? | Assembly | |
| 202 | + |
| 203 | +## Data section assembly |
| 204 | +| Offset (bytes) | Size (bytes) | Description | |
| 205 | +| -------------- | ------------ | -------------------------------------------------- | |
| 206 | +| 0 | 1 | Type - set to 0x0D | |
| 207 | +| 1 | ? | Assembly | |
| 208 | + |
| 209 | +## Extern function |
| 210 | +| Offset (bytes) | Size (bytes) | Description | |
| 211 | +| -------------- | ------------ | -------------------------------------------------- | |
| 212 | +| 0 | 1 | Type - set to 0x0E | |
| 213 | +| 1 | 1 | Extern type - see below table | |
| 214 | +| 2 | 4 | Number of return values | |
| 215 | +| 4 | 4 | Number of parameters | |
| 216 | +| 8 | ? | String - symbol name | |
| 217 | +| ? | ? | String - function name | |
| 218 | + |
| 219 | +After this, there are the return values, and then the parameters. Both have this |
| 220 | +format per value: |
| 221 | + |
| 222 | +| Offset (bytes) | Size (bytes) | Description | |
| 223 | +| -------------- | ------------ | -------------------------------------------------- | |
| 224 | +| 0 | 1 | Bool - is pointer? | |
| 225 | +| 1 | ? | Name of type | |
| 226 | + |
| 227 | +Extern types: |
| 228 | + |
| 229 | +| Value | Name | |
| 230 | +| ----- | ----------- | |
| 231 | +| 0 | Callisto | |
| 232 | +| 1 | Raw | |
| 233 | +| 2 | C | |
| 234 | + |
| 235 | +Callisto externs are currently due to be replaced with a better version, and raw |
| 236 | +externs are going to be removed. Do not use either. |
| 237 | + |
| 238 | +C externs must have either no return values (void) or one return value. |
0 commit comments