blob: cc8a115f319c9f0f9c5305331dc452324d6bb8c1 [file] [log] [blame]
Tom Rini8b0c8a12018-05-06 18:27:01 -04001/* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
Simon Glassfc03fb92016-11-07 08:47:10 -07002/*
3 * crt0-efi-arm.S - PE/COFF header for ARM EFI applications
4 *
5 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
6 *
Simon Glassfc03fb92016-11-07 08:47:10 -07007 * This file is taken and modified from the gnu-efi project.
8 */
9
Heinrich Schuchardt467fd7a2018-01-31 18:45:35 +000010#include <asm-generic/pe.h>
11
Simon Glassfc03fb92016-11-07 08:47:10 -070012 .section .text.head
13
14 /*
15 * Magic "MZ" signature for PE/COFF
16 */
17 .globl image_base
18image_base:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020019 .short IMAGE_DOS_SIGNATURE /* 'MZ' */
Simon Glassfc03fb92016-11-07 08:47:10 -070020 .skip 58 /* 'MZ' + pad + offset == 64 */
21 .long pe_header - image_base /* Offset to the PE header */
22pe_header:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020023 .long IMAGE_NT_SIGNATURE /* 'PE' */
Simon Glassfc03fb92016-11-07 08:47:10 -070024coff_header:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020025 .short IMAGE_FILE_MACHINE_THUMB /* Mixed ARM/Thumb */
Simon Glassfc03fb92016-11-07 08:47:10 -070026 .short 2 /* nr_sections */
27 .long 0 /* TimeDateStamp */
28 .long 0 /* PointerToSymbolTable */
Bin Menga15de9e2018-10-02 07:39:33 -070029 .long 0 /* NumberOfSymbols */
Simon Glassfc03fb92016-11-07 08:47:10 -070030 .short section_table - optional_header /* SizeOfOptionalHeader */
Bin Menga15de9e2018-10-02 07:39:33 -070031 /* Characteristics */
32 .short (IMAGE_FILE_EXECUTABLE_IMAGE | \
33 IMAGE_FILE_LINE_NUMS_STRIPPED | \
34 IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
35 IMAGE_FILE_32BIT_MACHINE | \
36 IMAGE_FILE_DEBUG_STRIPPED)
Simon Glassfc03fb92016-11-07 08:47:10 -070037optional_header:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020038 .short IMAGE_NT_OPTIONAL_HDR32_MAGIC /* PE32 format */
Simon Glassfc03fb92016-11-07 08:47:10 -070039 .byte 0x02 /* MajorLinkerVersion */
40 .byte 0x14 /* MinorLinkerVersion */
41 .long _edata - _start /* SizeOfCode */
42 .long 0 /* SizeOfInitializedData */
43 .long 0 /* SizeOfUninitializedData */
44 .long _start - image_base /* AddressOfEntryPoint */
45 .long _start - image_base /* BaseOfCode */
46 .long 0 /* BaseOfData */
47
48extra_header_fields:
49 .long 0 /* image_base */
50 .long 0x20 /* SectionAlignment */
51 .long 0x8 /* FileAlignment */
52 .short 0 /* MajorOperatingSystemVersion */
53 .short 0 /* MinorOperatingSystemVersion */
54 .short 0 /* MajorImageVersion */
55 .short 0 /* MinorImageVersion */
56 .short 0 /* MajorSubsystemVersion */
57 .short 0 /* MinorSubsystemVersion */
58 .long 0 /* Win32VersionValue */
59
60 .long _edata - image_base /* SizeOfImage */
61
62 /*
63 * Everything before the kernel image is considered part of the header
64 */
65 .long _start - image_base /* SizeOfHeaders */
66 .long 0 /* CheckSum */
Heinrich Schuchardt467fd7a2018-01-31 18:45:35 +000067 .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
Simon Glassfc03fb92016-11-07 08:47:10 -070068 .short 0 /* DllCharacteristics */
69 .long 0 /* SizeOfStackReserve */
70 .long 0 /* SizeOfStackCommit */
71 .long 0 /* SizeOfHeapReserve */
72 .long 0 /* SizeOfHeapCommit */
73 .long 0 /* LoaderFlags */
74 .long 0x6 /* NumberOfRvaAndSizes */
75
76 .quad 0 /* ExportTable */
77 .quad 0 /* ImportTable */
78 .quad 0 /* ResourceTable */
79 .quad 0 /* ExceptionTable */
80 .quad 0 /* CertificationTable */
81 .quad 0 /* BaseRelocationTable */
82
83section_table:
84
85 /*
86 * The EFI application loader requires a relocation section
87 * because EFI applications must be relocatable. This is a
88 * dummy section as far as we are concerned.
89 */
90 .ascii ".reloc"
91 .byte 0
92 .byte 0 /* end of 0 padding of section name */
93 .long 0
94 .long 0
95 .long 0 /* SizeOfRawData */
96 .long 0 /* PointerToRawData */
97 .long 0 /* PointerToRelocations */
98 .long 0 /* PointerToLineNumbers */
99 .short 0 /* NumberOfRelocations */
100 .short 0 /* NumberOfLineNumbers */
101 .long 0x42100040 /* Characteristics (section flags) */
102
103 .ascii ".text"
104 .byte 0
105 .byte 0
106 .byte 0 /* end of 0 padding of section name */
107 .long _edata - _start /* VirtualSize */
108 .long _start - image_base /* VirtualAddress */
109 .long _edata - _start /* SizeOfRawData */
110 .long _start - image_base /* PointerToRawData */
111
112 .long 0 /* PointerToRelocations (0 for executables) */
113 .long 0 /* PointerToLineNumbers (0 for executables) */
114 .short 0 /* NumberOfRelocations (0 for executables) */
115 .short 0 /* NumberOfLineNumbers (0 for executables) */
116 .long 0xe0500020 /* Characteristics (section flags) */
117
118_start:
119 stmfd sp!, {r0-r2, lr}
120
Simon Glassfc03fb92016-11-07 08:47:10 -0700121 adr r1, .L_DYNAMIC
122 ldr r0, [r1]
123 add r1, r0, r1
124 adr r0, image_base
125 bl _relocate
126 teq r0, #0
127 bne 0f
128
129 ldmfd sp, {r0-r1}
130 bl efi_main
131
1320: add sp, sp, #12
133 ldr pc, [sp], #4
134
135.L_DYNAMIC:
136 .word _DYNAMIC - .