Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2013 - 2017 Linaro, Ltd.
0004  * Copyright (C) 2013, 2014 Red Hat, Inc.
0005  */
0006 
0007 #include <linux/pe.h>
0008 #include <linux/sizes.h>
0009 
0010     .macro  efi_signature_nop
0011 #ifdef CONFIG_EFI
0012 .L_head:
0013     /*
0014      * This ccmp instruction has no meaningful effect except that
0015      * its opcode forms the magic "MZ" signature required by UEFI.
0016      */
0017     ccmp    x18, #0, #0xd, pl
0018 #else
0019     /*
0020      * Bootloaders may inspect the opcode at the start of the kernel
0021      * image to decide if the kernel is capable of booting via UEFI.
0022      * So put an ordinary NOP here, not the "MZ.." pseudo-nop above.
0023      */
0024     nop
0025 #endif
0026     .endm
0027 
0028     .macro  __EFI_PE_HEADER
0029 #ifdef CONFIG_EFI
0030     .set    .Lpe_header_offset, . - .L_head
0031     .long   PE_MAGIC
0032     .short  IMAGE_FILE_MACHINE_ARM64        // Machine
0033     .short  .Lsection_count             // NumberOfSections
0034     .long   0                   // TimeDateStamp
0035     .long   0                   // PointerToSymbolTable
0036     .long   0                   // NumberOfSymbols
0037     .short  .Lsection_table - .Loptional_header // SizeOfOptionalHeader
0038     .short  IMAGE_FILE_DEBUG_STRIPPED | \
0039         IMAGE_FILE_EXECUTABLE_IMAGE | \
0040         IMAGE_FILE_LINE_NUMS_STRIPPED       // Characteristics
0041 
0042 .Loptional_header:
0043     .short  PE_OPT_MAGIC_PE32PLUS           // PE32+ format
0044     .byte   0x02                    // MajorLinkerVersion
0045     .byte   0x14                    // MinorLinkerVersion
0046     .long   __initdata_begin - .Lefi_header_end // SizeOfCode
0047     .long   __pecoff_data_size          // SizeOfInitializedData
0048     .long   0                   // SizeOfUninitializedData
0049     .long   __efistub_efi_pe_entry - .L_head    // AddressOfEntryPoint
0050     .long   .Lefi_header_end - .L_head      // BaseOfCode
0051 
0052     .quad   0                   // ImageBase
0053     .long   SEGMENT_ALIGN               // SectionAlignment
0054     .long   PECOFF_FILE_ALIGNMENT           // FileAlignment
0055     .short  0                   // MajorOperatingSystemVersion
0056     .short  0                   // MinorOperatingSystemVersion
0057     .short  LINUX_EFISTUB_MAJOR_VERSION     // MajorImageVersion
0058     .short  LINUX_EFISTUB_MINOR_VERSION     // MinorImageVersion
0059     .short  0                   // MajorSubsystemVersion
0060     .short  0                   // MinorSubsystemVersion
0061     .long   0                   // Win32VersionValue
0062 
0063     .long   _end - .L_head              // SizeOfImage
0064 
0065     // Everything before the kernel image is considered part of the header
0066     .long   .Lefi_header_end - .L_head      // SizeOfHeaders
0067     .long   0                   // CheckSum
0068     .short  IMAGE_SUBSYSTEM_EFI_APPLICATION     // Subsystem
0069     .short  0                   // DllCharacteristics
0070     .quad   0                   // SizeOfStackReserve
0071     .quad   0                   // SizeOfStackCommit
0072     .quad   0                   // SizeOfHeapReserve
0073     .quad   0                   // SizeOfHeapCommit
0074     .long   0                   // LoaderFlags
0075     .long   (.Lsection_table - .) / 8       // NumberOfRvaAndSizes
0076 
0077     .quad   0                   // ExportTable
0078     .quad   0                   // ImportTable
0079     .quad   0                   // ResourceTable
0080     .quad   0                   // ExceptionTable
0081     .quad   0                   // CertificationTable
0082     .quad   0                   // BaseRelocationTable
0083 
0084 #ifdef CONFIG_DEBUG_EFI
0085     .long   .Lefi_debug_table - .L_head     // DebugTable
0086     .long   .Lefi_debug_table_size
0087 #endif
0088 
0089     // Section table
0090 .Lsection_table:
0091     .ascii  ".text\0\0\0"
0092     .long   __initdata_begin - .Lefi_header_end // VirtualSize
0093     .long   .Lefi_header_end - .L_head      // VirtualAddress
0094     .long   __initdata_begin - .Lefi_header_end // SizeOfRawData
0095     .long   .Lefi_header_end - .L_head      // PointerToRawData
0096 
0097     .long   0                   // PointerToRelocations
0098     .long   0                   // PointerToLineNumbers
0099     .short  0                   // NumberOfRelocations
0100     .short  0                   // NumberOfLineNumbers
0101     .long   IMAGE_SCN_CNT_CODE | \
0102         IMAGE_SCN_MEM_READ | \
0103         IMAGE_SCN_MEM_EXECUTE           // Characteristics
0104 
0105     .ascii  ".data\0\0\0"
0106     .long   __pecoff_data_size          // VirtualSize
0107     .long   __initdata_begin - .L_head      // VirtualAddress
0108     .long   __pecoff_data_rawsize           // SizeOfRawData
0109     .long   __initdata_begin - .L_head      // PointerToRawData
0110 
0111     .long   0                   // PointerToRelocations
0112     .long   0                   // PointerToLineNumbers
0113     .short  0                   // NumberOfRelocations
0114     .short  0                   // NumberOfLineNumbers
0115     .long   IMAGE_SCN_CNT_INITIALIZED_DATA | \
0116         IMAGE_SCN_MEM_READ | \
0117         IMAGE_SCN_MEM_WRITE         // Characteristics
0118 
0119     .set    .Lsection_count, (. - .Lsection_table) / 40
0120 
0121 #ifdef CONFIG_DEBUG_EFI
0122     /*
0123      * The debug table is referenced via its Relative Virtual Address (RVA),
0124      * which is only defined for those parts of the image that are covered
0125      * by a section declaration. Since this header is not covered by any
0126      * section, the debug table must be emitted elsewhere. So stick it in
0127      * the .init.rodata section instead.
0128      *
0129      * Note that the EFI debug entry itself may legally have a zero RVA,
0130      * which means we can simply put it right after the section headers.
0131      */
0132     __INITRODATA
0133 
0134     .align  2
0135 .Lefi_debug_table:
0136     // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
0137     .long   0                   // Characteristics
0138     .long   0                   // TimeDateStamp
0139     .short  0                   // MajorVersion
0140     .short  0                   // MinorVersion
0141     .long   IMAGE_DEBUG_TYPE_CODEVIEW       // Type
0142     .long   .Lefi_debug_entry_size          // SizeOfData
0143     .long   0                   // RVA
0144     .long   .Lefi_debug_entry - .L_head     // FileOffset
0145 
0146     .set    .Lefi_debug_table_size, . - .Lefi_debug_table
0147     .previous
0148 
0149 .Lefi_debug_entry:
0150     // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
0151     .ascii  "NB10"                  // Signature
0152     .long   0                   // Unknown
0153     .long   0                   // Unknown2
0154     .long   0                   // Unknown3
0155 
0156     .asciz  VMLINUX_PATH
0157 
0158     .set    .Lefi_debug_entry_size, . - .Lefi_debug_entry
0159 #endif
0160 
0161     .balign SEGMENT_ALIGN
0162 .Lefi_header_end:
0163 #else
0164     .set    .Lpe_header_offset, 0x0
0165 #endif
0166     .endm