blob: 542e1ad432aea5aedeba09e303de6dc03ed4f7a1 [file] [log] [blame]
Roy Franz81a0bc32015-09-23 20:17:54 -07001/*
Ard Biesheuvel609eaf02017-08-18 20:49:43 +01002 * Copyright (C) 2013-2017 Linaro Ltd
Roy Franz81a0bc32015-09-23 20:17:54 -07003 * Authors: Roy Franz <roy.franz@linaro.org>
4 * Ard Biesheuvel <ard.biesheuvel@linaro.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010011#include <linux/pe.h>
12#include <linux/sizes.h>
13
Roy Franz81a0bc32015-09-23 20:17:54 -070014 .macro __nop
15#ifdef CONFIG_EFI_STUB
16 @ This is almost but not quite a NOP, since it does clobber the
17 @ condition flags. But it is the best we can do for EFI, since
18 @ PE/COFF expects the magic string "MZ" at offset 0, while the
19 @ ARM/Linux boot protocol expects an executable instruction
20 @ there.
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010021 .inst MZ_MAGIC | (0x1310 << 16) @ tstne r0, #0x4d000
Roy Franz81a0bc32015-09-23 20:17:54 -070022#else
Ard Biesheuvel60ce2852017-06-09 10:14:53 +010023 AR_CLASS( mov r0, r0 )
24 M_CLASS( nop.w )
Roy Franz81a0bc32015-09-23 20:17:54 -070025#endif
26 .endm
27
28 .macro __EFI_HEADER
29#ifdef CONFIG_EFI_STUB
Roy Franz81a0bc32015-09-23 20:17:54 -070030 .set start_offset, __efi_start - start
31 .org start + 0x3c
32 @
33 @ The PE header can be anywhere in the file, but for
34 @ simplicity we keep it together with the MSDOS header
35 @ The offset to the PE/COFF header needs to be at offset
36 @ 0x3C in the MSDOS header.
37 @ The only 2 fields of the MSDOS header that are used are this
38 @ PE/COFF offset, and the "MZ" bytes at offset 0x0.
39 @
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010040 .long pe_header - start @ Offset to the PE header.
Roy Franz81a0bc32015-09-23 20:17:54 -070041
42pe_header:
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010043 .long PE_MAGIC
Roy Franz81a0bc32015-09-23 20:17:54 -070044
45coff_header:
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010046 .short IMAGE_FILE_MACHINE_THUMB @ Machine
47 .short section_count @ NumberOfSections
48 .long 0 @ TimeDateStamp
49 .long 0 @ PointerToSymbolTable
50 .long 0 @ NumberOfSymbols
51 .short section_table - optional_header @ SizeOfOptionalHeader
52 .short IMAGE_FILE_32BIT_MACHINE | \
53 IMAGE_FILE_DEBUG_STRIPPED | \
54 IMAGE_FILE_EXECUTABLE_IMAGE | \
55 IMAGE_FILE_LINE_NUMS_STRIPPED @ Characteristics
Roy Franz81a0bc32015-09-23 20:17:54 -070056
57optional_header:
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010058 .short PE_OPT_MAGIC_PE32 @ PE32 format
59 .byte 0x02 @ MajorLinkerVersion
60 .byte 0x14 @ MinorLinkerVersion
61 .long _end - __efi_start @ SizeOfCode
62 .long 0 @ SizeOfInitializedData
63 .long 0 @ SizeOfUninitializedData
64 .long efi_stub_entry - start @ AddressOfEntryPoint
65 .long start_offset @ BaseOfCode
66 .long 0 @ BaseOfData
Roy Franz81a0bc32015-09-23 20:17:54 -070067
68extra_header_fields:
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010069 .long 0 @ ImageBase
70 .long SZ_512 @ SectionAlignment
71 .long SZ_512 @ FileAlignment
72 .short 0 @ MajorOsVersion
73 .short 0 @ MinorOsVersion
74 .short 0 @ MajorImageVersion
75 .short 0 @ MinorImageVersion
76 .short 0 @ MajorSubsystemVersion
77 .short 0 @ MinorSubsystemVersion
78 .long 0 @ Win32VersionValue
Roy Franz81a0bc32015-09-23 20:17:54 -070079
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010080 .long _end - start @ SizeOfImage
81 .long start_offset @ SizeOfHeaders
82 .long 0 @ CheckSum
83 .short IMAGE_SUBSYSTEM_EFI_APPLICATION @ Subsystem
84 .short 0 @ DllCharacteristics
85 .long 0 @ SizeOfStackReserve
86 .long 0 @ SizeOfStackCommit
87 .long 0 @ SizeOfHeapReserve
88 .long 0 @ SizeOfHeapCommit
89 .long 0 @ LoaderFlags
90 .long (section_table - .) / 8 @ NumberOfRvaAndSizes
Roy Franz81a0bc32015-09-23 20:17:54 -070091
Ard Biesheuvel609eaf02017-08-18 20:49:43 +010092 .quad 0 @ ExportTable
93 .quad 0 @ ImportTable
94 .quad 0 @ ResourceTable
95 .quad 0 @ ExceptionTable
96 .quad 0 @ CertificationTable
97 .quad 0 @ BaseRelocationTable
Roy Franz81a0bc32015-09-23 20:17:54 -070098
99section_table:
Roy Franz81a0bc32015-09-23 20:17:54 -0700100 .ascii ".text\0\0\0"
Ard Biesheuvel609eaf02017-08-18 20:49:43 +0100101 .long _end - __efi_start @ VirtualSize
102 .long __efi_start @ VirtualAddress
103 .long _edata - __efi_start @ SizeOfRawData
104 .long __efi_start @ PointerToRawData
105 .long 0 @ PointerToRelocations
106 .long 0 @ PointerToLineNumbers
107 .short 0 @ NumberOfRelocations
108 .short 0 @ NumberOfLineNumbers
109 .long IMAGE_SCN_CNT_CODE | \
110 IMAGE_SCN_MEM_READ | \
111 IMAGE_SCN_MEM_WRITE | \
112 IMAGE_SCN_MEM_EXECUTE @ Characteristics
113
114 .set section_count, (. - section_table) / 40
Roy Franz81a0bc32015-09-23 20:17:54 -0700115
116 .align 9
117__efi_start:
118#endif
119 .endm