Make.rules incomplete/wrong; make -r failure
[syslinux-gnu-efi.git] / gnuefi / crt0-efi-arm.S
blobc5bb6d482dac08685d5b95f8eb3f47b1527cd777
1 /*
2  * crt0-efi-arm.S - PE/COFF header for ARM 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  */
19         .section        .text.head
21         /*
22          * Magic "MZ" signature for PE/COFF
23          */
24         .globl  ImageBase
25 ImageBase:
26         .ascii  "MZ"
27         .skip   58                              // 'MZ' + pad + offset == 64
28         .long   pe_header - ImageBase           // Offset to the PE header.
29 pe_header:
30         .ascii  "PE"
31         .short  0
32 coff_header:
33         .short  0x1c2                           // Mixed ARM/Thumb
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  0x306                           // Characteristics.
40                                                 // IMAGE_FILE_32BIT_MACHINE |
41                                                 // IMAGE_FILE_DEBUG_STRIPPED |
42                                                 // IMAGE_FILE_EXECUTABLE_IMAGE |
43                                                 // IMAGE_FILE_LINE_NUMS_STRIPPED
44 optional_header:
45         .short  0x10b                           // 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         .long   0                               // BaseOfData
55 extra_header_fields:
56         .long   0                               // ImageBase
57         .long   0x20                            // SectionAlignment
58         .long   0x8                             // FileAlignment
59         .short  0                               // MajorOperatingSystemVersion
60         .short  0                               // MinorOperatingSystemVersion
61         .short  0                               // MajorImageVersion
62         .short  0                               // MinorImageVersion
63         .short  0                               // MajorSubsystemVersion
64         .short  0                               // MinorSubsystemVersion
65         .long   0                               // Win32VersionValue
67         .long   _edata - ImageBase              // SizeOfImage
69         // Everything before the kernel image is considered part of the header
70         .long   _start - ImageBase              // SizeOfHeaders
71         .long   0                               // CheckSum
72         .short  EFI_SUBSYSTEM                   // Subsystem
73         .short  0                               // DllCharacteristics
74         .long   0                               // SizeOfStackReserve
75         .long   0                               // SizeOfStackCommit
76         .long   0                               // SizeOfHeapReserve
77         .long   0                               // SizeOfHeapCommit
78         .long   0                               // LoaderFlags
79         .long   0x6                             // NumberOfRvaAndSizes
81         .quad   0                               // ExportTable
82         .quad   0                               // ImportTable
83         .quad   0                               // ResourceTable
84         .quad   0                               // ExceptionTable
85         .quad   0                               // CertificationTable
86         .quad   0                               // BaseRelocationTable
88         // Section table
89 section_table:
91         /*
92          * The EFI application loader requires a relocation section
93          * because EFI applications must be relocatable.  This is a
94          * dummy section as far as we are concerned.
95          */
96         .ascii  ".reloc"
97         .byte   0
98         .byte   0                       // end of 0 padding of section name
99         .long   0
100         .long   0
101         .long   0                       // SizeOfRawData
102         .long   0                       // PointerToRawData
103         .long   0                       // PointerToRelocations
104         .long   0                       // PointerToLineNumbers
105         .short  0                       // NumberOfRelocations
106         .short  0                       // NumberOfLineNumbers
107         .long   0x42100040              // Characteristics (section flags)
110         .ascii  ".text"
111         .byte   0
112         .byte   0
113         .byte   0                       // end of 0 padding of section name
114         .long   _edata - _start         // VirtualSize
115         .long   _start - ImageBase      // VirtualAddress
116         .long   _edata - _start         // SizeOfRawData
117         .long   _start - ImageBase      // PointerToRawData
119         .long   0               // PointerToRelocations (0 for executables)
120         .long   0               // PointerToLineNumbers (0 for executables)
121         .short  0               // NumberOfRelocations  (0 for executables)
122         .short  0               // NumberOfLineNumbers  (0 for executables)
123         .long   0xe0500020      // Characteristics (section flags)
125 _start:
126         stmfd           sp!, {r0-r2, lr}
128         mov             r2, r0
129         mov             r3, r1
130         adr             r1, .L_DYNAMIC
131         ldr             r0, [r1]
132         add             r1, r0, r1
133         adr             r0, ImageBase
134         bl              _relocate
135         teq             r0, #0
136         bne             0f
138         ldmfd           sp, {r0-r1}
139         bl              efi_main
141 0:      add             sp, sp, #12
142         ldr             pc, [sp], #4
144 .L_DYNAMIC:
145         .word           _DYNAMIC - .