zephyr/include/linker/linker-tool-gcc.h

111 lines
3.4 KiB
C
Raw Normal View History

/*
* Copyright (c) 2013-2014, Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief GCC toolchain linker defs
*
* This header file defines the necessary macros used by the linker script for
* use with the GCC linker.
*/
#ifndef __LINKER_TOOL_GCC_H
#define __LINKER_TOOL_GCC_H
#if defined(CONFIG_ARM)
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
#elif defined(CONFIG_ARC)
OUTPUT_FORMAT("elf32-littlearc", "elf32-bigarc", "elf32-littlearc")
#elif defined(CONFIG_X86)
#if defined(__IAMCU)
OUTPUT_FORMAT("elf32-iamcu")
OUTPUT_ARCH(iamcu:intel)
#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")
arch: added support for the riscv32 architecture RISC-V is an open-source instruction set architecture. Added support for the 32bit version of RISC-V to Zephyr. 1) exceptions/interrupts/faults are handled at the architecture level via the __irq_wrapper handler. Context saving/restoring of registers can be handled at both architecture and SOC levels. If SOC-specific registers need to be saved, SOC level needs to provide __soc_save_context and __soc_restore_context functions that shall be accounted by the architecture level, when corresponding config variable RISCV_SOC_CONTEXT_SAVE is set. 2) As RISC-V architecture does not provide a clear ISA specification about interrupt handling, each RISC-V SOC handles it in its own way. Hence, at the architecture level, the __irq_wrapper handler expects the following functions to be provided by the SOC level: __soc_is_irq: to check if the exception is the result of an interrupt or not. __soc_handle_irq: handle pending IRQ at SOC level (ex: clear pending IRQ in SOC-specific IRQ register) 3) Thread/task scheduling, as well as IRQ offloading are handled via the RISC-V system call ("ecall"), which is also handled via the __irq_wrapper handler. The _Swap asm function just calls "ecall" to generate an exception. 4) As there is no conventional way of handling CPU power save in RISC-V, the default nano_cpu_idle and nano_cpu_atomic_idle functions just unlock interrupts and return to the caller, without issuing any CPU power saving instruction. Nonetheless, to allow SOC-level to implement proper CPU power save, nano_cpu_idle and nano_cpu_atomic_idle functions are defined as __weak at the architecture level. Change-Id: I980a161d0009f3f404ad22b226a6229fbb492389 Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-11 07:24:30 +08:00
#elif defined(CONFIG_RISCV32)
OUTPUT_ARCH(riscv)
OUTPUT_FORMAT("elf32-littleriscv")
#elif defined(CONFIG_XTENSA)
/* Not needed */
#else
#error Arch not supported.
toolchain: add support for iamcu toolchain See https://groups.google.com/forum/#!topic/ia32-abi/cn7TM6J_TIg for more details. • Support IA32 without FPU. • Minimum ISA: Pentium ISA without x87 FPU instructions. • Don't allow mixing i386 object files with Intel MCU object files. • Support floating point with software emulation: a. Long double is the same as double. b. Use __float80 for 80-bit double. • Minimize memory footprint: a. Code size b. Data size c. Stack size Here is the draft of Intel MCU psABI. The differences from IA32 psABI are 1. The minimum instruction set is Intel Pentium ISA minus instructions for x87 floating point unit. 2. There are no x87 floating point registers. 3. There are no vector registers. 4. Segment registers are optional. 5. Support for TLS relocations are optional. 6. Scalar types larger than 4 bytes are aligned to 4 bytes. 7. There are no vector types. 8. _Decimal32, _Decimal64, and _Decimal128 types are optional. 9. long double type is the same as double. 10. float, double and long double types are passed and returned in general purpose registers. 11. _Decimal32 and _Decimal64 types are passed in general purpose registers. 12. Aggregate types no larger than 8 bytes are passed and returned in general purpose registers. 13. Stack is 4-byte aligned. 14. The auxiliary vector support is optional. 15. Register %edx has undefined value at process entry. 16. New ELF machine code: EM_IAMCU. 17. New predefined C/C++ pre-processor symbols: __iamcu and __iamcu__ Change-Id: I6a0c45ad22d8f710b6f37a041aaa2fc1bf0b1c39 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2015-06-20 11:37:23 +08:00
#endif
/*
* The GROUP_START() and GROUP_END() macros are used to define a group
* of sections located in one memory area, such as RAM, ROM, etc.
* The <where> parameter is the name of the memory area.
*/
#define GROUP_START(where)
#define GROUP_END(where)
/*
* The GROUP_LINK_IN() macro is located at the end of the section
* description and tells the linker that this section is located in
* the memory area specified by <where> argument.
*/
#define GROUP_LINK_IN(where) > where
x86 link: Specify ALIGN_WITH_INPUT for XIP data sections Binutils ld has an annoying misfeature (apparently a regression from a few years ago) that alignment directives (and alignment specifiers on symbols) apply only to the runtime addresses and not, apparently, to the load address region specified with the "AT>" syntax. The net result is that by default the LMA output ends up too small for the addresses generated in RAM. See here for some details: https://sourceware.org/ml/binutils/2013-06/msg00246.html https://sourceware.org/ml/binutils/2014-01/msg00350.html The required workaround/fix is that AFAICT any section which can have inherit a separate VMA vs. LMA from a previous section must specify an "ALIGN_WITH_INPUT" attribute. Otherwise the sections will get out of sync and the XIP data will be wrong at runtime. No, I don't know why this isn't the default behavior. A further complexity is that this feature only works as advertised when the section is declared with the "AT> region" syntax after the block and not "AT(address)" in the header. If you use the header syntax (with or without ALIGN_WITH_INPUT), ld appears to DOUBLE-apply padding and the LMA ends up to big. This is almost certainly a binutils bug, but it's trivial to work around (and the working syntax is actually cleaner) so we adjust the usage here. Note finally that this patch includes an effective reversion of commit d82e9dd9 ("x86: HACK force alignment for _k_task_list section"), which was an earlier workaround for what seems to be the same issue. Jira: ZEP-955 Change-Id: I2accd92901cb61fb546658b87d6752c1cd14de3a Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-23 05:20:56 +08:00
/*
* As GROUP_LINK_IN(), but takes a second argument indicating the
* memory region (e.g. "ROM") for the load address. Used for
* initialized data sections that on XIP platforms must be copied at
* startup.
*
* And, because output directives in GNU ld are "sticky", this must
* also be used on the first section *after* such an initialized data
* section, specifying the same memory region (e.g. "RAM") for both
* vregion and lregion.
*/
#ifdef CONFIG_XIP
#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion AT> lregion
#else
#define GROUP_DATA_LINK_IN(vregion, lregion) > vregion
#endif
/*
* The GROUP_FOLLOWS_AT() macro is located at the end of the section
* and indicates that the section does not specify an address at which
* it is to be loaded, but that it follows a section which did specify
* such an address
*/
#define GROUP_FOLLOWS_AT(where) AT > where
/*
* The SECTION_PROLOGUE() macro is used to define the beginning of a section.
* The <name> parameter is the name of the section, and the <option> parameter
* is to include any special options such as (NOLOAD). Page alignment has its
* own parameter since it needs abstraction across the different toolchains.
* If not required, the <options> and <align> parameters should be left blank.
*/
#define SECTION_PROLOGUE(name, options, align) name options : align
/*
x86 link: Specify ALIGN_WITH_INPUT for XIP data sections Binutils ld has an annoying misfeature (apparently a regression from a few years ago) that alignment directives (and alignment specifiers on symbols) apply only to the runtime addresses and not, apparently, to the load address region specified with the "AT>" syntax. The net result is that by default the LMA output ends up too small for the addresses generated in RAM. See here for some details: https://sourceware.org/ml/binutils/2013-06/msg00246.html https://sourceware.org/ml/binutils/2014-01/msg00350.html The required workaround/fix is that AFAICT any section which can have inherit a separate VMA vs. LMA from a previous section must specify an "ALIGN_WITH_INPUT" attribute. Otherwise the sections will get out of sync and the XIP data will be wrong at runtime. No, I don't know why this isn't the default behavior. A further complexity is that this feature only works as advertised when the section is declared with the "AT> region" syntax after the block and not "AT(address)" in the header. If you use the header syntax (with or without ALIGN_WITH_INPUT), ld appears to DOUBLE-apply padding and the LMA ends up to big. This is almost certainly a binutils bug, but it's trivial to work around (and the working syntax is actually cleaner) so we adjust the usage here. Note finally that this patch includes an effective reversion of commit d82e9dd9 ("x86: HACK force alignment for _k_task_list section"), which was an earlier workaround for what seems to be the same issue. Jira: ZEP-955 Change-Id: I2accd92901cb61fb546658b87d6752c1cd14de3a Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-23 05:20:56 +08:00
* As for SECTION_PROLOGUE(), except that this one must (!) be used
* for data sections which on XIP platforms will have differing
x86 link: Specify ALIGN_WITH_INPUT for XIP data sections Binutils ld has an annoying misfeature (apparently a regression from a few years ago) that alignment directives (and alignment specifiers on symbols) apply only to the runtime addresses and not, apparently, to the load address region specified with the "AT>" syntax. The net result is that by default the LMA output ends up too small for the addresses generated in RAM. See here for some details: https://sourceware.org/ml/binutils/2013-06/msg00246.html https://sourceware.org/ml/binutils/2014-01/msg00350.html The required workaround/fix is that AFAICT any section which can have inherit a separate VMA vs. LMA from a previous section must specify an "ALIGN_WITH_INPUT" attribute. Otherwise the sections will get out of sync and the XIP data will be wrong at runtime. No, I don't know why this isn't the default behavior. A further complexity is that this feature only works as advertised when the section is declared with the "AT> region" syntax after the block and not "AT(address)" in the header. If you use the header syntax (with or without ALIGN_WITH_INPUT), ld appears to DOUBLE-apply padding and the LMA ends up to big. This is almost certainly a binutils bug, but it's trivial to work around (and the working syntax is actually cleaner) so we adjust the usage here. Note finally that this patch includes an effective reversion of commit d82e9dd9 ("x86: HACK force alignment for _k_task_list section"), which was an earlier workaround for what seems to be the same issue. Jira: ZEP-955 Change-Id: I2accd92901cb61fb546658b87d6752c1cd14de3a Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-23 05:20:56 +08:00
* virtual and load addresses (i.e. they'll be copied into RAM at
* program startup). Such a section must (!) also use
* GROUP_LINK_IN_LMA to specify the correct output load address.
*/
x86 link: Specify ALIGN_WITH_INPUT for XIP data sections Binutils ld has an annoying misfeature (apparently a regression from a few years ago) that alignment directives (and alignment specifiers on symbols) apply only to the runtime addresses and not, apparently, to the load address region specified with the "AT>" syntax. The net result is that by default the LMA output ends up too small for the addresses generated in RAM. See here for some details: https://sourceware.org/ml/binutils/2013-06/msg00246.html https://sourceware.org/ml/binutils/2014-01/msg00350.html The required workaround/fix is that AFAICT any section which can have inherit a separate VMA vs. LMA from a previous section must specify an "ALIGN_WITH_INPUT" attribute. Otherwise the sections will get out of sync and the XIP data will be wrong at runtime. No, I don't know why this isn't the default behavior. A further complexity is that this feature only works as advertised when the section is declared with the "AT> region" syntax after the block and not "AT(address)" in the header. If you use the header syntax (with or without ALIGN_WITH_INPUT), ld appears to DOUBLE-apply padding and the LMA ends up to big. This is almost certainly a binutils bug, but it's trivial to work around (and the working syntax is actually cleaner) so we adjust the usage here. Note finally that this patch includes an effective reversion of commit d82e9dd9 ("x86: HACK force alignment for _k_task_list section"), which was an earlier workaround for what seems to be the same issue. Jira: ZEP-955 Change-Id: I2accd92901cb61fb546658b87d6752c1cd14de3a Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-23 05:20:56 +08:00
#ifdef CONFIG_XIP
#define SECTION_DATA_PROLOGUE(name, options, align) \
name options : ALIGN_WITH_INPUT align
#else
#define SECTION_DATA_PROLOGUE(name, options, align) name options : align
#endif
#define SORT_BY_NAME(x) SORT(x)
#define OPTIONAL
#define COMMON_SYMBOLS *(COMMON)
#endif /* !__LINKER_TOOL_GCC_H */