Asm - Workgroup: 0x10c Standards Committee
Authors
- James Rhodes - jrhodes@redpointsoftware .com.au
This draft provides a formal structure for providing an assembly relocation table from within DCPU-16 programs.
As it stands, code generated by assemblers is either not relocatable, or the relocation format is not standardized. Thus this document suggests a standard mechanism for providing a table of addresses that need relocating.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119
For the purposes of this draft, the role of assemblers is to generate code from a defined syntax to DCPU-16 bytecode.
In this case, assemblers SHOULD provide an option to generate relocatable code, but MUST NOT generate relocatable code unless the user indicates that they wish to do so.
For purposes of future versioning, this document specifies version 1 of the relocation table format.
The format of the relocation table is as follows:
Contents of single Word | Content123 Word |
---|---|
Magic number (0x1234) | Version number (0x0001) |
Size of table | Entry 1 |
... | Entry N |
The assembly relocation table must be positioned inside the generated code, but have no effect on the program execution.
When an assembler generates relocatable code, the first instruction MUST be a jump to the start of the actual program code. This results in the first two words being:
Contents of single Word |
---|
SET PC, <next word literally> |
Location of first program instruction |
It is important to note that assemblers will have to offset all label addresses by the size of the relocation table, plus the two words at the start.
It is potentially possible for a malicious user to generate code which determines the offset of the resulting relocatable program when it is loaded into memory and executed.
This is possible by creating a label with a predetermined address if the program was running at 0x0, and calculating the difference between the actual address that the program would jump to and the original value.