From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 05/10] arm64/efi: update the PE/COFF header to be endian agnostic
Date: Mon, 21 Jul 2014 17:16:20 +0200 [thread overview]
Message-ID: <1405955785-13477-6-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1405955785-13477-1-git-send-email-ard.biesheuvel@linaro.org>
Update the PE/COFF header to use explicit little endian constants and use
explicit little endian linker symbols so that the PE/COFF header is always
emitted in little endian regardless of the endiannes of the kernel.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
arch/arm64/kernel/head.S | 48 ++++++++++++++++++++++++++----------------------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index c63f44f20ae3..5179d3df1024 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -123,7 +123,10 @@ efi_head:
.byte 0x4d
.byte 0x64
#ifdef CONFIG_EFI
- .long pe_header - efi_head // Offset to the PE header.
+ .byte pe_header - efi_head // Offset to the PE header.
+ .byte 0
+ .byte 0
+ .byte 0
#else
.word 0 // reserved
#endif
@@ -136,30 +139,31 @@ pe_header:
.ascii "PE"
.short 0
coff_header:
- .short 0xaa64 // AArch64
- .short 2 // nr_sections
+ le16 0xaa64 // AArch64
+ le16 2 // nr_sections
.long 0 // TimeDateStamp
.long 0 // PointerToSymbolTable
- .long 1 // NumberOfSymbols
- .short section_table - optional_header // SizeOfOptionalHeader
- .short 0x206 // Characteristics.
+ le32 1 // NumberOfSymbols
+ .byte section_table - optional_header // SizeOfOptionalHeader
+ .byte 0
+ le16 0x206 // Characteristics.
// IMAGE_FILE_DEBUG_STRIPPED |
// IMAGE_FILE_EXECUTABLE_IMAGE |
// IMAGE_FILE_LINE_NUMS_STRIPPED
optional_header:
- .short 0x20b // PE32+ format
+ le16 0x20b // PE32+ format
.byte 0x02 // MajorLinkerVersion
.byte 0x14 // MinorLinkerVersion
- .long _end - stext // SizeOfCode
+ .long _efi_code_virtsize_le // SizeOfCode
.long 0 // SizeOfInitializedData
.long 0 // SizeOfUninitializedData
- .long efi_stub_entry - efi_head // AddressOfEntryPoint
- .long stext_offset // BaseOfCode
+ .long _efi_entry_point_le // AddressOfEntryPoint
+ .long _efi_stext_offset_le // BaseOfCode
extra_header_fields:
.quad 0 // ImageBase
- .long 0x20 // SectionAlignment
- .long 0x8 // FileAlignment
+ le32 0x20 // SectionAlignment
+ le32 0x8 // FileAlignment
.short 0 // MajorOperatingSystemVersion
.short 0 // MinorOperatingSystemVersion
.short 0 // MajorImageVersion
@@ -168,19 +172,19 @@ extra_header_fields:
.short 0 // MinorSubsystemVersion
.long 0 // Win32VersionValue
- .long _end - efi_head // SizeOfImage
+ .long _efi_image_size_le // SizeOfImage
// Everything before the kernel image is considered part of the header
- .long stext_offset // SizeOfHeaders
+ .long _efi_stext_offset_le // SizeOfHeaders
.long 0 // CheckSum
- .short 0xa // Subsystem (EFI application)
+ le16 0xa // Subsystem (EFI application)
.short 0 // DllCharacteristics
.quad 0 // SizeOfStackReserve
.quad 0 // SizeOfStackCommit
.quad 0 // SizeOfHeapReserve
.quad 0 // SizeOfHeapCommit
.long 0 // LoaderFlags
- .long 0x6 // NumberOfRvaAndSizes
+ le32 0x6 // NumberOfRvaAndSizes
.quad 0 // ExportTable
.quad 0 // ImportTable
@@ -208,23 +212,23 @@ section_table:
.long 0 // PointerToLineNumbers
.short 0 // NumberOfRelocations
.short 0 // NumberOfLineNumbers
- .long 0x42100040 // Characteristics (section flags)
+ le32 0x42100040 // Characteristics (section flags)
.ascii ".text"
.byte 0
.byte 0
.byte 0 // end of 0 padding of section name
- .long _end - stext // VirtualSize
- .long stext_offset // VirtualAddress
- .long _edata - stext // SizeOfRawData
- .long stext_offset // PointerToRawData
+ .long _efi_code_virtsize_le // VirtualSize
+ .long _efi_stext_offset_le // VirtualAddress
+ .long _efi_code_rawsize_le // SizeOfRawData
+ .long _efi_stext_offset_le // PointerToRawData
.long 0 // PointerToRelocations (0 for executables)
.long 0 // PointerToLineNumbers (0 for executables)
.short 0 // NumberOfRelocations (0 for executables)
.short 0 // NumberOfLineNumbers (0 for executables)
- .long 0xe0500020 // Characteristics (section flags)
+ le32 0xe0500020 // Characteristics (section flags)
.align 5
#endif
--
1.8.3.2
next prev parent reply other threads:[~2014-07-21 15:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-21 15:16 [RFC PATCH 00/10] arm64: boot BE kernels from UEFI Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 01/10] arm64/efi: efistub: jump to 'stext' directly, not through the header Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 02/10] arm64/efi: efistub: cover entire static mem footprint in PE/COFF .text Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 03/10] arm64: add macros to emit little endian ASM constants Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 04/10] arm64: add EFI little endian constants to linker script Ard Biesheuvel
2014-07-30 14:18 ` Matt Fleming
2014-07-30 14:21 ` Ard Biesheuvel
2014-07-30 14:22 ` Will Deacon
2014-07-21 15:16 ` Ard Biesheuvel [this message]
2014-07-21 15:16 ` [RFC PATCH 06/10] arm64/efi: efistub: avoid using linker defined constants Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 07/10] arm64/efi: efistub: add support for booting a BE kernel Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 08/10] arm64/efi: use LE accessors to access UEFI data Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 09/10] arm64/efi: enable minimal UEFI Runtime Services for big endian Ard Biesheuvel
2014-07-23 9:34 ` Mark Rutland
2014-07-23 10:59 ` Ard Biesheuvel
2014-07-23 17:52 ` Ard Biesheuvel
2014-07-21 15:16 ` [RFC PATCH 10/10] arm64: Kconfig: enable UEFI on BE kernels Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405955785-13477-6-git-send-email-ard.biesheuvel@linaro.org \
--to=ard.biesheuvel@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).