From 11adf1b8cc657bb30c386da762960c6bbad74403 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Wed, 4 Jan 2023 23:19:26 +0000 Subject: [PATCH] link: Move x86-ism out of the linker script ... in preparation to reuse it for all architectures. In order to keep various parts of the linker script all together, use a multi-include file with header and footer delineations. While moving things, drop the alignment check for the two stacks. Neither need page alignment architecturally. Signed-off-by: Andrew Cooper --- arch/x86/include/arch/config.h | 2 + arch/x86/include/arch/link.lds.h | 65 ++++++++++++++++++++++++++++++++ arch/x86/link.lds.S | 58 ++++++++-------------------- 3 files changed, 82 insertions(+), 43 deletions(-) create mode 100644 arch/x86/include/arch/link.lds.h diff --git a/arch/x86/include/arch/config.h b/arch/x86/include/arch/config.h index f3b4471..ce7987a 100644 --- a/arch/x86/include/arch/config.h +++ b/arch/x86/include/arch/config.h @@ -11,6 +11,8 @@ #ifndef XTF_X86_CONFIG_H #define XTF_X86_CONFIG_H +#define XTF_VIRT_START (1 << 20) + #include #if defined(CONFIG_ENV_pv64) diff --git a/arch/x86/include/arch/link.lds.h b/arch/x86/include/arch/link.lds.h new file mode 100644 index 0000000..342c4ef --- /dev/null +++ b/arch/x86/include/arch/link.lds.h @@ -0,0 +1,65 @@ +/** + * @file arch/x86/include/arch/link.lds.h + * + * x86 details for the linker file. + */ + +#ifdef LINKER_HEADER + +/* Don't clobber the ld directive */ +#undef i386 + +#if defined(__x86_64__) + +OUTPUT_FORMAT("elf64-x86-64") +OUTPUT_ARCH(i386:x86-64) + +#elif defined(__i386__) + +OUTPUT_FORMAT("elf32-i386") +OUTPUT_ARCH(i386) + +#else +# error Bad architecture to link with +#endif + +ENTRY(_elf_start) + +#endif /* LINKER_HEADER */ + +#ifdef LINKER_FOOTER + +ASSERT(IS_ALIGNED(hypercall_page, PAGE_SIZE), "hypercall_page misaligned"); + +#ifdef CONFIG_HVM + +/* Check everything lives within l1_identmap[] for user and r/o mappings. */ +ASSERT(_end < (1 << (PT_ORDER + PAGE_SHIFT)), "Mappings exceed l1_identmap[]"); + +ASSERT(IS_ALIGNED(pae_l1_identmap, PAGE_SIZE), "pae_l1_identmap misaligned"); +ASSERT(IS_ALIGNED(pae_l2_identmap, PAGE_SIZE), "pae_l2_identmap misaligned"); +ASSERT(IS_ALIGNED(pae_l3_identmap, PAGE_SIZE), "pae_l3_identmap misaligned"); +ASSERT(IS_ALIGNED(pae_l4_identmap, PAGE_SIZE), "pae_l4_identmap misaligned"); + +ASSERT(IS_ALIGNED(pae32_l3_identmap, 32), "pae32_l3_ident misaligned"); + +ASSERT(IS_ALIGNED(pse_l1_identmap, PAGE_SIZE), "pse_l1_identmap misaligned"); +ASSERT(IS_ALIGNED(pse_l2_identmap, PAGE_SIZE), "pse_l2_identmap misaligned"); + +#else /* CONFIG_HVM */ + +ASSERT(IS_ALIGNED(gdt, PAGE_SIZE), "gdt misaligned"); + +#endif /* CONFIG_HVM */ + +#endif /* LINKER_FOOTER */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/arch/x86/link.lds.S b/arch/x86/link.lds.S index a7716d6..3a0907d 100644 --- a/arch/x86/link.lds.S +++ b/arch/x86/link.lds.S @@ -1,28 +1,19 @@ /* - * Common linker file for all x86 environments + * Common linker file for all architectures/environments */ #include #include -/* Don't clobber the ld directive */ -#undef i386 - -#if defined(__x86_64__) - -OUTPUT_FORMAT("elf64-x86-64") -OUTPUT_ARCH(i386:x86-64) - -#elif defined(__i386__) - -OUTPUT_FORMAT("elf32-i386") -OUTPUT_ARCH(i386) - -#else -# error Bad architecture to link with -#endif - -ENTRY(_elf_start) +/* + * Architecture must provide: + * - OUTPUT_FORMAT() + * - OUTPUT_ARCH() + * - ENTRY() + */ +#define LINKER_HEADER +#include +#undef LINKER_HEADER PHDRS { @@ -32,7 +23,7 @@ PHDRS SECTIONS { - . = SEGMENT_START("text-segment", MB(1)); + . = XTF_VIRT_START; _start = .; @@ -97,10 +88,6 @@ SECTIONS */ zeroptr = 0; -ASSERT(IS_ALIGNED(hypercall_page, PAGE_SIZE), "hypercall_page misaligned"); -ASSERT(IS_ALIGNED(boot_stack, PAGE_SIZE), "boot_stack misaligned"); -ASSERT(IS_ALIGNED(user_stack, PAGE_SIZE), "user_stack misaligned"); - ASSERT(IS_ALIGNED(__start_user_text, PAGE_SIZE), "__start_user_text misaligned"); ASSERT(IS_ALIGNED(__end_user_text, PAGE_SIZE), "__end_user_text misaligned"); ASSERT(IS_ALIGNED(__start_user_data, PAGE_SIZE), "__start_user_data misaligned"); @@ -108,26 +95,11 @@ ASSERT(IS_ALIGNED(__end_user_data, PAGE_SIZE), "__end_user_data misaligned") ASSERT(IS_ALIGNED(__start_user_bss, PAGE_SIZE), "__start_user_data misaligned"); ASSERT(IS_ALIGNED(__end_user_bss, PAGE_SIZE), "__end_user_data misaligned") -#ifdef CONFIG_HVM - -/* Check everything lives within l1_identmap[] for user and r/o mappings. */ -ASSERT(_end < (1 << (PT_ORDER + PAGE_SHIFT)), "Mappings exceed l1_identmap[]"); - -ASSERT(IS_ALIGNED(pae_l1_identmap, PAGE_SIZE), "pae_l1_identmap misaligned"); -ASSERT(IS_ALIGNED(pae_l2_identmap, PAGE_SIZE), "pae_l2_identmap misaligned"); -ASSERT(IS_ALIGNED(pae_l3_identmap, PAGE_SIZE), "pae_l3_identmap misaligned"); -ASSERT(IS_ALIGNED(pae_l4_identmap, PAGE_SIZE), "pae_l4_identmap misaligned"); - -ASSERT(IS_ALIGNED(pae32_l3_identmap, 32), "pae32_l3_ident misaligned"); - -ASSERT(IS_ALIGNED(pse_l1_identmap, PAGE_SIZE), "pse_l1_identmap misaligned"); -ASSERT(IS_ALIGNED(pse_l2_identmap, PAGE_SIZE), "pse_l2_identmap misaligned"); - -#else - -ASSERT(IS_ALIGNED(gdt, PAGE_SIZE), "gdt misaligned"); +/* Architecture may provide any extra asserts. */ +#define LINKER_FOOTER +#include +#undef LINKER_FOOTER -#endif /* * Local variables: * tab-width: 8 -- 2.39.5