public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Georg-Johann Lay <avr@gjlay.de>
To: gcc-patches@gcc.gnu.org
Subject: [patch,avr,applied] Addendum to target/112944: Initialize FLMAP as needed
Date: Mon, 12 Feb 2024 11:50:55 +0100	[thread overview]
Message-ID: <a6d864f8-bbd4-4941-a74d-8b661d6e70fa@gjlay.de> (raw)

This code will link against parts of the startup code
from AVR-LibC when it is needed to init bit-field FLMAP.

Johann

--

AVR: target/112944 - Addendum: Link code to initialize NVMCTRL_CTRLB.FLMAP

For devices that see a part for the flash memory in the RAM address space,
bit-field NVMCTRL_CTRLB.FLMAP must match the value of symbol __flmap.
This is achieved by dragging in startup code from lib<mcu>.a.
The mechanism is the same like for libgcc's __do_copy_data and 
__do_clear_bss.
The code is implemented in AVR-LibC #931 and can be dragged by referencing
__do_flmap_init.

In addition to setting FLMAP, that code also sets bit FLMAPLOCK provided
symbol __flmap_lock has a non-zero value.  This protects FLMAP from future
changes.

When the __do_flmap_init code is not wanted, the symbol can be satisfied by
linking with  -Wl,--defsym,__do_flmap_init=0

gcc/
	PR target/112944
	* config/avr/gen-avr-mmcu-specs.cc (print_mcu) [have_flmap]:
	<*link_rodata_in_ram>: Spec undefs symbol __do_flmap_init
	when not linked with -mrodata-in-ram.

diff --git a/gcc/config/avr/gen-avr-mmcu-specs.cc 
b/gcc/config/avr/gen-avr-mmcu-specs.cc
index ea69145d404..bb94bea12b0 100644
--- a/gcc/config/avr/gen-avr-mmcu-specs.cc
+++ b/gcc/config/avr/gen-avr-mmcu-specs.cc
@@ -369,7 +369,10 @@ print_mcu (const avr_mcu_t *mcu, const McuInfo &mi)
      }

    // -m[no-]rodata-in-ram affects linking.  Sanity check its usage.
-  fprintf (f, "*link_rodata_in_ram:\n\t%%(check_rodata_in_ram)\n\n");
+  fprintf (f, "*link_rodata_in_ram:\n\t%%(check_rodata_in_ram)");
+  if (mi.is_device && mi.have_flmap)
+    fprintf (f, " %%{!mrodata-in-ram:-u __do_flmap_init}");
+  fprintf (f, "\n\n");

    // Specs known to GCC.


                 reply	other threads:[~2024-02-12 10:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6d864f8-bbd4-4941-a74d-8b661d6e70fa@gjlay.de \
    --to=avr@gjlay.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).