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