diff --git a/include/arch/x86/intel64/linker.ld b/include/arch/x86/intel64/linker.ld index d6c224d768a..62e40483936 100644 --- a/include/arch/x86/intel64/linker.ld +++ b/include/arch/x86/intel64/linker.ld @@ -3,70 +3,75 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define DEVICE_INIT_LEVEL(level) \ - __device_##level##_start = .; \ - KEEP(*(SORT(.init_##level[0-9]))); \ - KEEP(*(SORT(.init_##level[1-9][0-9]))); +#define _LINKER +#define _ASMLANGUAGE + +#include +#include + +#define ROMABLE_REGION RAM +#define RAMABLE_REGION RAM ENTRY(CONFIG_KERNEL_ENTRY) SECTIONS { - /* - * The "locore" must be in the 64K of RAM, so that 16-bit code (with - * segment registers == 0x0000) and 32/64-bit code agree on addresses. - * ... there is no 16-bit code yet, but there will be when we add SMP. - */ + /* + * The "locore" must be in the 64K of RAM, so that 16-bit code (with + * segment registers == 0x0000) and 32/64-bit code agree on addresses. + * ... there is no 16-bit code yet, but there will be when we add SMP. + */ - .locore 0x8000 : ALIGN(16) + .locore 0x8000 : ALIGN(16) { *(.locore) *(.locore.*) } - /* - * The parts of the system that don't benefit from being in the locore - * start at the 1MB mark, otherwise the system size would be artificially - * clamped by the ISA memory hole/ROM space at 0x90000-0xFFFFF. - */ + /* + * The rest of the system is loaded in "normal" memory (typically + * placed above 1MB to avoid the by memory hole at 0x90000-0xFFFFF). + */ - .text 0x100000 : ALIGN(16) + SECTION_PROLOGUE(_TEXT_SECTION_NAME,,ALIGN(16)) { *(.text) *(.text.*) + } GROUP_LINK_IN(ROMABLE_REGION) + + #include + + SECTION_PROLOGUE(_RODATA_SECTION_NAME,,ALIGN(16)) + { + _image_rodata_start = .; + + *(.rodata) *(.rodata.*) - . = ALIGN(8); - __devconfig_start = .; - *(.devconfig.*) - KEEP(*(SORT_BY_NAME(.devconfig*))) - __devconfig_end = .; - } + #include - .data : ALIGN(16) + #ifdef CONFIG_CUSTOM_RODATA_LD + #include + #endif /* CONFIG_CUSTOM_RODATA_LD */ + + _image_rodata_end = .; + _image_rodata_size = _image_rodata_end - _image_rodata_start; + } GROUP_LINK_IN(ROMABLE_REGION) + + SECTION_PROLOGUE(_DATA_SECTION_NAME,,ALIGN(16)) { - *(.data*) + *(.data) + *(.data.*) + #include + #ifdef CONFIG_CUSTOM_RWDATA_LD + #include + #endif /* CONFIG_CUSTOM_RWDATA_LD */ + } GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) - . = ALIGN(8); - __device_init_start = .; - DEVICE_INIT_LEVEL(PRE_KERNEL_1) - DEVICE_INIT_LEVEL(PRE_KERNEL_2) - DEVICE_INIT_LEVEL(POST_KERNEL) - DEVICE_INIT_LEVEL(APPLICATION) - __device_init_end = .; +#include +#include - . = ALIGN(8); - __static_thread_data_list_start = .; - KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*))) - __static_thread_data_list_end = .; - - . = ALIGN(8); - _k_mem_pool_list_start = .; - KEEP(*(._k_mem_pool_static.*)) - _k_mem_pool_list_end = .; - } - - .bss : ALIGN(16) + SECTION_PROLOGUE(_BSS_SECTION_NAME, (NOLOAD), ALIGN(16)) { __bss_start = .; *(.bss) @@ -74,23 +79,37 @@ SECTIONS *(COMMON) . = ALIGN(8); /* so __bss_num_qwords is exact */ __bss_end = .; - } + } GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION) __bss_num_qwords = (__bss_end - __bss_start) >> 3; - .noinit (NOLOAD) : ALIGN(16) + SECTION_PROLOGUE(_NOINIT_SECTION_NAME, (NOLOAD), ALIGN(16)) { + *(.noinit) *(.noinit.*) - } + #include + } GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION) - /DISCARD/ : +#include +#ifdef CONFIG_CUSTOM_SECTIONS_LD +#include +#endif /* CONFIG_CUSTOM_SECTIONS_LD */ + + . = ALIGN(8); + _end = .; + + /DISCARD/ : { *(.comment*) *(.debug*) - *(.got*) - *(.igot.*) + *(.got) + *(.got.plt) + *(.igot) + *(.igot.plt) *(.iplt) + *(.plt) *(.note.GNU-stack) + *(.rel.*) *(.rela.*) } } diff --git a/include/linker/linker-tool-gcc.h b/include/linker/linker-tool-gcc.h index f19c5ff1d63..928d38b707a 100644 --- a/include/linker/linker-tool-gcc.h +++ b/include/linker/linker-tool-gcc.h @@ -25,8 +25,13 @@ #elif defined(CONFIG_ARC) OUTPUT_FORMAT("elf32-littlearc", "elf32-bigarc", "elf32-littlearc") #elif defined(CONFIG_X86) - OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") - OUTPUT_ARCH("i386") + #if defined (CONFIG_X86_LONGMODE) + OUTPUT_FORMAT("elf64-x86-64") + OUTPUT_ARCH("i386:x86-64") + #else + OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") + OUTPUT_ARCH("i386") + #endif #elif defined(CONFIG_NIOS2) OUTPUT_FORMAT("elf32-littlenios2", "elf32-bignios2", "elf32-littlenios2") #elif defined(CONFIG_RISCV) diff --git a/soc/x86/apollo_lake/linker.ld b/soc/x86/apollo_lake/linker.ld index b6d7703c090..dbc948fa764 100644 --- a/soc/x86/apollo_lake/linker.ld +++ b/soc/x86/apollo_lake/linker.ld @@ -8,12 +8,6 @@ #include #include -#ifdef CONFIG_X86_LONGMODE - -#include - -#else /* IA32 */ - #define PHYS_LOAD_ADDR DT_PHYS_RAM_ADDR #define PHYS_RAM_ADDR DT_PHYS_RAM_ADDR @@ -30,6 +24,8 @@ MEMORY IDT_LIST : ORIGIN = 2K, LENGTH = 2K } +#ifdef CONFIG_X86_LONGMODE +#include +#else #include - #endif /* CONFIG_X86_LONGMODE */