Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2013-2017 Linaro Ltd
0004  * Authors: Roy Franz <roy.franz@linaro.org>
0005  *          Ard Biesheuvel <ard.biesheuvel@linaro.org>
0006  */
0007 
0008 #include <linux/pe.h>
0009 #include <linux/sizes.h>
0010 
0011         .macro  __nop
0012  AR_CLASS(  mov r0, r0      )
0013   M_CLASS(  nop.w           )
0014         .endm
0015 
0016         .macro __initial_nops
0017 #ifdef CONFIG_EFI_STUB
0018         @ This is a two-instruction NOP, which happens to bear the
0019         @ PE/COFF signature "MZ" in the first two bytes, so the kernel
0020         @ is accepted as an EFI binary. Booting via the UEFI stub
0021         @ will not execute those instructions, but the ARM/Linux
0022         @ boot protocol does, so we need some NOPs here.
0023         .inst   MZ_MAGIC | (0xe225 << 16)   @ eor r5, r5, 0x4d000
0024         eor r5, r5, 0x4d000         @ undo previous insn
0025 #else
0026         __nop
0027         __nop
0028 #endif
0029         .endm
0030 
0031         .macro  __EFI_HEADER
0032 #ifdef CONFIG_EFI_STUB
0033         .set    start_offset, __efi_start - start
0034         .org    start + 0x3c
0035         @
0036         @ The PE header can be anywhere in the file, but for
0037         @ simplicity we keep it together with the MSDOS header
0038         @ The offset to the PE/COFF header needs to be at offset
0039         @ 0x3C in the MSDOS header.
0040         @ The only 2 fields of the MSDOS header that are used are this
0041         @ PE/COFF offset, and the "MZ" bytes at offset 0x0.
0042         @
0043         .long   pe_header - start       @ Offset to the PE header.
0044 
0045 pe_header:
0046         .long   PE_MAGIC
0047 
0048 coff_header:
0049         .short  IMAGE_FILE_MACHINE_THUMB    @ Machine
0050         .short  section_count           @ NumberOfSections
0051         .long   0               @ TimeDateStamp
0052         .long   0               @ PointerToSymbolTable
0053         .long   0               @ NumberOfSymbols
0054         .short  section_table - optional_header @ SizeOfOptionalHeader
0055         .short  IMAGE_FILE_32BIT_MACHINE | \
0056             IMAGE_FILE_DEBUG_STRIPPED | \
0057             IMAGE_FILE_EXECUTABLE_IMAGE | \
0058             IMAGE_FILE_LINE_NUMS_STRIPPED   @ Characteristics
0059 
0060 #define __pecoff_code_size (__pecoff_data_start - __efi_start)
0061 
0062 optional_header:
0063         .short  PE_OPT_MAGIC_PE32       @ PE32 format
0064         .byte   0x02                @ MajorLinkerVersion
0065         .byte   0x14                @ MinorLinkerVersion
0066         .long   __pecoff_code_size      @ SizeOfCode
0067         .long   __pecoff_data_size      @ SizeOfInitializedData
0068         .long   0               @ SizeOfUninitializedData
0069         .long   efi_pe_entry - start        @ AddressOfEntryPoint
0070         .long   start_offset            @ BaseOfCode
0071         .long   __pecoff_data_start - start @ BaseOfData
0072 
0073 extra_header_fields:
0074         .long   0               @ ImageBase
0075         .long   SZ_4K               @ SectionAlignment
0076         .long   SZ_512              @ FileAlignment
0077         .short  0               @ MajorOsVersion
0078         .short  0               @ MinorOsVersion
0079         .short  LINUX_EFISTUB_MAJOR_VERSION @ MajorImageVersion
0080         .short  LINUX_EFISTUB_MINOR_VERSION @ MinorImageVersion
0081         .short  0               @ MajorSubsystemVersion
0082         .short  0               @ MinorSubsystemVersion
0083         .long   0               @ Win32VersionValue
0084 
0085         .long   __pecoff_end - start        @ SizeOfImage
0086         .long   start_offset            @ SizeOfHeaders
0087         .long   0               @ CheckSum
0088         .short  IMAGE_SUBSYSTEM_EFI_APPLICATION @ Subsystem
0089         .short  0               @ DllCharacteristics
0090         .long   0               @ SizeOfStackReserve
0091         .long   0               @ SizeOfStackCommit
0092         .long   0               @ SizeOfHeapReserve
0093         .long   0               @ SizeOfHeapCommit
0094         .long   0               @ LoaderFlags
0095         .long   (section_table - .) / 8     @ NumberOfRvaAndSizes
0096 
0097         .quad   0               @ ExportTable
0098         .quad   0               @ ImportTable
0099         .quad   0               @ ResourceTable
0100         .quad   0               @ ExceptionTable
0101         .quad   0               @ CertificationTable
0102         .quad   0               @ BaseRelocationTable
0103 
0104 section_table:
0105         .ascii  ".text\0\0\0"
0106         .long   __pecoff_code_size      @ VirtualSize
0107         .long   __efi_start         @ VirtualAddress
0108         .long   __pecoff_code_size      @ SizeOfRawData
0109         .long   __efi_start         @ PointerToRawData
0110         .long   0               @ PointerToRelocations
0111         .long   0               @ PointerToLineNumbers
0112         .short  0               @ NumberOfRelocations
0113         .short  0               @ NumberOfLineNumbers
0114         .long   IMAGE_SCN_CNT_CODE | \
0115             IMAGE_SCN_MEM_READ | \
0116             IMAGE_SCN_MEM_EXECUTE       @ Characteristics
0117 
0118         .ascii  ".data\0\0\0"
0119         .long   __pecoff_data_size      @ VirtualSize
0120         .long   __pecoff_data_start - start @ VirtualAddress
0121         .long   __pecoff_data_rawsize       @ SizeOfRawData
0122         .long   __pecoff_data_start - start @ PointerToRawData
0123         .long   0               @ PointerToRelocations
0124         .long   0               @ PointerToLineNumbers
0125         .short  0               @ NumberOfRelocations
0126         .short  0               @ NumberOfLineNumbers
0127         .long   IMAGE_SCN_CNT_INITIALIZED_DATA | \
0128             IMAGE_SCN_MEM_READ | \
0129             IMAGE_SCN_MEM_WRITE     @ Characteristics
0130 
0131         .set    section_count, (. - section_table) / 40
0132 
0133         .align  12
0134 __efi_start:
0135 #endif
0136         .endm