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