LW Tool Chain
Prev |  |

# Chapter 6. Object Files

LWTOOLS uses a proprietary object file format. It is proprietary in the sense that it is specific to LWTOOLS, not that it is a hidden format. It would be hard to keep it hidden in an open source tool chain anyway. This chapter documents the object file format.

An object file consists of a series of sections each of which contains a list of exported symbols, a list of incomplete references, and a list of "local" symbols which may be used in calculating incomplete references. Each section will obviously also contain the object code.

Exported symbols must be completely resolved to an address within the section it is exported from. That is, an exported symbol must be a constant rather than defined in terms of other symbols.

Each object file starts with a magic number and version number. The magic number is the string "LWOBJ16" for this 16 bit object file format. The only defined version number is currently 0. Thus, the first 8 bytes of the object file are 4C574F424A313600

Each section has the following items in order:

- section name

- flags

- list of local symbols (and addresses within the section)

- list of exported symbols (and addresses within the section)

- list of incomplete references along with the expressions to calculate them

- the actual object code (for non-BSS sections)

The section starts with the name of the section with a NUL termination followed by a series of flag bytes terminated by NUL. There are only two flag bytes defined. A NUL (0) indicates no more flags and a value of 1 indicates the section is a BSS section. For a BSS section, no actual code is included in the object file.

Either a NULL section name or end of file indicate the presence of no more sections.

Each entry in the exported and local symbols table consists of the symbol (NUL terminated) followed by two bytes which contain the value in big endian order. The end of a symbol table is indicated by a NULL symbol name.

Each entry in the incomplete references table consists of an expression followed by a 16 bit offset where the reference goes. Expressions are defined as a series of terms up to an "end of expression" term. Each term consists of a single byte which identifies the type of term (see below) followed by any data required by the term. Then end of the list is flagged by a NULL expression (only an end of expression term).

Table 6-1. Object File Term Types

TERMTYPE | Meaning
--- | ---
00 | end of expression
01 | integer (16 bit in big endian order follows)
02 | external symbol reference (NUL terminated symbol name follows)
03 | local symbol reference (NUL terminated symbol name follows)
04 | operator (1 byte operator number)
05 | section base address reference
FF | This term will set flags for the expression. Each one of these terms will set a single flag. All of them should be specified first in an expression. If they are not, the behaviour is undefined. The byte following is the flag. Flag 01 indicates an 8 bit relocation. Flag 02 indicates a zero-width relocation (see the EXTDEP pseudo op in LWASM).

External references are resolved using other object files while local references are resolved using the local symbol table(s) from this file. This allows local symbols that are not exported to have the same names as exported symbols or external references.

Table 6-2. Object File Operator Numbers

Number | Operator
--- | ---
01 | addition (+)
02 | subtraction (-)
03 | multiplication (*)
04 | division (/)
05 | modulus (%)
06 | integer division (\) (same as division)
07 | bitwise and
08 | bitwise or
09 | bitwise xor
0A | boolean and
0B | boolean or
0C | unary negation, 2's complement (-)
0D | unary 1's complement (^)

An expression is represented in a postfix manner with both operands for binary operators preceding the operator and the single operand for unary operators preceding the operator.

Prev | Home |
Libraries and LWAR |  |