xref: /DragonStub/gnuefi/crt0-efi-aarch64.S (revision 9485c65f6d28b71ff697849c1c8d47fd077ccd07)
1/*
2 * crt0-efi-aarch64.S - PE/COFF header for AArch64 EFI applications
3 *
4 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice and this list of conditions, without modification.
11 * 2. The name of the author may not be used to endorse or promote products
12 *    derived from this software without specific prior written permission.
13 *
14 * Alternatively, this software may be distributed under the terms of the
15 * GNU General Public License as published by the Free Software Foundation;
16 * either version 2 of the License, or (at your option) any later version.
17 */
18
19	.section	.text.head
20
21	/*
22	 * Magic "MZ" signature for PE/COFF
23	 */
24	.globl	ImageBase
25ImageBase:
26	.ascii	"MZ"
27	.skip	58				// 'MZ' + pad + offset == 64
28	.long	pe_header - ImageBase		// Offset to the PE header.
29pe_header:
30	.ascii	"PE"
31	.short 	0
32coff_header:
33	.short	0xaa64				// AArch64
34	.short	2				// nr_sections
35	.long	0 				// TimeDateStamp
36	.long	0				// PointerToSymbolTable
37	.long	1				// NumberOfSymbols
38	.short	section_table - optional_header	// SizeOfOptionalHeader
39	.short	0x206				// Characteristics.
40						// IMAGE_FILE_DEBUG_STRIPPED |
41						// IMAGE_FILE_EXECUTABLE_IMAGE |
42						// IMAGE_FILE_LINE_NUMS_STRIPPED
43optional_header:
44	.short	0x20b				// PE32+ format
45	.byte	0x02				// MajorLinkerVersion
46	.byte	0x14				// MinorLinkerVersion
47	.long	_data - _start			// SizeOfCode
48	.long	_data_size			// SizeOfInitializedData
49	.long	0				// SizeOfUninitializedData
50	.long	_start - ImageBase		// AddressOfEntryPoint
51	.long	_start - ImageBase		// BaseOfCode
52
53extra_header_fields:
54	.quad	0				// ImageBase
55	.long	0x1000				// SectionAlignment
56	.long	0x200				// FileAlignment
57	.short	0				// MajorOperatingSystemVersion
58	.short	0				// MinorOperatingSystemVersion
59	.short	0				// MajorImageVersion
60	.short	0				// MinorImageVersion
61	.short	0				// MajorSubsystemVersion
62	.short	0				// MinorSubsystemVersion
63	.long	0				// Win32VersionValue
64
65	.long	_edata - ImageBase		// SizeOfImage
66
67	// Everything before the kernel image is considered part of the header
68	.long	_start - ImageBase		// SizeOfHeaders
69	.long	0				// CheckSum
70	.short	EFI_SUBSYSTEM			// Subsystem
71	.short	0				// DllCharacteristics
72	.quad	0				// SizeOfStackReserve
73	.quad	0				// SizeOfStackCommit
74	.quad	0				// SizeOfHeapReserve
75	.quad	0				// SizeOfHeapCommit
76	.long	0				// LoaderFlags
77	.long	0x6				// NumberOfRvaAndSizes
78
79	.quad	0				// ExportTable
80	.quad	0				// ImportTable
81	.quad	0				// ResourceTable
82	.quad	0				// ExceptionTable
83	.quad	0				// CertificationTable
84	.quad	0				// BaseRelocationTable
85
86	// Section table
87section_table:
88	.ascii	".text\0\0\0"
89	.long	_data - _start		// VirtualSize
90	.long	_start - ImageBase	// VirtualAddress
91	.long	_data - _start		// SizeOfRawData
92	.long	_start - ImageBase	// PointerToRawData
93
94	.long	0		// PointerToRelocations (0 for executables)
95	.long	0		// PointerToLineNumbers (0 for executables)
96	.short	0		// NumberOfRelocations  (0 for executables)
97	.short	0		// NumberOfLineNumbers  (0 for executables)
98	.long	0x60000020	// Characteristics (section flags)
99
100	.ascii	".data\0\0\0"
101	.long	_data_size		// VirtualSize
102	.long	_data - ImageBase	// VirtualAddress
103	.long	_data_size		// SizeOfRawData
104	.long	_data - ImageBase	// PointerToRawData
105
106	.long	0		// PointerToRelocations (0 for executables)
107	.long	0		// PointerToLineNumbers (0 for executables)
108	.short	0		// NumberOfRelocations  (0 for executables)
109	.short	0		// NumberOfLineNumbers  (0 for executables)
110	.long	0xc0000040	// Characteristics (section flags)
111
112	.align		12
113_start:
114	stp		x29, x30, [sp, #-32]!
115	mov		x29, sp
116
117	stp		x0, x1, [sp, #16]
118	mov		x2, x0
119	mov		x3, x1
120	adr		x0, ImageBase
121	adrp		x1, _DYNAMIC
122	add		x1, x1, #:lo12:_DYNAMIC
123	bl		_relocate
124	cbnz		x0, 0f
125
126	ldp		x0, x1, [sp, #16]
127	bl		efi_main
128
1290:	ldp		x29, x30, [sp], #32
130	ret
131