[PATCH v4 2/3] libgloss: arm: Add hardfault handler for M-profile
Christophe Lyon <[email protected]> Wed, 24 Jun 2026 21:58:34 +0200
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
After reaching a hardfault, the simulator enters an infinite loop unless we map the handler to 'abort'. The patch adds this minimal setup for M-profile in the new libgloss/arm/cpu-init/rdimon-aem-m.S and introduces the new libgloss/arm/elf-mprofile-mps2.specs to add the mapping to the right memory address. 2026-05-29 Andre Vieira <[email protected]> Christophe Lyon <[email protected]> libgloss/ * Makefile.in: Add entry for arm/mprofile-mps2.specs. * arm/Makefile.inc: Add entry for mprofile-mps2.specs. * arm/cpu-init/rdimon-aem-m.S: New file. * arm/cpu-init/rdimon-aem.S: Include rdimon-aem-m.S. * arm/elf-mprofile-mps2.specs: New file. --- libgloss/Makefile.in | 1 + libgloss/arm/Makefile.inc | 3 ++- libgloss/arm/cpu-init/rdimon-aem-m.S | 39 ++++++++++++++++++++++++++++ libgloss/arm/cpu-init/rdimon-aem.S | 1 + libgloss/arm/elf-mprofile-mps2.specs | 26 +++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 libgloss/arm/cpu-init/rdimon-aem-m.S create mode 100644 libgloss/arm/elf-mprofile-mps2.specs diff --git a/libgloss/Makefile.in b/libgloss/Makefile.in index 5146a7880..c03ea4e6b 100644 --- a/libgloss/Makefile.in +++ b/libgloss/Makefile.in @@ -2255,6 +2255,7 @@ TEXINFO_TEX = ../texinfo/texinfo.tex @CONFIG_ARM_TRUE@ arm/aprofile-validation-v2m.specs \ @CONFIG_ARM_TRUE@ arm/aprofile-ve-v2m.specs \ @CONFIG_ARM_TRUE@ arm/aprofile-ve.specs arm/pid.specs \ +@CONFIG_ARM_TRUE@ arm/mprofile-mps2.specs \ @CONFIG_ARM_TRUE@ arm/iq80310.specs @CONFIG_ARM_TRUE@arm_libgloss_linux_a_SOURCES = \ @CONFIG_ARM_TRUE@ arm/linux-syscalls0.c \ diff --git a/libgloss/arm/Makefile.inc b/libgloss/arm/Makefile.inc index 41fce3c99..5c740edcb 100644 --- a/libgloss/arm/Makefile.inc +++ b/libgloss/arm/Makefile.inc @@ -47,7 +47,8 @@ multilibtool_LIBRARIES += %D%/librdpmon.a %D%/aprofile-validation.specs \ %D%/aprofile-validation-v2m.specs \ %D%/aprofile-ve-v2m.specs \ - %D%/aprofile-ve.specs + %D%/aprofile-ve.specs \ + %D%/mprofile-mps2.specs multilibtool_DATA += \ %D%/rdimon-crt0.o \ %D%/rdimon-crt0-v2m.o diff --git a/libgloss/arm/cpu-init/rdimon-aem-m.S b/libgloss/arm/cpu-init/rdimon-aem-m.S new file mode 100644 index 000000000..611849077 --- /dev/null +++ b/libgloss/arm/cpu-init/rdimon-aem-m.S @@ -0,0 +1,39 @@ +/* Copyright (c) 2026 ARM Ltd. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the company may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +/* This file gives a basic initialisation of an M-profile core. + + We define a hardfault handler, required to prevent the simulator + from entering into an infinite loop. This handler is located at + address 0xc by default when linking with mprofile-mps2.specs which + uses --section-start=.hardfault_handler_addr=0xc. */ + +#if (__ARM_ARCH_PROFILE == 'M') + /* On M-profile, call abort in case of hardfault: this causes the + simulator to abort execution instead of going into an infinite + loop. */ + .section .hardfault_handler_addr, "a" + .word abort +#endif diff --git a/libgloss/arm/cpu-init/rdimon-aem.S b/libgloss/arm/cpu-init/rdimon-aem.S index 7bd086bbf..208257fe0 100644 --- a/libgloss/arm/cpu-init/rdimon-aem.S +++ b/libgloss/arm/cpu-init/rdimon-aem.S @@ -27,3 +27,4 @@ manage multilibs without affecting the build system. */ #include "rdimon-aem-a.S" +#include "rdimon-aem-m.S" diff --git a/libgloss/arm/elf-mprofile-mps2.specs b/libgloss/arm/elf-mprofile-mps2.specs new file mode 100644 index 000000000..edaf71917 --- /dev/null +++ b/libgloss/arm/elf-mprofile-mps2.specs @@ -0,0 +1,26 @@ +# rdimon.specs +# +# Spec file for AArch32 M profile baremetal newlib with version 2 of +# the AngelAPI semi-hosting using the SVC trap instruction. +# +# This version supports extensibility through an extension mechanism. + +%rename link_gcc_c_sequence rdimon_link_gcc_c_sequence + +%rename link old_link + +*link: +--section-start=.hardfault_handler_addr=0xc %(old_link) + +*rdimon_libc: +%{!specs=nano.specs:-lc} %{specs=nano.specs:-lc_nano} + +*rdimon_libgloss: +%{!specs=nano.specs:-lrdimon} %{specs=nano.specs:-lrdimon_nano} + +*link_gcc_c_sequence: +%(rdimon_link_gcc_c_sequence) --start-group %G %(rdimon_libc) %(rdimon_libgloss) --end-group + +*startfile: +crti%O%s crtbegin%O%s cpu-init/rdimon-aem.o%s %{!pg:rdimon-crt0%O%s} %{pg:rdimon-crt0%O%s} + -- 2.34.1