1*b95f138fSHeinrich Schuchardt/* SPDX-License-Identifier: GPL-2.0+ */ 2*b95f138fSHeinrich Schuchardt/* 3*b95f138fSHeinrich Schuchardt * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org> 4*b95f138fSHeinrich Schuchardt * Copright (C) 2018 Alexander Graf <agraf@suse.de> 5*b95f138fSHeinrich Schuchardt * 6*b95f138fSHeinrich Schuchardt * Redistribution and use in source and binary forms, with or without 7*b95f138fSHeinrich Schuchardt * modification, are permitted provided that the following conditions 8*b95f138fSHeinrich Schuchardt * are met: 9*b95f138fSHeinrich Schuchardt * 1. Redistributions of source code must retain the above copyright 10*b95f138fSHeinrich Schuchardt * notice and this list of conditions, without modification. 11*b95f138fSHeinrich Schuchardt * 2. The name of the author may not be used to endorse or promote products 12*b95f138fSHeinrich Schuchardt * derived from this software without specific prior written permission. 13*b95f138fSHeinrich Schuchardt * 14*b95f138fSHeinrich Schuchardt * Alternatively, this software may be distributed under the terms of the 15*b95f138fSHeinrich Schuchardt * GNU General Public License as published by the Free Software Foundation; 16*b95f138fSHeinrich Schuchardt * either version 2 of the License, or (at your option) any later version. 17*b95f138fSHeinrich Schuchardt */ 18*b95f138fSHeinrich Schuchardt 19*b95f138fSHeinrich Schuchardt#ifndef EFI_SUBSYSTEM 20*b95f138fSHeinrich Schuchardt#define EFI_SUBSYSTEM 10 21*b95f138fSHeinrich Schuchardt#endif 22*b95f138fSHeinrich Schuchardt 23*b95f138fSHeinrich Schuchardt .section .text.head 24*b95f138fSHeinrich Schuchardt 25*b95f138fSHeinrich Schuchardt /* 26*b95f138fSHeinrich Schuchardt * Magic "MZ" signature for PE/COFF 27*b95f138fSHeinrich Schuchardt */ 28*b95f138fSHeinrich Schuchardt .globl ImageBase 29*b95f138fSHeinrich SchuchardtImageBase: 30*b95f138fSHeinrich Schuchardt .ascii "MZ" 31*b95f138fSHeinrich Schuchardt .skip 58 // 'MZ' + pad + offset == 64 32*b95f138fSHeinrich Schuchardt .long pe_header - ImageBase // Offset to the PE header. 33*b95f138fSHeinrich Schuchardtpe_header: 34*b95f138fSHeinrich Schuchardt .ascii "PE" 35*b95f138fSHeinrich Schuchardt .short 0 36*b95f138fSHeinrich Schuchardtcoff_header: 37*b95f138fSHeinrich Schuchardt .short 0x5064 // riscv64 38*b95f138fSHeinrich Schuchardt .short 2 // nr_sections 39*b95f138fSHeinrich Schuchardt .long 0 // TimeDateStamp 40*b95f138fSHeinrich Schuchardt .long 0 // PointerToSymbolTable 41*b95f138fSHeinrich Schuchardt .long 1 // NumberOfSymbols 42*b95f138fSHeinrich Schuchardt .short section_table - optional_header // SizeOfOptionalHeader 43*b95f138fSHeinrich Schuchardt .short 0x206 // Characteristics. 44*b95f138fSHeinrich Schuchardt // IMAGE_FILE_DEBUG_STRIPPED | 45*b95f138fSHeinrich Schuchardt // IMAGE_FILE_EXECUTABLE_IMAGE | 46*b95f138fSHeinrich Schuchardt // IMAGE_FILE_LINE_NUMS_STRIPPED 47*b95f138fSHeinrich Schuchardtoptional_header: 48*b95f138fSHeinrich Schuchardt .short 0x20b // PE32+ format 49*b95f138fSHeinrich Schuchardt .byte 0x02 // MajorLinkerVersion 50*b95f138fSHeinrich Schuchardt .byte 0x14 // MinorLinkerVersion 51*b95f138fSHeinrich Schuchardt .long _data - _start // SizeOfCode 52*b95f138fSHeinrich Schuchardt .long _data_size // SizeOfInitializedData 53*b95f138fSHeinrich Schuchardt .long 0 // SizeOfUninitializedData 54*b95f138fSHeinrich Schuchardt .long _start - ImageBase // AddressOfEntryPoint 55*b95f138fSHeinrich Schuchardt .long _start - ImageBase // BaseOfCode 56*b95f138fSHeinrich Schuchardt 57*b95f138fSHeinrich Schuchardtextra_header_fields: 58*b95f138fSHeinrich Schuchardt .quad 0 // ImageBase 59*b95f138fSHeinrich Schuchardt .long 0x1000 // SectionAlignment 60*b95f138fSHeinrich Schuchardt .long 0x200 // FileAlignment 61*b95f138fSHeinrich Schuchardt .short 0 // MajorOperatingSystemVersion 62*b95f138fSHeinrich Schuchardt .short 0 // MinorOperatingSystemVersion 63*b95f138fSHeinrich Schuchardt .short 0 // MajorImageVersion 64*b95f138fSHeinrich Schuchardt .short 0 // MinorImageVersion 65*b95f138fSHeinrich Schuchardt .short 0 // MajorSubsystemVersion 66*b95f138fSHeinrich Schuchardt .short 0 // MinorSubsystemVersion 67*b95f138fSHeinrich Schuchardt .long 0 // Win32VersionValue 68*b95f138fSHeinrich Schuchardt 69*b95f138fSHeinrich Schuchardt .long _edata - ImageBase // SizeOfImage 70*b95f138fSHeinrich Schuchardt 71*b95f138fSHeinrich Schuchardt // Everything before the kernel image is considered part of the header 72*b95f138fSHeinrich Schuchardt .long _start - ImageBase // SizeOfHeaders 73*b95f138fSHeinrich Schuchardt .long 0 // CheckSum 74*b95f138fSHeinrich Schuchardt .short EFI_SUBSYSTEM // Subsystem 75*b95f138fSHeinrich Schuchardt .short 0 // DllCharacteristics 76*b95f138fSHeinrich Schuchardt .quad 0 // SizeOfStackReserve 77*b95f138fSHeinrich Schuchardt .quad 0 // SizeOfStackCommit 78*b95f138fSHeinrich Schuchardt .quad 0 // SizeOfHeapReserve 79*b95f138fSHeinrich Schuchardt .quad 0 // SizeOfHeapCommit 80*b95f138fSHeinrich Schuchardt .long 0 // LoaderFlags 81*b95f138fSHeinrich Schuchardt .long 0x6 // NumberOfRvaAndSizes 82*b95f138fSHeinrich Schuchardt 83*b95f138fSHeinrich Schuchardt .quad 0 // ExportTable 84*b95f138fSHeinrich Schuchardt .quad 0 // ImportTable 85*b95f138fSHeinrich Schuchardt .quad 0 // ResourceTable 86*b95f138fSHeinrich Schuchardt .quad 0 // ExceptionTable 87*b95f138fSHeinrich Schuchardt .quad 0 // CertificationTable 88*b95f138fSHeinrich Schuchardt .quad 0 // BaseRelocationTable 89*b95f138fSHeinrich Schuchardt 90*b95f138fSHeinrich Schuchardt // Section table 91*b95f138fSHeinrich Schuchardtsection_table: 92*b95f138fSHeinrich Schuchardt /* 93*b95f138fSHeinrich Schuchardt * The EFI application loader requires a relocation section 94*b95f138fSHeinrich Schuchardt * because EFI applications must be relocatable. This is a 95*b95f138fSHeinrich Schuchardt * dummy section as far as we are concerned. 96*b95f138fSHeinrich Schuchardt */ 97*b95f138fSHeinrich Schuchardt .ascii ".reloc\0\0" 98*b95f138fSHeinrich Schuchardt .long 0 99*b95f138fSHeinrich Schuchardt .long 0 100*b95f138fSHeinrich Schuchardt .long 0 // SizeOfRawData 101*b95f138fSHeinrich Schuchardt .long 0 // PointerToRawData 102*b95f138fSHeinrich Schuchardt .long 0 // PointerToRelocations 103*b95f138fSHeinrich Schuchardt .long 0 // PointerToLineNumbers 104*b95f138fSHeinrich Schuchardt .short 0 // NumberOfRelocations 105*b95f138fSHeinrich Schuchardt .short 0 // NumberOfLineNumbers 106*b95f138fSHeinrich Schuchardt .long 0x42100040 // Characteristics (section flags) 107*b95f138fSHeinrich Schuchardt 108*b95f138fSHeinrich Schuchardt .ascii ".text\0\0\0" 109*b95f138fSHeinrich Schuchardt .long _edata - _start // VirtualSize 110*b95f138fSHeinrich Schuchardt .long _start - ImageBase // VirtualAddress 111*b95f138fSHeinrich Schuchardt .long _edata - _start // SizeOfRawData 112*b95f138fSHeinrich Schuchardt .long _start - ImageBase // PointerToRawData 113*b95f138fSHeinrich Schuchardt 114*b95f138fSHeinrich Schuchardt .long 0 // PointerToRelocations (0 for executables) 115*b95f138fSHeinrich Schuchardt .long 0 // PointerToLineNumbers (0 for executables) 116*b95f138fSHeinrich Schuchardt .short 0 // NumberOfRelocations (0 for executables) 117*b95f138fSHeinrich Schuchardt .short 0 // NumberOfLineNumbers (0 for executables) 118*b95f138fSHeinrich Schuchardt .long 0xe0500020 // Characteristics (section flags) 119*b95f138fSHeinrich Schuchardt 120*b95f138fSHeinrich Schuchardt .align 12 121*b95f138fSHeinrich Schuchardt .globl _start 122*b95f138fSHeinrich Schuchardt_start: 123*b95f138fSHeinrich Schuchardt addi sp, sp, -24 124*b95f138fSHeinrich Schuchardt sd a0, 0(sp) 125*b95f138fSHeinrich Schuchardt sd a1, 8(sp) 126*b95f138fSHeinrich Schuchardt sd ra, 16(sp) 127*b95f138fSHeinrich Schuchardt lla a0, ImageBase 128*b95f138fSHeinrich Schuchardt lla a1, _DYNAMIC 129*b95f138fSHeinrich Schuchardt call _relocate 130*b95f138fSHeinrich Schuchardt bne a0, zero, 0f 131*b95f138fSHeinrich Schuchardt ld a1, 8(sp) 132*b95f138fSHeinrich Schuchardt ld a0, 0(sp) 133*b95f138fSHeinrich Schuchardt call efi_main 134*b95f138fSHeinrich Schuchardt ld ra, 16(sp) 135*b95f138fSHeinrich Schuchardt0: addi sp, sp, 24 136*b95f138fSHeinrich Schuchardt ret 137