diff --git a/.gitignore b/.gitignore index 970b638e..e9b0e08f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.a *.tar.* *.tar +*.so diff --git a/Make.defaults b/Make.defaults index a4ecac0a..0068e319 100755 --- a/Make.defaults +++ b/Make.defaults @@ -34,7 +34,7 @@ # SUCH DAMAGE. # -TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi) +TOPDIR ?= $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi) # # Variables below overridable from command-line: @@ -89,6 +89,16 @@ ifeq ($(ARCH),amd64) override ARCH := x86_64 endif +GCCVERSION := $(shell $(CC) -dumpversion | cut -f1 -d.) +GCCMINOR := $(shell $(CC) -dumpversion | cut -f2 -d.) +USING_CLANG := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang) + +# Rely on GCC MS ABI support? +GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \ + || ( [ $(GCCVERSION) -eq "4" ] \ + && [ $(GCCMINOR) -ge "7" ] ) ) \ + && echo 1) + # # Where to build the package # @@ -114,20 +124,15 @@ ifeq ($(ARCH),ia32) endif endif +# Set ISO C mode +CPPFLAGS += -std=c11 + ifeq ($(ARCH),x86_64) - GCCVERSION := $(shell $(CC) -dumpversion | cut -f1 -d.) - GCCMINOR := $(shell $(CC) -dumpversion | cut -f2 -d.) - USING_CLANG := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang) - - # Rely on GCC MS ABI support? - GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ] \ - || ( [ $(GCCVERSION) -eq "4" ] \ - && [ $(GCCMINOR) -ge "7" ] ) ) \ - && echo 1) ifeq ($(GCCNEWENOUGH),1) - CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args -std=c11 - else ifeq ($(USING_CLANG),clang) - CPPFLAGS += -DGNU_EFI_USE_MS_ABI -std=c11 + CPPFLAGS += -DGNU_EFI_USE_MS_ABI + ifneq ($(USING_CLANG),clang) + CPPFLAGS += -maccumulate-outgoing-args + endif endif CFLAGS += -mno-red-zone @@ -156,18 +161,16 @@ endif ifneq ($(ARCH),arm) ifneq ($(ARCH),mips64el) ifneq ($(ARCH),riscv64) -ifneq ($(ARCH),loongarch64) export HAVE_EFI_OBJCOPY=y endif endif endif -endif ifeq ($(ARCH),arm) CFLAGS += -marm endif -ifeq ($(ARCH),aarch64) +ifneq (,$(filter $(ARCH),aarch64 arm loongarch64)) LDFLAGS += -z common-page-size=4096 LDFLAGS += -z max-page-size=4096 endif @@ -190,7 +193,6 @@ else CFLAGS += $(ARCH3264) -g -O2 -Wall -Wextra -Wno-pointer-sign -Werror \ -funsigned-char -fshort-wchar -fno-strict-aliasing \ -ffreestanding -fno-stack-protector -fno-stack-check \ - -fno-stack-check \ $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,) endif diff --git a/Make.rules b/Make.rules index b2707818..cdb7aab0 100644 --- a/Make.rules +++ b/Make.rules @@ -37,9 +37,9 @@ .SECONDARY: %.efi: %.so - $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \ + $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .rodata -j .rel \ -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \ - -j .reloc $(FORMAT) $*.so $@ + -j .areloc -j .reloc $(FORMAT) $*.so $@ %.efi.debug: %.so $(OBJCOPY) -j .debug_info -j .debug_abbrev -j .debug_aranges \ diff --git a/Makefile b/Makefile index e58d02ac..e0b3062a 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ # SUCH DAMAGE. # -export VERSION = 3.0.17 +export VERSION = 3.0.18 MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) SRCDIR = $(dir $(MKFILE_PATH)) @@ -82,7 +82,7 @@ $(SUBDIRS): $(MAKE) -C $(OBJDIR)/$@ -f $(SRCDIR)/$@/Makefile SRCDIR=$(SRCDIR)/$@ ARCH=$(ARCH) clean: - rm -f *~ + @rm -vrf *~ @set -e ; for d in $(SUBDIRS); do \ if [ -d $(OBJDIR)/$$d ]; then \ $(MAKE) -C $(OBJDIR)/$$d -f $(SRCDIR)/$$d/Makefile SRCDIR=$(SRCDIR)/$$d clean; \ diff --git a/apps/Makefile b/apps/Makefile index 424ee9d0..18980f16 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -37,23 +37,21 @@ SRCDIR = . VPATH = $(SRCDIR) +TOPDIR = $(SRCDIR)/.. include $(SRCDIR)/../Make.defaults -TOPDIR = $(SRCDIR)/.. - -CDIR=$(TOPDIR)/.. LINUX_HEADERS = /usr/src/sys/build APPSDIR = $(LIBDIR)/gnuefi/apps CPPFLAGS += -D__KERNEL__ -I$(LINUX_HEADERS)/include -CRTOBJS = ../gnuefi/crt0-efi-$(ARCH).o +CRTOBJS = $(TOPDIR)/$(ARCH)/gnuefi/crt0-efi-$(ARCH).o LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_efi.lds ifneq (,$(findstring FreeBSD,$(OS))) LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds endif -LDFLAGS += -shared -Bsymbolic -L../lib -L../gnuefi $(CRTOBJS) +LDFLAGS += -shared -Bsymbolic -L$(TOPDIR)/$(ARCH)/lib -L$(TOPDIR)/$(ARCH)/gnuefi $(CRTOBJS) LOADLIBES += -lefi -lgnuefi LOADLIBES += $(LIBGCC) @@ -92,7 +90,7 @@ all: $(TARGETS) ctors_test.so : ctors_fns.o ctors_test.o clean: - rm -f $(TARGETS) *~ *.o *.so + @rm -vf $(TARGETS) *~ *.o *.so install: mkdir -p $(INSTALLROOT)$(APPSDIR) diff --git a/apps/ctors_dtors_priority_test.c b/apps/ctors_dtors_priority_test.c index 0458c083..e8a39906 100644 --- a/apps/ctors_dtors_priority_test.c +++ b/apps/ctors_dtors_priority_test.c @@ -2,22 +2,22 @@ #include // 101 in init_array, 65434 in ctors -static void __attribute__((constructor(101))) ctors101() { +static void __attribute__((constructor(101))) EFI_NO_TAIL_CALL ctors101() { Print(L"1) ctor with lower numbered priority \r\n"); } // 65434 in init_array, 101 in ctors -static void __attribute__((constructor(65434))) ctors65434() { +static void __attribute__((constructor(65434))) EFI_NO_TAIL_CALL ctors65434() { Print(L"2) ctor with higher numbered priority \r\n"); } // 101 in fini_array, 65434 in dtors -static void __attribute__((destructor(101))) dtors101() { +static void __attribute__((destructor(101))) EFI_NO_TAIL_CALL dtors101() { Print(L"4) dtor with lower numbered priority \r\n"); } // 65434 in fini_array, 101 in dtors -static void __attribute__((destructor(65434))) dtors65434() { +static void __attribute__((destructor(65434))) EFI_NO_TAIL_CALL dtors65434() { Print(L"3) dtor with higher numbered priority \r\n"); } diff --git a/apps/ctors_fns.c b/apps/ctors_fns.c index 62419046..70274475 100644 --- a/apps/ctors_fns.c +++ b/apps/ctors_fns.c @@ -9,14 +9,14 @@ int constructed_value = 0; -static void __attribute__((__constructor__)) ctor(void) +static void __attribute__((__constructor__)) EFI_NO_TAIL_CALL ctor(void) { Print(L"%a:%d:%a() constructed_value:%d\n", __FILE__, __LINE__, __func__, constructed_value); constructed_value = 1; Print(L"%a:%d:%a() constructed_value:%d\n", __FILE__, __LINE__, __func__, constructed_value); } -static void __attribute__((__destructor__)) dtor(void) +static void __attribute__((__destructor__)) EFI_NO_TAIL_CALL dtor(void) { Print(L"%a:%d:%a() constructed_value:%d\n", __FILE__, __LINE__, __func__, constructed_value); constructed_value = 0; diff --git a/apps/debughook.c b/apps/debughook.c index 78e4a767..c862f0fe 100644 --- a/apps/debughook.c +++ b/apps/debughook.c @@ -37,13 +37,7 @@ GetVariable(CHAR16 *var, UINT8 **data, UINTN *len, EFI_GUID owner) EFI_GUID DUMMY_GUID = {0x55aad538, 0x8f82, 0x4e2a, {0xa4,0xf0,0xbe, 0x59, 0x13, 0xb6, 0x5f, 0x1e}}; -#if defined(__clang__) -# define _OPTNONE __attribute__((optnone)) -#else -# define _OPTNONE __attribute__((__optimize__("0"))) -#endif - -static _OPTNONE void +static EFI_OPTNONE void DebugHook(void) { EFI_GUID guid = DUMMY_GUID; diff --git a/gnuefi/Makefile b/gnuefi/Makefile index e0c9da84..68dfced5 100644 --- a/gnuefi/Makefile +++ b/gnuefi/Makefile @@ -37,12 +37,10 @@ SRCDIR = . VPATH = $(SRCDIR) +TOPDIR = $(SRCDIR)/.. include $(SRCDIR)/../Make.defaults -TOPDIR = $(SRCDIR)/.. - -CDIR=$(TOPDIR)/.. PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig FILES = reloc_$(ARCH) @@ -69,7 +67,7 @@ gnu-efi.pc: clean: - rm -f $(TARGETS) *~ *.o $(OBJS) + @rm -vf $(TARGETS) *~ *.o $(OBJS) install: mkdir -p $(INSTALLROOT)$(LIBDIR) diff --git a/gnuefi/crt0-efi-aarch64.S b/gnuefi/crt0-efi-aarch64.S index 60166980..236b5444 100644 --- a/gnuefi/crt0-efi-aarch64.S +++ b/gnuefi/crt0-efi-aarch64.S @@ -20,6 +20,7 @@ .align 12 .globl _start + .type _start,%function _start: stp x29, x30, [sp, #-32]! mov x29, sp @@ -42,15 +43,15 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .long 0 +dummy: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc, "a" label1: - .long dummy-label1 // Page RVA - .long 12 // Block Size (2*4+2*2), must be aligned by 32 Bits - .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy - .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .4byte dummy-label1 // Page RVA + .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy #if defined(__ELF__) && defined(__linux__) .section .note.GNU-stack,"",%progbits diff --git a/gnuefi/crt0-efi-arm.S b/gnuefi/crt0-efi-arm.S index 716699b6..d84d43cf 100644 --- a/gnuefi/crt0-efi-arm.S +++ b/gnuefi/crt0-efi-arm.S @@ -25,103 +25,132 @@ ImageBase: .ascii "MZ" .skip 58 // 'MZ' + pad + offset == 64 - .long pe_header - ImageBase // Offset to the PE header. + .4byte pe_header - ImageBase // Offset to the PE header. pe_header: .ascii "PE" - .short 0 + .2byte 0 coff_header: - .short 0x1c2 // Mixed ARM/Thumb - .short 2 // nr_sections - .long 0 // TimeDateStamp - .long 0 // PointerToSymbolTable - .long 0 // NumberOfSymbols - .short section_table - optional_header // SizeOfOptionalHeader - .short 0x306 // Characteristics. + .2byte 0x1c2 // Mixed ARM/Thumb + .2byte 4 // nr_sections + .4byte 0 // TimeDateStamp + .4byte 0 // PointerToSymbolTable + .4byte 0 // NumberOfSymbols + .2byte section_table - optional_header // SizeOfOptionalHeader + .2byte 0x306 // Characteristics. // IMAGE_FILE_32BIT_MACHINE | // IMAGE_FILE_DEBUG_STRIPPED | // IMAGE_FILE_EXECUTABLE_IMAGE | // IMAGE_FILE_LINE_NUMS_STRIPPED optional_header: - .short 0x10b // PE32+ format + .2byte 0x10b // PE32+ format .byte 0x02 // MajorLinkerVersion .byte 0x14 // MinorLinkerVersion - .long _edata - _start // SizeOfCode - .long 0 // SizeOfInitializedData - .long 0 // SizeOfUninitializedData - .long _start - ImageBase // AddressOfEntryPoint - .long _start - ImageBase // BaseOfCode - .long 0 // BaseOfData + .4byte _etext - _start // SizeOfCode + .4byte _alldata_size - ImageBase // SizeOfInitializedData + .4byte 0 // SizeOfUninitializedData + .4byte _start - ImageBase // AddressOfEntryPoint + .4byte _start - ImageBase // BaseOfCode + .4byte _reloc - ImageBase // BaseOfData extra_header_fields: - .long 0 // ImageBase - .long 0x20 // SectionAlignment - .long 0x8 // FileAlignment - .short 0 // MajorOperatingSystemVersion - .short 0 // MinorOperatingSystemVersion - .short 0 // MajorImageVersion - .short 0 // MinorImageVersion - .short 0 // MajorSubsystemVersion - .short 0 // MinorSubsystemVersion - .long 0 // Win32VersionValue - - .long _edata - ImageBase // SizeOfImage + .4byte 0 // ImageBase + .4byte 0x1000 // SectionAlignment + .4byte 0x1000 // FileAlignment + .2byte 0 // MajorOperatingSystemVersion + .2byte 0 // MinorOperatingSystemVersion + .2byte 0 // MajorImageVersion + .2byte 0 // MinorImageVersion + .2byte 0 // MajorSubsystemVersion + .2byte 0 // MinorSubsystemVersion + .4byte 0 // Win32VersionValue + + .4byte _image_end - ImageBase // SizeOfImage // Everything before the kernel image is considered part of the header - .long _start - ImageBase // SizeOfHeaders - .long 0 // CheckSum - .short EFI_SUBSYSTEM // Subsystem - .short 0 // DllCharacteristics - .long 0 // SizeOfStackReserve - .long 0 // SizeOfStackCommit - .long 0 // SizeOfHeapReserve - .long 0 // SizeOfHeapCommit - .long 0 // LoaderFlags - .long 0x6 // NumberOfRvaAndSizes - - .quad 0 // ExportTable - .quad 0 // ImportTable - .quad 0 // ResourceTable - .quad 0 // ExceptionTable - .quad 0 // CertificationTable - .quad 0 // BaseRelocationTable + .4byte _start - ImageBase // SizeOfHeaders + .4byte 0 // CheckSum + .2byte EFI_SUBSYSTEM // Subsystem + .2byte 0 // DllCharacteristics + .4byte 0 // SizeOfStackReserve + .4byte 0 // SizeOfStackCommit + .4byte 0 // SizeOfHeapReserve + .4byte 0 // SizeOfHeapCommit + .4byte 0 // LoaderFlags + .4byte 0x10 // NumberOfRvaAndSizes + + .8byte 0 // ExportTable + .8byte 0 // ImportTable + .8byte 0 // ResourceTable + .8byte 0 // ExceptionTable + .8byte 0 // CertificationTable + .4byte _reloc - ImageBase // BaseRelocationTable (VirtualAddress) + .4byte _reloc_vsize - ImageBase // BaseRelocationTable (Size) + .8byte 0 // Debug + .8byte 0 // Architecture + .8byte 0 // Global Ptr + .8byte 0 // TLS Table + .8byte 0 // Load Config Table + .8byte 0 // Bound Import + .8byte 0 // IAT + .8byte 0 // Delay Import Descriptor + .8byte 0 // CLR Runtime Header + .8byte 0 // Reserved, must be zero // Section table section_table: + .ascii ".text\0\0\0" + .4byte _evtext - _start // VirtualSize + .4byte _start - ImageBase // VirtualAddress + .4byte _etext - _start // SizeOfRawData + .4byte _start - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations (0 for executables) + .4byte 0 // PointerToLineNumbers (0 for executables) + .2byte 0 // NumberOfRelocations (0 for executables) + .2byte 0 // NumberOfLineNumbers (0 for executables) + .4byte 0x60000020 // Characteristics (section flags) + /* * The EFI application loader requires a relocation section * because EFI applications must be relocatable. This is a * dummy section as far as we are concerned. */ - .ascii ".reloc" - .byte 0 - .byte 0 // end of 0 padding of section name - .long 0 - .long 0 - .long 0 // SizeOfRawData - .long 0 // PointerToRawData - .long 0 // PointerToRelocations - .long 0 // PointerToLineNumbers - .short 0 // NumberOfRelocations - .short 0 // NumberOfLineNumbers - .long 0x42100040 // Characteristics (section flags) - - - .ascii ".text" - .byte 0 - .byte 0 - .byte 0 // end of 0 padding of section name - .long _edata - _start // VirtualSize - .long _start - ImageBase // VirtualAddress - .long _edata - _start // SizeOfRawData - .long _start - ImageBase // PointerToRawData - - .long 0 // PointerToRelocations (0 for executables) - .long 0 // PointerToLineNumbers (0 for executables) - .short 0 // NumberOfRelocations (0 for executables) - .short 0 // NumberOfLineNumbers (0 for executables) - .long 0xe0500020 // Characteristics (section flags) - + .ascii ".reloc\0\0" + .4byte _reloc_vsize - ImageBase // VirtualSize + .4byte _reloc - ImageBase // VirtualAddress + .4byte _reloc_size - ImageBase // SizeOfRawData + .4byte _reloc - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0x42000040 // Characteristics (section flags) + + .ascii ".data\0\0\0" + .4byte _data_vsize - ImageBase // VirtualSize + .4byte _data - ImageBase // VirtualAddress + .4byte _data_size - ImageBase // SizeOfRawData + .4byte _data - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0xC0000040 // Characteristics (section flags) + + .ascii ".rodata\0" + .4byte _rodata_vsize - ImageBase // VirtualSize + .4byte _rodata - ImageBase // VirtualAddress + .4byte _rodata_size - ImageBase // SizeOfRawData + .4byte _rodata - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0x40000040 // Characteristics (section flags) + +.balign 256 +.globl _start +.type _start,%function _start: stmfd sp!, {r0-r2, lr} @@ -142,7 +171,19 @@ _start: ldr pc, [sp], #4 .L_DYNAMIC: - .word _DYNAMIC - . + .4byte _DYNAMIC - . + +// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: + + .data +dummy: .4byte 0 + +#define IMAGE_REL_ABSOLUTE 0 + .section .areloc + .4byte dummy // Page RVA + .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy #if defined(__ELF__) && defined(__linux__) .section .note.GNU-stack,"",%progbits diff --git a/gnuefi/crt0-efi-ia32.S b/gnuefi/crt0-efi-ia32.S index df3340ac..e7023ab5 100644 --- a/gnuefi/crt0-efi-ia32.S +++ b/gnuefi/crt0-efi-ia32.S @@ -37,6 +37,7 @@ .align 4 .globl _start + .type _start,%function _start: pushl %ebp movl %esp,%ebp @@ -67,14 +68,14 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .long 0 +dummy: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc - .long dummy // Page RVA - .long 12 // Block Size (2*4+2*2), must be aligned by 32 Bits - .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy - .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .4byte dummy // Page RVA + .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy #if defined(__ELF__) && defined(__linux__) .section .note.GNU-stack,"",%progbits diff --git a/gnuefi/crt0-efi-loongarch64.S b/gnuefi/crt0-efi-loongarch64.S index af45d46c..af939ffb 100644 --- a/gnuefi/crt0-efi-loongarch64.S +++ b/gnuefi/crt0-efi-loongarch64.S @@ -17,115 +17,8 @@ * either version 2 of the License, or (at your option) any later version. */ -#ifndef EFI_SUBSYSTEM -#define EFI_SUBSYSTEM 0xa -#endif - .section .text.head - - /* - * Magic "MZ" signature for PE/COFF - */ - .globl ImageBase -ImageBase: - .ascii "MZ" - .skip 58 // 'MZ' + pad + offset == 64 - .long pe_header - ImageBase // Offset to the PE header. -pe_header: - .ascii "PE" - .short 0 -coff_header: - .short 0x6264 // loongarch64 little endian - .short 2 // nr_sections - .long 0 // TimeDateStamp - .long 0 // PointerToSymbolTable - .long 1 // NumberOfSymbols - .short section_table - optional_header // SizeOfOptionalHeader - .short 0x206 // Characteristics. - // IMAGE_FILE_DEBUG_STRIPPED | - // IMAGE_FILE_EXECUTABLE_IMAGE | - // IMAGE_FILE_LINE_NUMS_STRIPPED -optional_header: - .short 0x20b // PE32+ format - .byte 0x02 // MajorLinkerVersion - .byte 0x14 // MinorLinkerVersion - .long _edata - _start // SizeOfCode - .long 0 // SizeOfInitializedData - .long 0 // SizeOfUninitializedData - .long _start - ImageBase // AddressOfEntryPoint - .long _start - ImageBase // BaseOfCode - -extra_header_fields: - .quad 0 // ImageBase - .long 0x20 // SectionAlignment - .long 0x8 // FileAlignment - .short 0 // MajorOperatingSystemVersion - .short 0 // MinorOperatingSystemVersion - .short 0 // MajorImageVersion - .short 0 // MinorImageVersion - .short 0 // MajorSubsystemVersion - .short 0 // MinorSubsystemVersion - .long 0 // Win32VersionValue - - .long _edata - ImageBase // SizeOfImage - - // Everything before the kernel image is considered part of the header - .long _start - ImageBase // SizeOfHeaders - .long 0 // CheckSum - .short EFI_SUBSYSTEM // Subsystem - .short 0 // DllCharacteristics - .quad 0 // SizeOfStackReserve - .quad 0 // SizeOfStackCommit - .quad 0 // SizeOfHeapReserve - .quad 0 // SizeOfHeapCommit - .long 0 // LoaderFlags - .long 0x6 // NumberOfRvaAndSizes - - .quad 0 // ExportTable - .quad 0 // ImportTable - .quad 0 // ResourceTable - .quad 0 // ExceptionTable - .quad 0 // CertificationTable - .quad 0 // BaseRelocationTable - - // Section table -section_table: - - /* - * The EFI application loader requires a relocation section - * because EFI applications must be relocatable. This is a - * dummy section as far as we are concerned. - */ - .ascii ".reloc" - .byte 0 - .byte 0 // end of 0 padding of section name - .long 0 - .long 0 - .long 0 // SizeOfRawData - .long 0 // PointerToRawData - .long 0 // PointerToRelocations - .long 0 // PointerToLineNumbers - .short 0 // NumberOfRelocations - .short 0 // NumberOfLineNumbers - .long 0x42100040 // Characteristics (section flags) - - - .ascii ".text" - .byte 0 - .byte 0 - .byte 0 // end of 0 padding of section name - .long _edata - _start // VirtualSize - .long _start - ImageBase // VirtualAddress - .long _edata - _start // SizeOfRawData - .long _start - ImageBase // PointerToRawData - - .long 0 // PointerToRelocations (0 for executables) - .long 0 // PointerToLineNumbers (0 for executables) - .short 0 // NumberOfRelocations (0 for executables) - .short 0 // NumberOfLineNumbers (0 for executables) - .long 0xe0500020 // Characteristics (section flags) - - .align 4 - + .text + .align 12 .globl _start .type _start, @function _start: @@ -143,9 +36,25 @@ _start: ld.d $a0, $sp, 8 ld.d $a1, $sp, 16 - bl efi_main + bl _entry 0: ld.d $ra, $sp, 0 addi.d $sp, $sp, 24 jr $ra - .end _start + +// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: + + .data +dummy: .4byte 0 + +#define IMAGE_REL_ABSOLUTE 0 + .section .reloc, "a" +label1: + .4byte dummy-label1 // Page RVA + .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + +#if defined(__ELF__) && defined(__linux__) + .section .note.GNU-stack,"",%progbits +#endif diff --git a/gnuefi/crt0-efi-mips64el.S b/gnuefi/crt0-efi-mips64el.S index cecabfbd..334c3086 100644 --- a/gnuefi/crt0-efi-mips64el.S +++ b/gnuefi/crt0-efi-mips64el.S @@ -26,63 +26,73 @@ ImageBase: .ascii "MZ" .skip 58 // 'MZ' + pad + offset == 64 - .long pe_header - ImageBase // Offset to the PE header. + .4byte pe_header - ImageBase // Offset to the PE header. pe_header: .ascii "PE" - .short 0 + .2byte 0 coff_header: - .short 0x166 // MIPS little endian - .short 2 // nr_sections - .long 0 // TimeDateStamp - .long 0 // PointerToSymbolTable - .long 0 // NumberOfSymbols - .short section_table - optional_header // SizeOfOptionalHeader - .short 0x206 // Characteristics. + .2byte 0x166 // MIPS little endian + .2byte 2 // nr_sections + .4byte 0 // TimeDateStamp + .4byte 0 // PointerToSymbolTable + .4byte 0 // NumberOfSymbols + .2byte section_table - optional_header // SizeOfOptionalHeader + .2byte 0x206 // Characteristics. // IMAGE_FILE_DEBUG_STRIPPED | // IMAGE_FILE_EXECUTABLE_IMAGE | // IMAGE_FILE_LINE_NUMS_STRIPPED optional_header: - .short 0x20b // PE32+ format + .2byte 0x20b // PE32+ format .byte 0x02 // MajorLinkerVersion .byte 0x14 // MinorLinkerVersion - .long _edata - _start // SizeOfCode - .long 0 // SizeOfInitializedData - .long 0 // SizeOfUninitializedData - .long _start - ImageBase // AddressOfEntryPoint - .long _start - ImageBase // BaseOfCode + .4byte _edata - _start // SizeOfCode + .4byte 0 // SizeOfInitializedData + .4byte 0 // SizeOfUninitializedData + .4byte _start - ImageBase // AddressOfEntryPoint + .4byte _start - ImageBase // BaseOfCode extra_header_fields: - .quad 0 // ImageBase - .long 0x20 // SectionAlignment - .long 0x8 // FileAlignment - .short 0 // MajorOperatingSystemVersion - .short 0 // MinorOperatingSystemVersion - .short 0 // MajorImageVersion - .short 0 // MinorImageVersion - .short 0 // MajorSubsystemVersion - .short 0 // MinorSubsystemVersion - .long 0 // Win32VersionValue - - .long _edata - ImageBase // SizeOfImage + .8byte 0 // ImageBase + .4byte 0x20 // SectionAlignment + .4byte 0x8 // FileAlignment + .2byte 0 // MajorOperatingSystemVersion + .2byte 0 // MinorOperatingSystemVersion + .2byte 0 // MajorImageVersion + .2byte 0 // MinorImageVersion + .2byte 0 // MajorSubsystemVersion + .2byte 0 // MinorSubsystemVersion + .4byte 0 // Win32VersionValue + + .4byte _edata - ImageBase // SizeOfImage // Everything before the kernel image is considered part of the header - .long _start - ImageBase // SizeOfHeaders - .long 0 // CheckSum - .short EFI_SUBSYSTEM // Subsystem - .short 0 // DllCharacteristics - .quad 0 // SizeOfStackReserve - .quad 0 // SizeOfStackCommit - .quad 0 // SizeOfHeapReserve - .quad 0 // SizeOfHeapCommit - .long 0 // LoaderFlags - .long 0x6 // NumberOfRvaAndSizes - - .quad 0 // ExportTable - .quad 0 // ImportTable - .quad 0 // ResourceTable - .quad 0 // ExceptionTable - .quad 0 // CertificationTable - .quad 0 // BaseRelocationTable + .4byte _start - ImageBase // SizeOfHeaders + .4byte 0 // CheckSum + .2byte EFI_SUBSYSTEM // Subsystem + .2byte 0 // DllCharacteristics + .8byte 0 // SizeOfStackReserve + .8byte 0 // SizeOfStackCommit + .8byte 0 // SizeOfHeapReserve + .8byte 0 // SizeOfHeapCommit + .4byte 0 // LoaderFlags + .4byte 0x10 // NumberOfRvaAndSizes + + .8byte 0 // ExportTable + .8byte 0 // ImportTable + .8byte 0 // ResourceTable + .8byte 0 // ExceptionTable + .8byte 0 // CertificationTable + .8byte 0 // BaseRelocationTable + .8byte 0 // Debug + .8byte 0 // Architecture + .8byte 0 // Global Ptr + .8byte 0 // TLS Table + .8byte 0 // Load Config Table + .8byte 0 // Bound Import + .8byte 0 // IAT + .8byte 0 // Delay Import Descriptor + .8byte 0 // CLR Runtime Header + .8byte 0 // Reserved, must be zero // Section table section_table: @@ -95,31 +105,31 @@ section_table: .ascii ".reloc" .byte 0 .byte 0 // end of 0 padding of section name - .long 0 - .long 0 - .long 0 // SizeOfRawData - .long 0 // PointerToRawData - .long 0 // PointerToRelocations - .long 0 // PointerToLineNumbers - .short 0 // NumberOfRelocations - .short 0 // NumberOfLineNumbers - .long 0x42100040 // Characteristics (section flags) + .4byte 0 + .4byte 0 + .4byte 0 // SizeOfRawData + .4byte 0 // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0x42100040 // Characteristics (section flags) .ascii ".text" .byte 0 .byte 0 .byte 0 // end of 0 padding of section name - .long _edata - _start // VirtualSize - .long _start - ImageBase // VirtualAddress - .long _edata - _start // SizeOfRawData - .long _start - ImageBase // PointerToRawData - - .long 0 // PointerToRelocations (0 for executables) - .long 0 // PointerToLineNumbers (0 for executables) - .short 0 // NumberOfRelocations (0 for executables) - .short 0 // NumberOfLineNumbers (0 for executables) - .long 0xe0500020 // Characteristics (section flags) + .4byte _edata - _start // VirtualSize + .4byte _start - ImageBase // VirtualAddress + .4byte _edata - _start // SizeOfRawData + .4byte _start - ImageBase // PointerToRawData + + .4byte 0 // PointerToRelocations (0 for executables) + .4byte 0 // PointerToLineNumbers (0 for executables) + .2byte 0 // NumberOfRelocations (0 for executables) + .2byte 0 // NumberOfLineNumbers (0 for executables) + .4byte 0xe0500020 // Characteristics (section flags) .set push .set noreorder diff --git a/gnuefi/crt0-efi-riscv64.S b/gnuefi/crt0-efi-riscv64.S index 2322b567..712ed03f 100644 --- a/gnuefi/crt0-efi-riscv64.S +++ b/gnuefi/crt0-efi-riscv64.S @@ -29,96 +29,130 @@ ImageBase: .ascii "MZ" .skip 58 // 'MZ' + pad + offset == 64 - .long pe_header - ImageBase // Offset to the PE header. + .4byte pe_header - ImageBase // Offset to the PE header. pe_header: .ascii "PE" - .short 0 + .2byte 0 coff_header: - .short 0x5064 // riscv64 - .short 2 // nr_sections - .long 0 // TimeDateStamp - .long 0 // PointerToSymbolTable - .long 0 // NumberOfSymbols - .short section_table - optional_header // SizeOfOptionalHeader - .short 0x206 // Characteristics. + .2byte 0x5064 // riscv64 + .2byte 4 // nr_sections + .4byte 0 // TimeDateStamp + .4byte 0 // PointerToSymbolTable + .4byte 0 // NumberOfSymbols + .2byte section_table - optional_header // SizeOfOptionalHeader + .2byte 0x206 // Characteristics. // IMAGE_FILE_DEBUG_STRIPPED | // IMAGE_FILE_EXECUTABLE_IMAGE | // IMAGE_FILE_LINE_NUMS_STRIPPED optional_header: - .short 0x20b // PE32+ format + .2byte 0x20b // PE32+ format .byte 0x02 // MajorLinkerVersion .byte 0x14 // MinorLinkerVersion - .long _data - _start // SizeOfCode - .long _data_size // SizeOfInitializedData - .long 0 // SizeOfUninitializedData - .long _start - ImageBase // AddressOfEntryPoint - .long _start - ImageBase // BaseOfCode + .4byte _text_size - ImageBase // SizeOfCode + .4byte _alldata_size - ImageBase // SizeOfInitializedData + .4byte 0 // SizeOfUninitializedData + .4byte _start - ImageBase // AddressOfEntryPoint + .4byte _text - ImageBase // BaseOfCode extra_header_fields: - .quad 0 // ImageBase - .long 0x1000 // SectionAlignment - .long 0x200 // FileAlignment - .short 0 // MajorOperatingSystemVersion - .short 0 // MinorOperatingSystemVersion - .short 0 // MajorImageVersion - .short 0 // MinorImageVersion - .short 0 // MajorSubsystemVersion - .short 0 // MinorSubsystemVersion - .long 0 // Win32VersionValue - - .long _edata - ImageBase // SizeOfImage + .8byte 0 // ImageBase + .4byte 0x1000 // SectionAlignment + .4byte 0x1000 // FileAlignment + .2byte 0 // MajorOperatingSystemVersion + .2byte 0 // MinorOperatingSystemVersion + .2byte 0 // MajorImageVersion + .2byte 0 // MinorImageVersion + .2byte 0 // MajorSubsystemVersion + .2byte 0 // MinorSubsystemVersion + .4byte 0 // Win32VersionValue + + .4byte _image_end - ImageBase // SizeOfImage // Everything before the kernel image is considered part of the header - .long _start - ImageBase // SizeOfHeaders - .long 0 // CheckSum - .short EFI_SUBSYSTEM // Subsystem - .short 0 // DllCharacteristics - .quad 0 // SizeOfStackReserve - .quad 0 // SizeOfStackCommit - .quad 0 // SizeOfHeapReserve - .quad 0 // SizeOfHeapCommit - .long 0 // LoaderFlags - .long 0x6 // NumberOfRvaAndSizes - - .quad 0 // ExportTable - .quad 0 // ImportTable - .quad 0 // ResourceTable - .quad 0 // ExceptionTable - .quad 0 // CertificationTable - .quad 0 // BaseRelocationTable + .4byte _text - ImageBase // SizeOfHeaders + .4byte 0 // CheckSum + .2byte EFI_SUBSYSTEM // Subsystem + .2byte 0 // DllCharacteristics + .8byte 0 // SizeOfStackReserve + .8byte 0 // SizeOfStackCommit + .8byte 0 // SizeOfHeapReserve + .8byte 0 // SizeOfHeapCommit + .4byte 0 // LoaderFlags + .4byte 0x10 // NumberOfRvaAndSizes + + .8byte 0 // ExportTable + .8byte 0 // ImportTable + .8byte 0 // ResourceTable + .8byte 0 // ExceptionTable + .8byte 0 // CertificationTable + .4byte _reloc - ImageBase // BaseRelocationTable (VirtualAddress) + .4byte _reloc_vsize - ImageBase // BaseRelocationTable (Size) + .8byte 0 // Debug + .8byte 0 // Architecture + .8byte 0 // Global Ptr + .8byte 0 // TLS Table + .8byte 0 // Load Config Table + .8byte 0 // Bound Import + .8byte 0 // IAT + .8byte 0 // Delay Import Descriptor + .8byte 0 // CLR Runtime Header + .8byte 0 // Reserved, must be zero // Section table section_table: + + .ascii ".text\0\0\0" + .4byte _text_vsize - ImageBase // VirtualSize + .4byte _text - ImageBase // VirtualAddress + .4byte _text_size - ImageBase // SizeOfRawData + .4byte _text - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations (0 for executables) + .4byte 0 // PointerToLineNumbers (0 for executables) + .2byte 0 // NumberOfRelocations (0 for executables) + .2byte 0 // NumberOfLineNumbers (0 for executables) + .4byte 0x60000020 // Characteristics (section flags) + /* * The EFI application loader requires a relocation section * because EFI applications must be relocatable. This is a * dummy section as far as we are concerned. */ .ascii ".reloc\0\0" - .long 0 - .long 0 - .long 0 // SizeOfRawData - .long 0 // PointerToRawData - .long 0 // PointerToRelocations - .long 0 // PointerToLineNumbers - .short 0 // NumberOfRelocations - .short 0 // NumberOfLineNumbers - .long 0x42100040 // Characteristics (section flags) + .4byte _reloc_vsize - ImageBase // VirtualSize + .4byte _reloc - ImageBase // VirtualAddress + .4byte _reloc_size - ImageBase // SizeOfRawData + .4byte _reloc - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0x42000040 // Characteristics (section flags) - .ascii ".text\0\0\0" - .long _edata - _start // VirtualSize - .long _start - ImageBase // VirtualAddress - .long _edata - _start // SizeOfRawData - .long _start - ImageBase // PointerToRawData - - .long 0 // PointerToRelocations (0 for executables) - .long 0 // PointerToLineNumbers (0 for executables) - .short 0 // NumberOfRelocations (0 for executables) - .short 0 // NumberOfLineNumbers (0 for executables) - .long 0xe0500020 // Characteristics (section flags) - - .align 12 + .ascii ".data\0\0\0" + .4byte _data_vsize - ImageBase // VirtualSize + .4byte _data - ImageBase // VirtualAddress + .4byte _data_size - ImageBase // SizeOfRawData + .4byte _data - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0xC0000040 // Characteristics (section flags) + + .ascii ".rodata\0" + .4byte _rodata_vsize - ImageBase // VirtualSize + .4byte _rodata - ImageBase // VirtualAddress + .4byte _rodata_size - ImageBase // SizeOfRawData + .4byte _rodata - ImageBase // PointerToRawData + .4byte 0 // PointerToRelocations + .4byte 0 // PointerToLineNumbers + .2byte 0 // NumberOfRelocations + .2byte 0 // NumberOfLineNumbers + .4byte 0x40000040 // Characteristics (section flags) + + .text .globl _start + .type _start,%function _start: addi sp, sp, -24 sd a0, 0(sp) @@ -130,11 +164,24 @@ _start: bne a0, zero, 0f ld a1, 8(sp) ld a0, 0(sp) - call efi_main + call _entry ld ra, 16(sp) 0: addi sp, sp, 24 ret +// hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: + + .data +dummy: .4byte 0 + +#define IMAGE_REL_ABSOLUTE 0 + .section .reloc, "a" +label1: + .4byte dummy-label1 // Page RVA + .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + #if defined(__ELF__) && defined(__linux__) .section .note.GNU-stack,"",%progbits #endif diff --git a/gnuefi/crt0-efi-x86_64.S b/gnuefi/crt0-efi-x86_64.S index 5179439f..b1f599fc 100644 --- a/gnuefi/crt0-efi-x86_64.S +++ b/gnuefi/crt0-efi-x86_64.S @@ -38,6 +38,7 @@ .align 4 .globl _start + .type _start,%function _start: subq $8, %rsp pushq %rcx @@ -65,15 +66,15 @@ _start: // hand-craft a dummy .reloc section so EFI knows it's a relocatable executable: .data -dummy: .long 0 +dummy: .4byte 0 #define IMAGE_REL_ABSOLUTE 0 .section .reloc, "a" label1: - .long dummy-label1 // Page RVA - .long 12 // Block Size (2*4+2*2), must be aligned by 32 Bits - .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy - .word (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .4byte dummy-label1 // Page RVA + .4byte 12 // Block Size (2*4+2*2), must be aligned by 32 Bits + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy + .2byte (IMAGE_REL_ABSOLUTE<<12) + 0 // reloc for dummy #if defined(__ELF__) && defined(__linux__) .section .note.GNU-stack,"",%progbits diff --git a/gnuefi/elf_aarch64_efi.lds b/gnuefi/elf_aarch64_efi.lds index c487d8d0..d0176697 100644 --- a/gnuefi/elf_aarch64_efi.lds +++ b/gnuefi/elf_aarch64_efi.lds @@ -17,18 +17,17 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) - *(.srodata) - *(.rodata*) + *(.plt) . = ALIGN(16); } _etext = .; - _text_size = . - _text; - . = ALIGN(4096); + _text_size = _etext - _text; + . = ALIGN(65536); .reloc : { KEEP (*(.reloc)) } - . = ALIGN(65536); + . = ALIGN(4096); .dynamic : { *(.dynamic) } . = ALIGN(4096); .data : @@ -99,9 +98,11 @@ SECTIONS } . = ALIGN(4096); .rela.plt : { *(.rela.plt) } + . = ALIGN(4096); + .rodata : { *(.rodata*) } . = ALIGN(512); _edata = .; - _data_size = . - _data; + _data_size = _edata - _data; . = ALIGN(4096); .dynsym : { *(.dynsym) } diff --git a/gnuefi/elf_arm_efi.lds b/gnuefi/elf_arm_efi.lds index b6564402..cae55eae 100644 --- a/gnuefi/elf_arm_efi.lds +++ b/gnuefi/elf_arm_efi.lds @@ -3,24 +3,36 @@ OUTPUT_ARCH(arm) ENTRY(_start) SECTIONS { - .text 0x0 : { - _text = .; + .text 0 : { *(.text.head) + _text = .; *(.text) *(.text.*) *(.gnu.linkonce.t.*) - *(.srodata) - *(.rodata*) + *(.plt) . = ALIGN(16); - } - _etext = .; - _text_size = . - _text; + _evtext = .; + . = ALIGN(4096); + _etext = .; + } =0 + _text_vsize = _evtext - _text; + _text_size = _etext - _text; + . = ALIGN(4096); + _reloc = .; + .areloc : { + *(.areloc) + _evreloc = .; + . = ALIGN(4096); + _ereloc = .; + } =0 + _reloc_vsize = _evreloc - _reloc; + _reloc_size = _ereloc - _reloc; . = ALIGN(4096); + _data = .; .dynamic : { *(.dynamic) } . = ALIGN(4096); .data : { - _data = .; *(.sdata) *(.data) *(.data1) @@ -67,9 +79,15 @@ SECTIONS *(COMMON) . = ALIGN(16); _bss_end = .; - } + _evdata = .; + . = ALIGN(4096); + _edata = .; + } =0 + _data_vsize = _evdata - _data; + _data_size = _edata - _data; . = ALIGN(4096); + _rodata = .; .rel : { *(.rel.text*) @@ -85,8 +103,17 @@ SECTIONS } . = ALIGN(4096); .rel.plt : { *(.rel.plt) } - _edata = .; - _data_size = . - _etext; + . = ALIGN(4096); + .rodata : { + *(.rodata*) + _evrodata = .; + . = ALIGN(4096); + _erodata = .; + } =0 + _rodata_vsize = _evrodata - _rodata; + _rodata_size = _erodata - _rodata; + _image_end = .; + _alldata_size = _image_end - _reloc; . = ALIGN(4096); .dynsym : { *(.dynsym) } @@ -94,10 +121,16 @@ SECTIONS .dynstr : { *(.dynstr) } . = ALIGN(4096); .note.gnu.build-id : { *(.note.gnu.build-id) } + . = ALIGN(4096); + .hash : { *(.hash) } + . = ALIGN(4096); + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .ARM.exidx : { *(.ARM.exidx*) } + .ARM.extab : { *(.ARM.extab*) } /DISCARD/ : { - *(.rel.reloc) - *(.eh_frame) + *(.rel.areloc) *(.note.GNU-stack) } .comment 0 : { *(.comment) } diff --git a/gnuefi/elf_ia32_efi.lds b/gnuefi/elf_ia32_efi.lds index a84c6736..13614540 100644 --- a/gnuefi/elf_ia32_efi.lds +++ b/gnuefi/elf_ia32_efi.lds @@ -17,17 +17,17 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + *(.plt) . = ALIGN(16); } _etext = .; - _text_size = . - _text; + _text_size = _etext - _text; . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); .data : { _data = .; *(.got.plt) *(.got) - *(.rodata*) *(.data) *(.data1) *(.data.*) @@ -88,8 +88,10 @@ SECTIONS } . = ALIGN(4096); .rel.plt : { *(.rel.plt) } + . = ALIGN(4096); + .rodata : { *(.rodata*) } _edata = .; - _data_size = . - _etext; + _data_size = _edata - _etext; . = ALIGN(4096); .reloc : /* This is the PECOFF .reloc section! */ { diff --git a/gnuefi/elf_ia32_fbsd_efi.lds b/gnuefi/elf_ia32_fbsd_efi.lds index 61ae5c5a..650000cb 100644 --- a/gnuefi/elf_ia32_fbsd_efi.lds +++ b/gnuefi/elf_ia32_fbsd_efi.lds @@ -18,7 +18,7 @@ SECTIONS . = ALIGN(16); } _etext = .; - _text_size = . - _text; + _text_size = _etext - _text; . = ALIGN(4096); .sdata : { @@ -97,7 +97,7 @@ SECTIONS *(.data.rel*) } _edata = .; - _data_size = . - _etext; + _data_size = _edata - _etext; . = ALIGN(4096); .reloc : /* This is the PECOFF .reloc section! */ { diff --git a/gnuefi/elf_ia64_efi.lds b/gnuefi/elf_ia64_efi.lds index 74014cef..eb8a7ad8 100644 --- a/gnuefi/elf_ia64_efi.lds +++ b/gnuefi/elf_ia64_efi.lds @@ -17,10 +17,11 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + *(.plt) . = ALIGN(16); } _etext = .; - _text_size = . - _text; + _text_size = _etext - _text; . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); __gp = ALIGN (8) + 0x200000; .sdata : @@ -97,7 +98,7 @@ SECTIONS . = ALIGN(4096); .rela.plt : { *(.rela.plt) } _edata = .; - _data_size = . - _etext; + _data_size = _edata - _etext; . = ALIGN(4096); .reloc : /* This is the PECOFF .reloc section! */ { diff --git a/gnuefi/elf_loongarch64_efi.lds b/gnuefi/elf_loongarch64_efi.lds index e7b4d6bc..57d046d3 100644 --- a/gnuefi/elf_loongarch64_efi.lds +++ b/gnuefi/elf_loongarch64_efi.lds @@ -3,20 +3,34 @@ OUTPUT_ARCH(loongarch) ENTRY(_start) SECTIONS { - .text 0x0 : { + . = 0; + ImageBase = .; + /* .hash and/or .gnu.hash MUST come first! */ + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .eh_frame : { *(.eh_frame) } + .gcc_except_table : { *(.gcc_except_table*) } + . = ALIGN(4096); + .text : { _text = .; - *(.text.head) *(.text) *(.text.*) *(.gnu.linkonce.t.*) - *(.srodata) - *(.rodata*) + *(.plt) . = ALIGN(16); } _etext = .; - _text_size = . - _text; + _text_size = _etext - _text; + . = ALIGN(4096); + .reloc : + { + KEEP (*(.reloc)) + } + . = ALIGN(65536); .dynamic : { *(.dynamic) } - .data : ALIGN(4096) + . = ALIGN(4096); + .data : { _data = .; *(.sdata) @@ -26,6 +40,33 @@ SECTIONS *(.got.plt) *(.got) + /* + * Note that these aren't the using the GNU "CONSTRUCTOR" output section + * command, so they don't start with a size. Because of p2align and the + * end/END definitions, and the fact that they're mergeable, they can also + * have NULLs which aren't guaranteed to be at the end. + */ + . = ALIGN(16); + __init_array_start = .; + *(SORT(.init_array.*)) + *(.init_array) + __init_array_end = .; + . = ALIGN(16); + __CTOR_LIST__ = .; + *(SORT(.ctors.*)) + *(.ctors) + __CTOR_END__ = .; + . = ALIGN(16); + __DTOR_LIST__ = .; + *(SORT(.dtors.*)) + *(.dtors) + __DTOR_END__ = .; + . = ALIGN(16); + __fini_array_start = .; + *(SORT(.fini_array.*)) + *(.fini_array) + __fini_array_end = .; + /* the EFI loader doesn't seem to like a .bss section, so we stick it all into .data: */ . = ALIGN(16); @@ -33,19 +74,35 @@ SECTIONS *(.sbss) *(.scommon) *(.dynbss) - *(.bss) + *(.bss*) *(COMMON) + *(.rel.local) . = ALIGN(16); + _bss_end = .; } - .rela.dyn : { *(.rela.dyn) } + . = ALIGN(4096); + .rela : + { + *(.rela.text*) + *(.rela.data*) + *(.rela.got) + *(.rela.dyn) + *(.rela.stab) + *(.rela.init_array*) + *(.rela.fini_array*) + *(.rela.ctors*) + *(.rela.dtors*) + + } + . = ALIGN(4096); .rela.plt : { *(.rela.plt) } - .rela.got : { *(.rela.got) } - .rela.data : { *(.rela.data) *(.rela.data*) } + . = ALIGN(4096); + .rodata : { *(.rodata*) } . = ALIGN(512); _edata = .; - _data_size = . - _data; + _data_size = _edata - _data; . = ALIGN(4096); .dynsym : { *(.dynsym) } @@ -53,10 +110,9 @@ SECTIONS .dynstr : { *(.dynstr) } . = ALIGN(4096); .note.gnu.build-id : { *(.note.gnu.build-id) } - /DISCARD/ : + .ignored.reloc : { - *(.rel.reloc) - *(.eh_frame) + *(.rela.reloc) *(.note.GNU-stack) } .comment 0 : { *(.comment) } diff --git a/gnuefi/elf_mips64el_efi.lds b/gnuefi/elf_mips64el_efi.lds index a9fe787e..a0d1a5b6 100644 --- a/gnuefi/elf_mips64el_efi.lds +++ b/gnuefi/elf_mips64el_efi.lds @@ -9,12 +9,11 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) - *(.srodata) - *(.rodata*) + *(.plt) . = ALIGN(16); } _etext = .; - _text_size = . - _text; + _text_size = _etext - _text; . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); .dynamic : { *(.dynamic) } . = ALIGN(4096); @@ -84,8 +83,10 @@ SECTIONS } . = ALIGN(4096); .rel.plt : { *(.rel.plt) } + . = ALIGN(4096); + .rodata : { *(.rodata*) } _edata = .; - _data_size = . - _etext; + _data_size = _edata - _etext; . = ALIGN(4096); .dynsym : { *(.dynsym) } diff --git a/gnuefi/elf_riscv64_efi.lds b/gnuefi/elf_riscv64_efi.lds index d5153e96..ac7055a5 100644 --- a/gnuefi/elf_riscv64_efi.lds +++ b/gnuefi/elf_riscv64_efi.lds @@ -3,82 +3,140 @@ OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv") OUTPUT_ARCH(riscv) ENTRY(_start) -SECTIONS { -.text 0x0 : - { - _text = .; - *(.text.head) - *(.text) - *(.text.*) - *(.gnu.linkonce.t.*) - *(.srodata) - *(.rodata*) - . = ALIGN(16); - } - _etext = .; - _text_size = . - _text; -. = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); -.dynamic : - { *(.dynamic) } -.data : - ALIGN(4096) - { - _data = .; - *(.sdata) - *(.data) - *(.data1) - *(.data.*) - *(.got.plt) - *(.got) +SECTIONS +{ + .text 0 : { + *(.text.head) + . = ALIGN(4096); + _text = .; + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.plt) + . = ALIGN(16); + _evtext = .; + . = ALIGN(4096); + _etext = .; + } =0 + _text_vsize = _evtext - _text; + _text_size = _etext - _text; + . = ALIGN(4096); + _reloc = .; + .reloc : { + *(.reloc) + _evreloc = .; + . = ALIGN(4096); + _ereloc = .; + } =0 + _reloc_vsize = _evreloc - _reloc; + _reloc_size = _ereloc - _reloc; + . = ALIGN(4096); + _data = .; + .dynamic : { *(.dynamic) } + . = ALIGN(4096); + .data : + { + *(.sdata) + *(.data) + *(.data1) + *(.data.*) + *(.got.plt) + *(.got) + + /* + * Note that these aren't the using the GNU "CONSTRUCTOR" output section + * command, so they don't start with a size. Because of p2align and the + * end/END definitions, and the fact that they're mergeable, they can also + * have NULLs which aren't guaranteed to be at the end. + */ + . = ALIGN(16); + __init_array_start = .; + *(SORT(.init_array.*)) + *(.init_array) + __init_array_end = .; + . = ALIGN(16); + __CTOR_LIST__ = .; + *(SORT(.ctors.*)) + *(.ctors) + __CTOR_END__ = .; + . = ALIGN(16); + __DTOR_LIST__ = .; + *(SORT(.dtors.*)) + *(.dtors) + __DTOR_END__ = .; + . = ALIGN(16); + __fini_array_start = .; + *(SORT(.fini_array.*)) + *(.fini_array) + __fini_array_end = .; - /* the EFI loader doesn't seem to like a .bss section, so we stick - it all into .data: */ - . = ALIGN(16); - _bss = .; - *(.sbss) - *(.scommon) - *(.dynbss) - *(.bss*) - *(COMMON) - . = ALIGN(16); - _bss_end = .; - } + /* the EFI loader doesn't seem to like a .bss section, so we stick + it all into .data: */ + . = ALIGN(16); + _bss = .; + *(.sbss) + *(.scommon) + *(.dynbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(16); + _bss_end = .; + _evdata = .; + . = ALIGN(4096); + _edata = .; + } =0 + _data_vsize = _evdata - _data; + _data_size = _edata - _data; -. = ALIGN(4096); -.rela : + . = ALIGN(4096); + _rodata = .; + .rela : { *(.rela.text*) *(.rela.data*) *(.rela.got) *(.rela.dyn) *(.rela.stab) - *(.rela.init_array) - *(.rela.fini_array) - *(.rela.ctors) - *(.rela.dtors) + *(.rela.init_array*) + *(.rela.fini_array*) + *(.rela.ctors*) + *(.rela.dtors*) + } -. = ALIGN(4096); -.rela.plt : { *(.rela.plt) } - . = ALIGN(512); - _edata = .; - _data_size = . - _data; + . = ALIGN(4096); + .rela.plt : { *(.rela.plt) } + . = ALIGN(4096); + .rodata : { + *(.rodata*) + _evrodata = .; + . = ALIGN(4096); + _erodata = .; + } =0 + _rodata_vsize = _evrodata - _rodata; + _rodata_size = _erodata - _rodata; + _image_end = .; + _alldata_size = _image_end - _reloc; - . = ALIGN(4096); -.dynsym : - { *(.dynsym) } - . = ALIGN(4096); -.dynstr : - { *(.dynstr) } - . = ALIGN(4096); -.note.gnu.build-id : - { *(.note.gnu.build-id) } -. = DATA_SEGMENT_END (.); -/DISCARD/ : - { - *(.rel.reloc) - *(.eh_frame) - *(.note.GNU-stack) - } -.comment 0 : - { *(.comment) } + . = ALIGN(4096); + .dynsym : { *(.dynsym) } + . = ALIGN(4096); + .dynstr : { *(.dynstr) } + . = ALIGN(4096); + .note.gnu.build-id : { *(.note.gnu.build-id) } + . = ALIGN(4096); + .hash : { *(.hash) } + . = ALIGN(4096); + .gnu.hash : { *(.gnu.hash) } + . = ALIGN(4096); + .eh_frame : { *(.eh_frame) } + . = ALIGN(4096); + .gcc_except_table : { *(.gcc_except_table*) } + /DISCARD/ : + { + *(.rela.reloc) + *(.note.GNU-stack) + } + .comment 0 : { *(.comment) } } + diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds index 0f4b63b6..e9f395e5 100644 --- a/gnuefi/elf_x86_64_efi.lds +++ b/gnuefi/elf_x86_64_efi.lds @@ -19,10 +19,11 @@ SECTIONS *(.text) *(.text.*) *(.gnu.linkonce.t.*) + *(.plt) . = ALIGN(16); } _etext = .; - _text_size = . - _text; + _text_size = _etext - _text; . = ALIGN(4096); .reloc : { @@ -33,7 +34,6 @@ SECTIONS .data : { _data = .; - *(.rodata*) *(.got.plt) *(.got) *(.data*) @@ -78,7 +78,7 @@ SECTIONS .note.gnu.build-id : { *(.note.gnu.build-id) } _edata = .; - _data_size = . - _etext; + _data_size = _edata - _etext; . = ALIGN(4096); .dynamic : { *(.dynamic) } . = ALIGN(4096); @@ -97,6 +97,8 @@ SECTIONS . = ALIGN(4096); .rela.plt : { *(.rela.plt) } . = ALIGN(4096); + .rodata : { *(.rodata*) } + . = ALIGN(4096); .dynsym : { *(.dynsym) } . = ALIGN(4096); .dynstr : { *(.dynstr) } diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds index dd10d882..a0dc6c0a 100644 --- a/gnuefi/elf_x86_64_fbsd_efi.lds +++ b/gnuefi/elf_x86_64_fbsd_efi.lds @@ -22,7 +22,7 @@ SECTIONS . = ALIGN(16); } _etext = .; - _text_size = . - _text; + _text_size = _etext - _text; .reloc : { *(.reloc) @@ -31,7 +31,6 @@ SECTIONS .data : { _data = .; - *(.rodata*) *(.got.plt) *(.got) *(.data*) @@ -88,8 +87,10 @@ SECTIONS *(.rela.ctors*) *(.rela.dtors*) } + . = ALIGN(4096); + .rodata : { *(.rodata*) } _edata = .; - _data_size = . - _etext; + _data_size = _edata - _etext; . = ALIGN(4096); .dynsym : { *(.dynsym) } . = ALIGN(4096); diff --git a/gnuefi/reloc_riscv64.c b/gnuefi/reloc_riscv64.c index 0b02d83f..e4296026 100644 --- a/gnuefi/reloc_riscv64.c +++ b/gnuefi/reloc_riscv64.c @@ -81,8 +81,7 @@ EFI_STATUS EFIAPI _relocate(long ldbase, Elf_Dyn *dyn) *addr = ldbase + rel->r_addend; break; default: - /* Panic */ - while (1) ; + break; } rel = (Elf_Rela *)((char *)rel + relent); relsz -= relent; diff --git a/inc/Makefile b/inc/Makefile index db3929f6..b5de1faf 100644 --- a/inc/Makefile +++ b/inc/Makefile @@ -1,12 +1,9 @@ SRCDIR = . VPATH = $(SRCDIR) - -include $(SRCDIR)/../Make.defaults - TOPDIR = $(SRCDIR)/.. -CDIR=$(TOPDIR)/.. +include $(SRCDIR)/../Make.defaults all: diff --git a/inc/aarch64/efisetjmp_arch.h b/inc/aarch64/efisetjmp_arch.h index d960706d..74e1f874 100644 --- a/inc/aarch64/efisetjmp_arch.h +++ b/inc/aarch64/efisetjmp_arch.h @@ -29,6 +29,6 @@ typedef struct { UINT64 D13; UINT64 D14; UINT64 D15; -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_AARCH64_SETJMP_H */ diff --git a/inc/arm/efisetjmp_arch.h b/inc/arm/efisetjmp_arch.h index 17f5dc0f..b8094537 100644 --- a/inc/arm/efisetjmp_arch.h +++ b/inc/arm/efisetjmp_arch.h @@ -16,6 +16,6 @@ typedef struct { UINT32 R12; UINT32 R13; UINT32 R14; -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_ARM_SETJMP_H */ diff --git a/inc/efi.h b/inc/efi.h index b251a344..6d833741 100644 --- a/inc/efi.h +++ b/inc/efi.h @@ -33,6 +33,10 @@ Revision History #ifndef _EFI_INCLUDE_ #define _EFI_INCLUDE_ +#ifdef __cplusplus +extern "C" { +#endif + #define EFI_FIRMWARE_VENDOR L"INTEL" #define EFI_FIRMWARE_MAJOR_REVISION 12 #define EFI_FIRMWARE_MINOR_REVISION 33 @@ -79,4 +83,8 @@ Revision History #include "efipoint.h" #include "efishell.h" +#ifdef __cplusplus +} +#endif + #endif diff --git a/inc/efiapi.h b/inc/efiapi.h index 01a09388..778d513d 100644 --- a/inc/efiapi.h +++ b/inc/efiapi.h @@ -24,8 +24,10 @@ Revision History // EFI Specification Revision // +#define EFI_SPECIFICATION_REVISION_MAJORMINOR(major, minor) ((major<<16) | (minor)) #define EFI_SPECIFICATION_MAJOR_REVISION 1 #define EFI_SPECIFICATION_MINOR_REVISION 02 +#define EFI_SPECIFICATION_VERSION EFI_SPECIFICATION_REVISION_MAJORMINOR(EFI_SPECIFICATION_MAJOR_REVISION, EFI_SPECIFICATION_MINOR_REVISION) // // Declare forward referenced data structures @@ -229,6 +231,7 @@ VOID #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020 #define EFI_VARIABLE_APPEND_WRITE 0x00000040 +#define EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS 0x00000080 // Variable size limitation #define EFI_MAXIMUM_VARIABLE_SIZE 1024 @@ -770,8 +773,22 @@ typedef struct _EFI_TABLE_HEADER { // EFI Runtime Serivces Table // -#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552 -#define EFI_RUNTIME_SERVICES_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION) +#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552 +#define EFI_1_02_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(1, 02) +#define EFI_1_10_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(1, 10) +#define EFI_2_00_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 00) +#define EFI_2_10_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 10) +#define EFI_2_20_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 20) +#define EFI_2_30_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 30) +#define EFI_2_31_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 31) +#define EFI_2_40_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 40) +#define EFI_2_50_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 50) +#define EFI_2_60_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 60) +#define EFI_2_70_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 70) +#define EFI_2_80_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 80) +#define EFI_2_90_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 90) +#define EFI_2_100_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 100) +#define EFI_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_VERSION typedef struct { EFI_TABLE_HEADER Hdr; @@ -817,8 +834,22 @@ typedef struct { // EFI Boot Services Table // -#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42 -#define EFI_BOOT_SERVICES_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION) +#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42 +#define EFI_1_02_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(1, 02) +#define EFI_1_10_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(1, 10) +#define EFI_2_00_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 00) +#define EFI_2_10_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 10) +#define EFI_2_20_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 20) +#define EFI_2_30_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 30) +#define EFI_2_31_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 31) +#define EFI_2_40_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 40) +#define EFI_2_50_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 50) +#define EFI_2_60_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 60) +#define EFI_2_70_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 70) +#define EFI_2_80_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 80) +#define EFI_2_90_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 90) +#define EFI_2_100_BOOT_SERVICES_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 100) +#define EFI_BOOT_SERVICES_REVISION EFI_SPECIFICATION_VERSION typedef struct _EFI_BOOT_SERVICES { @@ -960,7 +991,21 @@ typedef struct _EFI_CONFIGURATION_TABLE { #define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249 -#define EFI_SYSTEM_TABLE_REVISION (EFI_SPECIFICATION_MAJOR_REVISION<<16) | (EFI_SPECIFICATION_MINOR_REVISION) +#define EFI_1_02_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(1, 02) +#define EFI_1_10_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(1, 10) +#define EFI_2_00_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 00) +#define EFI_2_10_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 10) +#define EFI_2_20_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 20) +#define EFI_2_30_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 30) +#define EFI_2_31_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 31) +#define EFI_2_40_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 40) +#define EFI_2_50_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 50) +#define EFI_2_60_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 60) +#define EFI_2_70_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 70) +#define EFI_2_80_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 80) +#define EFI_2_90_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 90) +#define EFI_2_100_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_REVISION_MAJORMINOR(2, 100) +#define EFI_SYSTEM_TABLE_REVISION EFI_SPECIFICATION_VERSION typedef struct _EFI_SYSTEM_TABLE { EFI_TABLE_HEADER Hdr; diff --git a/inc/eficompiler.h b/inc/eficompiler.h index 26636c7b..6f6ff7dc 100644 --- a/inc/eficompiler.h +++ b/inc/eficompiler.h @@ -19,9 +19,39 @@ Module Name: #endif #ifdef _MSC_EXTENSIONS -#define ALIGN(x) __declspec(align(x)) +#define EFI_NO_TAIL_CALL #else -#define ALIGN(x) __attribute__((__aligned__(x))) +#ifdef __clang__ +#define EFI_NO_TAIL_CALL __attribute__((disable_tail_calls)) +#else +#define EFI_NO_TAIL_CALL __attribute__((optimize("no-optimize-sibling-calls"))) +#endif +#endif + +#ifdef _MSC_EXTENSIONS +#define EFI_OPTNONE +#else +#ifdef __clang__ +#define EFI_OPTNONE __attribute__((optnone)) +#else +#define EFI_OPTNONE __attribute__((__optimize__("0"))) +#endif +#endif + +#ifdef _MSC_EXTENSIONS +#define EFI_ALIGN(x) __declspec(align(x)) +#else +#define EFI_ALIGN(x) __attribute__((__aligned__(x))) +#endif + +#ifndef ALIGN +#define ALIGN(x) EFI_ALIGN(x) +#endif + +#ifdef _MSC_EXTENSIONS +#define EFI_NORETURN __declspec(noreturn) +#else +#define EFI_NORETURN __attribute__((noreturn)) #endif /* Also add a catch-all on __attribute__() for MS compilers */ diff --git a/inc/efidef.h b/inc/efidef.h index 5953b693..2934b118 100644 --- a/inc/efidef.h +++ b/inc/efidef.h @@ -182,23 +182,36 @@ typedef enum { EfiMemoryMappedIO, EfiMemoryMappedIOPortSpace, EfiPalCode, + EfiPersistentMemory, + EfiUnacceptedMemoryType, EfiMaxMemoryType } EFI_MEMORY_TYPE; -// possible caching types for the memory range -#define EFI_MEMORY_UC 0x0000000000000001 -#define EFI_MEMORY_WC 0x0000000000000002 -#define EFI_MEMORY_WT 0x0000000000000004 -#define EFI_MEMORY_WB 0x0000000000000008 -#define EFI_MEMORY_UCE 0x0000000000000010 -// physical memory protection on range -#define EFI_MEMORY_WP 0x0000000000001000 -#define EFI_MEMORY_RP 0x0000000000002000 -#define EFI_MEMORY_XP 0x0000000000004000 +// Memory cacheability attribute +#define EFI_MEMORY_UC 0x0000000000000001 +#define EFI_MEMORY_WC 0x0000000000000002 +#define EFI_MEMORY_WT 0x0000000000000004 +#define EFI_MEMORY_WB 0x0000000000000008 +#define EFI_MEMORY_UCE 0x0000000000000010 + +// Physical memory protection attribute +#define EFI_MEMORY_WP 0x0000000000001000 +#define EFI_MEMORY_RP 0x0000000000002000 +#define EFI_MEMORY_XP 0x0000000000004000 +#define EFI_MEMORY_RO 0x0000000000020000 + +// Runtime memory attribute +#define EFI_MEMORY_NV 0x0000000000008000 +#define EFI_MEMORY_RUNTIME 0x8000000000000000 + +// Other memory attribute +#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000 +#define EFI_MEMORY_SP 0x0000000000040000 +#define EFI_MEMORY_CPU_CRYPTO 0x0000000000080000 +#define EFI_MEMORY_ISA_VALID 0x4000000000000000 +#define EFI_MEMORY_ISA_MASK 0x0FFFF00000000000 -// range requires a runtime mapping -#define EFI_MEMORY_RUNTIME 0x8000000000000000 #define EFI_MEMORY_DESCRIPTOR_VERSION 1 typedef struct { @@ -236,5 +249,10 @@ typedef CHAR8 ISO_639_2; 0x0000000000000008 #define EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED \ 0x0000000000000010 +#define EFI_OS_INDICATIONS_START_OS_RECOVERY 0x0000000000000020 +#define EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY \ + 0x0000000000000040 +#define EFI_OS_INDICATIONS_JSON_CONFIG_DATA_REFRESH \ + 0x0000000000000080 #endif diff --git a/inc/efierr.h b/inc/efierr.h index 5a66e1a0..ac9ef7ba 100644 --- a/inc/efierr.h +++ b/inc/efierr.h @@ -57,12 +57,17 @@ Revision History #define EFI_END_OF_FILE EFIERR(31) #define EFI_INVALID_LANGUAGE EFIERR(32) #define EFI_COMPROMISED_DATA EFIERR(33) +#define EFI_IP_ADDRESS_CONFLICT EFIERR(34) +#define EFI_HTTP_ERROR EFIERR(35) #define EFI_WARN_UNKOWN_GLYPH EFIWARN(1) #define EFI_WARN_UNKNOWN_GLYPH EFIWARN(1) #define EFI_WARN_DELETE_FAILURE EFIWARN(2) #define EFI_WARN_WRITE_FAILURE EFIWARN(3) #define EFI_WARN_BUFFER_TOO_SMALL EFIWARN(4) +#define EFI_WARN_STALE_DATA EFIWARN(5) +#define EFI_WARN_FILE_SYSTEM EFIWARN(6) +#define EFI_WARN_RESET_REQUIRED EFIWARN(7) #endif diff --git a/inc/efilib.h b/inc/efilib.h index e73177c0..f35d2edf 100644 --- a/inc/efilib.h +++ b/inc/efilib.h @@ -19,6 +19,10 @@ Revision History --*/ +#ifdef __cplusplus +extern "C" { +#endif + #include "efidebug.h" #include "efipart.h" #if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__) @@ -283,17 +287,17 @@ ZeroMem ( IN UINTN Size ); -VOID +VOID EFIAPI SetMem ( IN VOID *Buffer, IN UINTN Size, IN UINT8 Value ); -VOID +VOID EFIAPI CopyMem ( IN VOID *Dest, - IN CONST VOID *Src, + IN VOID *Src, IN UINTN len ); @@ -1078,4 +1082,8 @@ extern EFI_DEVICE_IO_INTERFACE *GlobalIoFncs; #define Port80(_PostCode) GlobalIoFncs->Io.Write (GlobalIoFncs, IO_UINT16, (UINT64)0x80, 1, &(_PostCode)) +#ifdef __cplusplus +} +#endif + #endif diff --git a/inc/efiprot.h b/inc/efiprot.h index 3e4d60b9..c4457de1 100644 --- a/inc/efiprot.h +++ b/inc/efiprot.h @@ -1428,4 +1428,39 @@ typedef struct _EFI_EBC_PROTOCOL { EFI_EBC_GET_VERSION GetVersion; } EFI_EBC_PROTOCOL; +INTERFACE_DECL(_EFI_MEMORY_ATTRIBUTE_PROTOCOL); + +typedef +EFI_STATUS +(EFIAPI *EFI_GET_MEMORY_ATTRIBUTES)( + IN struct _EFI_MEMORY_ATTRIBUTE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + OUT UINT64 *Attributes + ); + +typedef +EFI_STATUS +(EFIAPI *EFI_SET_MEMORY_ATTRIBUTES)( + IN struct _EFI_MEMORY_ATTRIBUTE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ); + +typedef +EFI_STATUS +(EFIAPI *EFI_CLEAR_MEMORY_ATTRIBUTES)( + IN struct _EFI_MEMORY_ATTRIBUTE_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length, + IN UINT64 Attributes + ); + +typedef struct _EFI_MEMORY_ATTRIBUTE_PROTOCOL { + EFI_GET_MEMORY_ATTRIBUTES GetMemoryAttributes; + EFI_SET_MEMORY_ATTRIBUTES SetMemoryAttributes; + EFI_CLEAR_MEMORY_ATTRIBUTES ClearMemoryAttributes; +} EFI_MEMORY_ATTRIBUTE_PROTOCOL; + #endif diff --git a/inc/efisetjmp.h b/inc/efisetjmp.h index de69194b..4037688b 100644 --- a/inc/efisetjmp.h +++ b/inc/efisetjmp.h @@ -5,6 +5,6 @@ #include "efisetjmp_arch.h" extern UINTN setjmp(jmp_buf env) __attribute__((returns_twice)); -extern VOID longjmp(jmp_buf env, UINTN value) __attribute__((noreturn)); +extern VOID longjmp(jmp_buf env, UINTN value) EFI_NORETURN; #endif /* GNU_EFI_SETJMP_H */ diff --git a/inc/ia32/efisetjmp_arch.h b/inc/ia32/efisetjmp_arch.h index a5c1a81c..f65432eb 100644 --- a/inc/ia32/efisetjmp_arch.h +++ b/inc/ia32/efisetjmp_arch.h @@ -10,6 +10,6 @@ typedef struct { UINT32 Ebp; UINT32 Esp; UINT32 Eip; -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_IA32_SETJMP_H */ diff --git a/inc/ia64/efisetjmp_arch.h b/inc/ia64/efisetjmp_arch.h index ceda4481..7b674f6b 100644 --- a/inc/ia64/efisetjmp_arch.h +++ b/inc/ia64/efisetjmp_arch.h @@ -42,6 +42,6 @@ typedef struct { UINT64 Predicates; UINT64 LoopCount; UINT64 FPSR; -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_IA64_SETJMP_H */ diff --git a/inc/loongarch64/efibind.h b/inc/loongarch64/efibind.h index aaf3fb7e..8ed83a55 100644 --- a/inc/loongarch64/efibind.h +++ b/inc/loongarch64/efibind.h @@ -42,9 +42,10 @@ typedef int64_t intptr_t; // Basic EFI types of various widths // -#ifndef __WCHAR_TYPE__ -# define __WCHAR_TYPE__ short -#endif +#include + +typedef wchar_t CHAR16; +#define WCHAR CHAR16 typedef uint64_t UINT64; typedef int64_t INT64; @@ -54,12 +55,13 @@ typedef int32_t INT32; typedef uint16_t UINT16; typedef int16_t INT16; + typedef uint8_t UINT8; +typedef char CHAR8; typedef int8_t INT8; -typedef __WCHAR_TYPE__ WCHAR; #undef VOID -#define VOID void +typedef void VOID; typedef int64_t INTN; typedef uint64_t UINTN; diff --git a/inc/loongarch64/efisetjmp_arch.h b/inc/loongarch64/efisetjmp_arch.h index 18aefaf4..41ff410a 100644 --- a/inc/loongarch64/efisetjmp_arch.h +++ b/inc/loongarch64/efisetjmp_arch.h @@ -18,6 +18,6 @@ typedef struct { UINT64 S6; UINT64 S7; UINT64 S8; -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_LOONGARCH64_SETJMP_H */ diff --git a/inc/mips64el/efisetjmp_arch.h b/inc/mips64el/efisetjmp_arch.h index 2b8f756e..e241284d 100644 --- a/inc/mips64el/efisetjmp_arch.h +++ b/inc/mips64el/efisetjmp_arch.h @@ -29,6 +29,6 @@ typedef struct { UINT64 F30; UINT64 F31; #endif -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_MIPS64EL_SETJMP_H */ diff --git a/inc/riscv64/efisetjmp_arch.h b/inc/riscv64/efisetjmp_arch.h index 9288c1fa..bb6f467e 100644 --- a/inc/riscv64/efisetjmp_arch.h +++ b/inc/riscv64/efisetjmp_arch.h @@ -35,6 +35,6 @@ typedef struct { UINT64 fs9; UINT64 fs10; UINT64 fs11; -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_RISCV64_SETJMP_H */ diff --git a/inc/x86_64/efisetjmp_arch.h b/inc/x86_64/efisetjmp_arch.h index b1ad1fe3..8d100ae6 100644 --- a/inc/x86_64/efisetjmp_arch.h +++ b/inc/x86_64/efisetjmp_arch.h @@ -17,6 +17,6 @@ typedef struct { UINT64 Rip; UINT64 MxCsr; UINT8 XmmBuffer[160]; // XMM6 - XMM15 -} ALIGN(JMPBUF_ALIGN) jmp_buf[1]; +} EFI_ALIGN(JMPBUF_ALIGN) jmp_buf[1]; #endif /* GNU_EFI_X86_64_SETJMP_H */ diff --git a/lib/Makefile b/lib/Makefile index 4e0c9bee..ec1f9e3a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -37,12 +37,10 @@ SRCDIR = . VPATH = $(SRCDIR) +TOPDIR = $(SRCDIR)/.. include $(SRCDIR)/../Make.defaults -TOPDIR = $(SRCDIR)/.. - -CDIR = $(TOPDIR)/.. FILES = boxdraw smbios console crc data debug dpath \ entry error event exit guid hand hw init lock \ misc pause print sread str cmdline\ @@ -80,7 +78,7 @@ libefi.a: $(OBJS) $(AR) $(ARFLAGS) $@ $^ clean: - rm -f libefi.a *~ $(OBJS) */*.o + @rm -vf libefi.a *~ $(OBJS) */*.o $(LIBDIRINSTALL): mkdir -p $@ diff --git a/lib/ctors.S b/lib/ctors.S index de3f2311..4a66a4e6 100644 --- a/lib/ctors.S +++ b/lib/ctors.S @@ -8,35 +8,30 @@ * end/END definitions, and the fact that they're mergeable, they can also * have NULLs which aren't guaranteed to be at the end. */ - .section .init_array, "aw", @init_array - .p2align 3, 0 + .section .init_array,"aw",%init_array + .p2align 4, 0 .globl __init_array_start __init_array_start: - .p2align 3, 0 .globl __init_array_end __init_array_end: - .section .ctors, "aw", @progbits - .p2align 3, 0 + .section .ctors,"aw",%progbits + .p2align 4, 0 .globl __CTOR_LIST__ __CTOR_LIST__: - .p2align 3, 0 .globl __CTOR_END__ __CTOR_END__: - .section .dtors, "aw", @progbits - .p2align 3, 0 + .section .dtors,"aw",%progbits + .p2align 4, 0 .globl __DTOR_LIST__ __DTOR_LIST__: - .p2align 3, 0 .globl __DTOR_END__ __DTOR_END__: - .section .fini_array, "aw", @fini_array - .p2align 3, 0 + .section .fini_array,"aw",%fini_array + .p2align 4, 0 .globl __fini_array_start __fini_array_start: - .p2align 3, 0 .globl __fini_array_end __fini_array_end: - .p2align 3, 0 #if defined(__ELF__) && defined(__linux__) .section .note.GNU-stack,"",%progbits diff --git a/lib/error.c b/lib/error.c index 9f3b230d..38e03e89 100644 --- a/lib/error.c +++ b/lib/error.c @@ -55,12 +55,17 @@ ErrorCodeTable_Type ErrorCodeTable[] = { { EFI_END_OF_FILE, L"End of File"}, { EFI_INVALID_LANGUAGE, L"Invalid Languages"}, { EFI_COMPROMISED_DATA, L"Compromised Data"}, + { EFI_IP_ADDRESS_CONFLICT, L"IP Address Conflict"}, + { EFI_HTTP_ERROR, L"HTTP Error"}, // warnings { EFI_WARN_UNKNOWN_GLYPH, L"Warning Unknown Glyph"}, { EFI_WARN_DELETE_FAILURE, L"Warning Delete Failure"}, { EFI_WARN_WRITE_FAILURE, L"Warning Write Failure"}, { EFI_WARN_BUFFER_TOO_SMALL, L"Warning Buffer Too Small"}, + { EFI_WARN_STALE_DATA, L"Warning Stale Data"}, + { EFI_WARN_FILE_SYSTEM, L"Warning File System"}, + { EFI_WARN_RESET_REQUIRED, L"Warning Reset Required"}, { 0, NULL} } ; diff --git a/lib/loongarch64/efi_stub.S b/lib/loongarch64/efi_stub.S index 464eae58..b3fba1d0 100644 --- a/lib/loongarch64/efi_stub.S +++ b/lib/loongarch64/efi_stub.S @@ -1 +1,4 @@ /* This stub is a stub to make the build happy */ +#if defined(__ELF__) && defined(__linux__) + .section .note.GNU-stack,"",%progbits +#endif diff --git a/lib/misc.c b/lib/misc.c index 78d61fc2..1d2e2415 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -98,7 +98,7 @@ ZeroMem ( RtZeroMem (Buffer, Size); } -VOID +VOID EFIAPI SetMem ( IN VOID *Buffer, IN UINTN Size, @@ -108,10 +108,10 @@ SetMem ( RtSetMem (Buffer, Size, Value); } -VOID +VOID EFIAPI CopyMem ( IN VOID *Dest, - IN CONST VOID *Src, + IN VOID *Src, IN UINTN len ) { diff --git a/lib/str.c b/lib/str.c index b9b156bd..a2f87503 100644 --- a/lib/str.c +++ b/lib/str.c @@ -205,7 +205,7 @@ StrDuplicate ( Size = StrSize(Src); Dest = AllocatePool (Size); if (Dest) { - CopyMem (Dest, Src, Size); + CopyMem (Dest, (void *)Src, Size); } return Dest; }