Skip to content

Instantly share code, notes, and snippets.

@enkore
Created April 11, 2012 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enkore/2359185 to your computer and use it in GitHub Desktop.
Save enkore/2359185 to your computer and use it in GitHub Desktop.

RFC X1001 - Assembly Relocation Table

Asm - Workgroup: 0x10c Standards Committee

Authors

This draft provides a formal structure for providing an assembly relocation table from within DCPU-16 programs.

Introduction

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.

Requirements Language

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

Role of Assemblers

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.

Relocation Table Format

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

Relocation Table Positioning

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.

Security Considerations

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment