1ead384d9SHuacai Chen/* SPDX-License-Identifier: GPL-2.0 */ 2ead384d9SHuacai Chen/* 3ead384d9SHuacai Chen * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 4ead384d9SHuacai Chen */ 5ead384d9SHuacai Chen 6ead384d9SHuacai Chen#include <linux/pe.h> 7ead384d9SHuacai Chen#include <linux/sizes.h> 8ead384d9SHuacai Chen 9ead384d9SHuacai Chen .macro __EFI_PE_HEADER 10ead384d9SHuacai Chen .long PE_MAGIC 11ead384d9SHuacai Chen.Lcoff_header: 12ead384d9SHuacai Chen .short IMAGE_FILE_MACHINE_LOONGARCH64 /* Machine */ 13ead384d9SHuacai Chen .short .Lsection_count /* NumberOfSections */ 14ead384d9SHuacai Chen .long 0 /* TimeDateStamp */ 15ead384d9SHuacai Chen .long 0 /* PointerToSymbolTable */ 16ead384d9SHuacai Chen .long 0 /* NumberOfSymbols */ 17ead384d9SHuacai Chen .short .Lsection_table - .Loptional_header /* SizeOfOptionalHeader */ 18ead384d9SHuacai Chen .short IMAGE_FILE_DEBUG_STRIPPED | \ 19ead384d9SHuacai Chen IMAGE_FILE_EXECUTABLE_IMAGE | \ 20ead384d9SHuacai Chen IMAGE_FILE_LINE_NUMS_STRIPPED /* Characteristics */ 21ead384d9SHuacai Chen 22ead384d9SHuacai Chen.Loptional_header: 23ead384d9SHuacai Chen .short PE_OPT_MAGIC_PE32PLUS /* PE32+ format */ 24ead384d9SHuacai Chen .byte 0x02 /* MajorLinkerVersion */ 25ead384d9SHuacai Chen .byte 0x14 /* MinorLinkerVersion */ 26ead384d9SHuacai Chen .long __inittext_end - .Lefi_header_end /* SizeOfCode */ 27*414cefc7SWANG Rui .long _kernel_vsize /* SizeOfInitializedData */ 28ead384d9SHuacai Chen .long 0 /* SizeOfUninitializedData */ 29ead384d9SHuacai Chen .long __efistub_efi_pe_entry - _head /* AddressOfEntryPoint */ 30ead384d9SHuacai Chen .long .Lefi_header_end - _head /* BaseOfCode */ 31ead384d9SHuacai Chen 32ead384d9SHuacai Chen.Lextra_header_fields: 33ead384d9SHuacai Chen .quad 0 /* ImageBase */ 34ead384d9SHuacai Chen .long PECOFF_SEGMENT_ALIGN /* SectionAlignment */ 35ead384d9SHuacai Chen .long PECOFF_FILE_ALIGN /* FileAlignment */ 36ead384d9SHuacai Chen .short 0 /* MajorOperatingSystemVersion */ 37ead384d9SHuacai Chen .short 0 /* MinorOperatingSystemVersion */ 38ead384d9SHuacai Chen .short LINUX_EFISTUB_MAJOR_VERSION /* MajorImageVersion */ 39ead384d9SHuacai Chen .short LINUX_EFISTUB_MINOR_VERSION /* MinorImageVersion */ 40ead384d9SHuacai Chen .short 0 /* MajorSubsystemVersion */ 41ead384d9SHuacai Chen .short 0 /* MinorSubsystemVersion */ 42ead384d9SHuacai Chen .long 0 /* Win32VersionValue */ 43ead384d9SHuacai Chen 44ead384d9SHuacai Chen .long _end - _head /* SizeOfImage */ 45ead384d9SHuacai Chen 46ead384d9SHuacai Chen /* Everything before the kernel image is considered part of the header */ 47ead384d9SHuacai Chen .long .Lefi_header_end - _head /* SizeOfHeaders */ 48ead384d9SHuacai Chen .long 0 /* CheckSum */ 49ead384d9SHuacai Chen .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */ 50ead384d9SHuacai Chen .short 0 /* DllCharacteristics */ 51ead384d9SHuacai Chen .quad 0 /* SizeOfStackReserve */ 52ead384d9SHuacai Chen .quad 0 /* SizeOfStackCommit */ 53ead384d9SHuacai Chen .quad 0 /* SizeOfHeapReserve */ 54ead384d9SHuacai Chen .quad 0 /* SizeOfHeapCommit */ 55ead384d9SHuacai Chen .long 0 /* LoaderFlags */ 56ead384d9SHuacai Chen .long (.Lsection_table - .) / 8 /* NumberOfRvaAndSizes */ 57ead384d9SHuacai Chen 58ead384d9SHuacai Chen .quad 0 /* ExportTable */ 59ead384d9SHuacai Chen .quad 0 /* ImportTable */ 60ead384d9SHuacai Chen .quad 0 /* ResourceTable */ 61ead384d9SHuacai Chen .quad 0 /* ExceptionTable */ 62ead384d9SHuacai Chen .quad 0 /* CertificationTable */ 63ead384d9SHuacai Chen .quad 0 /* BaseRelocationTable */ 64ead384d9SHuacai Chen 65ead384d9SHuacai Chen /* Section table */ 66ead384d9SHuacai Chen.Lsection_table: 67ead384d9SHuacai Chen .ascii ".text\0\0\0" 68ead384d9SHuacai Chen .long __inittext_end - .Lefi_header_end /* VirtualSize */ 69ead384d9SHuacai Chen .long .Lefi_header_end - _head /* VirtualAddress */ 70ead384d9SHuacai Chen .long __inittext_end - .Lefi_header_end /* SizeOfRawData */ 71ead384d9SHuacai Chen .long .Lefi_header_end - _head /* PointerToRawData */ 72ead384d9SHuacai Chen 73ead384d9SHuacai Chen .long 0 /* PointerToRelocations */ 74ead384d9SHuacai Chen .long 0 /* PointerToLineNumbers */ 75ead384d9SHuacai Chen .short 0 /* NumberOfRelocations */ 76ead384d9SHuacai Chen .short 0 /* NumberOfLineNumbers */ 77ead384d9SHuacai Chen .long IMAGE_SCN_CNT_CODE | \ 78ead384d9SHuacai Chen IMAGE_SCN_MEM_READ | \ 79ead384d9SHuacai Chen IMAGE_SCN_MEM_EXECUTE /* Characteristics */ 80ead384d9SHuacai Chen 81ead384d9SHuacai Chen .ascii ".data\0\0\0" 82*414cefc7SWANG Rui .long _kernel_vsize /* VirtualSize */ 83ead384d9SHuacai Chen .long __initdata_begin - _head /* VirtualAddress */ 84*414cefc7SWANG Rui .long _kernel_rsize /* SizeOfRawData */ 85ead384d9SHuacai Chen .long __initdata_begin - _head /* PointerToRawData */ 86ead384d9SHuacai Chen 87ead384d9SHuacai Chen .long 0 /* PointerToRelocations */ 88ead384d9SHuacai Chen .long 0 /* PointerToLineNumbers */ 89ead384d9SHuacai Chen .short 0 /* NumberOfRelocations */ 90ead384d9SHuacai Chen .short 0 /* NumberOfLineNumbers */ 91ead384d9SHuacai Chen .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ 92ead384d9SHuacai Chen IMAGE_SCN_MEM_READ | \ 93ead384d9SHuacai Chen IMAGE_SCN_MEM_WRITE /* Characteristics */ 94ead384d9SHuacai Chen 95ead384d9SHuacai Chen .set .Lsection_count, (. - .Lsection_table) / 40 96ead384d9SHuacai Chen 97ead384d9SHuacai Chen .balign 0x10000 /* PECOFF_SEGMENT_ALIGN */ 98ead384d9SHuacai Chen.Lefi_header_end: 99ead384d9SHuacai Chen .endm 100