1b95f138fSHeinrich Schuchardt/* SPDX-License-Identifier: GPL-2.0+ */ 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 32b95f138fSHeinrich Schuchardt .long pe_header - ImageBase // Offset to the PE header. 33b95f138fSHeinrich Schuchardtpe_header: 34b95f138fSHeinrich Schuchardt .ascii "PE" 35b95f138fSHeinrich Schuchardt .short 0 36b95f138fSHeinrich Schuchardtcoff_header: 37b95f138fSHeinrich Schuchardt .short 0x5064 // riscv64 38b95f138fSHeinrich Schuchardt .short 2 // nr_sections 39b95f138fSHeinrich Schuchardt .long 0 // TimeDateStamp 40b95f138fSHeinrich Schuchardt .long 0 // PointerToSymbolTable 4131a6aab4SAlfonso Sánchez-Beato .long 0 // NumberOfSymbols 42b95f138fSHeinrich Schuchardt .short section_table - optional_header // SizeOfOptionalHeader 43b95f138fSHeinrich Schuchardt .short 0x206 // Characteristics. 44b95f138fSHeinrich Schuchardt // IMAGE_FILE_DEBUG_STRIPPED | 45b95f138fSHeinrich Schuchardt // IMAGE_FILE_EXECUTABLE_IMAGE | 46b95f138fSHeinrich Schuchardt // IMAGE_FILE_LINE_NUMS_STRIPPED 47b95f138fSHeinrich Schuchardtoptional_header: 48b95f138fSHeinrich Schuchardt .short 0x20b // PE32+ format 49b95f138fSHeinrich Schuchardt .byte 0x02 // MajorLinkerVersion 50b95f138fSHeinrich Schuchardt .byte 0x14 // MinorLinkerVersion 51b95f138fSHeinrich Schuchardt .long _data - _start // SizeOfCode 52b95f138fSHeinrich Schuchardt .long _data_size // SizeOfInitializedData 53b95f138fSHeinrich Schuchardt .long 0 // SizeOfUninitializedData 54b95f138fSHeinrich Schuchardt .long _start - ImageBase // AddressOfEntryPoint 55b95f138fSHeinrich Schuchardt .long _start - ImageBase // BaseOfCode 56b95f138fSHeinrich Schuchardt 57b95f138fSHeinrich Schuchardtextra_header_fields: 58b95f138fSHeinrich Schuchardt .quad 0 // ImageBase 59b95f138fSHeinrich Schuchardt .long 0x1000 // SectionAlignment 60b95f138fSHeinrich Schuchardt .long 0x200 // FileAlignment 61b95f138fSHeinrich Schuchardt .short 0 // MajorOperatingSystemVersion 62b95f138fSHeinrich Schuchardt .short 0 // MinorOperatingSystemVersion 63b95f138fSHeinrich Schuchardt .short 0 // MajorImageVersion 64b95f138fSHeinrich Schuchardt .short 0 // MinorImageVersion 65b95f138fSHeinrich Schuchardt .short 0 // MajorSubsystemVersion 66b95f138fSHeinrich Schuchardt .short 0 // MinorSubsystemVersion 67b95f138fSHeinrich Schuchardt .long 0 // Win32VersionValue 68b95f138fSHeinrich Schuchardt 69b95f138fSHeinrich Schuchardt .long _edata - ImageBase // SizeOfImage 70b95f138fSHeinrich Schuchardt 71b95f138fSHeinrich Schuchardt // Everything before the kernel image is considered part of the header 72b95f138fSHeinrich Schuchardt .long _start - ImageBase // SizeOfHeaders 73b95f138fSHeinrich Schuchardt .long 0 // CheckSum 74b95f138fSHeinrich Schuchardt .short EFI_SUBSYSTEM // Subsystem 75b95f138fSHeinrich Schuchardt .short 0 // DllCharacteristics 76b95f138fSHeinrich Schuchardt .quad 0 // SizeOfStackReserve 77b95f138fSHeinrich Schuchardt .quad 0 // SizeOfStackCommit 78b95f138fSHeinrich Schuchardt .quad 0 // SizeOfHeapReserve 79b95f138fSHeinrich Schuchardt .quad 0 // SizeOfHeapCommit 80b95f138fSHeinrich Schuchardt .long 0 // LoaderFlags 81b95f138fSHeinrich Schuchardt .long 0x6 // NumberOfRvaAndSizes 82b95f138fSHeinrich Schuchardt 83b95f138fSHeinrich Schuchardt .quad 0 // ExportTable 84b95f138fSHeinrich Schuchardt .quad 0 // ImportTable 85b95f138fSHeinrich Schuchardt .quad 0 // ResourceTable 86b95f138fSHeinrich Schuchardt .quad 0 // ExceptionTable 87b95f138fSHeinrich Schuchardt .quad 0 // CertificationTable 88b95f138fSHeinrich Schuchardt .quad 0 // BaseRelocationTable 89b95f138fSHeinrich Schuchardt 90b95f138fSHeinrich Schuchardt // Section table 91b95f138fSHeinrich Schuchardtsection_table: 92b95f138fSHeinrich Schuchardt /* 93b95f138fSHeinrich Schuchardt * The EFI application loader requires a relocation section 94b95f138fSHeinrich Schuchardt * because EFI applications must be relocatable. This is a 95b95f138fSHeinrich Schuchardt * dummy section as far as we are concerned. 96b95f138fSHeinrich Schuchardt */ 97b95f138fSHeinrich Schuchardt .ascii ".reloc\0\0" 98b95f138fSHeinrich Schuchardt .long 0 99b95f138fSHeinrich Schuchardt .long 0 100b95f138fSHeinrich Schuchardt .long 0 // SizeOfRawData 101b95f138fSHeinrich Schuchardt .long 0 // PointerToRawData 102b95f138fSHeinrich Schuchardt .long 0 // PointerToRelocations 103b95f138fSHeinrich Schuchardt .long 0 // PointerToLineNumbers 104b95f138fSHeinrich Schuchardt .short 0 // NumberOfRelocations 105b95f138fSHeinrich Schuchardt .short 0 // NumberOfLineNumbers 106b95f138fSHeinrich Schuchardt .long 0x42100040 // Characteristics (section flags) 107b95f138fSHeinrich Schuchardt 108b95f138fSHeinrich Schuchardt .ascii ".text\0\0\0" 109b95f138fSHeinrich Schuchardt .long _edata - _start // VirtualSize 110b95f138fSHeinrich Schuchardt .long _start - ImageBase // VirtualAddress 111b95f138fSHeinrich Schuchardt .long _edata - _start // SizeOfRawData 112b95f138fSHeinrich Schuchardt .long _start - ImageBase // PointerToRawData 113b95f138fSHeinrich Schuchardt 114b95f138fSHeinrich Schuchardt .long 0 // PointerToRelocations (0 for executables) 115b95f138fSHeinrich Schuchardt .long 0 // PointerToLineNumbers (0 for executables) 116b95f138fSHeinrich Schuchardt .short 0 // NumberOfRelocations (0 for executables) 117b95f138fSHeinrich Schuchardt .short 0 // NumberOfLineNumbers (0 for executables) 118b95f138fSHeinrich Schuchardt .long 0xe0500020 // Characteristics (section flags) 119b95f138fSHeinrich Schuchardt 120b95f138fSHeinrich Schuchardt .align 12 121b95f138fSHeinrich Schuchardt .globl _start 122b95f138fSHeinrich Schuchardt_start: 123b95f138fSHeinrich Schuchardt addi sp, sp, -24 124b95f138fSHeinrich Schuchardt sd a0, 0(sp) 125b95f138fSHeinrich Schuchardt sd a1, 8(sp) 126b95f138fSHeinrich Schuchardt sd ra, 16(sp) 127b95f138fSHeinrich Schuchardt lla a0, ImageBase 128b95f138fSHeinrich Schuchardt lla a1, _DYNAMIC 129b95f138fSHeinrich Schuchardt call _relocate 130b95f138fSHeinrich Schuchardt bne a0, zero, 0f 131b95f138fSHeinrich Schuchardt ld a1, 8(sp) 132b95f138fSHeinrich Schuchardt ld a0, 0(sp) 133b95f138fSHeinrich Schuchardt call efi_main 134b95f138fSHeinrich Schuchardt ld ra, 16(sp) 135b95f138fSHeinrich Schuchardt0: addi sp, sp, 24 136b95f138fSHeinrich Schuchardt ret 137*803b49c4SSergei Trofimovich 138*803b49c4SSergei Trofimovich#if defined(__ELF__) && defined(__linux__) 139*803b49c4SSergei Trofimovich .section .note.GNU-stack,"",%progbits 140*803b49c4SSergei Trofimovich#endif 141