The bulk of the iPXE binary (the .textdata section) is physically relocated at runtime to the top of the 32-bit address space in order to allow space for an OS to be loaded. The relocation is achieved with the assistance of segmentation: we adjust the code and data segment bases so that the link-time addresses remain valid. Segmentation is not available (for normal code and data segments) in long mode. We choose to compile the C code with -mcmodel=kernel and use a link-time address of 0xffffffffeb000000. This choice allows us to identity-map the entirety of the 32-bit address space, and to alias our chosen link-time address to the physical location of our .textdata section. (This requires the .textdata section to always be aligned to a page boundary.) We simultaneously choose to set the 32-bit virtual address segment bases such that the link-time addresses may simply be truncated to 32 bits in order to generate a valid 32-bit virtual address. This allows symbols in .textdata to be trivially accessed by both 32-bit and 64-bit code. There is no (sensible) way in 32-bit assembly code to generate the required R_X86_64_32S relocation records for these truncated symbols. However, subtracting the fixed constant 0xffffffff00000000 has the same effect as truncation, and can be represented in a standard R_X86_64_32 relocation record. We define the VIRTUAL() macro to abstract away this truncation operation, and apply it to all references by 32-bit (or 16-bit) assembly code to any symbols within the .textdata section. We define "virt_offset" for a 64-bit build as "the value to be added to an address within .textdata in order to obtain its physical address". With this definition, the low 32 bits of "virt_offset" can be treated by 32-bit code as functionally equivalent to "virt_offset" in a 32-bit build. We define "text16" and "data16" for a 64-bit build as the physical addresses of the .text16 and .data16 sections. Since a physical address within the 32-bit address space may be used directly as a 64-bit virtual address (thanks to the identity map), this definition provides the most natural access to variables in .text16 and .data16. Note that this requires a minor adjustment in prot_to_real(), which accesses .text16 using 32-bit virtual addresses. Signed-off-by: Michael Brown <mcb30@ipxe.org>tags/v1.20.1
|
|
||
32 |
|
32 |
|
33 |
|
33 |
|
34 |
|
34 |
|
35 |
|
|
|
|
35 |
|
|
36 |
|
36 |
|
37 |
|
37 |
|
38 |
|
38 |
|
39 |
|
39 |
|
40 |
|
40 |
|
41 |
|
|
|
|
41 |
|
|
42 |
|
42 |
|
43 |
|
43 |
|
44 |
|
44 |
|
|
|
||
78 |
|
78 |
|
79 |
|
79 |
|
80 |
|
80 |
|
81 |
|
|
|
|
81 |
|
|
82 |
|
82 |
|
83 |
|
83 |
|
84 |
|
84 |
|
|
|
||
88 |
|
88 |
|
89 |
|
89 |
|
90 |
|
90 |
|
91 |
|
|
|
|
91 |
|
|
92 |
|
92 |
|
93 |
|
93 |
|
94 |
|
94 |
|
|
|
||
134 |
|
134 |
|
135 |
|
135 |
|
136 |
|
136 |
|
137 |
|
|
|
|
137 |
|
|
138 |
|
138 |
|
139 |
|
139 |
|
140 |
|
140 |
|
|
|
||
7 |
|
7 |
|
8 |
|
8 |
|
9 |
|
9 |
|
10 |
|
|
|
11 |
|
10 |
|
12 |
|
11 |
|
13 |
|
12 |
|
|
|
||
16 |
|
15 |
|
17 |
|
16 |
|
18 |
|
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 |
|
|
19 |
|
52 |
|
20 |
|
53 |
|
21 |
|
54 |
|
|
|
||
24 |
|
57 |
|
25 |
|
58 |
|
26 |
|
59 |
|
27 |
|
|
|
|
60 |
|
|
28 |
|
61 |
|
29 |
|
62 |
|
30 |
|
63 |
|
|
|
||
42 |
|
75 |
|
43 |
|
76 |
|
44 |
|
77 |
|
45 |
|
|
|
|
78 |
|
|
46 |
|
79 |
|
47 |
|
80 |
|
48 |
|
81 |
|
|
|
||
19 |
|
19 |
|
20 |
|
20 |
|
21 |
|
21 |
|
22 |
|
|
|
23 |
|
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
24 |
|
38 |
|
25 |
|
39 |
|
26 |
|
40 |
|
|
|
||
126 |
|
140 |
|
127 |
|
141 |
|
128 |
|
142 |
|
129 |
|
|
|
|
143 |
|
|
130 |
|
144 |
|
131 |
|
145 |
|
132 |
|
146 |
|
|
|
||
137 |
|
151 |
|
138 |
|
152 |
|
139 |
|
153 |
|
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
143 |
|
157 |
|
144 |
|
158 |
|
145 |
|
159 |
|
|
|
||
168 |
|
182 |
|
169 |
|
183 |
|
170 |
|
184 |
|
171 |
|
|
|
|
185 |
|
|
172 |
|
186 |
|
173 |
|
187 |
|
174 |
|
188 |
|
|
|
||
181 |
|
195 |
|
182 |
|
196 |
|
183 |
|
197 |
|
|
198 |
|
|
184 |
|
199 |
|
|
200 |
|
|
185 |
|
201 |
|
186 |
|
202 |
|
187 |
|
203 |
|
|
|
||
195 |
|
211 |
|
196 |
|
212 |
|
197 |
|
213 |
|
198 |
|
|
|
|
214 |
|
|
199 |
|
215 |
|
200 |
|
216 |
|
201 |
|
217 |
|
|
|
||
207 |
|
223 |
|
208 |
|
224 |
|
209 |
|
225 |
|
210 |
|
|
|
|
226 |
|
|
211 |
|
227 |
|
212 |
|
228 |
|
213 |
|
229 |
|
|
|
||
221 |
|
237 |
|
222 |
|
238 |
|
223 |
|
239 |
|
224 |
|
|
|
|
240 |
|
|
225 |
|
241 |
|
226 |
|
242 |
|
227 |
|
243 |
|
|
|
||
312 |
|
328 |
|
313 |
|
329 |
|
314 |
|
330 |
|
315 |
|
|
|
|
331 |
|
|
316 |
|
332 |
|
317 |
|
333 |
|
318 |
|
334 |
|
|
|
||
323 |
|
339 |
|
324 |
|
340 |
|
325 |
|
341 |
|
326 |
|
|
|
|
342 |
|
|
327 |
|
343 |
|
328 |
|
344 |
|
329 |
|
|
|
|
345 |
|
|
330 |
|
346 |
|
331 |
|
347 |
|
332 |
|
|
|
|
348 |
|
|
333 |
|
349 |
|
334 |
|
|
|
|
350 |
|
|
335 |
|
351 |
|
336 |
|
352 |
|
337 |
|
353 |
|
|
|
||
365 |
|
381 |
|
366 |
|
382 |
|
367 |
|
383 |
|
368 |
|
|
|
|
384 |
|
|
|
385 |
|
|
369 |
|
386 |
|
370 |
|
387 |
|
371 |
|
388 |
|
|
|
||
377 |
|
394 |
|
378 |
|
395 |
|
379 |
|
396 |
|
380 |
|
|
|
381 |
|
|
|
|
397 |
|
|
|
398 |
|
|
382 |
|
399 |
|
383 |
|
400 |
|
384 |
|
401 |
|
385 |
|
402 |
|
386 |
|
|
|
|
403 |
|
|
387 |
|
404 |
|
388 |
|
405 |
|
389 |
|
406 |
|
390 |
|
407 |
|
391 |
|
408 |
|
392 |
|
409 |
|
393 |
|
|
|
|
410 |
|
|
394 |
|
411 |
|
395 |
|
412 |
|
396 |
|
413 |
|
|
|
||
512 |
|
529 |
|
513 |
|
530 |
|
514 |
|
531 |
|
515 |
|
|
|
|
532 |
|
|
516 |
|
533 |
|
517 |
|
534 |
|
518 |
|
535 |
|
|
|
||
589 |
|
606 |
|
590 |
|
607 |
|
591 |
|
608 |
|
592 |
|
|
|
|
609 |
|
|
593 |
|
610 |
|
594 |
|
611 |
|
595 |
|
612 |
|
|
|
||
605 |
|
622 |
|
606 |
|
623 |
|
607 |
|
624 |
|
608 |
|
|
|
|
625 |
|
|
609 |
|
626 |
|
610 |
|
627 |
|
611 |
|
628 |
|
|
|
||
665 |
|
682 |
|
666 |
|
683 |
|
667 |
|
684 |
|
|
685 |
|
|
|
686 |
|
|
668 |
|
687 |
|
669 |
|
688 |
|
670 |
|
689 |
|
|
|
||
7 |
|
7 |
|
8 |
|
8 |
|
9 |
|
9 |
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
10 |
|
15 |
|
11 |
|
16 |
|
12 |
|
|
|
||
1 |
|
1 |
|
2 |
|
2 |
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
3 |
|
7 |
|
4 |
|
8 |
|
5 |
|
9 |
|
|
|
||
1 |
|
1 |
|
2 |
|
2 |
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
3 |
|
12 |
|
4 |
|
13 |
|
5 |
|
14 |
|