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