From: kettenis Date: Fri, 29 Jul 2022 21:34:59 +0000 (+0000) Subject: Give to PE/COFF file proper .text and .data sections, and fill in the X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=09ce6c0661b90c6c2535c9b67b87f0366c17d369;p=openbsd Give to PE/COFF file proper .text and .data sections, and fill in the characteristics field in the COFF header. Makes our bootloader work in the x13s. With help from mlarkin@. ok mlarkin@ --- diff --git a/sys/arch/arm64/stand/efiboot/conf.c b/sys/arch/arm64/stand/efiboot/conf.c index a0438d9fef3..68a063d310c 100644 --- a/sys/arch/arm64/stand/efiboot/conf.c +++ b/sys/arch/arm64/stand/efiboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.37 2022/04/06 21:27:03 kettenis Exp $ */ +/* $OpenBSD: conf.c,v 1.38 2022/07/29 21:34:59 kettenis Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -46,7 +46,7 @@ #include "efipxe.h" #include "softraid_arm64.h" -const char version[] = "1.9"; +const char version[] = "1.10"; int debug = 0; struct fs_ops file_system[] = { diff --git a/sys/arch/arm64/stand/efiboot/ldscript.arm64 b/sys/arch/arm64/stand/efiboot/ldscript.arm64 index d422bfafc9b..e06e652cd2c 100644 --- a/sys/arch/arm64/stand/efiboot/ldscript.arm64 +++ b/sys/arch/arm64/stand/efiboot/ldscript.arm64 @@ -1,4 +1,4 @@ -/* $OpenBSD: ldscript.arm64,v 1.3 2021/05/15 14:20:11 kettenis Exp $ */ +/* $OpenBSD: ldscript.arm64,v 1.4 2022/07/29 21:34:59 kettenis Exp $ */ ENTRY(_start) SECTIONS @@ -13,7 +13,9 @@ SECTIONS *(.gnu.warning) *(.plt) } =0xD4200000 - . = ALIGN(16); + . = ALIGN(4096); + _etext = .; + __data_start = .; .data : { *(.rodata .rodata.* .gnu.linkonce.r.*) *(.rodata1) @@ -76,6 +78,7 @@ SECTIONS .dynsym : { *(.dynsym) } .dynstr : { *(.dynstr) } _edata = .; + __data_size = . - __data_start; /* Unused sections */ .hash : { *(.hash) } diff --git a/sys/arch/arm64/stand/efiboot/start.S b/sys/arch/arm64/stand/efiboot/start.S index 0a4e02bdb9c..2cdb214275d 100644 --- a/sys/arch/arm64/stand/efiboot/start.S +++ b/sys/arch/arm64/stand/efiboot/start.S @@ -1,4 +1,4 @@ -/* $OpenBSD: start.S,v 1.3 2017/01/22 01:38:25 kettenis Exp $ */ +/* $OpenBSD: start.S,v 1.4 2022/07/29 21:34:59 kettenis Exp $ */ /*- * Copyright (c) 2014 Andrew Turner * All rights reserved. @@ -40,6 +40,9 @@ #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 #define IMAGE_SCN_MEM_READ 0x40000000 +#define IMAGE_SCN_MEM_WRITE 0x80000000 + + .globl __data_start .section .peheader, "a" efi_start: @@ -61,22 +64,22 @@ coff_head: .long 0 /* No symbol table */ .long 0 /* No symbols */ .short section_table - optional_header /* Optional header size */ - .short 0 /* Characteristics TODO: Fill in */ + .short 0x0206 /* Characteristics */ optional_header: .short 0x020b /* PE32+ (64-bit addressing) */ .byte 0 /* Major linker version */ .byte 0 /* Minor linker version */ - .long _edata - _end_header /* Code size */ - .long 0 /* No initialized data */ + .long _etext - _end_header /* Code size */ + .long __data_size /* Initialized data size */ .long 0 /* No uninitialized data */ .long _start - efi_start /* Entry point */ .long _end_header - efi_start /* Start of code */ optional_windows_header: .quad 0 /* Image base */ - .long 32 /* Section Alignment */ - .long 8 /* File alignment */ + .long 4096 /* Section Alignment */ + .long 512 /* File alignment */ .short 0 /* Major OS version */ .short 0 /* Minor OS version */ .short 0 /* Major image version */ @@ -105,36 +108,39 @@ optional_windows_header: .quad 0 section_table: - /* We need a .reloc section for EFI */ - .ascii ".reloc" + /* The contents of the loader */ + .ascii ".text" + .byte 0 .byte 0 .byte 0 /* Pad to 8 bytes */ - .long 0 /* Virtual size */ - .long 0 /* Virtual address */ - .long 0 /* Size of raw data */ - .long 0 /* Pointer to raw data */ + .long _etext - _end_header /* Virtual size */ + .long _end_header - efi_start /* Virtual address */ + .long _etext - _end_header /* Size of raw data */ + .long _end_header - efi_start /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ - .long (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | \ - IMAGE_SCN_MEM_DISCARDABLE) /* Characteristics */ + .long (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | \ + IMAGE_SCN_MEM_READ) /* Characteristics */ /* The contents of the loader */ - .ascii ".text" + .ascii ".data" .byte 0 .byte 0 .byte 0 /* Pad to 8 bytes */ - .long _edata - _end_header /* Virtual size */ - .long _end_header - efi_start /* Virtual address */ - .long _edata - _end_header /* Size of raw data */ - .long _end_header - efi_start /* Pointer to raw data */ + .long __data_size /* Virtual size */ + .long __data_start - efi_start /* Virtual address */ + .long __data_size /* Size of raw data */ + .long __data_start - efi_start /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ - .long (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | \ - IMAGE_SCN_MEM_READ) /* Characteristics */ + .long (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | \ + IMAGE_SCN_MEM_WRITE) /* Characteristics */ + + .align 12 _end_header: .text