blob: 3c2cef6ec73cb56a918e859ac267df7376b190ea [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 */
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +010028 .short 3 /* nr_sections */
Simon Glass61378fd2016-11-07 08:47:11 -070029 .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 | \
Heinrich Schuchardte84ab962022-12-23 02:16:03 +010037 IMAGE_FILE_LARGE_ADDRESS_AWARE | \
Bin Menga15de9e2018-10-02 07:39:33 -070038 IMAGE_FILE_DEBUG_STRIPPED)
Simon Glass61378fd2016-11-07 08:47:11 -070039optional_header:
Heinrich Schuchardtd680e9a2019-07-11 06:39:32 +020040 .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
Simon Glass61378fd2016-11-07 08:47:11 -070041 .byte 0x02 /* MajorLinkerVersion */
42 .byte 0x14 /* MinorLinkerVersion */
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +010043 .long _etext - _start /* SizeOfCode */
Simon Glass61378fd2016-11-07 08:47:11 -070044 .long 0 /* SizeOfInitializedData */
45 .long 0 /* SizeOfUninitializedData */
46 .long _start - ImageBase /* AddressOfEntryPoint */
47 .long _start - ImageBase /* BaseOfCode */
48
49extra_header_fields:
50 .quad 0 /* ImageBase */
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +010051 .long 0x1000 /* SectionAlignment */
Heinrich Schuchardtf2634792022-01-14 21:40:15 +010052 .long 0x200 /* FileAlignment */
Simon Glass61378fd2016-11-07 08:47:11 -070053 .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 - ImageBase /* SizeOfImage */
62
63 /*
64 * Everything before the kernel image is considered part of the header
65 */
66 .long _start - ImageBase /* SizeOfHeaders */
67 .long 0 /* CheckSum */
Heinrich Schuchardt467fd7a2018-01-31 18:45:35 +000068 .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
Simon Glass61378fd2016-11-07 08:47:11 -070069 .short 0 /* DllCharacteristics */
70 .quad 0 /* SizeOfStackReserve */
71 .quad 0 /* SizeOfStackCommit */
72 .quad 0 /* SizeOfHeapReserve */
73 .quad 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
84 /* Section table */
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 */
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +0100103 /* Characteristics (section flags) */
104 .long (IMAGE_SCN_MEM_READ | \
105 IMAGE_SCN_MEM_DISCARDABLE | \
106 IMAGE_SCN_CNT_INITIALIZED_DATA)
Simon Glass61378fd2016-11-07 08:47:11 -0700107
108 .ascii ".text"
109 .byte 0
110 .byte 0
111 .byte 0 /* end of 0 padding of section name */
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +0100112 .long _etext - _start /* VirtualSize */
Simon Glass61378fd2016-11-07 08:47:11 -0700113 .long _start - ImageBase /* VirtualAddress */
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +0100114 .long _etext - _start /* SizeOfRawData */
Simon Glass61378fd2016-11-07 08:47:11 -0700115 .long _start - ImageBase /* PointerToRawData */
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +0100116 .long 0 /* PointerToRelocations */
117 .long 0 /* PointerToLineNumbers */
118 .short 0 /* NumberOfRelocations */
119 .short 0 /* NumberOfLineNumbers */
120 /* Characteristics (section flags) */
121 .long (IMAGE_SCN_MEM_READ | \
122 IMAGE_SCN_MEM_EXECUTE | \
123 IMAGE_SCN_CNT_CODE)
Simon Glass61378fd2016-11-07 08:47:11 -0700124
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +0100125 .ascii ".data"
126 .byte 0
127 .byte 0
128 .byte 0 /* end of 0 padding of section name */
129 .long _data_size /* VirtualSize */
130 .long _data - ImageBase /* VirtualAddress */
131 .long _data_size /* SizeOfRawData */
132 .long _data - ImageBase /* PointerToRawData */
133 .long 0 /* PointerToRelocations */
134 .long 0 /* PointerToLineNumbers */
135 .short 0 /* NumberOfRelocations */
136 .short 0 /* NumberOfLineNumbers */
137 /* Characteristics (section flags) */
138 .long (IMAGE_SCN_MEM_WRITE | \
139 IMAGE_SCN_MEM_READ | \
140 IMAGE_SCN_CNT_INITIALIZED_DATA)
Simon Glass61378fd2016-11-07 08:47:11 -0700141
Heinrich Schuchardt7b298a52022-12-31 11:58:54 +0100142 .align 12
Simon Glass61378fd2016-11-07 08:47:11 -0700143_start:
144 stp x29, x30, [sp, #-32]!
145 mov x29, sp
146
147 stp x0, x1, [sp, #16]
Simon Glass61378fd2016-11-07 08:47:11 -0700148 adr x0, ImageBase
149 adrp x1, _DYNAMIC
150 add x1, x1, #:lo12:_DYNAMIC
151 bl _relocate
152 cbnz x0, 0f
153
154 ldp x0, x1, [sp, #16]
155 bl efi_main
156
1570: ldp x29, x30, [sp], #32
158 ret