10f9c15feSbmeng@tinylab.org/* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */ 2b95f138fSHeinrich Schuchardt/* 3b95f138fSHeinrich Schuchardt * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 4b95f138fSHeinrich Schuchardt * Copright (C) 2018 Alexander Graf <agraf@suse.de> 5b95f138fSHeinrich Schuchardt * 6b95f138fSHeinrich Schuchardt * Redistribution and use in source and binary forms, with or without 7b95f138fSHeinrich Schuchardt * modification, are permitted provided that the following conditions 8b95f138fSHeinrich Schuchardt * are met: 9b95f138fSHeinrich Schuchardt * 1. Redistributions of source code must retain the above copyright 10b95f138fSHeinrich Schuchardt * notice and this list of conditions, without modification. 11b95f138fSHeinrich Schuchardt * 2. The name of the author may not be used to endorse or promote products 12b95f138fSHeinrich Schuchardt * derived from this software without specific prior written permission. 13b95f138fSHeinrich Schuchardt * 14b95f138fSHeinrich Schuchardt * Alternatively, this software may be distributed under the terms of the 15b95f138fSHeinrich Schuchardt * GNU General Public License as published by the Free Software Foundation; 16b95f138fSHeinrich Schuchardt * either version 2 of the License, or (at your option) any later version. 17b95f138fSHeinrich Schuchardt */ 18b95f138fSHeinrich Schuchardt 19b95f138fSHeinrich Schuchardt#ifndef EFI_SUBSYSTEM 20b95f138fSHeinrich Schuchardt#define EFI_SUBSYSTEM 10 21b95f138fSHeinrich Schuchardt#endif 22b95f138fSHeinrich Schuchardt 23b95f138fSHeinrich Schuchardt .section .text.head 24b95f138fSHeinrich Schuchardt 25b95f138fSHeinrich Schuchardt /* 26b95f138fSHeinrich Schuchardt * Magic "MZ" signature for PE/COFF 27b95f138fSHeinrich Schuchardt */ 28b95f138fSHeinrich Schuchardt .globl ImageBase 29b95f138fSHeinrich SchuchardtImageBase: 30b95f138fSHeinrich Schuchardt .ascii "MZ" 31b95f138fSHeinrich Schuchardt .skip 58 // 'MZ' + pad + offset == 64 329e6cb215SCallum Farmer .4byte pe_header - ImageBase // Offset to the PE header. 33b95f138fSHeinrich Schuchardtpe_header: 34b95f138fSHeinrich Schuchardt .ascii "PE" 359e6cb215SCallum Farmer .2byte 0 36b95f138fSHeinrich Schuchardtcoff_header: 379e6cb215SCallum Farmer .2byte 0x5064 // riscv64 389e6cb215SCallum Farmer .2byte 2 // nr_sections 399e6cb215SCallum Farmer .4byte 0 // TimeDateStamp 409e6cb215SCallum Farmer .4byte 0 // PointerToSymbolTable 419e6cb215SCallum Farmer .4byte 0 // NumberOfSymbols 429e6cb215SCallum Farmer .2byte section_table - optional_header // SizeOfOptionalHeader 439e6cb215SCallum Farmer .2byte 0x206 // Characteristics. 44b95f138fSHeinrich Schuchardt // IMAGE_FILE_DEBUG_STRIPPED | 45b95f138fSHeinrich Schuchardt // IMAGE_FILE_EXECUTABLE_IMAGE | 46b95f138fSHeinrich Schuchardt // IMAGE_FILE_LINE_NUMS_STRIPPED 47b95f138fSHeinrich Schuchardtoptional_header: 489e6cb215SCallum Farmer .2byte 0x20b // PE32+ format 49b95f138fSHeinrich Schuchardt .byte 0x02 // MajorLinkerVersion 50b95f138fSHeinrich Schuchardt .byte 0x14 // MinorLinkerVersion 519e6cb215SCallum Farmer .4byte _data - _start // SizeOfCode 521e0f0df5SCallum Farmer .4byte _edata - _data // SizeOfInitializedData 539e6cb215SCallum Farmer .4byte 0 // SizeOfUninitializedData 549e6cb215SCallum Farmer .4byte _start - ImageBase // AddressOfEntryPoint 559e6cb215SCallum Farmer .4byte _start - ImageBase // BaseOfCode 56b95f138fSHeinrich Schuchardt 57b95f138fSHeinrich Schuchardtextra_header_fields: 589e6cb215SCallum Farmer .8byte 0 // ImageBase 599e6cb215SCallum Farmer .4byte 0x1000 // SectionAlignment 609e6cb215SCallum Farmer .4byte 0x200 // FileAlignment 619e6cb215SCallum Farmer .2byte 0 // MajorOperatingSystemVersion 629e6cb215SCallum Farmer .2byte 0 // MinorOperatingSystemVersion 639e6cb215SCallum Farmer .2byte 0 // MajorImageVersion 649e6cb215SCallum Farmer .2byte 0 // MinorImageVersion 659e6cb215SCallum Farmer .2byte 0 // MajorSubsystemVersion 669e6cb215SCallum Farmer .2byte 0 // MinorSubsystemVersion 679e6cb215SCallum Farmer .4byte 0 // Win32VersionValue 68b95f138fSHeinrich Schuchardt 699e6cb215SCallum Farmer .4byte _edata - ImageBase // SizeOfImage 70b95f138fSHeinrich Schuchardt 71b95f138fSHeinrich Schuchardt // Everything before the kernel image is considered part of the header 729e6cb215SCallum Farmer .4byte _start - ImageBase // SizeOfHeaders 739e6cb215SCallum Farmer .4byte 0 // CheckSum 749e6cb215SCallum Farmer .2byte EFI_SUBSYSTEM // Subsystem 759e6cb215SCallum Farmer .2byte 0 // DllCharacteristics 769e6cb215SCallum Farmer .8byte 0 // SizeOfStackReserve 779e6cb215SCallum Farmer .8byte 0 // SizeOfStackCommit 789e6cb215SCallum Farmer .8byte 0 // SizeOfHeapReserve 799e6cb215SCallum Farmer .8byte 0 // SizeOfHeapCommit 809e6cb215SCallum Farmer .4byte 0 // LoaderFlags 81039ca9d9SCallum Farmer .4byte 0x10 // NumberOfRvaAndSizes 82b95f138fSHeinrich Schuchardt 839e6cb215SCallum Farmer .8byte 0 // ExportTable 849e6cb215SCallum Farmer .8byte 0 // ImportTable 859e6cb215SCallum Farmer .8byte 0 // ResourceTable 869e6cb215SCallum Farmer .8byte 0 // ExceptionTable 879e6cb215SCallum Farmer .8byte 0 // CertificationTable 889e6cb215SCallum Farmer .8byte 0 // BaseRelocationTable 89039ca9d9SCallum Farmer .8byte 0 // Debug 90039ca9d9SCallum Farmer .8byte 0 // Architecture 91039ca9d9SCallum Farmer .8byte 0 // Global Ptr 92039ca9d9SCallum Farmer .8byte 0 // TLS Table 93039ca9d9SCallum Farmer .8byte 0 // Load Config Table 94039ca9d9SCallum Farmer .8byte 0 // Bound Import 95039ca9d9SCallum Farmer .8byte 0 // IAT 96039ca9d9SCallum Farmer .8byte 0 // Delay Import Descriptor 97039ca9d9SCallum Farmer .8byte 0 // CLR Runtime Header 98039ca9d9SCallum Farmer .8byte 0 // Reserved, must be zero 99b95f138fSHeinrich Schuchardt 100b95f138fSHeinrich Schuchardt // Section table 101b95f138fSHeinrich Schuchardtsection_table: 102b95f138fSHeinrich Schuchardt /* 103b95f138fSHeinrich Schuchardt * The EFI application loader requires a relocation section 104b95f138fSHeinrich Schuchardt * because EFI applications must be relocatable. This is a 105b95f138fSHeinrich Schuchardt * dummy section as far as we are concerned. 106b95f138fSHeinrich Schuchardt */ 107b95f138fSHeinrich Schuchardt .ascii ".reloc\0\0" 1089e6cb215SCallum Farmer .4byte 0 1099e6cb215SCallum Farmer .4byte 0 1109e6cb215SCallum Farmer .4byte 0 // SizeOfRawData 1119e6cb215SCallum Farmer .4byte 0 // PointerToRawData 1129e6cb215SCallum Farmer .4byte 0 // PointerToRelocations 1139e6cb215SCallum Farmer .4byte 0 // PointerToLineNumbers 1149e6cb215SCallum Farmer .2byte 0 // NumberOfRelocations 1159e6cb215SCallum Farmer .2byte 0 // NumberOfLineNumbers 1169e6cb215SCallum Farmer .4byte 0x42100040 // Characteristics (section flags) 117b95f138fSHeinrich Schuchardt 118b95f138fSHeinrich Schuchardt .ascii ".text\0\0\0" 1199e6cb215SCallum Farmer .4byte _edata - _start // VirtualSize 1209e6cb215SCallum Farmer .4byte _start - ImageBase // VirtualAddress 1219e6cb215SCallum Farmer .4byte _edata - _start // SizeOfRawData 1229e6cb215SCallum Farmer .4byte _start - ImageBase // PointerToRawData 123b95f138fSHeinrich Schuchardt 1249e6cb215SCallum Farmer .4byte 0 // PointerToRelocations (0 for executables) 1259e6cb215SCallum Farmer .4byte 0 // PointerToLineNumbers (0 for executables) 1269e6cb215SCallum Farmer .2byte 0 // NumberOfRelocations (0 for executables) 1279e6cb215SCallum Farmer .2byte 0 // NumberOfLineNumbers (0 for executables) 1289e6cb215SCallum Farmer .4byte 0xe0500020 // Characteristics (section flags) 129b95f138fSHeinrich Schuchardt 130b95f138fSHeinrich Schuchardt .align 12 131b95f138fSHeinrich Schuchardt .globl _start 132*64027ee9SCallum Farmer .type _start,%function 133b95f138fSHeinrich Schuchardt_start: 134b95f138fSHeinrich Schuchardt addi sp, sp, -24 135b95f138fSHeinrich Schuchardt sd a0, 0(sp) 136b95f138fSHeinrich Schuchardt sd a1, 8(sp) 137b95f138fSHeinrich Schuchardt sd ra, 16(sp) 138b95f138fSHeinrich Schuchardt lla a0, ImageBase 139b95f138fSHeinrich Schuchardt lla a1, _DYNAMIC 140b95f138fSHeinrich Schuchardt call _relocate 141b95f138fSHeinrich Schuchardt bne a0, zero, 0f 142b95f138fSHeinrich Schuchardt ld a1, 8(sp) 143b95f138fSHeinrich Schuchardt ld a0, 0(sp) 144d96b34e0SCallum Farmer call _entry 145b95f138fSHeinrich Schuchardt ld ra, 16(sp) 146b95f138fSHeinrich Schuchardt0: addi sp, sp, 24 147b95f138fSHeinrich Schuchardt ret 148803b49c4SSergei Trofimovich 149803b49c4SSergei Trofimovich#if defined(__ELF__) && defined(__linux__) 150803b49c4SSergei Trofimovich .section .note.GNU-stack,"",%progbits 151803b49c4SSergei Trofimovich#endif 152