2019-06-04 10:11:33 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2017-03-23 19:00:46 +00:00
/ *
* Copyright ( C ) 2 0 1 3 - 2 0 1 7 L i n a r o , L t d .
* Copyright ( C ) 2 0 1 3 , 2 0 1 4 R e d H a t , I n c .
* /
2017-03-23 19:00:50 +00:00
# include < l i n u x / p e . h >
# include < l i n u x / s i z e s . h >
2020-11-17 13:47:29 +01:00
.macro efi_signature_nop
# ifdef C O N F I G _ E F I
.L_head :
/ *
* This c c m p i n s t r u c t i o n h a s n o m e a n i n g f u l e f f e c t e x c e p t t h a t
* its o p c o d e f o r m s t h e m a g i c " M Z " s i g n a t u r e r e q u i r e d b y U E F I .
* /
ccmp x18 , #0 , #0xd , p l
# else
/ *
* Bootloaders m a y i n s p e c t t h e o p c o d e a t t h e s t a r t o f t h e k e r n e l
* image t o d e c i d e i f t h e k e r n e l i s c a p a b l e o f b o o t i n g v i a U E F I .
* So p u t a n o r d i n a r y N O P h e r e , n o t t h e " M Z . . " p s e u d o - n o p a b o v e .
* /
nop
# endif
.endm
2017-03-23 19:00:46 +00:00
.macro __EFI_PE_HEADER
2020-11-17 13:47:29 +01:00
# ifdef C O N F I G _ E F I
.set .Lpe_header_offset , . - .L_head
2017-03-23 19:00:50 +00:00
.long PE_MAGIC
.short IMAGE_FILE_MACHINE_ARM64 / / Machine
2020-11-17 13:47:28 +01:00
.short .Lsection_count / / NumberOfSections
2017-03-23 19:00:46 +00:00
.long 0 / / TimeDateStamp
.long 0 / / PointerToSymbolTable
2017-03-23 19:00:48 +00:00
.long 0 / / NumberOfSymbols
2020-11-17 13:47:28 +01:00
.short .Lsection_table - .Loptional_header / / SizeOfOptionalHeader
2017-03-23 19:00:50 +00:00
.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
2020-11-17 13:47:28 +01:00
.Loptional_header :
2017-03-23 19:00:50 +00:00
.short PE_OPT_MAGIC_PE32PLUS / / PE3 2 + f o r m a t
2017-03-23 19:00:46 +00:00
.byte 0x02 / / MajorLinkerVersion
.byte 0x14 / / MinorLinkerVersion
2020-11-17 13:47:28 +01:00
.long __initdata_begin - .Lefi_header_end / / SizeOfCode
2017-03-23 19:00:51 +00:00
.long __pecoff_data_size / / SizeOfInitializedData
2017-03-23 19:00:46 +00:00
.long 0 / / SizeOfUninitializedData
2020-11-17 13:47:29 +01:00
.long __efistub_efi_pe_entry - .L_head / / AddressOfEntryPoint
.long .Lefi_header_end - .L_head / / BaseOfCode
2017-03-23 19:00:46 +00:00
.quad 0 / / ImageBase
2020-04-13 17:55:18 +02:00
.long SEGMENT_ALIGN / / SectionAlignment
2017-03-23 19:00:46 +00:00
.long PECOFF_FILE_ALIGNMENT / / FileAlignment
.short 0 / / MajorOperatingSystemVersion
.short 0 / / MinorOperatingSystemVersion
2020-02-20 11:06:00 +01:00
.short LINUX_EFISTUB_MAJOR_VERSION / / MajorImageVersion
.short LINUX_EFISTUB_MINOR_VERSION / / MinorImageVersion
2017-03-23 19:00:46 +00:00
.short 0 / / MajorSubsystemVersion
.short 0 / / MinorSubsystemVersion
.long 0 / / Win3 2 V e r s i o n V a l u e
2020-11-17 13:47:29 +01:00
.long _end - .L_head / / SizeOfImage
2017-03-23 19:00:46 +00:00
/ / 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
2020-11-17 13:47:29 +01:00
.long .Lefi_header_end - .L_head / / SizeOfHeaders
2017-03-23 19:00:46 +00:00
.long 0 / / CheckSum
2017-03-23 19:00:50 +00:00
.short IMAGE_SUBSYSTEM_EFI_APPLICATION / / Subsystem
2023-03-10 13:30:05 +01:00
.short IMAGE_DLL_CHARACTERISTICS_NX_COMPAT / / DllCharacteristics
2017-03-23 19:00:46 +00:00
.quad 0 / / SizeOfStackReserve
.quad 0 / / SizeOfStackCommit
.quad 0 / / SizeOfHeapReserve
.quad 0 / / SizeOfHeapCommit
.long 0 / / LoaderFlags
2020-11-17 13:47:28 +01:00
.long ( .Lsection_table - . ) / 8 / / NumberOfRvaAndSizes
2017-03-23 19:00:46 +00:00
.quad 0 / / ExportTable
.quad 0 / / ImportTable
.quad 0 / / ResourceTable
.quad 0 / / ExceptionTable
.quad 0 / / CertificationTable
.quad 0 / / BaseRelocationTable
2023-04-18 15:49:48 +02:00
# if d e f i n e d ( C O N F I G _ D E B U G _ E F I ) | | d e f i n e d ( C O N F I G _ A R M 6 4 _ B T I _ K E R N E L )
2020-11-17 13:47:29 +01:00
.long .Lefi_debug_table - .L_head / / DebugTable
2020-11-17 13:47:28 +01:00
.long .Lefi_debug_table_size
2023-04-18 15:49:48 +02:00
/ *
* The d e b u g t a b l e i s r e f e r e n c e d v i a i t s R e l a t i v e V i r t u a l A d d r e s s ( R V A ) ,
* which i s o n l y d e f i n e d f o r t h o s e p a r t s o f t h e i m a g e t h a t a r e c o v e r e d
* by a s e c t i o n d e c l a r a t i o n . S i n c e t h i s h e a d e r i s n o t c o v e r e d b y a n y
* section, t h e d e b u g t a b l e m u s t b e e m i t t e d e l s e w h e r e . S o s t i c k i t i n
* the . i n i t . r o d a t a s e c t i o n i n s t e a d .
*
* Note t h a t t h e p a y l o a d s t h e m s e l v e s a r e p e r m i t t e d t o h a v e z e r o R V A s ,
* which m e a n s w e c a n s i m p l y p u t t h o s e r i g h t a f t e r t h e s e c t i o n h e a d e r s .
* /
_ _ INITRODATA
.align 2
.Lefi_debug_table :
# ifdef C O N F I G _ D E B U G _ E F I
/ / EFI_ I M A G E _ D E B U G _ D I R E C T O R Y _ E N T R Y
.long 0 / / Characteristics
.long 0 / / TimeDateStamp
.short 0 / / MajorVersion
.short 0 / / MinorVersion
.long IMAGE_DEBUG_TYPE_CODEVIEW / / Type
.long .Lefi_debug_entry_size / / SizeOfData
.long 0 / / RVA
.long .Lefi_debug_entry - .L_head / / FileOffset
# endif
# ifdef C O N F I G _ A R M 6 4 _ B T I _ K E R N E L
.long 0 / / Characteristics
.long 0 / / TimeDateStamp
.short 0 / / MajorVersion
.short 0 / / MinorVersion
.long IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS / / Type
.long 4 / / SizeOfData
.long 0 / / RVA
.long .Lefi_dll_characteristics_ex - .L_head / / FileOffset
# endif
.set .Lefi_debug_table_size , . - .Lefi_debug_table
.previous
2017-03-23 19:00:46 +00:00
# endif
/ / Section t a b l e
2020-11-17 13:47:28 +01:00
.Lsection_table :
2017-03-23 19:00:50 +00:00
.ascii " .text \ 0 \ 0 \ 0 "
2020-11-17 13:47:28 +01:00
.long __initdata_begin - .Lefi_header_end / / VirtualSize
2020-11-17 13:47:29 +01:00
.long .Lefi_header_end - .L_head / / VirtualAddress
2020-11-17 13:47:28 +01:00
.long __initdata_begin - .Lefi_header_end / / SizeOfRawData
2020-11-17 13:47:29 +01:00
.long .Lefi_header_end - .L_head / / PointerToRawData
2017-03-23 19:00:46 +00:00
.long 0 / / PointerToRelocations
.long 0 / / PointerToLineNumbers
.short 0 / / NumberOfRelocations
.short 0 / / NumberOfLineNumbers
2017-03-23 19:00:50 +00:00
.long IMAGE_SCN_CNT_CODE | \
2017-03-23 19:00:51 +00:00
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 "
.long __pecoff_data_size / / VirtualSize
2020-11-17 13:47:29 +01:00
.long __initdata_begin - .L_head / / VirtualAddress
2017-03-23 19:00:51 +00:00
.long __pecoff_data_rawsize / / SizeOfRawData
2020-11-17 13:47:29 +01:00
.long __initdata_begin - .L_head / / PointerToRawData
2017-03-23 19:00:51 +00:00
.long 0 / / PointerToRelocations
.long 0 / / PointerToLineNumbers
.short 0 / / NumberOfRelocations
.short 0 / / NumberOfLineNumbers
.long IMAGE_SCN_CNT_INITIALIZED_DATA | \
2017-03-23 19:00:50 +00:00
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
2020-11-17 13:47:28 +01:00
.set .Lsection_count , ( . - .Lsection_table ) / 4 0
2017-03-23 19:00:46 +00:00
# ifdef C O N F I G _ D E B U G _ E F I
2020-11-17 13:47:28 +01:00
.Lefi_debug_entry :
2017-03-23 19:00:46 +00:00
/ / EFI_ I M A G E _ D E B U G _ C O D E V I E W _ N B 1 0 _ E N T R Y
.ascii " NB1 0 " / / S i g n a t u r e
.long 0 / / Unknown
.long 0 / / Unknown2
.long 0 / / Unknown3
.asciz VMLINUX_PATH
2020-11-17 13:47:28 +01:00
.set .Lefi_debug_entry_size , . - .Lefi_debug_entry
2017-03-23 19:00:46 +00:00
# endif
2023-04-18 15:49:48 +02:00
# ifdef C O N F I G _ A R M 6 4 _ B T I _ K E R N E L
.Lefi_dll_characteristics_ex :
.long IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT
# endif
2017-03-23 19:00:46 +00:00
2020-10-27 08:32:06 +01:00
.balign SEGMENT_ALIGN
2020-11-17 13:47:28 +01:00
.Lefi_header_end :
2020-11-17 13:47:29 +01:00
# else
.set .Lpe_header_offset , 0 x0
# endif
2017-03-23 19:00:46 +00:00
.endm