blob: b5dfd4e381955a105fedd55b4a7e234ea4035a3e [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 */
Heinrich Schuchardt7e9a00e2024-02-26 22:24:08 +010026 .short 3 /* nr_sections */
Simon Glassfc03fb92016-11-07 08:47:10 -070027 .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 */
Heinrich Schuchardtf2634792022-01-14 21:40:15 +010050 .long 0x200 /* SectionAlignment */
51 .long 0x200 /* FileAlignment */
Simon Glassfc03fb92016-11-07 08:47:10 -070052 .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 */
Heinrich Schuchardt299425d2024-02-14 21:43:21 +010068#if CONFIG_VENDOR_EFI
Simon Glassfc03fb92016-11-07 08:47:10 -070069 .short 0 /* DllCharacteristics */
Heinrich Schuchardt299425d2024-02-14 21:43:21 +010070#else
71 .short IMAGE_DLLCHARACTERISTICS_NX_COMPAT
72#endif
Simon Glassfc03fb92016-11-07 08:47:10 -070073 .long 0 /* SizeOfStackReserve */
74 .long 0 /* SizeOfStackCommit */
75 .long 0 /* SizeOfHeapReserve */
76 .long 0 /* SizeOfHeapCommit */
77 .long 0 /* LoaderFlags */
78 .long 0x6 /* NumberOfRvaAndSizes */
79
80 .quad 0 /* ExportTable */
81 .quad 0 /* ImportTable */
82 .quad 0 /* ResourceTable */
83 .quad 0 /* ExceptionTable */
84 .quad 0 /* CertificationTable */
85 .quad 0 /* BaseRelocationTable */
86
87section_table:
88
89 /*
90 * The EFI application loader requires a relocation section
91 * because EFI applications must be relocatable. This is a
92 * dummy section as far as we are concerned.
93 */
94 .ascii ".reloc"
95 .byte 0
96 .byte 0 /* end of 0 padding of section name */
97 .long 0
98 .long 0
99 .long 0 /* SizeOfRawData */
100 .long 0 /* PointerToRawData */
101 .long 0 /* PointerToRelocations */
102 .long 0 /* PointerToLineNumbers */
103 .short 0 /* NumberOfRelocations */
104 .short 0 /* NumberOfLineNumbers */
Heinrich Schuchardt7e9a00e2024-02-26 22:24:08 +0100105 /* Characteristics (section flags) */
106 .long (IMAGE_SCN_MEM_READ | \
107 IMAGE_SCN_MEM_DISCARDABLE | \
108 IMAGE_SCN_CNT_INITIALIZED_DATA)
Simon Glassfc03fb92016-11-07 08:47:10 -0700109
110 .ascii ".text"
111 .byte 0
112 .byte 0
113 .byte 0 /* end of 0 padding of section name */
Heinrich Schuchardt7e9a00e2024-02-26 22:24:08 +0100114 .long _text_size /* VirtualSize */
Simon Glassfc03fb92016-11-07 08:47:10 -0700115 .long _start - image_base /* VirtualAddress */
Heinrich Schuchardt7e9a00e2024-02-26 22:24:08 +0100116 .long _text_size /* SizeOfRawData */
Simon Glassfc03fb92016-11-07 08:47:10 -0700117 .long _start - image_base /* PointerToRawData */
Heinrich Schuchardt7e9a00e2024-02-26 22:24:08 +0100118 .long 0 /* PointerToRelocations */
119 .long 0 /* PointerToLineNumbers */
120 .short 0 /* NumberOfRelocations */
121 .short 0 /* NumberOfLineNumbers */
122 /* Characteristics (section flags) */
123 .long (IMAGE_SCN_MEM_READ | \
124 IMAGE_SCN_MEM_EXECUTE | \
125 IMAGE_SCN_CNT_CODE)
Simon Glassfc03fb92016-11-07 08:47:10 -0700126
Heinrich Schuchardt7e9a00e2024-02-26 22:24:08 +0100127 .ascii ".data"
128 .byte 0
129 .byte 0
130 .byte 0 /* end of 0 padding of section name */
131 .long _data_size /* VirtualSize */
132 .long _data - image_base /* VirtualAddress */
133 .long _data_size /* SizeOfRawData */
134 .long _data - image_base /* PointerToRawData */
135 .long 0 /* PointerToRelocations */
136 .long 0 /* PointerToLineNumbers */
137 .short 0 /* NumberOfRelocations */
138 .short 0 /* NumberOfLineNumbers */
139 /* Characteristics (section flags) */
140 .long (IMAGE_SCN_MEM_WRITE | \
141 IMAGE_SCN_MEM_READ | \
142 IMAGE_SCN_CNT_INITIALIZED_DATA)
Simon Glassfc03fb92016-11-07 08:47:10 -0700143
Heinrich Schuchardt09028632024-02-26 22:24:07 +0100144 .align 12
Simon Glassfc03fb92016-11-07 08:47:10 -0700145_start:
146 stmfd sp!, {r0-r2, lr}
147
Simon Glassfc03fb92016-11-07 08:47:10 -0700148 adr r1, .L_DYNAMIC
149 ldr r0, [r1]
150 add r1, r0, r1
Heinrich Schuchardt09028632024-02-26 22:24:07 +0100151 adrl r0, image_base
Simon Glassfc03fb92016-11-07 08:47:10 -0700152 bl _relocate
153 teq r0, #0
154 bne 0f
155
156 ldmfd sp, {r0-r1}
157 bl efi_main
158
1590: add sp, sp, #12
160 ldr pc, [sp], #4
161
162.L_DYNAMIC:
163 .word _DYNAMIC - .