crt0-efi-arm.S revision 1.1 1 /* $NetBSD: crt0-efi-arm.S,v 1.1 2018/08/16 18:17:47 jmcneill Exp $ */
2
3 /*
4 * crt0-efi-arm.S - PE/COFF header for ARM EFI applications
5 *
6 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel (at) linaro.org>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice and this list of conditions, without modification.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * Alternatively, this software may be distributed under the terms of the
17 * GNU General Public License as published by the Free Software Foundation;
18 * either version 2 of the License, or (at your option) any later version.
19 */
20
21 .section .text.head
22
23 /*
24 * Magic "MZ" signature for PE/COFF
25 */
26 .globl ImageBase
27 ImageBase:
28 .ascii "MZ"
29 .skip 58 // 'MZ' + pad + offset == 64
30 .long pe_header - ImageBase // Offset to the PE header.
31 pe_header:
32 .ascii "PE"
33 .short 0
34 coff_header:
35 .short 0x1c2 // Mixed ARM/Thumb
36 .short 2 // nr_sections
37 .long 0 // TimeDateStamp
38 .long 0 // PointerToSymbolTable
39 .long 1 // NumberOfSymbols
40 .short section_table - optional_header // SizeOfOptionalHeader
41 .short 0x306 // Characteristics.
42 // IMAGE_FILE_32BIT_MACHINE |
43 // IMAGE_FILE_DEBUG_STRIPPED |
44 // IMAGE_FILE_EXECUTABLE_IMAGE |
45 // IMAGE_FILE_LINE_NUMS_STRIPPED
46 optional_header:
47 .short 0x10b // PE32+ format
48 .byte 0x02 // MajorLinkerVersion
49 .byte 0x14 // MinorLinkerVersion
50 .long _edata - _start // SizeOfCode
51 .long 0 // SizeOfInitializedData
52 .long 0 // SizeOfUninitializedData
53 .long _start - ImageBase // AddressOfEntryPoint
54 .long _start - ImageBase // BaseOfCode
55 .long 0 // BaseOfData
56
57 extra_header_fields:
58 .long 0 // ImageBase
59 .long 0x20 // SectionAlignment
60 .long 0x8 // FileAlignment
61 .short 0 // MajorOperatingSystemVersion
62 .short 0 // MinorOperatingSystemVersion
63 .short 0 // MajorImageVersion
64 .short 0 // MinorImageVersion
65 .short 0 // MajorSubsystemVersion
66 .short 0 // MinorSubsystemVersion
67 .long 0 // Win32VersionValue
68
69 .long _edata - ImageBase // SizeOfImage
70
71 // Everything before the kernel image is considered part of the header
72 .long _start - ImageBase // SizeOfHeaders
73 .long 0 // CheckSum
74 .short EFI_SUBSYSTEM // Subsystem
75 .short 0 // DllCharacteristics
76 .long 0 // SizeOfStackReserve
77 .long 0 // SizeOfStackCommit
78 .long 0 // SizeOfHeapReserve
79 .long 0 // SizeOfHeapCommit
80 .long 0 // LoaderFlags
81 .long 0x6 // NumberOfRvaAndSizes
82
83 .quad 0 // ExportTable
84 .quad 0 // ImportTable
85 .quad 0 // ResourceTable
86 .quad 0 // ExceptionTable
87 .quad 0 // CertificationTable
88 .quad 0 // BaseRelocationTable
89
90 // Section table
91 section_table:
92
93 /*
94 * The EFI application loader requires a relocation section
95 * because EFI applications must be relocatable. This is a
96 * dummy section as far as we are concerned.
97 */
98 .ascii ".reloc"
99 .byte 0
100 .byte 0 // end of 0 padding of section name
101 .long 0
102 .long 0
103 .long 0 // SizeOfRawData
104 .long 0 // PointerToRawData
105 .long 0 // PointerToRelocations
106 .long 0 // PointerToLineNumbers
107 .short 0 // NumberOfRelocations
108 .short 0 // NumberOfLineNumbers
109 .long 0x42100040 // Characteristics (section flags)
110
111
112 .ascii ".text"
113 .byte 0
114 .byte 0
115 .byte 0 // end of 0 padding of section name
116 .long _edata - _start // VirtualSize
117 .long _start - ImageBase // VirtualAddress
118 .long _edata - _start // SizeOfRawData
119 .long _start - ImageBase // PointerToRawData
120
121 .long 0 // PointerToRelocations (0 for executables)
122 .long 0 // PointerToLineNumbers (0 for executables)
123 .short 0 // NumberOfRelocations (0 for executables)
124 .short 0 // NumberOfLineNumbers (0 for executables)
125 .long 0xe0500020 // Characteristics (section flags)
126
127 _start:
128 stmfd sp!, {r0-r2, lr}
129
130 mov r2, r0
131 mov r3, r1
132 adr r1, .L_DYNAMIC
133 ldr r0, [r1]
134 add r1, r0, r1
135 adr r0, ImageBase
136 bl _relocate
137 teq r0, #0
138 bne 0f
139
140 ldmfd sp, {r0-r1}
141 bl efi_main
142
143 0: add sp, sp, #12
144 ldr pc, [sp], #4
145
146 .L_DYNAMIC:
147 .word _DYNAMIC - .
148