blob: 492195f7654f4da5ea9d463585559cf4669b7c30 [file] [log] [blame]
Tom Rini8b0c8a12018-05-06 18:27:01 -04001/* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
Simon Glass61378fd2016-11-07 08:47:11 -07002/*
3 * crt0-efi-aarch64.S - PE/COFF header for aarch64 EFI applications
4 *
5 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
6 *
Simon Glass61378fd2016-11-07 08:47:11 -07007 *
8 * This file is taken and modified from the gnu-efi project.
9 */
10
Heinrich Schuchardt467fd7a2018-01-31 18:45:35 +000011#include <asm-generic/pe.h>
12
Simon Glass61378fd2016-11-07 08:47:11 -070013 .section .text.head
14
15 /*
16 * Magic "MZ" signature for PE/COFF
17 */
18 .globl ImageBase
19ImageBase:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020020 .short IMAGE_DOS_SIGNATURE /* 'MZ' */
Heinrich Schuchardtd6bc9ec2021-01-29 12:35:51 +010021 .skip 54 /* 'MZ' + pad + offset == 64 */
22 .long LINUX_ARM64_MAGIC /* For GRUB's linux command */
Simon Glass61378fd2016-11-07 08:47:11 -070023 .long pe_header - ImageBase /* Offset to the PE header */
24pe_header:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020025 .long IMAGE_NT_SIGNATURE /* 'PE' */
Simon Glass61378fd2016-11-07 08:47:11 -070026coff_header:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020027 .short IMAGE_FILE_MACHINE_ARM64 /* AArch64 */
Simon Glass61378fd2016-11-07 08:47:11 -070028 .short 2 /* nr_sections */
29 .long 0 /* TimeDateStamp */
30 .long 0 /* PointerToSymbolTable */
Bin Menga15de9e2018-10-02 07:39:33 -070031 .long 0 /* NumberOfSymbols */
Simon Glass61378fd2016-11-07 08:47:11 -070032 .short section_table - optional_header /* SizeOfOptionalHeader */
Bin Menga15de9e2018-10-02 07:39:33 -070033 /* Characteristics */
34 .short (IMAGE_FILE_EXECUTABLE_IMAGE | \
35 IMAGE_FILE_LINE_NUMS_STRIPPED | \
36 IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
37 IMAGE_FILE_DEBUG_STRIPPED)
Simon Glass61378fd2016-11-07 08:47:11 -070038optional_header:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020039 .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
Simon Glass61378fd2016-11-07 08:47:11 -070040 .byte 0x02 /* MajorLinkerVersion */
41 .byte 0x14 /* MinorLinkerVersion */
42 .long _edata - _start /* SizeOfCode */
43 .long 0 /* SizeOfInitializedData */
44 .long 0 /* SizeOfUninitializedData */
45 .long _start - ImageBase /* AddressOfEntryPoint */
46 .long _start - ImageBase /* BaseOfCode */
47
48extra_header_fields:
49 .quad 0 /* ImageBase */
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 - ImageBase /* SizeOfImage */
61
62 /*
63 * Everything before the kernel image is considered part of the header
64 */
65 .long _start - ImageBase /* SizeOfHeaders */
66 .long 0 /* CheckSum */
Heinrich Schuchardt467fd7a2018-01-31 18:45:35 +000067 .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
Simon Glass61378fd2016-11-07 08:47:11 -070068 .short 0 /* DllCharacteristics */
69 .quad 0 /* SizeOfStackReserve */
70 .quad 0 /* SizeOfStackCommit */
71 .quad 0 /* SizeOfHeapReserve */
72 .quad 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
83 /* Section table */
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
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 - ImageBase /* VirtualAddress */
111 .long _edata - _start /* SizeOfRawData */
112 .long _start - ImageBase /* 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 stp x29, x30, [sp, #-32]!
122 mov x29, sp
123
124 stp x0, x1, [sp, #16]
Simon Glass61378fd2016-11-07 08:47:11 -0700125 adr x0, ImageBase
126 adrp x1, _DYNAMIC
127 add x1, x1, #:lo12:_DYNAMIC
128 bl _relocate
129 cbnz x0, 0f
130
131 ldp x0, x1, [sp, #16]
132 bl efi_main
133
1340: ldp x29, x30, [sp], #32
135 ret