]> xenbits.xensource.com Git - xtf.git/commitdiff
link: Move x86-ism out of the linker script
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 4 Jan 2023 23:19:26 +0000 (23:19 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 11 Jan 2023 01:03:19 +0000 (01:03 +0000)
... 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 <andrew.cooper3@citrix.com>
arch/x86/include/arch/config.h
arch/x86/include/arch/link.lds.h [new file with mode: 0644]
arch/x86/link.lds.S

index f3b4471434a8c22a304c61de5d09e4112387c581..ce7987ab58a1554759957029869d2acbd4afa863 100644 (file)
@@ -11,6 +11,8 @@
 #ifndef XTF_X86_CONFIG_H
 #define XTF_X86_CONFIG_H
 
+#define XTF_VIRT_START (1 << 20)
+
 #include <xtf/macro_magic.h>
 
 #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 (file)
index 0000000..342c4ef
--- /dev/null
@@ -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:
+ */
index a7716d6d97f019dc0447fa91b84897c50abf9a42..3a0907d9a0e4fcb38e172f3407192807822a8c36 100644 (file)
@@ -1,28 +1,19 @@
 /*
- * Common linker file for all x86 environments
+ * Common linker file for all architectures/environments
  */
 
 #include <xtf/numbers.h>
 #include <arch/page.h>
 
-/* 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 <arch/link.lds.h>
+#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 <arch/link.lds.h>
+#undef LINKER_FOOTER
 
-#endif
 /*
  * Local variables:
  * tab-width: 8