18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2013 - 2017 Linaro, Ltd.
48c2ecf20Sopenharmony_ci * Copyright (C) 2013, 2014 Red Hat, Inc.
58c2ecf20Sopenharmony_ci * Copyright (C) 2020, 2021 Loongson, Inc.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
88c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as
98c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/pe.h>
138c2ecf20Sopenharmony_ci#include <linux/sizes.h>
148c2ecf20Sopenharmony_ci#include <generated/utsrelease.h>
158c2ecf20Sopenharmony_ci#include <generated/compile.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	.macro	__EFI_PE_HEADER
188c2ecf20Sopenharmony_ci	.long	PE_MAGIC
198c2ecf20Sopenharmony_cicoff_header:
208c2ecf20Sopenharmony_ci	.short	IMAGE_FILE_MACHINE_LOONGARCH		/* Machine */
218c2ecf20Sopenharmony_ci	.short	section_count				/* NumberOfSections */
228c2ecf20Sopenharmony_ci	.long	0 					/* TimeDateStamp */
238c2ecf20Sopenharmony_ci	.long	0					/* PointerToSymbolTable */
248c2ecf20Sopenharmony_ci	.long	0					/* NumberOfSymbols */
258c2ecf20Sopenharmony_ci	.short	section_table - optional_header		/* SizeOfOptionalHeader */
268c2ecf20Sopenharmony_ci	.short	IMAGE_FILE_DEBUG_STRIPPED | \
278c2ecf20Sopenharmony_ci		IMAGE_FILE_EXECUTABLE_IMAGE | \
288c2ecf20Sopenharmony_ci		IMAGE_FILE_LINE_NUMS_STRIPPED		/* Characteristics */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cioptional_header:
318c2ecf20Sopenharmony_ci	.short	PE_OPT_MAGIC_PE32PLUS			/* PE32+ format */
328c2ecf20Sopenharmony_ci	.byte	0x02					/* MajorLinkerVersion */
338c2ecf20Sopenharmony_ci	.byte	0x14					/* MinorLinkerVersion */
348c2ecf20Sopenharmony_ci	.long	_data - efi_header_end			/* SizeOfCode */
358c2ecf20Sopenharmony_ci	.long	_end - _data				/* SizeOfInitializedData */
368c2ecf20Sopenharmony_ci	.long	0					/* SizeOfUninitializedData */
378c2ecf20Sopenharmony_ci	.long	efi_pe_entry - _text			/* AddressOfEntryPoint */
388c2ecf20Sopenharmony_ci	.long	efi_header_end - _text			/* BaseOfCode */
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciextra_header_fields:
418c2ecf20Sopenharmony_ci	.quad	0					/* ImageBase */
428c2ecf20Sopenharmony_ci	.long	PECOFF_SEGMENT_ALIGN			/* SectionAlignment */
438c2ecf20Sopenharmony_ci	.long	PECOFF_FILE_ALIGN			/* FileAlignment */
448c2ecf20Sopenharmony_ci	.short	0					/* MajorOperatingSystemVersion */
458c2ecf20Sopenharmony_ci	.short	0					/* MinorOperatingSystemVersion */
468c2ecf20Sopenharmony_ci	.short	LINUX_EFISTUB_MAJOR_VERSION		/* MajorImageVersion */
478c2ecf20Sopenharmony_ci	.short	LINUX_EFISTUB_MINOR_VERSION		/* MinorImageVersion */
488c2ecf20Sopenharmony_ci	.short	0					/* MajorSubsystemVersion */
498c2ecf20Sopenharmony_ci	.short	0					/* MinorSubsystemVersion */
508c2ecf20Sopenharmony_ci	.long	0					/* Win32VersionValue */
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	.long	_end - _text				/* SizeOfImage */
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	/* Everything before the kernel image is considered part of the header */
558c2ecf20Sopenharmony_ci	.long	efi_header_end - _head			/* SizeOfHeaders */
568c2ecf20Sopenharmony_ci	.long	0					/* CheckSum */
578c2ecf20Sopenharmony_ci	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION		/* Subsystem */
588c2ecf20Sopenharmony_ci	.short	0					/* DllCharacteristics */
598c2ecf20Sopenharmony_ci	.quad	0					/* SizeOfStackReserve */
608c2ecf20Sopenharmony_ci	.quad	0					/* SizeOfStackCommit */
618c2ecf20Sopenharmony_ci	.quad	0					/* SizeOfHeapReserve */
628c2ecf20Sopenharmony_ci	.quad	0					/* SizeOfHeapCommit */
638c2ecf20Sopenharmony_ci	.long	0					/* LoaderFlags */
648c2ecf20Sopenharmony_ci	.long	(section_table - .) / 8			/* NumberOfRvaAndSizes */
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	.quad	0					/* ExportTable */
678c2ecf20Sopenharmony_ci	.quad	0					/* ImportTable */
688c2ecf20Sopenharmony_ci	.quad	0					/* ResourceTable */
698c2ecf20Sopenharmony_ci	.quad	0					/* ExceptionTable */
708c2ecf20Sopenharmony_ci	.quad	0					/* CertificationTable */
718c2ecf20Sopenharmony_ci	.quad	0					/* BaseRelocationTable */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	/* Section table */
748c2ecf20Sopenharmony_cisection_table:
758c2ecf20Sopenharmony_ci	.ascii	".text\0\0\0"
768c2ecf20Sopenharmony_ci	.long	_data - efi_header_end			/* VirtualSize */
778c2ecf20Sopenharmony_ci	.long	efi_header_end - _text			/* VirtualAddress */
788c2ecf20Sopenharmony_ci	.long	_data - efi_header_end			/* SizeOfRawData */
798c2ecf20Sopenharmony_ci	.long	efi_header_end - _text			/* PointerToRawData */
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	.long	0					/* PointerToRelocations */
828c2ecf20Sopenharmony_ci	.long	0					/* PointerToLineNumbers */
838c2ecf20Sopenharmony_ci	.short	0					/* NumberOfRelocations */
848c2ecf20Sopenharmony_ci	.short	0					/* NumberOfLineNumbers */
858c2ecf20Sopenharmony_ci	.long	IMAGE_SCN_CNT_CODE | \
868c2ecf20Sopenharmony_ci		IMAGE_SCN_MEM_READ | \
878c2ecf20Sopenharmony_ci		IMAGE_SCN_MEM_EXECUTE			/* Characteristics */
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	.ascii	".data\0\0\0"
908c2ecf20Sopenharmony_ci	.long	_end - _data				/* VirtualSize */
918c2ecf20Sopenharmony_ci	.long	_data - _text				/* VirtualAddress */
928c2ecf20Sopenharmony_ci	.long	_edata - _data				/* SizeOfRawData */
938c2ecf20Sopenharmony_ci	.long	_data - _text				/* PointerToRawData */
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	.long	0					/* PointerToRelocations */
968c2ecf20Sopenharmony_ci	.long	0					/* PointerToLineNumbers */
978c2ecf20Sopenharmony_ci	.short	0					/* NumberOfRelocations */
988c2ecf20Sopenharmony_ci	.short	0					/* NumberOfLineNumbers */
998c2ecf20Sopenharmony_ci	.long	IMAGE_SCN_CNT_INITIALIZED_DATA | \
1008c2ecf20Sopenharmony_ci		IMAGE_SCN_MEM_READ | \
1018c2ecf20Sopenharmony_ci		IMAGE_SCN_MEM_WRITE			/* Characteristics */
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	.org 0x20e
1048c2ecf20Sopenharmony_ci	.word kernel_version - 512 -  _head
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	.set	section_count, (. - section_table) / 40
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	.balign	0x10000					/* PECOFF_SEGMENT_ALIGN */
1098c2ecf20Sopenharmony_ciefi_header_end:
1108c2ecf20Sopenharmony_ci	.endm
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	.section ".head.text","ax"
1138c2ecf20Sopenharmony_ci_head:
1148c2ecf20Sopenharmony_ci	/* "MZ", MS-DOS header */
1158c2ecf20Sopenharmony_ci	.byte 	0x4d
1168c2ecf20Sopenharmony_ci	.byte 	0x5a
1178c2ecf20Sopenharmony_ci	.org	0x3c
1188c2ecf20Sopenharmony_ci	/* Offset to the PE header */
1198c2ecf20Sopenharmony_ci	.long	pe_header - _head
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cipe_header:
1228c2ecf20Sopenharmony_ci	__EFI_PE_HEADER
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistart:
1258c2ecf20Sopenharmony_ci	.globl	start
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cikernel_entaddr:
1288c2ecf20Sopenharmony_ci	.quad	KERNEL_ENTRY
1298c2ecf20Sopenharmony_ci	.globl	kernel_entaddr
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cikernel_version:
1328c2ecf20Sopenharmony_ci	.ascii  UTS_RELEASE " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ") " UTS_VERSION "\0"
133