efi: Adjust for new reduced-gnu-efi

This commit is contained in:
mintsuki 2022-04-20 04:00:00 +02:00
parent 1af09d0749
commit df7e43df7f
6 changed files with 268 additions and 185 deletions

View File

@ -219,11 +219,11 @@ $(call MKESCAPE,$(BUILDDIR))/stage2.bin: $(call MKESCAPE,$(BUILDDIR))/limine.sys
$(call MKESCAPE,$(BUILDDIR))/stage2.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_stage2only.elf $(call MKESCAPE,$(BUILDDIR))/stage2.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_stage2only.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \ cd '$(call SHESCAPE,$(BUILDDIR))' && \
'$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' stage2 32 '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' stage2 32 '\.text'
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf $(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \ cd '$(call SHESCAPE,$(BUILDDIR))' && \
'$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 32 '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 32 '\.text'
$(call MKESCAPE,$(BUILDDIR))/limine.sys: $(call MKESCAPE,$(BUILDDIR))/limine.elf $(call MKESCAPE,$(BUILDDIR))/limine.sys: $(call MKESCAPE,$(BUILDDIR))/limine.elf
$(LIMINE_OBJCOPY) -O binary '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)' $(LIMINE_OBJCOPY) -O binary '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)'
@ -279,10 +279,10 @@ ifeq ($(TARGET), uefi64)
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf $(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \ cd '$(call SHESCAPE,$(BUILDDIR))' && \
'$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 64 '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 64 '\.sect'
$(call MKESCAPE,$(BUILDDIR))/BOOTX64.EFI: $(call MKESCAPE,$(BUILDDIR))/limine.elf $(call MKESCAPE,$(BUILDDIR))/BOOTX64.EFI: $(call MKESCAPE,$(BUILDDIR))/limine.elf
$(LIMINE_OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc -j .sbat --target efi-app-x86_64 '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)' $(LIMINE_OBJCOPY) -O binary '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/reduced-gnu-efi/gnuefi/crt0-efi-x86_64.o: reduced-gnu-efi $(call MKESCAPE,$(BUILDDIR))/reduced-gnu-efi/gnuefi/crt0-efi-x86_64.o: reduced-gnu-efi
true true
@ -326,10 +326,10 @@ ifeq ($(TARGET), uefi32)
$(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf $(call MKESCAPE,$(BUILDDIR))/full.map.o: $(call MKESCAPE,$(BUILDDIR))/limine_nomap.elf
cd '$(call SHESCAPE,$(BUILDDIR))' && \ cd '$(call SHESCAPE,$(BUILDDIR))' && \
'$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 32 '$(call SHESCAPE,$(SRCDIR))/gensyms.sh' '$(call SHESCAPE,$<)' full 32 '\.sect'
$(call MKESCAPE,$(BUILDDIR))/BOOTIA32.EFI: $(call MKESCAPE,$(BUILDDIR))/limine.elf $(call MKESCAPE,$(BUILDDIR))/BOOTIA32.EFI: $(call MKESCAPE,$(BUILDDIR))/limine.elf
$(LIMINE_OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc -j .sbat --target efi-app-ia32 '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)' $(LIMINE_OBJCOPY) -O binary '$(call SHESCAPE,$<)' '$(call SHESCAPE,$@)'
$(call MKESCAPE,$(BUILDDIR))/reduced-gnu-efi/gnuefi/crt0-efi-ia32.o: reduced-gnu-efi $(call MKESCAPE,$(BUILDDIR))/reduced-gnu-efi/gnuefi/crt0-efi-ia32.o: reduced-gnu-efi
true true

View File

@ -27,8 +27,8 @@ TMP3=$(mktemp)
TMP4=$(mktemp) TMP4=$(mktemp)
"$LIMINE_OBJDUMP" -t "$1" | ( "$SED" '/[[:<:]]d[[:>:]]/d' 2>/dev/null || "$SED" '/\bd\b/d' ) | sort > "$TMP1" "$LIMINE_OBJDUMP" -t "$1" | ( "$SED" '/[[:<:]]d[[:>:]]/d' 2>/dev/null || "$SED" '/\bd\b/d' ) | sort > "$TMP1"
"$GREP" "\.text" < "$TMP1" | cut -d' ' -f1 > "$TMP2" "$GREP" "$4" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
"$GREP" "\.text" < "$TMP1" | "$AWK" 'NF{ print $NF }' > "$TMP3" "$GREP" "$4" < "$TMP1" | "$AWK" 'NF{ print $NF }' > "$TMP3"
echo "section .$2_map" > "$TMP4" echo "section .$2_map" > "$TMP4"
echo "global $2_map" >> "$TMP4" echo "global $2_map" >> "$TMP4"

View File

@ -11,7 +11,7 @@
#if bios == 1 #if bios == 1
extern symbol stage2_map; extern symbol stage2_map;
#elif uefi == 1 #elif uefi == 1
extern symbol ImageBase; extern symbol __image_base;
#endif #endif
extern symbol full_map; extern symbol full_map;
@ -27,7 +27,7 @@ static char *trace_address(size_t *off, size_t addr) {
#elif uefi == 1 #elif uefi == 1
limine_map = full_map; limine_map = full_map;
addr -= (size_t)ImageBase; addr -= (size_t)__image_base;
#endif #endif
uintptr_t prev_addr = 0; uintptr_t prev_addr = 0;

View File

@ -1,107 +1,143 @@
/* The following code originates from gnu-efi */ OUTPUT_FORMAT(elf32-i386)
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386) OUTPUT_ARCH(i386)
ENTRY(_start) ENTRY(_start)
PHDRS
{
null PT_NULL FLAGS(0) ;
segm PT_LOAD FLAGS(7) ;
dynamic PT_DYNAMIC FLAGS(7) ;
}
SECTIONS SECTIONS
{ {
. = 0; . = 0;
ImageBase = .; __image_base = .;
/* .hash and/or .gnu.hash MUST come first! */ __image_size = __image_end - __image_base;
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) } .sect : {
. = ALIGN(4096); *(.pe_header)
.text :
{ . = ALIGN(0x1000);
_text = .;
*(.text) __text_start = .;
*(.text.*) __text_size = __text_end - __text_start;
*(.gnu.linkonce.t.*) *(.text .text.*)
. = ALIGN(16); . = ALIGN(0x1000);
} __text_end = .;
_etext = .;
_text_size = . - _text; __reloc_start = .;
. = ALIGN(4096); __reloc_size = __reloc_end - __reloc_start;
.sdata : *(.reloc)
{ . = ALIGN(0x1000);
_data = .; __reloc_end = .;
*(.got.plt)
*(.got) __sbat_start = .;
*(.srodata) __sbat_size = __sbat_end - __sbat_start;
*(.sdata) *(.sbat)
*(.sbss) . = ALIGN(0x1000);
*(.scommon) __sbat_end = .;
}
. = ALIGN(4096); __data_start = .;
.data : __data_size = __data_end - __data_start;
{ *(.rodata .rodata.*)
*(.rodata*)
*(.got.plt)
*(.got)
#ifdef LINKER_NOMAP #ifdef LINKER_NOMAP
full_map = .; full_map = .;
#else #else
*(.full_map) *(.full_map)
#endif #endif
*(.no_unwind) *(.no_unwind)
data_begin = .; data_begin = .;
*(.data) *(.data .data.*)
*(.data1) *(.bss .bss.*)
*(.data.*) *(COMMON)
*(.sdata)
/* the EFI loader doesn't seem to like a .bss section, so we stick
it all into .data: */
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
data_end = .; data_end = .;
} . = ALIGN(0x1000);
.note.gnu.build-id : { *(.note.gnu.build-id) } } :segm
. = ALIGN(4096); .rel : {
.dynamic : { *(.dynamic) } *(.rel .rel.*)
. = ALIGN(4096); . = ALIGN(0x1000);
.rel : } :segm
{
*(.rel.data)
*(.rel.data.*)
*(.rel.got)
*(.rel.stab)
*(.data.rel.ro.local)
*(.data.rel.local)
*(.data.rel.ro)
*(.data.rel*)
}
_edata = .;
_data_size = . - _etext;
. = ALIGN(4096); .got : {
.sbat : *(.got .got.*)
{ . = ALIGN(0x1000);
_sbat = .; } :segm
*(.sbat)
*(.sbat.*)
}
_esbat = .;
_sbat_size = . - _sbat;
. = ALIGN(4096); .dynamic : {
.reloc : /* This is the PECOFF .reloc section! */ __dynamic = .;
{ *(.dynamic)
*(.reloc) . = ALIGN(0x1000);
} } :segm :dynamic
. = ALIGN(4096);
.dynsym : { *(.dynsym) } __data_end = .;
. = ALIGN(4096); __image_end = .;
.dynstr : { *(.dynstr) }
. = ALIGN(4096); .symtab 0 : {
/DISCARD/ : *(.symtab)
{ } :null
*(.rel.reloc)
*(.eh_frame) .strtab 0 : {
*(.note.GNU-stack) *(.strtab)
} } :null
.comment 0 : { *(.comment) }
.shstrtab 0 : {
*(.shstrtab)
} :null
.debug_aranges 0 : {
*(.debug_aranges)
} :null
.debug_pubnames 0 : {
*(.debug_pubnames)
} :null
.debug_info 0 : {
*(.debug_info)
} :null
.debug_abbrev 0 : {
*(.debug_abbrev)
} :null
.debug_line 0 : {
*(.debug_line)
} :null
.debug_loclists 0 : {
*(.debug_loclists)
} :null
.debug_rnglists 0 : {
*(.debug_rnglists)
} :null
.debug_frame 0 : {
*(.debug_frame)
} :null
.debug_loc 0 : {
*(.debug_loc)
} :null
.debug_ranges 0 : {
*(.debug_ranges)
} :null
.debug_str 0 : {
*(.debug_str)
} :null
.debug_line_str 0 : {
*(.debug_line_str)
} :null
/DISCARD/ : {
*(*)
}
} }

View File

@ -1,96 +1,143 @@
/* The following code originates from gnu-efi */ OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
OUTPUT_ARCH(i386:x86-64) OUTPUT_ARCH(i386:x86-64)
ENTRY(_start) ENTRY(_start)
PHDRS
{
null PT_NULL FLAGS(0) ;
segm PT_LOAD FLAGS(7) ;
dynamic PT_DYNAMIC FLAGS(7) ;
}
SECTIONS SECTIONS
{ {
. = 0; . = 0;
ImageBase = .; __image_base = .;
/* .hash and/or .gnu.hash MUST come first! */ __image_size = __image_end - __image_base;
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) } .sect : {
. = ALIGN(4096); *(.pe_header)
.eh_frame :
{ . = ALIGN(0x1000);
*(.eh_frame)
} __text_start = .;
. = ALIGN(4096); __text_size = __text_end - __text_start;
.text : *(.text .text.*)
{ . = ALIGN(0x1000);
_text = .; __text_end = .;
*(.text)
*(.text.*) __reloc_start = .;
*(.gnu.linkonce.t.*) __reloc_size = __reloc_end - __reloc_start;
. = ALIGN(16); *(.reloc)
} . = ALIGN(0x1000);
_etext = .; __reloc_end = .;
_text_size = . - _text;
. = ALIGN(4096); __sbat_start = .;
.reloc : __sbat_size = __sbat_end - __sbat_start;
{ *(.sbat)
*(.reloc) . = ALIGN(0x1000);
} __sbat_end = .;
. = ALIGN(4096);
.data : __data_start = .;
{ __data_size = __data_end - __data_start;
_data = .; *(.rodata .rodata.*)
*(.rodata*)
*(.got.plt)
*(.got)
#ifdef LINKER_NOMAP #ifdef LINKER_NOMAP
full_map = .; full_map = .;
#else #else
*(.full_map) *(.full_map)
#endif #endif
*(.no_unwind) *(.no_unwind)
data_begin = .; data_begin = .;
*(.data*) *(.data .data.*)
*(.sdata) *(.bss .bss.*)
/* the EFI loader doesn't seem to like a .bss section, so we stick *(COMMON)
it all into .data: */
*(.sbss)
*(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
data_end = .; data_end = .;
*(.rel.local) . = ALIGN(0x1000);
} } :segm
.note.gnu.build-id : { *(.note.gnu.build-id) }
_edata = .; .rela : {
_data_size = . - _etext; *(.rela .rela.*)
. = ALIGN(0x1000);
} :segm
. = ALIGN(4096); .got : {
.sbat : *(.got .got.*)
{ . = ALIGN(0x1000);
_sbat = .; } :segm
*(.sbat)
*(.sbat.*)
}
_esbat = .;
_sbat_size = . - _sbat;
. = ALIGN(4096); .dynamic : {
.dynamic : { *(.dynamic) } __dynamic = .;
. = ALIGN(4096); *(.dynamic)
.rela : . = ALIGN(0x1000);
{ } :segm :dynamic
*(.rela.data*)
*(.rela.got) __data_end = .;
*(.rela.stab) __image_end = .;
}
. = ALIGN(4096); .symtab 0 : {
.dynsym : { *(.dynsym) } *(.symtab)
. = ALIGN(4096); } :null
.dynstr : { *(.dynstr) }
. = ALIGN(4096); .strtab 0 : {
.ignored.reloc : *(.strtab)
{ } :null
*(.rela.reloc)
*(.eh_frame) .shstrtab 0 : {
*(.note.GNU-stack) *(.shstrtab)
} } :null
.comment 0 : { *(.comment) }
.debug_aranges 0 : {
*(.debug_aranges)
} :null
.debug_pubnames 0 : {
*(.debug_pubnames)
} :null
.debug_info 0 : {
*(.debug_info)
} :null
.debug_abbrev 0 : {
*(.debug_abbrev)
} :null
.debug_line 0 : {
*(.debug_line)
} :null
.debug_loclists 0 : {
*(.debug_loclists)
} :null
.debug_rnglists 0 : {
*(.debug_rnglists)
} :null
.debug_frame 0 : {
*(.debug_frame)
} :null
.debug_loc 0 : {
*(.debug_loc)
} :null
.debug_ranges 0 : {
*(.debug_ranges)
} :null
.debug_str 0 : {
*(.debug_str)
} :null
.debug_line_str 0 : {
*(.debug_line_str)
} :null
/DISCARD/ : {
*(*)
}
} }

View File

@ -279,8 +279,8 @@ void init_memmap(void) {
#endif #endif
#if uefi == 1 #if uefi == 1
extern symbol ImageBase; extern symbol __image_base;
extern symbol _edata; extern symbol __image_end;
void init_memmap(void) { void init_memmap(void) {
EFI_STATUS status; EFI_STATUS status;
@ -388,10 +388,10 @@ void init_memmap(void) {
memcpy(untouched_memmap, memmap, memmap_entries * sizeof(struct e820_entry_t)); memcpy(untouched_memmap, memmap, memmap_entries * sizeof(struct e820_entry_t));
untouched_memmap_entries = memmap_entries; untouched_memmap_entries = memmap_entries;
size_t bootloader_size = ALIGN_UP((uintptr_t)_edata - (uintptr_t)ImageBase, 4096); size_t bootloader_size = ALIGN_UP((uintptr_t)__image_end - (uintptr_t)__image_base, 4096);
// Allocate bootloader itself // Allocate bootloader itself
memmap_alloc_range((uintptr_t)ImageBase, bootloader_size, memmap_alloc_range((uintptr_t)__image_base, bootloader_size,
MEMMAP_BOOTLOADER_RECLAIMABLE, false, true, false, true); MEMMAP_BOOTLOADER_RECLAIMABLE, false, true, false, true);
sanitise_entries(memmap, &memmap_entries, false); sanitise_entries(memmap, &memmap_entries, false);