xref: /DragonStub/gnuefi/crt0-efi-mips64el.S (revision 2ed6486834634130fe7bc9b8803b0113767fc7c1)
1/*
2 * crt0-efi-mips64el.S - PE/COFF header for MIPS64 EFI applications
3 *
4 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
5 * Copright (C) 2017 Heiher <r@hev.cc>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice and this list of conditions, without modification.
12 * 2. The name of the author may not be used to endorse or promote products
13 *    derived from this software without specific prior written permission.
14 *
15 * Alternatively, this software may be distributed under the terms of the
16 * GNU General Public License as published by the Free Software Foundation;
17 * either version 2 of the License, or (at your option) any later version.
18 */
19
20	.section	.text.head
21
22	/*
23	 * Magic "MZ" signature for PE/COFF
24	 */
25	.globl	ImageBase
26ImageBase:
27	.ascii	"MZ"
28	.skip	58				// 'MZ' + pad + offset == 64
29	.long	pe_header - ImageBase		// Offset to the PE header.
30pe_header:
31	.ascii	"PE"
32	.short 	0
33coff_header:
34	.short	0x166				// MIPS little endian
35	.short	2				// nr_sections
36	.long	0 				// TimeDateStamp
37	.long	0				// PointerToSymbolTable
38	.long	0				// NumberOfSymbols
39	.short	section_table - optional_header	// SizeOfOptionalHeader
40	.short	0x206				// Characteristics.
41						// IMAGE_FILE_DEBUG_STRIPPED |
42						// IMAGE_FILE_EXECUTABLE_IMAGE |
43						// IMAGE_FILE_LINE_NUMS_STRIPPED
44optional_header:
45	.short	0x20b				// PE32+ format
46	.byte	0x02				// MajorLinkerVersion
47	.byte	0x14				// MinorLinkerVersion
48	.long	_edata - _start			// SizeOfCode
49	.long	0				// SizeOfInitializedData
50	.long	0				// SizeOfUninitializedData
51	.long	_start - ImageBase		// AddressOfEntryPoint
52	.long	_start - ImageBase		// BaseOfCode
53
54extra_header_fields:
55	.quad	0				// ImageBase
56	.long	0x20				// SectionAlignment
57	.long	0x8				// FileAlignment
58	.short	0				// MajorOperatingSystemVersion
59	.short	0				// MinorOperatingSystemVersion
60	.short	0				// MajorImageVersion
61	.short	0				// MinorImageVersion
62	.short	0				// MajorSubsystemVersion
63	.short	0				// MinorSubsystemVersion
64	.long	0				// Win32VersionValue
65
66	.long	_edata - ImageBase		// SizeOfImage
67
68	// Everything before the kernel image is considered part of the header
69	.long	_start - ImageBase		// SizeOfHeaders
70	.long	0				// CheckSum
71	.short	EFI_SUBSYSTEM			// Subsystem
72	.short	0				// DllCharacteristics
73	.quad	0				// SizeOfStackReserve
74	.quad	0				// SizeOfStackCommit
75	.quad	0				// SizeOfHeapReserve
76	.quad	0				// SizeOfHeapCommit
77	.long	0				// LoaderFlags
78	.long	0x6				// NumberOfRvaAndSizes
79
80	.quad	0				// ExportTable
81	.quad	0				// ImportTable
82	.quad	0				// ResourceTable
83	.quad	0				// ExceptionTable
84	.quad	0				// CertificationTable
85	.quad	0				// BaseRelocationTable
86
87	// Section table
88section_table:
89
90	/*
91	 * The EFI application loader requires a relocation section
92	 * because EFI applications must be relocatable.  This is a
93	 * dummy section as far as we are concerned.
94	 */
95	.ascii	".reloc"
96	.byte	0
97	.byte	0			// end of 0 padding of section name
98	.long	0
99	.long	0
100	.long	0			// SizeOfRawData
101	.long	0			// PointerToRawData
102	.long	0			// PointerToRelocations
103	.long	0			// PointerToLineNumbers
104	.short	0			// NumberOfRelocations
105	.short	0			// NumberOfLineNumbers
106	.long	0x42100040		// Characteristics (section flags)
107
108
109	.ascii	".text"
110	.byte	0
111	.byte	0
112	.byte	0        		// end of 0 padding of section name
113	.long	_edata - _start		// VirtualSize
114	.long	_start - ImageBase	// VirtualAddress
115	.long	_edata - _start		// SizeOfRawData
116	.long	_start - ImageBase	// PointerToRawData
117
118	.long	0		// PointerToRelocations (0 for executables)
119	.long	0		// PointerToLineNumbers (0 for executables)
120	.short	0		// NumberOfRelocations  (0 for executables)
121	.short	0		// NumberOfLineNumbers  (0 for executables)
122	.long	0xe0500020	// Characteristics (section flags)
123
124	.set		push
125	.set		noreorder
126	.align		4
127
128	.globl	_start
129	.ent	_start
130	.type	_start, @function
131_start:
132	daddiu		$sp, -32
133	sd		$ra, ($sp)
134
135	// Get pc & gp
136	.align		3
137	bal		1f
138	sd		$gp, 8($sp)
139_pc:
140	.dword		_gp
141	.dword		_DYNAMIC
142	.dword		_relocate
1431:
144	// pc in ra
145	ld		$gp, ($ra)
146	dli		$t0, _pc
147	dsubu		$gp, $t0
148	daddu		$gp, $ra
149
150	sd		$a0, 16($sp)
151	sd		$a1, 24($sp)
152
153	// a2: ImageHandle
154	move		$a2, $a0
155	// a3: SystemTable
156	move		$a3, $a1
157	// a0: ImageBase
158	dli		$t1, ImageBase - _pc
159	daddu		$a0, $ra, $t1
160	// a1: DynamicSection
161	ld		$t1, 8($ra)
162	dsubu		$t1, $t0
163	daddu		$a1, $ra, $t1
164	// call _relocate
165	ld		$t1, 16($ra)
166	dsubu		$t1, $t0
167	daddu		$t9, $ra, $t1
168	jalr		$t9
169	nop
170	bnez		$v0, 1b
171	nop
172
173	// a0: ImageHandle
174	ld		$a0, 16($sp)
175	// call efi_main
176	dla		$t9, efi_main
177	jalr		$t9
178	// a1: SystemTable
179	ld		$a1, 24($sp)
180
1811:
182	ld		$gp, 8($sp)
183	ld		$ra, ($sp)
184	jr		$ra
185	daddiu		$sp, 32
186	.end		_start
187
188	.set		pop
189