From 19f747847ffb39cb2df43376ff569bf18a026362 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Wed, 18 Mar 2020 13:05:50 +0100 Subject: [PATCH] zipl/boot: use C pre-processor for linker script generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use C pre-processor for linker script generation and refactor some constants. This allows the usage of the constants in our "linker scripts" `*.lds.S` (actually, these are assembler files, so we can make us of the C pre-processor and its capabilities). While at it, enforce the described memory layout in the generated linker script. Reviewed-by: Stefan Haberland Reviewed-by: Philipp Rudo Signed-off-by: Marc Hartmayer Signed-off-by: Jan Höppner --- include/boot/loaders_layout.h | 10 ++++++ zipl/boot/.gitignore | 2 ++ zipl/boot/Makefile | 20 ++++++++++-- zipl/boot/stage2.c | 1 + zipl/boot/stage2.h | 3 -- zipl/boot/{stage2.lds => stage2.lds.S} | 44 ++++++++++++++++++++++---- zipl/boot/{stage3.lds => stage3.lds.S} | 29 ++++++++++++++--- 7 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 zipl/boot/.gitignore rename zipl/boot/{stage2.lds => stage2.lds.S} (57%) rename zipl/boot/{stage3.lds => stage3.lds.S} (53%) diff --git a/include/boot/loaders_layout.h b/include/boot/loaders_layout.h index dd82ce17..5fc6d257 100644 --- a/include/boot/loaders_layout.h +++ b/include/boot/loaders_layout.h @@ -14,19 +14,29 @@ #include "lib/zt_common.h" #include "linux_layout.h" +#define STAGE2_DESC _AC(0x78, UL) +#define STAGE2_ENTRY _AC(0x2018, UL) +#define STAGE2_HEAP_ADDRESS _AC(0x6000, UL) +#define STAGE2_HEAP_SIZE _AC(0x3000, UL) +#define STAGE2_STACK_ADDRESS _AC(0xe400, UL) +#define STAGE2_STACK_SIZE _AC(0x1c00, UL) + #define STAGE3_ENTRY _AC(0xa000, UL) #define STAGE2_LOAD_ADDRESS _AC(0x2000, UL) #define STAGE3_LOAD_ADDRESS STAGE3_ENTRY #define IMAGE_LOAD_ADDRESS IMAGE_ENTRY +#define STAGE3_MAXIMUM_SIZE _AC(0x3000, UL) #define STAGE3_HEAP_SIZE _AC(0x4000, UL) #define STAGE3_HEAP_ADDRESS _AC(0x2000, UL) #define STAGE3_STACK_SIZE _AC(0x1000, UL) #define STAGE3_STACK_ADDRESS _AC(0xF000, UL) #define STAGE3_PARAMS_ADDRESS _AC(0x9000, UL) +#define STAGE3_PARAMS_MAXIMUM_SIZE _AC(0x1000, UL) #define COMMAND_LINE_EXTRA _AC(0xE000, UL) +#define COMMAND_LINE_EXTRA_SIZE _AC(0x0400, UL) #ifndef __ASSEMBLER__ #endif /* __ASSEMBLER__ */ diff --git a/zipl/boot/.gitignore b/zipl/boot/.gitignore new file mode 100644 index 00000000..352157d0 --- /dev/null +++ b/zipl/boot/.gitignore @@ -0,0 +1,2 @@ +*.lds +*.lds.d diff --git a/zipl/boot/Makefile b/zipl/boot/Makefile index 190beb0c..359189e5 100644 --- a/zipl/boot/Makefile +++ b/zipl/boot/Makefile @@ -1,8 +1,11 @@ # Common definitions include ../../common.mak -ALL_CFLAGS = $(NO_PIE_CFLAGS) -Os -g -I $(rootdir)/zipl/include \ - -I $(rootdir)/include -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \ +INCLUDE_PATHS := $(rootdir)/zipl/include $(rootdir)/include +INCLUDE_PARMS := $(addprefix -I,$(INCLUDE_PATHS)) + +ALL_CFLAGS = $(NO_PIE_CFLAGS) -Os -g $(INCLUDE_PARMS) \ + -DS390_TOOLS_RELEASE=$(S390_TOOLS_RELEASE) \ -fno-builtin -ffreestanding -fno-asynchronous-unwind-tables \ -fno-delete-null-pointer-checks \ -fexec-charset=IBM1047 -m64 -mpacked-stack \ @@ -26,6 +29,17 @@ all: data.o data.h tape0.bin stage3.bin %.o: %.c $(CC) $(ALL_CFLAGS) -c -o $@ $< +# Dependencies for the .lds generation +sources_lds_S = $(wildcard *.lds.S) +dependencies_lds_S = $(sources_lds_S:%.lds.S=.%.lds.d) +# Include all ".lds.d" dependency files for all make targets except for "clean" +ifneq ($(MAKECMDGOALS),clean) +-include $(dependencies_lds_S) +endif + +%.lds: %.lds.S + $(CPP) -Wp,-MD,.$@.d,-MT,$@ $(INCLUDE_PARMS) -P -C -o $@ $< + eckd2dump_sv.exec: \ head.o stage2dump.o cio.o eckd2dump.o eckd2dump_sv.o \ libc.o ebcdic.o sclp.o entry.o stage2.lds @@ -104,6 +118,6 @@ data.h: data.o clean: rm -f *.o *.exec *.bin $(FILES) data.o data.h tape0.bin *.xxx *.yyy \ - stage3.bin + stage3.bin *.lds *.lds.d .PHONY: all clean diff --git a/zipl/boot/stage2.c b/zipl/boot/stage2.c index c8b28cd0..78591c1a 100644 --- a/zipl/boot/stage2.c +++ b/zipl/boot/stage2.c @@ -15,6 +15,7 @@ #include "libc.h" #include "menu.h" #include "boot/s390.h" +#include "boot/loaders_layout.h" #include "stage2.h" static int is_null_descriptor(disk_blockptr_t *address) diff --git a/zipl/boot/stage2.h b/zipl/boot/stage2.h index ecdf58ef..b29eea1b 100644 --- a/zipl/boot/stage2.h +++ b/zipl/boot/stage2.h @@ -16,9 +16,6 @@ #define DESCR_PER_BLOCK _AC(16, U) -/* ADRESS */ -#define STAGE2_DESC _AC(0x78, UL) - #ifndef __ASSEMBLER__ diff --git a/zipl/boot/stage2.lds b/zipl/boot/stage2.lds.S similarity index 57% rename from zipl/boot/stage2.lds rename to zipl/boot/stage2.lds.S index 34ed0146..c4c94566 100644 --- a/zipl/boot/stage2.lds +++ b/zipl/boot/stage2.lds.S @@ -25,15 +25,19 @@ * 0x5000-0x51ff eckd2dump_mv parameter block (426 bytes) */ +#include "boot/loaders_layout.h" + SECTIONS { - . = 0x78; + . = STAGE2_DESC; __stage2_desc = .; - . = 0x2000; + . = STAGE2_LOAD_ADDRESS; .stage2.head : { *(.stage2.head) } - . = 0x2018; - .text.start : { *(.text.start) } + . = STAGE2_ENTRY; + .text.start : { + *(.text.start) + } .text : { *(.text) } __ex_table_start = .; .ex_table : { *(.ex_table) } @@ -52,12 +56,38 @@ SECTIONS .bss : { *(.bss) } __bss_stop = .; - . = 0x6000; + . = STAGE2_HEAP_ADDRESS; __heap_start = .; - . = 0x9000; + .heap : { + . += STAGE2_HEAP_SIZE; + ASSERT(__heap_stop - __heap_start == STAGE2_HEAP_SIZE, + "Heap section doesn't conform to the described memory layout"); + } __heap_stop = .; - . = 0xf000; + /* Memory reserved for stage3. Use a dummy section to check if changes + * in stage3 memory layout work with stage2 and vice versa. + */ + . = STAGE3_PARAMS_ADDRESS; + .stage3 : { + . += STAGE3_PARAMS_MAXIMUM_SIZE; + + . = STAGE3_LOAD_ADDRESS - STAGE3_PARAMS_ADDRESS; + . += STAGE3_MAXIMUM_SIZE; + + . = COMMAND_LINE_EXTRA - STAGE3_PARAMS_ADDRESS; + . += COMMAND_LINE_EXTRA_SIZE; + } + + . = STAGE2_STACK_ADDRESS; + __stack_start = .; + .stack : { + . += STAGE2_STACK_SIZE; + ASSERT(__stack_end - __stack_start == STAGE2_STACK_SIZE, + "Stack section doesn't conform to the described memory layout"); + } + __stack_end = .; + .eh_frame : { *(.eh_frame) } .note.gnu.build-id : { *(.note.gnu.build-id) } } diff --git a/zipl/boot/stage3.lds b/zipl/boot/stage3.lds.S similarity index 53% rename from zipl/boot/stage3.lds rename to zipl/boot/stage3.lds.S index a9f17fb3..2362d4f5 100644 --- a/zipl/boot/stage3.lds +++ b/zipl/boot/stage3.lds.S @@ -13,21 +13,26 @@ * 0xf000-0xffff Stack */ +#include "boot/loaders_layout.h" + SECTIONS { . = 0x0; - . = 0x2000; + . = STAGE3_HEAP_ADDRESS; __heap_start = .; - . = 0x6000; + .heap : { + . += STAGE3_HEAP_SIZE; + ASSERT(__heap_stop - __heap_start == STAGE3_HEAP_SIZE, + "Heap section doesn't conform to the described memory layout"); + } __heap_stop = .; - /* stage 3 parameter */ - . = 0x9000; + . = STAGE3_PARAMS_ADDRESS; _stage3_parms = .; - . = 0xa000; + . = STAGE3_ENTRY; .text.start : { *(.text.start) } .text : { *(.text) } __ex_table_start = .; @@ -40,4 +45,18 @@ SECTIONS __bss_stop = .; .rodata : {*(.rodata) } .data : { *(.data) } + + . = COMMAND_LINE_EXTRA; + .cmdline_extra : { + . += COMMAND_LINE_EXTRA_SIZE; + } + + . = STAGE3_STACK_ADDRESS; + __stack_start = .; + .stack : { + . += STAGE3_STACK_SIZE; + ASSERT(__stack_end - __stack_start == STAGE3_STACK_SIZE, + "Stack section doesn't conform to the described memory layout"); + } + __stack_end = .; }