-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Align CRT0 exit function naming * Push .reloc after .data * Make our dummy .reloc sections not depend on section order. Signed-off-by: Callum Farmer <[email protected]>
- Loading branch information
Showing
11 changed files
with
171 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
/* | ||
* crt0-efi-aarch64.S - PE/COFF header for AArch64 EFI applications | ||
* crt0-efi-aarch64-local.S - PE/COFF header for AArch64 EFI applications (without suitable objcopy) | ||
* | ||
* Copyright (C) 2014 Linaro Ltd. <[email protected]> | ||
* | ||
|
@@ -108,6 +109,17 @@ section_table: | |
.2byte 0 // NumberOfLineNumbers (0 for executables) | ||
.4byte 0x60000020 // Characteristics (section flags) | ||
|
||
.ascii ".data\0\0\0" | ||
.4byte _data_vsize - ImageBase // VirtualSize | ||
.4byte _data - ImageBase // VirtualAddress | ||
.4byte _data_size - ImageBase // SizeOfRawData | ||
.4byte _data - ImageBase // PointerToRawData | ||
.4byte 0 // PointerToRelocations | ||
.4byte 0 // PointerToLineNumbers | ||
.2byte 0 // NumberOfRelocations | ||
.2byte 0 // NumberOfLineNumbers | ||
.4byte 0xC0000040 // Characteristics (section flags) | ||
|
||
/* | ||
* The EFI application loader requires a relocation section | ||
* because EFI applications must be relocatable. This is a | ||
|
@@ -124,17 +136,6 @@ section_table: | |
.2byte 0 // NumberOfLineNumbers | ||
.4byte 0x42000040 // Characteristics (section flags) | ||
|
||
.ascii ".data\0\0\0" | ||
.4byte _data_vsize - ImageBase // VirtualSize | ||
.4byte _data - ImageBase // VirtualAddress | ||
.4byte _data_size - ImageBase // SizeOfRawData | ||
.4byte _data - ImageBase // PointerToRawData | ||
.4byte 0 // PointerToRelocations | ||
.4byte 0 // PointerToLineNumbers | ||
.2byte 0 // NumberOfRelocations | ||
.2byte 0 // NumberOfLineNumbers | ||
.4byte 0xC0000040 // Characteristics (section flags) | ||
|
||
.ascii ".rodata\0" | ||
.4byte _rodata_vsize - ImageBase // VirtualSize | ||
.4byte _rodata - ImageBase // VirtualAddress | ||
|
@@ -145,7 +146,7 @@ section_table: | |
.2byte 0 // NumberOfRelocations | ||
.2byte 0 // NumberOfLineNumbers | ||
.4byte 0x40000040 // Characteristics (section flags) | ||
|
||
#ifdef USING_SBAT | ||
.ascii ".sbat\0\0\0" | ||
.4byte _sbat_vsize - ImageBase // VirtualSize | ||
|
@@ -173,6 +174,7 @@ section_table: | |
.4byte 0x40000040 // Characteristics (section flags) | ||
#endif | ||
|
||
|
||
.text | ||
.globl _start | ||
.type _start,%function | ||
|
@@ -187,23 +189,24 @@ _start: | |
adrp x1, _DYNAMIC | ||
add x1, x1, #:lo12:_DYNAMIC | ||
bl _relocate | ||
cbnz x0, 0f | ||
cbnz x0, .L_exit | ||
|
||
ldp x0, x1, [sp, #16] | ||
bl efi_main | ||
bl _entry | ||
|
||
0: ldp x29, x30, [sp], #32 | ||
.L_exit: | ||
ldp x29, x30, [sp], #32 | ||
ret | ||
// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: | ||
|
||
// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: | ||
|
||
.data | ||
dummy: .4byte 0 | ||
dummy0: .4byte 0 | ||
dummy1: .4byte 0 | ||
|
||
#define IMAGE_REL_ABSOLUTE 0 | ||
.section .reloc, "a" | ||
label1: | ||
.4byte dummy-label1 // Page RVA | ||
.section .reloc, "a", %progbits | ||
.4byte dummy1 - dummy0 // Page RVA | ||
.4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits | ||
.2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy | ||
.2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause */ | ||
/* | ||
* crt0-efi-riscv64-local.S - PE/COFF header for RISC-V 64 EFI applications (without suitable objcopy) | ||
* | ||
* Copyright (C) 2014 Linaro Ltd. <[email protected]> | ||
* Copyright (C) 2018 Alexander Graf <[email protected]> | ||
* | ||
|
@@ -16,7 +18,6 @@ | |
* either version 2 of the License, or (at your option) any later version. | ||
*/ | ||
|
||
|
||
.section .text.head | ||
|
||
/* | ||
|
@@ -68,7 +69,7 @@ extra_header_fields: | |
// Everything before the kernel image is considered part of the header | ||
.4byte _text - ImageBase // SizeOfHeaders | ||
.4byte 0 // CheckSum | ||
.2byte EFI_SUBSYSTEM // Subsystem | ||
.2byte EFI_SUBSYSTEM // Subsystem | ||
.2byte 0 // DllCharacteristics | ||
.8byte 0 // SizeOfStackReserve | ||
.8byte 0 // SizeOfStackCommit | ||
|
@@ -109,6 +110,17 @@ section_table: | |
.2byte 0 // NumberOfLineNumbers (0 for executables) | ||
.4byte 0x60000020 // Characteristics (section flags) | ||
|
||
.ascii ".data\0\0\0" | ||
.4byte _data_vsize - ImageBase // VirtualSize | ||
.4byte _data - ImageBase // VirtualAddress | ||
.4byte _data_size - ImageBase // SizeOfRawData | ||
.4byte _data - ImageBase // PointerToRawData | ||
.4byte 0 // PointerToRelocations | ||
.4byte 0 // PointerToLineNumbers | ||
.2byte 0 // NumberOfRelocations | ||
.2byte 0 // NumberOfLineNumbers | ||
.4byte 0xC0000040 // Characteristics (section flags) | ||
|
||
/* | ||
* The EFI application loader requires a relocation section | ||
* because EFI applications must be relocatable. This is a | ||
|
@@ -125,17 +137,6 @@ section_table: | |
.2byte 0 // NumberOfLineNumbers | ||
.4byte 0x42000040 // Characteristics (section flags) | ||
|
||
.ascii ".data\0\0\0" | ||
.4byte _data_vsize - ImageBase // VirtualSize | ||
.4byte _data - ImageBase // VirtualAddress | ||
.4byte _data_size - ImageBase // SizeOfRawData | ||
.4byte _data - ImageBase // PointerToRawData | ||
.4byte 0 // PointerToRelocations | ||
.4byte 0 // PointerToLineNumbers | ||
.2byte 0 // NumberOfRelocations | ||
.2byte 0 // NumberOfLineNumbers | ||
.4byte 0xC0000040 // Characteristics (section flags) | ||
|
||
.ascii ".rodata\0" | ||
.4byte _rodata_vsize - ImageBase // VirtualSize | ||
.4byte _rodata - ImageBase // VirtualAddress | ||
|
@@ -185,23 +186,24 @@ _start: | |
lla a0, ImageBase | ||
lla a1, _DYNAMIC | ||
call _relocate | ||
bne a0, zero, 0f | ||
bne a0, zero, .L_exit | ||
ld a1, 8(sp) | ||
ld a0, 0(sp) | ||
call efi_main | ||
call _entry | ||
ld ra, 16(sp) | ||
0: addi sp, sp, 24 | ||
.L_exit: | ||
addi sp, sp, 24 | ||
ret | ||
|
||
// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: | ||
|
||
.data | ||
dummy: .4byte 0 | ||
dummy0: .4byte 0 | ||
dummy1: .4byte 0 | ||
|
||
#define IMAGE_REL_ABSOLUTE 0 | ||
.section .reloc, "a" | ||
label1: | ||
.4byte dummy-label1 // Page RVA | ||
.section .reloc, "a", %progbits | ||
.4byte dummy1 - dummy0 // Page RVA | ||
.4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits | ||
.2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy | ||
.2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy | ||
|
Oops, something went wrong.