From patchwork Sat Dec 9 17:37:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 81792 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39FC23858430 for ; Sat, 9 Dec 2023 17:37:44 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.163]) by sourceware.org (Postfix) with ESMTPS id 868413858CD1 for ; Sat, 9 Dec 2023 17:37:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 868413858CD1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 868413858CD1 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=81.169.146.163 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1702143447; cv=pass; b=mBbykVuEziOA3vRE4DC/rZQcVPQp8ukB3lbsR8IAgrlsuKhhyhKLVbYfvve3LV9Q+PTlFdFGBCypCAmNtE/abkjFc6uc4p2/vfbxc5c/taimlrrJSalJZBaCD7qZas7TMcX54bk2+qEg1DPDRa/D7Im4WhRtZ7a4gEUPOs3wsQw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1702143447; c=relaxed/simple; bh=chb8nx2HM8N8q9uPAxLb1d2mMGMAV+m7VelVpbz0lBQ=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version:To: From:Subject; b=FpvJ1mrQFtAOmgYGtCcAPyLdyL/9UYAJBVRVG8nZcke4FF7BQ34UjluJaDsJXF9FYEP+n6TaVgkDix7v49f6LulW+3lpSbjWAsqx9kGdDFcZdjhKqh68+fJHh+uVDaYzpVQuL+nb6O0hLO547jlwI3iWNL1iCWFoVlvrsB48Qik= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1702143442; cv=none; d=strato.com; s=strato-dkim-0002; b=AOQUrkaRqbWNonfeZUVcz8iwgrZU3s8M1CGTnoaWCvfQY4vtm0lcShOBB9ryM1jLWN jIAEyX9jQUQEJx5FQk8bNRlEgBWl7jU6u1EILmszTcd7fm4rWVVFT8LFoLEGCeXghVc3 hEaj+VJPxusYY8TVvcDJmuqH0/Kl0xb70+ALhfh4rW8OtZ52v7mJg/QkxrbMWnB06e8J DAFsGBJrmnNhEqffoYEMKsh+jX+kGyGa4cFtlANDfmKUbgT6xQf3+YaBJtU9htz5Bwda 2/wzuD51fRXJIauWB+ayuFP0QrKiV2l6A7oZu8yz9kaRjP+Y8lt5tsAqyAa9NQD3Qqi0 h1rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1702143442; s=strato-dkim-0002; d=strato.com; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=SPRV8XENwrfEEHo8SSmIyR8n/Aa7aLpTqff2kSzxAtE=; b=XThb+Z8OySzJc8gFMnd2PBCGBSghfnGqRpu8FkicahoNYImmUeXzqrDmbrqD2ScBGl Cf3PTv4uadoYSsrzzP35vv6enLx+nkcxcC09IMWjtDwelWx/BtBu9PrkTQryOiOdlpke e5oZ5Xj0ObDzG7pS3ZsA3coTUsfh2MyJ0gE57fmq7fZoyzO4rP7TBTx6M0Eb2T8nofy7 t94VzrFoU+9y3kyIOnxjQ0IX9WaUNSN5JvHLqQB96XCm561h+nYjzs8sA1cF2VANCcF3 gIxcgzKX45ZJYgE4ndm4/iwWs1hqVn0uboyutteyaJO4EmUpcDVd4umsdcmOgL44ei8N dHtg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1702143442; s=strato-dkim-0002; d=gjlay.de; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=SPRV8XENwrfEEHo8SSmIyR8n/Aa7aLpTqff2kSzxAtE=; b=W+8eiXfX8nS+VD/4LyMr/NJBaBz+xhXbHNne68PX7kdP6csfhryltsaCeIHLUl37AC ADuCDkzOZ11ykJ3hkJKX326meHSzHBF7uLUHBCWtTiXEGRDolijKaXfClQ9KE7lJEclK LISapRlrsSqMiV2V7h7l2A24i6FFLGTgwNZ/6Pd7DKidcuPibXuKqYA0KHBgURHdyrIE zvlVAOuE4NzRaNvD159F//uGu7ciYij10gHA7XbK57qKKXAeb2i5J+q/9m/viukHIQKD s13kXqkcu1zHnQOJnHeQ31GAUz+rQIrkdhbmuVSIU2Jx0IfKOkDtg8UFHGR0UBBCcVLk 3BPw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1702143442; s=strato-dkim-0003; d=gjlay.de; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=SPRV8XENwrfEEHo8SSmIyR8n/Aa7aLpTqff2kSzxAtE=; b=KKlgn/9+d1hPHlOiNdmtO4KcenZEBSOlNDlIR6L/njcZSW1i3r16QAfo/GpdznYPdg /rfr8kDLJVAwWjKFL3Ag== X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkSjsSjo3O/MHXSz1aalw==" Received: from [192.168.2.102] by smtp.strato.de (RZmta 49.10.0 DYNA|AUTH) with ESMTPSA id Lf3d8bzB9HbMRmN (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Sat, 9 Dec 2023 18:37:22 +0100 (CET) Message-ID: <959585a4-d3b7-499a-ad6a-3a3ae7f805cc@gjlay.de> Date: Sat, 9 Dec 2023 18:37:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: binutils@sourceware.org From: Georg-Johann Lay Subject: [patch, avr] PR31124: Support rodata in flash for more AVR devices X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org This patch adds two new emulations in order to support rodata in flash for more devices. Purpose of the new emulations is to provide linker descriptions for rodata in flash. Apart from that, the behaviour is the same like for the existing emulation. I added comments to avr.sc which explain the new symbols. If anything is unclear, then I am happy to improve the explanations. What I am unsure about is the ABSOLUTE in avrxmega2_flmap.x: .rodata __rodata_start : AT (__rodata_load_start) { ... __rodata_end = ABSOLUTE(.) ; } > rodata No other places in the ld scripts use ABSOLUTE, e.g. for __data_end in: .data : { ... PROVIDE (__data_end = .) ; } > data AT> text Johan --- PR31124: AVR: Add emulations to support rodata in flash for AVR64* and AVR128* devices. AVR devices from the AVR64* and AVR128* families support that rodata can be located in in program memory. This patch adds new emulations eavrxmega2_flmap and eavrxmega4_flmap. The purpose of the new emulations is to provide new linker description files which facilitate rodata in flash. Apart from a different linker script, the new emulation behave exactly the same like the existing avrxmega2 and avrxmega4. For a detailed explanation of the new symbols and their purposes, cf. the comments in ld/scripttempl/avr.sc. ld/ PR 31124 * configure.tgt (targ_extra_emuls) [targ=avr-*-*]: Add eavrxmega2_flmap, eavrxmega4_flmap. * Makefile.am (ALL_EMULATION_SOURCES): Add eavrxmega2_flmap.c, eavrxmega4_flmap.c. * Makefile.in: Regenerate. * emulparams/avrxmega2.sh (MAYBE_FLMAP): Set to 1. * emulparams/avrxmega4.sh (MAYBE_FLMAP): Set to 1. * emulparams/avrxmega2_flmap.sh: New file. * emulparams/avrxmega4_flmap.sh: New file. * scripttempl/avr.sc: Adjust comments. [MAYBE_FLMAP]: Define symbols: __do_init_flmap, __flmap, __flmap_lsl4, __flmap_init_label. [HAVE_FLMAP]: Add MEMORY region rodata. Add output section .rodata. Define symbols: ___RODATA_VMA__, __RODATA_ORIGIN__, __RODATA_LDS_OFFSET__, __RODATA_REGION_LENGTH__, __RODATA_FLASH_START__, __rodata_start, __rodata_end, __rodata_load_start, __rodata_load_end. diff --git a/ld/Makefile.am b/ld/Makefile.am index 9664d4c7709..5769f3cee87 100644 --- a/ld/Makefile.am +++ b/ld/Makefile.am @@ -198,8 +198,10 @@ ALL_EMULATION_SOURCES = \ eavrtiny.c \ eavrxmega1.c \ eavrxmega2.c \ + eavrxmega2_flmap.c \ eavrxmega3.c \ eavrxmega4.c \ + eavrxmega4_flmap.c \ eavrxmega5.c \ eavrxmega6.c \ eavrxmega7.c \ diff --git a/ld/Makefile.in b/ld/Makefile.in index d025227971a..41b0d8cccf8 100644 --- a/ld/Makefile.in +++ b/ld/Makefile.in @@ -709,8 +709,10 @@ ALL_EMULATION_SOURCES = \ eavrtiny.c \ eavrxmega1.c \ eavrxmega2.c \ + eavrxmega2_flmap.c \ eavrxmega3.c \ eavrxmega4.c \ + eavrxmega4_flmap.c \ eavrxmega5.c \ eavrxmega6.c \ eavrxmega7.c \ @@ -1331,8 +1333,10 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrtiny.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega1.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega2.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega2_flmap.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega3.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega4.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega4_flmap.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega5.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega6.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eavrxmega7.Po@am__quote@ diff --git a/ld/configure.tgt b/ld/configure.tgt index 3aa595ef130..afd4303246e 100644 --- a/ld/configure.tgt +++ b/ld/configure.tgt @@ -253,7 +253,7 @@ arm*-*-haiku*) targ_emul=armelf_haiku targ_extra_emuls=armelf ;; avr-*-*) targ_emul=avr2 - targ_extra_emuls="avr1 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega1 avrxmega2 avrxmega3 avrxmega4 avrxmega5 avrxmega6 avrxmega7 avrtiny" + targ_extra_emuls="avr1 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega1 avrxmega2 avrxmega2_flmap avrxmega3 avrxmega4 avrxmega4_flmap avrxmega5 avrxmega6 avrxmega7 avrtiny" ;; bfin-*-elf | bfin-*-rtems*) targ_emul=elf32bfin diff --git a/ld/emulparams/avrxmega2.sh b/ld/emulparams/avrxmega2.sh index 3f3d86518de..d8c7e194a28 100644 --- a/ld/emulparams/avrxmega2.sh +++ b/ld/emulparams/avrxmega2.sh @@ -18,3 +18,5 @@ FUSE_LENGTH=1K LOCK_LENGTH=1K SIGNATURE_LENGTH=1K USER_SIGNATURE_LENGTH=1K + +MAYBE_FLMAP=1 diff --git a/ld/emulparams/avrxmega2_flmap.sh b/ld/emulparams/avrxmega2_flmap.sh new file mode 100644 index 00000000000..1e5adbe9fc2 --- /dev/null +++ b/ld/emulparams/avrxmega2_flmap.sh @@ -0,0 +1,31 @@ +ARCH=avr:102 +MACHINE= +SCRIPT_NAME=avr +OUTPUT_FORMAT="elf32-avr" +MAXPAGESIZE=1 +EMBEDDED=yes +TEMPLATE_NAME=elf + +TEXT_LENGTH=1024K +DATA_ORIGIN=0x802000 +DATA_LENGTH=0xffa0 +EXTRA_EM_FILE=avrelf + +FUSE_NAME=fuse + +EEPROM_LENGTH=64K +FUSE_LENGTH=1K +LOCK_LENGTH=1K +SIGNATURE_LENGTH=1K +USER_SIGNATURE_LENGTH=1K + +MAYBE_FLMAP=1 + +# Above is a copy of the contents of avrxmega2.sh + +HAVE_FLMAP=1 +RODATA_VMA=0xa00000 +RODATA_LENGTH=32K +RODATA_LDS_OFFSET=0x8000 +RODATA_FLASH_START=32K +FLMAP_MASK=0x1 diff --git a/ld/emulparams/avrxmega4.sh b/ld/emulparams/avrxmega4.sh index d7b377135ee..787e516ee9a 100644 --- a/ld/emulparams/avrxmega4.sh +++ b/ld/emulparams/avrxmega4.sh @@ -18,3 +18,5 @@ FUSE_LENGTH=1K LOCK_LENGTH=1K SIGNATURE_LENGTH=1K USER_SIGNATURE_LENGTH=1K + +MAYBE_FLMAP=1 diff --git a/ld/emulparams/avrxmega4_flmap.sh b/ld/emulparams/avrxmega4_flmap.sh new file mode 100644 index 00000000000..c2f6b9ce0b4 --- /dev/null +++ b/ld/emulparams/avrxmega4_flmap.sh @@ -0,0 +1,31 @@ +ARCH=avr:104 +MACHINE= +SCRIPT_NAME=avr +OUTPUT_FORMAT="elf32-avr" +MAXPAGESIZE=1 +EMBEDDED=yes +TEMPLATE_NAME=elf + +TEXT_LENGTH=1024K +DATA_ORIGIN=0x802000 +DATA_LENGTH=0xffa0 +EXTRA_EM_FILE=avrelf + +FUSE_NAME=fuse + +EEPROM_LENGTH=64K +FUSE_LENGTH=1K +LOCK_LENGTH=1K +SIGNATURE_LENGTH=1K +USER_SIGNATURE_LENGTH=1K + +MAYBE_FLMAP=1 + +# Above is a copy of the contents of avrxmega4.sh + +HAVE_FLMAP=1 +RODATA_VMA=0xa00000 +RODATA_LENGTH=32K +RODATA_LDS_OFFSET=0x8000 +RODATA_FLASH_START=96K +FLMAP_MASK=0x3 diff --git a/ld/scripttempl/avr.sc b/ld/scripttempl/avr.sc index 61cccfccde8..9f2977cfd6d 100644 --- a/ld/scripttempl/avr.sc +++ b/ld/scripttempl/avr.sc @@ -5,9 +5,9 @@ # notice and this notice are preserved. # RODATA_PM_OFFSET -# If empty, .rodata sections will be part of .data. This is for -# devices where it is not possible to use LD* instructions to read -# from flash. +# If empty and not HAVE_FLMAP, .rodata sections will be part of .data. +# This is for devices where it is not possible to use LD* instructions +# to read from flash. # # If non-empty, .rodata is not part of .data and the .rodata # objects are assigned addresses at an offest of RODATA_PM_OFFSET. @@ -15,6 +15,60 @@ # LD* instructions, provided the addresses are offset by # __RODATA_PM_OFFSET__ (which defaults to RODATA_PM_OFFSET). +# HAVE_FLMAP +# The .rodata section is located in program memory. Devices from +# the AVR64* and AVR128* families (from avrxmega2 and avrxmega4) +# see a 32k segment of their program memory in their RAM address +# space. Which 32k segment is visible is determined by the +# bit-field NVMCTRL_CTRLB.FLMAP. +# Output section .rodata is placed in MEMORY region rodata. +# The LMA of the .rodata section can be set by means of: +# * __flmap specifies which 32k block is visible in RAM. +# * __RODATA_FLASH_START__ specifies the byte address of the +# rodata LMA and is used if __flmap is undefined. +# * When __flmap and __RODATA_FLASH_START__ are undefined, then an +# emulation-specific default is used (the last 32k block). + +# MAYBE_FLMAP +# For devices from avrxmega2 and avrxmega4: The user can chose whether +# or not .rodata is located in flash (if HAVE_FLMAP) or located in +# in RAM (if not HAVE_FLMAP by means of -mrodata-in-ram). This is +# achieved by new emulations avrxmega2_flmap and avrxmega4_flmap that +# are selected by compiler option -mno-rodata-in-ram. +# +# In order to facilitate initialization of NVMCTRL_CTRLB.FLMAP in +# the startup code irrespective of HAVE_FLMAP, the follwing symbols +# are defined in order to communicate with the startup code. +# Notice that the hardware default for FLMAP is the last 32k block, +# so that explicit initialization of FLMAP is only required when the +# user wants to deviate from the defauls. +# +# __flmap = HAVE_FLMAP +# ? given by __flmap resp. __RODATA_FLASH_START__ >> 15 +# : 0; +# +# __flmap_lsl4 = __flmap << 4; +# +# __flmap_init_label = HAVE_FLMAP +# ? __flmap_init_start +# : __flmap_noinit_start; +# Supposed to be used as a jump target for RJMP so that the code +# can initialize FLMAP / skip initialization of FLMAP depending +# on the chosen emulation, and without the need to support two code +# versions of crt.o for the two possble emulations. +# +# __do_init_flmap = HAVE_FLMAP ? 1 : 0; +# Whether or not FLMAP is supposed to be initialized according +# to, and for the purpose of, .rodata in flash. +# +# Apart from that, the compiler (device-specs actually) defines the +# following macros: +# +# __AVR_HAVE_FLMAP__ +# Defined if a device has the NVMCTRL_CTRLB.FLMAP bitfield +# *AND* if it's unknown at compile-time / assembler-time whether +# emulation avrxmega* is used or avrxmega*_flmap. + cat < data} EOF +# Devices like AVR128DA32 and AVR64DA32 see a 32 KiB block of their program +# memory at 0x8000 (RODATA_LDS_OFFSET). Which portion will be determined by +# bitfield NVMCTRL_CTRLB.FLMAP. + +if test -n "${MAYBE_FLMAP}" && test -n "${RELOCATING}"; then + cat <> 15); +__RODATA_FLASH_START__ = __flmap << 15; +__rodata_load_start = MAX (__data_load_end, __RODATA_FLASH_START__); +PROVIDE (__flmap_lsl4 = __flmap << 4) ; +__rodata_start = __RODATA_ORIGIN__ + __rodata_load_start - __RODATA_FLASH_START__;} + + .rodata ${RELOCATING+ __rodata_start} ${RELOCATING-0} : ${RELOCATING+ AT (__rodata_load_start)} + { + *(.rodata) + ${RELOCATING+ *(.rodata*)} + ${RELOCATING+ *(.gnu.linkonce.r*)} + ${RELOCATING+ __rodata_end = ABSOLUTE(.) ;} + } ${RELOCATING+ > rodata} + +${RELOCATING+ __rodata_load_end = __rodata_load_start + __rodata_end - __rodata_start;} + +EOF +fi + if test -n "${EEPROM_LENGTH}"; then cat <