From 48448055fb70862ff3914f8a714ff5c4128e6ced Mon Sep 17 00:00:00 2001 From: Georg-Johann Lay Date: Thu, 11 Jan 2024 22:11:25 +0100 Subject: AVR: Support .rodata in Flash for AVR64* and AVR128* Devices. These devices see a 32 KiB block of their program memory (flash) in the RAM address space. This can be used to support .rodata in flash provided Binutils support PR31124 (Add new emulations which locate .rodata in flash). This patch does the following: * configure checks availability of Binutils PR31124. * Add new command line options -mrodata-in-ram and -mflmap. While -flmap is for internal usage (communicate hardware properties from device-specs to the compiler proper), -mrodata-in-ram is a user space option that allows to return to the current rodata-in-ram layout. * Adjust gen-avr-mmcu-specs.cc so that device-specs are generated that sanity check options, and that translate -m[no-]rodata-in-ram to its emulation. * Objects in .rodata don't drag __do_copy_data. * Document new options and built-in macros. PR target/112944 gcc/ * configure.ac [target=avr]: Check availability of emulations avrxmega2_flmap and avrxmega4_flmap, resulting in new config vars HAVE_LD_AVR_AVRXMEGA2_FLMAP and HAVE_LD_AVR_AVRXMEGA4_FLMAP. * configure: Regenerate. * config.in: Regenerate. * doc/invoke.texi (AVR Options): Document -mflmap, -mrodata-in-ram, __AVR_HAVE_FLMAP__, __AVR_RODATA_IN_RAM__. * config/avr/avr.opt (-mflmap, -mrodata-in-ram): New options. * config/avr/avr-arch.h (enum avr_device_specific_features): Add AVR_ISA_FLMAP. * config/avr/avr-mcus.def (AVR_MCU) [avr64*, avr128*]: Set isa flag AVR_ISA_FLMAP. * config/avr/avr.cc (avr_arch_index, avr_has_rodata_p): New vars. (avr_set_core_architecture): Set avr_arch_index. (have_avrxmega2_flmap, have_avrxmega4_flmap) (have_avrxmega3_rodata_in_flash): Set new static const bool according to configure results. (avr_rodata_in_flash_p): New function using them. (avr_asm_init_sections): Let readonly_data_section->unnamed.callback track avr_need_copy_data_p only if not avr_rodata_in_flash_p(). (avr_asm_named_section): Track avr_has_rodata_p. (avr_file_end): Emit __do_copy_data also when avr_has_rodata_p and not avr_rodata_in_flash_p (). * config/avr/specs.h (CC1_SPEC): Add %(cc1_rodata_in_ram). (LINK_SPEC): Add %(link_rodata_in_ram). (LINK_ARCH_SPEC): Remove. * config/avr/gen-avr-mmcu-specs.cc (have_avrxmega3_rodata_in_flash) (have_avrxmega2_flmap, have_avrxmega4_flmap): Set new static const bool according to configure results. (diagnose_mrodata_in_ram): New function. (print_mcu): Generate specs with the following changes: <*cc1_misc, *asm_misc, *link_misc>: New specs so that we don't need to extend avr/specs.h each time we add a new bell or whistle. <*cc1_rodata_in_ram, *link_rodata_in_ram>: New specs to diagnose -m[no-]rodata-in-ram. <*cpp_rodata_in_ram>: New. Does -D__AVR_RODATA_IN_RAM__=0/1. <*cpp_mcu>: Add -D__AVR_AVR_FLMAP__ if it applies. <*cpp>: Add %(cpp_rodata_in_ram). <*link_arch>: Use emulation avrxmega2_flmap, avrxmega4_flmap as requested. <*self_spec>: Add -mflmap or %/ld/scripttempl/avr.sc. */ enum avr_device_specific_features { @@ -175,9 +203,12 @@ enum avr_device_specific_features AVR_SHORT_SP = 0x2, /* Stack Pointer has 8 bits width. */ AVR_ERRATA_SKIP = 0x4, /* device has a core erratum. */ AVR_ISA_LDS = 0x8, /* whether LDS / STS is valid for all data in static - storage. Only useful for reduced Tiny. */ - AVR_ISA_RCALL = 0x10 /* Use RJMP / RCALL even though JMP / CALL - are available (-mshort-calls). */ + storage. Only useful for reduced Tiny. */ + AVR_ISA_RCALL = 0x10, /* Use RJMP / RCALL even though JMP / CALL + are available (-mshort-calls). */ + AVR_ISA_FLMAP = 0x20 /* Has NVMCTRL_CTRLB.FLMAP to select which 32 KiB + block of program memory is visible in the RAM + address space. */ }; /* Map architecture to its texinfo string. */ diff --git a/gcc/config/avr/avr-mcus.def b/gcc/config/avr/avr-mcus.def index 87b5924..9fb2377 100644 --- a/gcc/config/avr/avr-mcus.def +++ b/gcc/config/avr/avr-mcus.def @@ -306,21 +306,21 @@ AVR_MCU ("atxmega16c4", ARCH_AVRXMEGA2, AVR_ISA_RMW, "__AVR_ATxmega16C4__" AVR_MCU ("atxmega32a4u", ARCH_AVRXMEGA2, AVR_ISA_RMW, "__AVR_ATxmega32A4U__", 0x2000, 0x0, 0x9000, 0) AVR_MCU ("atxmega32c4", ARCH_AVRXMEGA2, AVR_ISA_RMW, "__AVR_ATxmega32C4__", 0x2000, 0x0, 0x9000, 0) AVR_MCU ("atxmega32e5", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_ATxmega32E5__", 0x2000, 0x0, 0x9000, 0) -AVR_MCU ("avr64da28", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DA28__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64da32", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DA32__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64da48", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DA48__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64da64", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DA64__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64db28", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DB28__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64db32", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DB32__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64db48", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DB48__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64db64", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DB64__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64dd14", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DD14__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64dd20", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DD20__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64dd28", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DD28__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64dd32", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64DD32__", 0x6000, 0x0, 0x10000, 0) -AVR_MCU ("avr64ea28", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64EA28__", 0x6800, 0x0, 0x10000, 0) -AVR_MCU ("avr64ea32", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64EA32__", 0x6800, 0x0, 0x10000, 0) -AVR_MCU ("avr64ea48", ARCH_AVRXMEGA2, AVR_ISA_NONE, "__AVR_AVR64EA48__", 0x6800, 0x0, 0x10000, 0) +AVR_MCU ("avr64da28", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DA28__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64da32", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DA32__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64da48", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DA48__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64da64", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DA64__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64db28", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DB28__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64db32", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DB32__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64db48", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DB48__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64db64", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DB64__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64dd14", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DD14__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64dd20", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DD20__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64dd28", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DD28__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64dd32", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64DD32__", 0x6000, 0x0, 0x10000, 0) +AVR_MCU ("avr64ea28", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64EA28__", 0x6800, 0x0, 0x10000, 0) +AVR_MCU ("avr64ea32", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64EA32__", 0x6800, 0x0, 0x10000, 0) +AVR_MCU ("avr64ea48", ARCH_AVRXMEGA2, AVR_ISA_FLMAP, "__AVR_AVR64EA48__", 0x6800, 0x0, 0x10000, 0) /* Xmega, Flash + RAM < 64K, flash visible in RAM address space */ AVR_MCU ("avrxmega3", ARCH_AVRXMEGA3, AVR_ISA_NONE, NULL, 0x3f00, 0x0, 0x8000, 0) AVR_MCU ("attiny202", ARCH_AVRXMEGA3, AVR_ISA_RCALL, "__AVR_ATtiny202__", 0x3f80, 0x0, 0x800, 0x8000) @@ -393,14 +393,14 @@ AVR_MCU ("atxmega64b1", ARCH_AVRXMEGA4, AVR_ISA_RMW, "__AVR_ATxmega64B1__" AVR_MCU ("atxmega64b3", ARCH_AVRXMEGA4, AVR_ISA_RMW, "__AVR_ATxmega64B3__", 0x2000, 0x0, 0x11000, 0) AVR_MCU ("atxmega64c3", ARCH_AVRXMEGA4, AVR_ISA_RMW, "__AVR_ATxmega64C3__", 0x2000, 0x0, 0x11000, 0) AVR_MCU ("atxmega64d4", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_ATxmega64D4__", 0x2000, 0x0, 0x11000, 0) -AVR_MCU ("avr128da28", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DA28__", 0x4000, 0x0, 0x20000, 0) -AVR_MCU ("avr128da32", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DA32__", 0x4000, 0x0, 0x20000, 0) -AVR_MCU ("avr128da48", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DA48__", 0x4000, 0x0, 0x20000, 0) -AVR_MCU ("avr128da64", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DA64__", 0x4000, 0x0, 0x20000, 0) -AVR_MCU ("avr128db28", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DB28__", 0x4000, 0x0, 0x20000, 0) -AVR_MCU ("avr128db32", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DB32__", 0x4000, 0x0, 0x20000, 0) -AVR_MCU ("avr128db48", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DB48__", 0x4000, 0x0, 0x20000, 0) -AVR_MCU ("avr128db64", ARCH_AVRXMEGA4, AVR_ISA_NONE, "__AVR_AVR128DB64__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128da28", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DA28__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128da32", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DA32__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128da48", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DA48__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128da64", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DA64__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128db28", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DB28__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128db32", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DB32__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128db48", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DB48__", 0x4000, 0x0, 0x20000, 0) +AVR_MCU ("avr128db64", ARCH_AVRXMEGA4, AVR_ISA_FLMAP, "__AVR_AVR128DB64__", 0x4000, 0x0, 0x20000, 0) /* Xmega, 64K < Flash <= 128K, RAM > 64K */ AVR_MCU ("avrxmega5", ARCH_AVRXMEGA5, AVR_ISA_NONE, NULL, 0x2000, 0x0, 0x11000, 0) AVR_MCU ("atxmega64a1", ARCH_AVRXMEGA5, AVR_ISA_NONE, "__AVR_ATxmega64A1__", 0x2000, 0x0, 0x11000, 0) diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc index 4bc3cf9..d77e1aad 100644 --- a/gcc/config/avr/avr.cc +++ b/gcc/config/avr/avr.cc @@ -220,6 +220,7 @@ static GTY(()) rtx xstring_e; /* Current architecture. */ const avr_arch_t *avr_arch; +enum avr_arch_id avr_arch_index; /* Unnamed sections associated to __attribute__((progmem)) aka. PROGMEM or to address space __flash* or __memx. Only used as singletons inside @@ -229,9 +230,10 @@ static GTY(()) section *progmem_section[ADDR_SPACE_COUNT]; /* Condition for insns/expanders from avr-dimode.md. */ bool avr_have_dimode = true; -/* To track if code will use .bss and/or .data. */ +/* To track if code will use .bss, .data, .rodata. */ bool avr_need_clear_bss_p = false; bool avr_need_copy_data_p = false; +bool avr_has_rodata_p = false; /* Transform UP into lowercase and write the result to LO. @@ -1059,6 +1061,7 @@ avr_set_core_architecture (void) && mcu->macro == NULL) { avr_arch = &avr_arch_types[mcu->arch_id]; + avr_arch_index = mcu->arch_id; if (avr_n_flash < 0) avr_n_flash = 1 + (mcu->flash_size - 1) / 0x10000; @@ -10758,6 +10761,49 @@ avr_insert_attributes (tree node, tree *attributes) } } +#ifdef HAVE_LD_AVR_AVRXMEGA2_FLMAP +static const bool have_avrxmega2_flmap = true; +#else +static const bool have_avrxmega2_flmap = false; +#endif + +#ifdef HAVE_LD_AVR_AVRXMEGA4_FLMAP +static const bool have_avrxmega4_flmap = true; +#else +static const bool have_avrxmega4_flmap = false; +#endif + +#ifdef HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH +static const bool have_avrxmega3_rodata_in_flash = true; +#else +static const bool have_avrxmega3_rodata_in_flash = false; +#endif + + +static bool +avr_rodata_in_flash_p () +{ + switch (avr_arch_index) + { + default: + break; + + case ARCH_AVRTINY: + return true; + + case ARCH_AVRXMEGA3: + return have_avrxmega3_rodata_in_flash; + + case ARCH_AVRXMEGA2: + return avr_flmap && have_avrxmega2_flmap && avr_rodata_in_ram != 1; + + case ARCH_AVRXMEGA4: + return avr_flmap && have_avrxmega4_flmap && avr_rodata_in_ram != 1; + } + + return false; +} + /* Implement `ASM_OUTPUT_ALIGNED_DECL_LOCAL'. */ /* Implement `ASM_OUTPUT_ALIGNED_DECL_COMMON'. */ @@ -10890,13 +10936,11 @@ avr_output_addr_attrib (tree decl, const char *name, static void avr_asm_init_sections (void) { - /* Override section callbacks to keep track of `avr_need_clear_bss_p' - resp. `avr_need_copy_data_p'. If flash is not mapped to RAM then - we have also to track .rodata because it is located in RAM then. */ + /* Override section callbacks to keep track of `avr_need_clear_bss_p', + `avr_need_copy_data_p' and `avr_has_rodata_p'. + Track also .rodata for the case when .rodata is located in RAM. */ -#if defined HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH - if (avr_arch->flash_pm_offset == 0) -#endif + if (! avr_rodata_in_flash_p ()) readonly_data_section->unnamed.callback = avr_output_data_section_asm_op; data_section->unnamed.callback = avr_output_data_section_asm_op; bss_section->unnamed.callback = avr_output_bss_section_asm_op; @@ -10937,13 +10981,9 @@ avr_asm_named_section (const char *name, unsigned int flags, tree decl) avr_need_copy_data_p = (startswith (name, ".data") || startswith (name, ".gnu.linkonce.d")); - if (!avr_need_copy_data_p -#if defined HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH - && avr_arch->flash_pm_offset == 0 -#endif - ) - avr_need_copy_data_p = (startswith (name, ".rodata") - || startswith (name, ".gnu.linkonce.r")); + if (!avr_has_rodata_p) + avr_has_rodata_p = (startswith (name, ".rodata") + || startswith (name, ".gnu.linkonce.r")); if (!avr_need_clear_bss_p) avr_need_clear_bss_p = startswith (name, ".bss"); @@ -11273,7 +11313,8 @@ avr_file_end (void) linking in the initialization code from libgcc if resp. sections are empty, see PR18145. */ - if (avr_need_copy_data_p) + if (avr_need_copy_data_p + || (avr_has_rodata_p && ! avr_rodata_in_flash_p ())) fputs (".global __do_copy_data\n", asm_out_file); if (avr_need_clear_bss_p) diff --git a/gcc/config/avr/avr.opt b/gcc/config/avr/avr.opt index e757308..ee0b406 100644 --- a/gcc/config/avr/avr.opt +++ b/gcc/config/avr/avr.opt @@ -94,6 +94,14 @@ mstrict-X Target Var(avr_strict_X) Init(0) When accessing RAM, use X as imposed by the hardware, i.e. just use pre-decrement, post-increment and indirect addressing with the X register. Without this option, the compiler may assume that there is an addressing mode X+const similar to Y+const and Z+const and emit instructions to emulate such an addressing mode for X. +mflmap +Target Var(avr_flmap) Init(0) +The device has the bitfield NVMCTRL_CTRLB.FLMAP. This option is used internally. + +mrodata-in-ram +Target Var(avr_rodata_in_ram) Init(-1) +The device has the .rodata section located in the RAM area. + ;; For rationale behind -msp8 see explanation in avr.h. msp8 Target RejectNegative Var(avr_sp8) Init(0) diff --git a/gcc/config/avr/gen-avr-mmcu-specs.cc b/gcc/config/avr/gen-avr-mmcu-specs.cc index 89f8680..eb9ab88 100644 --- a/gcc/config/avr/gen-avr-mmcu-specs.cc +++ b/gcc/config/avr/gen-avr-mmcu-specs.cc @@ -50,6 +50,8 @@ #define SPECFILE_USAGE_URL \ "https://gcc.gnu.org/gcc-5/changes.html" +#define WIKI_URL \ + "https://gcc.gnu.org/wiki/avr-gcc#spec-files" static const char header[] = "#\n" @@ -68,9 +70,13 @@ static const char header[] = static const char help_copy_paste[] = "# If you intend to use an existing device specs file as a starting point\n" - "# for a new device spec file, make sure you are copying from a specs\n" - "# file for a device from the same core architecture and SP width.\n" - "# See <" SPECFILE_USAGE_URL "> for a description\n" + "# for a new device spec file, make sure you are copying from a specs file\n" + "# for a device from the same or compatible:\n" + "# compiler version, compiler vendor, core architecture, SP width,\n" + "# short-calls and FLMAP.\n" + "# Otherwise, errors and wrong or sub-optimal code may likely occur.\n" + "# See <" WIKI_URL ">\n" + "# and <" SPECFILE_USAGE_URL "> for a description\n" "# of how to use such own spec files.\n"; #if defined (WITH_AVRLIBC) @@ -103,6 +109,60 @@ static const char help_dev_lib_name[] = "\n"; #endif // WITH_AVRLIBC + +#ifdef HAVE_LD_AVR_AVRXMEGA2_FLMAP +static const bool have_avrxmega2_flmap = true; +#else +static const bool have_avrxmega2_flmap = false; +#endif + +#ifdef HAVE_LD_AVR_AVRXMEGA4_FLMAP +static const bool have_avrxmega4_flmap = true; +#else +static const bool have_avrxmega4_flmap = false; +#endif + +#ifdef HAVE_LD_AVR_AVRXMEGA3_RODATA_IN_FLASH +static const bool have_avrxmega3_rodata_in_flash = true; +#else +static const bool have_avrxmega3_rodata_in_flash = false; +#endif + + +static void +diagnose_mrodata_in_ram (FILE *f, const char *spec, const avr_mcu_t *mcu) +{ + enum avr_arch_id arch_id = mcu->arch_id; + const avr_arch_t *arch = &avr_arch_types[arch_id]; + const bool is_arch = mcu->macro == NULL; + const bool flmap = (mcu->dev_attribute & AVR_ISA_FLMAP); + const bool have_flmap2 = have_avrxmega2_flmap && arch_id == ARCH_AVRXMEGA2; + const bool have_flmap4 = have_avrxmega4_flmap && arch_id == ARCH_AVRXMEGA4; + const bool have_flmap = flmap && (have_flmap2 || have_flmap4); + + const bool rodata_in_flash = (arch_id == ARCH_AVRTINY + || (arch_id == ARCH_AVRXMEGA3 + && have_avrxmega3_rodata_in_flash)); + fprintf (f, "%s:\n", spec); + if (rodata_in_flash && is_arch) + fprintf (f, "\t%%{mrodata-in-ram: %%e-mrodata-in-ram not supported" + " for %s}", mcu->name); + else if (rodata_in_flash) + fprintf (f, "\t%%{mrodata-in-ram: %%e-mrodata-in-ram not supported" + " for %s (arch=%s)}", mcu->name, arch->name); + else if (is_arch) + { + if (! have_flmap2 && ! have_flmap4) + fprintf (f, "\t%%{mno-rodata-in-ram: %%e-mno-rodata-in-ram not" + " supported for %s}", mcu->name); + } + else if (! have_flmap) + fprintf (f, "\t%%{mno-rodata-in-ram: %%e-mno-rodata-in-ram not supported" + " for %s (arch=%s)}", mcu->name, arch->name); + fprintf (f, "\n\n"); +} + + static void print_mcu (const avr_mcu_t *mcu) { @@ -130,6 +190,7 @@ print_mcu (const avr_mcu_t *mcu) bool rmw = (mcu->dev_attribute & AVR_ISA_RMW) != 0; bool sp8 = (mcu->dev_attribute & AVR_SHORT_SP) != 0; bool rcall = (mcu->dev_attribute & AVR_ISA_RCALL); + bool flmap = (mcu->dev_attribute & AVR_ISA_FLMAP); bool is_arch = mcu->macro == NULL; bool is_device = ! is_arch; int flash_pm_offset = 0; @@ -166,13 +227,24 @@ print_mcu (const avr_mcu_t *mcu) rcall_spec = rcall ? "-mshort-calls" : "%name); else - fprintf (f, "device %s (core %s, %d-bit SP%s)\n", mcu->name, - arch->name, sp8 ? 8 : 16, rcall ? ", short-calls" : ""); + fprintf (f, "device %s (core %s, %d-bit SP%s%s)\n", mcu->name, + arch->name, sp8 ? 8 : 16, rcall ? ", short-calls" : "", + have_flmap ? ", FLMAP" : ""); fprintf (f, "%s\n", header); if (is_device) @@ -212,6 +284,11 @@ print_mcu (const avr_mcu_t *mcu) ? "\t%{!mno-absdata: -mabsdata}" : "\t%{mabsdata}"); + // -m[no-]rodata-in-ram basically affects linking, but sanity-check early. + diagnose_mrodata_in_ram (f, "*cc1_rodata_in_ram", mcu); + + fprintf (f, "*cc1_misc:\n\t%%(cc1_rodata_in_ram)\n\n"); + // avr-gcc specific specs for assembling / the assembler. fprintf (f, "*asm_arch:\n\t-mmcu=%s\n\n", arch->name); @@ -235,6 +312,8 @@ print_mcu (const avr_mcu_t *mcu) ? "\t%{mno-skip-bug}" : "\t%{!mskip-bug: -mno-skip-bug}"); + fprintf (f, "*asm_misc:\n" /* empty */ "\n\n"); + // avr-specific specs for linking / the linker. int wrap_k = @@ -253,7 +332,10 @@ print_mcu (const avr_mcu_t *mcu) fprintf (f, "*link_relax:\n\t%s\n\n", LINK_RELAX_SPEC); - fprintf (f, "*link_arch:\n\t%s", LINK_ARCH_SPEC); + // -m[no-]rodata-in-ram affects linking. Sanity check its usage. + diagnose_mrodata_in_ram (f, "*link_rodata_in_ram", mcu); + + fprintf (f, "*link_arch:\n\t%s", link_arch_spec); if (is_device && flash_pm_offset) fprintf (f, " --defsym=__RODATA_PM_OFFSET__=0x%x", flash_pm_offset); @@ -274,12 +356,15 @@ print_mcu (const avr_mcu_t *mcu) fprintf (f, "\n\n"); } + fprintf (f, "*link_misc:\n\t%%(link_rodata_in_ram)\n\n"); + // Specs known to GCC. if (is_device) { fprintf (f, "*self_spec:\n"); fprintf (f, "\t%%name); + fprintf (f, "%s ", flmap_spec); fprintf (f, "%s ", rcall_spec); fprintf (f, "%s\n\n", sp8_spec); @@ -298,10 +383,26 @@ print_mcu (const avr_mcu_t *mcu) fprintf (f, " -U__AVR_PM_BASE_ADDRESS__"); fprintf (f, " -D__AVR_PM_BASE_ADDRESS__=0x%x", flash_pm_offset); } + if (have_flmap) + fprintf (f, " -D__AVR_HAVE_FLMAP__"); + + fprintf (f, "\n\n"); // *cpp_mcu + + const bool rodata_in_flash = (arch_id == ARCH_AVRTINY + || (arch_id == ARCH_AVRXMEGA3 + && have_avrxmega3_rodata_in_flash)); + fprintf (f, "*cpp_rodata_in_ram:\n\t-D__AVR_RODATA_IN_RAM__="); + if (rodata_in_flash) + fprintf (f, "0"); + else if (! have_flmap) + fprintf (f, "1"); + else + fprintf (f, "%%{!mrodata-in-ram:%%{!mno-rodata-in-ram:0}}" + "%%{mrodata-in-ram:1}" "%%{mno-rodata-in-ram:0}"); fprintf (f, "\n\n"); fprintf (f, "*cpp:\n"); - fprintf (f, "\t%%(cpp_mcu)"); + fprintf (f, "\t%%(cpp_mcu) %%(cpp_rodata_in_ram)"); #if defined (WITH_AVRLIBC) fprintf (f, " %%(cpp_avrlibc)"); #endif // WITH_AVRLIBC diff --git a/gcc/config/avr/specs.h b/gcc/config/avr/specs.h index 433231f..5744020 100644 --- a/gcc/config/avr/specs.h +++ b/gcc/config/avr/specs.h @@ -35,7 +35,8 @@ along with GCC; see the file COPYING3. If not see "%(cc1_n_flash) " \ "%(cc1_errata_skip) " \ "%(cc1_rmw) " \ - "%(cc1_absdata) " + "%(cc1_absdata) " \ + "%(cc1_misc) " #undef CC1PLUS_SPEC #define CC1PLUS_SPEC \ @@ -53,10 +54,8 @@ along with GCC; see the file COPYING3. If not see "%(asm_relax) " \ "%(asm_rmw) " \ "%(asm_gccisr) " \ - "%(asm_errata_skip) " - -#define LINK_ARCH_SPEC \ - "%{mmcu=*:-m%*} " + "%(asm_errata_skip) " \ + "%(asm_misc) " #define LINK_RELAX_SPEC \ "%{mrelax:--relax} " @@ -68,6 +67,7 @@ along with GCC; see the file COPYING3. If not see "%(link_text_start) " \ "%(link_relax) " \ "%(link_pmem_wrap) " \ + "%(link_misc) " \ "%{shared:%eshared is not supported} " #undef LIB_SPEC -- cgit v1.1