2020-09-17 15:37:13 -07:00
/* SPDX-License-Identifier: GPL-2.0-only */
/ *
* Copyright ( C ) 2 0 2 0 W e s t e r n D i g i t a l C o r p o r a t i o n o r i t s a f f i l i a t e s .
* Adapted f r o m a r c h / a r m 6 4 / k e r n e l / e f i - h e a d e r . S
* /
# include < l i n u x / p e . h >
# include < l i n u x / s i z e s . h >
2023-03-29 06:53:24 +02:00
# include < a s m / s e t _ m e m o r y . h >
2020-09-17 15:37:13 -07:00
.macro __EFI_PE_HEADER
.long PE_MAGIC
coff_header :
# ifdef C O N F I G _ 6 4 B I T
.short IMAGE_FILE_MACHINE_RISCV64 / / Machine
# else
.short IMAGE_FILE_MACHINE_RISCV32 / / Machine
# endif
.short section_count / / NumberOfSections
.long 0 / / TimeDateStamp
.long 0 / / PointerToSymbolTable
.long 0 / / NumberOfSymbols
.short section_table - optional_ h e a d e r / / S i z e O f O p t i o n a l H e a d e r
.short IMAGE_FILE_DEBUG_STRIPPED | \
IMAGE_ F I L E _ E X E C U T A B L E _ I M A G E | \
IMAGE_ F I L E _ L I N E _ N U M S _ S T R I P P E D / / C h a r a c t e r i s t i c s
optional_header :
# ifdef C O N F I G _ 6 4 B I T
.short PE_OPT_MAGIC_PE32PLUS / / PE3 2 + f o r m a t
# else
.short PE_OPT_MAGIC_PE32 / / PE3 2 f o r m a t
# endif
.byte 0x02 / / MajorLinkerVersion
.byte 0x14 / / MinorLinkerVersion
.long __pecoff_text_end - efi_ h e a d e r _ e n d / / S i z e O f C o d e
2023-03-29 06:53:24 +02:00
# ifdef _ _ c l a n g _ _
.long __pecoff_data_virt_size / / SizeOfInitializedData
# else
.long __pecoff_data_virt_end - _ _ pecoff_ t e x t _ e n d / / S i z e O f I n i t i a l i z e d D a t a
# endif
2020-09-17 15:37:13 -07:00
.long 0 / / SizeOfUninitializedData
.long __efistub_efi_pe_entry - _ start / / A d d r e s s O f E n t r y P o i n t
.long efi_header_end - _ start / / B a s e O f C o d e
# ifdef C O N F I G _ 3 2 B I T
.long __pecoff_text_end - _ start / / B a s e O f D a t a
# endif
extra_header_fields :
.quad 0 / / ImageBase
.long PECOFF_SECTION_ALIGNMENT / / SectionAlignment
.long PECOFF_FILE_ALIGNMENT / / FileAlignment
.short 0 / / MajorOperatingSystemVersion
.short 0 / / MinorOperatingSystemVersion
.short LINUX_EFISTUB_MAJOR_VERSION / / MajorImageVersion
.short LINUX_EFISTUB_MINOR_VERSION / / MinorImageVersion
.short 0 / / MajorSubsystemVersion
.short 0 / / MinorSubsystemVersion
.long 0 / / Win3 2 V e r s i o n V a l u e
.long _end - _ start / / S i z e O f I m a g e
/ / Everything b e f o r e t h e k e r n e l i m a g e i s c o n s i d e r e d p a r t o f t h e h e a d e r
.long efi_header_end - _ start / / S i z e O f H e a d e r s
.long 0 / / CheckSum
.short IMAGE_SUBSYSTEM_EFI_APPLICATION / / Subsystem
.short 0 / / DllCharacteristics
.quad 0 / / SizeOfStackReserve
.quad 0 / / SizeOfStackCommit
.quad 0 / / SizeOfHeapReserve
.quad 0 / / SizeOfHeapCommit
.long 0 / / LoaderFlags
.long ( section_ t a b l e - . ) / 8 / / N u m b e r O f R v a A n d S i z e s
.quad 0 / / ExportTable
.quad 0 / / ImportTable
.quad 0 / / ResourceTable
.quad 0 / / ExceptionTable
.quad 0 / / CertificationTable
.quad 0 / / BaseRelocationTable
/ / Section t a b l e
section_table :
.ascii " .text \ 0 \ 0 \ 0 "
.long __pecoff_text_end - efi_ h e a d e r _ e n d / / V i r t u a l S i z e
.long efi_header_end - _ start / / V i r t u a l A d d r e s s
.long __pecoff_text_end - efi_ h e a d e r _ e n d / / S i z e O f R a w D a t a
.long efi_header_end - _ start / / P o i n t e r T o R a w D a t a
.long 0 / / PointerToRelocations
.long 0 / / PointerToLineNumbers
.short 0 / / NumberOfRelocations
.short 0 / / NumberOfLineNumbers
.long IMAGE_SCN_CNT_CODE | \
IMAGE_ S C N _ M E M _ R E A D | \
IMAGE_ S C N _ M E M _ E X E C U T E / / C h a r a c t e r i s t i c s
.ascii " .data \ 0 \ 0 \ 0 "
2023-03-29 06:53:24 +02:00
# ifdef _ _ c l a n g _ _
.long __pecoff_data_virt_size / / VirtualSize
# else
.long __pecoff_data_virt_end - _ _ pecoff_ t e x t _ e n d / / V i r t u a l S i z e
# endif
2020-09-17 15:37:13 -07:00
.long __pecoff_text_end - _ start / / V i r t u a l A d d r e s s
2023-03-29 06:53:24 +02:00
# ifdef _ _ c l a n g _ _
.long __pecoff_data_raw_size / / SizeOfRawData
# else
.long __pecoff_data_raw_end - _ _ pecoff_ t e x t _ e n d / / S i z e O f R a w D a t a
# endif
2020-09-17 15:37:13 -07:00
.long __pecoff_text_end - _ start / / P o i n t e r T o R a w D a t a
.long 0 / / PointerToRelocations
.long 0 / / PointerToLineNumbers
.short 0 / / NumberOfRelocations
.short 0 / / NumberOfLineNumbers
.long IMAGE_SCN_CNT_INITIALIZED_DATA | \
IMAGE_ S C N _ M E M _ R E A D | \
IMAGE_ S C N _ M E M _ W R I T E / / C h a r a c t e r i s t i c s
.set section_ c o u n t , ( . - s e c t i o n _ t a b l e ) / 4 0
.balign 0x1000
efi_header_end :
.endm