/
Draft_Assembly_Relocation_Table.txt
220 lines (85 loc) · 4.75 KB
/
Draft_Assembly_Relocation_Table.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
RFC X1001 (Draft-Asm) J. Rhodes, Ed.
Redpoint Software
April 2012
Assembly Relocation Table
Abstract
This draft provides a formal structure for providing an assembly
relocation table from within DCPU-16 programs.
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1. Requirements Language . . . . . . . . . . . . . . . . . . . 2
2. Role of Assemblers . . . . . . . . . . . . . . . . . . . . . . 2
3. Relocation Table Format . . . . . . . . . . . . . . . . . . . . 2
4. Relocation Table Position . . . . . . . . . . . . . . . . . . . 3
5. Security Considerations . . . . . . . . . . . . . . . . . . . . 3
6. Normative References . . . . . . . . . . . . . . . . . . . . . 3
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 3
Rhodes [Page 1]
Assembly Relocation Table April 2012
1. 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.
1.1. 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 [RFC2119].
2. 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.
3. 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 |
+-------------------------+
| Magic number (0x1234) |
| Version number (0x0001) |
| Size of table |
| Entry 1 |
| ... |
| Entry N |
+-------------------------+
Table 1: Relocation Table
Rhodes [Page 2]
Assembly Relocation Table April 2012
4. Relocation Table Position
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 |
+---------------------------------------+
Table 2: Relocation Setup Table
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.
5. 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.
6. Normative References
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997.
Rhodes [Page 3]
Assembly Relocation Table April 2012
Author's Address
James Rhodes (editor)
Redpoint Software
Email: jrhodes@redpointsoftware.com.au
URI: http://www.redpointsoftware.com.au/
Rhodes [Page 4]