This page describes the system module file format version 0.3
A system module file has informations about interfaces, implementations and functions, besides data and code relocation data.
The file is made of sections: header, strings, used functions, used functions relocation, data relocation, code relocation and implemented interfaces.
File's header resides at the beginning and has informations about size and position of each section, besides global module information. The format is:
Size | Description |
---|---|
16 bytes | File's MD5 fingerprint/message-digest |
4 bytes | SM03 - ID (System Module 0.3) |
4 bytes | Module code start |
4 bytes | Module code size |
4 bytes | Module data start |
4 bytes | Module data size |
4 bytes | Module uninitialized data size |
4 bytes | Used functions section start |
4 bytes | Used functions section size |
4 bytes | Used functions relocation section start |
4 bytes | Used functions relocation section size |
4 bytes | Implemented interfaces section start |
4 bytes | Implemented interfaces section size |
4 bytes | Data relocation section start |
4 bytes | Data relocation section size |
4 bytes | Code relocation section start |
4 bytes | Code relocation section size |
4 bytes | File's strings section start |
2 bytes | File's strings section size |
2 bytes | Module version |
2 bytes | Module properties |
2 bytes | Comment index |
4 bytes | Phase0Start function start |
4 bytes | Phase1Start function start |
4 bytes | Shutdown function start |
If a section has 0 size it doesn't exist. So, if data section has 0 size, module has no data.
The MD5 member is used to validate the rest of the file.
Uninitialized data have 0 as initial value.
Module data area is composed in the following way: initialized data + uninitialized data.
The version member has the following meaning: the first byte (version >> 8) is the first version, next 4 bits (version & 0xf0) are another version and the last 4 bits (version & 0x0f) are the last version. For example: 0.1.0 or 20.15.10
The property member has no meaning yet.
If there is no start or shutdown function, function start must be 0xffffffff.
This section holds all used strings. Strings end with a 0 byte. Is the same type of string used in C/C++.
The first string must be the empty string, that is, the first section's byte is 0.
Strings in this section must be unique.
This section holds information about functions used by the module.
Each entry has this format:
Size | Description |
---|---|
2 bytes | Interface name index |
2 bytes | Implementation name index |
2 bytes | Function number |
The interface name and the implementation name can have at most 32 chars each including the terminating zero.
This section holds information about location and type of relocation to apply to call interfaces functions.
This section must be sorted by the offset in crescent order.
Each entry has this format:
Size | Description |
---|---|
4 bytes | Offset inside code where the function is called |
1 byte | Relocation properties |
3 bytes | Used function index |
Properties can be:
Size | Position | Description |
---|---|---|
1 bit | bit 0 | 1 - absolute relocation; 0 - relative relocation |
In absolute relocation used function start address is put in the offset.
In relative relocation used function start address is subtracted of the offset. It's a call relative to the current address.
This section holds all module's implemented interfaces.
The format is as follow: interface information, implementations informations, another interface information, more implementations, and so for.
It has the following format:
Size | Description |
---|---|
2 bytes | Interface name index |
2 bytes | Number of functions in the interface |
2 bytes | Number of implementations in the interface |
4 bytes | Implementation's functions start (relative to the beginning of the file) |
2 bytes | Implementation name index |
... | ...(more implementations from this interface) |
... | ...(more interfaces) |
The interface name and the implementation name can have at most 32 chars each including the terminating zero.
Section with an implementation's functions has this format:
Size | Description |
---|---|
4 bytes | Code start (relative to the beginning of the module code) |
1 byte | Properties |
1 byte | Number of words (4 bytes) in stack |
... | ...(more functions) |
The number of words member is used only by user functions and say how many words of 4 bytes must be copyed from user stack to system stack when the function is called by an user module.
The properties member has this format:
Size | Position | Description |
---|---|---|
1 bit | bit 0 | 1 - system; 0 - user function |
1 bit | bit 1 | 1 - function not implemented |
This section has this format:
Size | Description |
---|---|
4 bytes | Data relocation block size |
4 bytes | Code relocation block size |
as far as 4GB bytes | Data relocation block |
as far as 4GB bytes | Code relocation block |
Data relocation block has information about relocation to data (a variable wants the address of another variable in the data block).
Code relocation block has information about relocation to code (a variable wants the address of a code chunk).
Each entry in these blocks is an offset inside data block to the reference that must be changed. Each relocation is computed as follow: block start + 32 bits word in the offset to be changed.
This section has this format:
Size | Description |
---|---|
4 bytes | Data relocation block size |
4 bytes | Code relocation block size |
as far as 4GB bytes | Data relocation block |
as far as 4GB bytes | Code relocation block |
Data relocation block has information about relocation to data (code wants the address of a variable in the data block).
Code relocation block has information about relocation to code (code wants the address of a code chunk).
Each entry in these blocks is an offset inside code block to the reference that must be changed. Each relocation is computed as follow: block start + 32 bits word in the offset to be changed.