From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1652) id 24F8D3857C49; Wed, 27 Apr 2022 14:51:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24F8D3857C49 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Christophe Lyon To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/arm: Define MSP and PSP registers for M-Profile X-Act-Checkin: binutils-gdb X-Git-Author: Christophe Lyon X-Git-Refname: refs/heads/master X-Git-Oldrev: fcaa1071d7921c4f7c7592a10ed7b84830ec8c49 X-Git-Newrev: 9074667a8583b33ff1b9590232c15e67f2d1d607 Message-Id: <20220427145122.24F8D3857C49@sourceware.org> Date: Wed, 27 Apr 2022 14:51:22 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Apr 2022 14:51:22 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9074667a8583= b33ff1b9590232c15e67f2d1d607 commit 9074667a8583b33ff1b9590232c15e67f2d1d607 Author: Christophe Lyon Date: Fri Apr 1 10:22:08 2022 +0100 gdb/arm: Define MSP and PSP registers for M-Profile =20 This patch removes the hardcoded access to PSP in arm_m_exception_cache() and relies on the definition with the XML descriptions. =20 Signed-off-by: Christophe Lyon Signed-off-by: Christophe Lyon Diff: --- gdb/arch/arm.c | 6 +++ gdb/arch/arm.h | 1 + gdb/arm-tdep.c | 80 +++++++++++++++++++++++++----------= ---- gdb/arm-tdep.h | 3 ++ gdb/features/Makefile | 1 + gdb/features/arm/arm-m-system.c | 15 ++++++++ gdb/features/arm/arm-m-system.xml | 12 ++++++ 7 files changed, 89 insertions(+), 29 deletions(-) diff --git a/gdb/arch/arm.c b/gdb/arch/arm.c index 126e46a950a..bc6e5ce3f09 100644 --- a/gdb/arch/arm.c +++ b/gdb/arch/arm.c @@ -28,6 +28,7 @@ #include "../features/arm/arm-m-profile.c" #include "../features/arm/arm-m-profile-with-fpa.c" #include "../features/arm/arm-m-profile-mve.c" +#include "../features/arm/arm-m-system.c" =20 /* See arm.h. */ =20 @@ -446,6 +447,11 @@ arm_create_mprofile_target_description (arm_m_profile_= type m_type) regnum =3D create_feature_arm_arm_m_profile_mve (tdesc, regnum); break; =20 + case ARM_M_TYPE_SYSTEM: + regnum =3D create_feature_arm_arm_m_profile (tdesc, regnum); + regnum =3D create_feature_arm_arm_m_system (tdesc, regnum); + break; + default: error (_("Invalid Arm M type: %d"), m_type); } diff --git a/gdb/arch/arm.h b/gdb/arch/arm.h index 755391fe6fe..0728bea1501 100644 --- a/gdb/arch/arm.h +++ b/gdb/arch/arm.h @@ -105,6 +105,7 @@ enum arm_m_profile_type { ARM_M_TYPE_VFP_D16, ARM_M_TYPE_WITH_FPA, ARM_M_TYPE_MVE, + ARM_M_TYPE_SYSTEM, ARM_M_TYPE_INVALID }; =20 diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 66e26e6e212..6b4b00993fa 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3076,9 +3076,9 @@ arm_m_exception_cache (struct frame_info *this_frame) { struct gdbarch *gdbarch =3D get_frame_arch (this_frame); enum bfd_endian byte_order =3D gdbarch_byte_order (gdbarch); + arm_gdbarch_tdep *tdep =3D (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch); struct arm_prologue_cache *cache; CORE_ADDR lr; - CORE_ADDR sp; CORE_ADDR unwound_sp; LONGEST xpsr; uint32_t exc_return; @@ -3094,7 +3094,6 @@ arm_m_exception_cache (struct frame_info *this_frame) to the exception and if FPU is used (causing extended stack frame). = */ =20 lr =3D get_frame_register_unsigned (this_frame, ARM_LR_REGNUM); - sp =3D get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); =20 /* Check EXC_RETURN indicator bits. */ exc_return =3D (((lr >> 28) & 0xf) =3D=3D 0xf); @@ -3103,37 +3102,13 @@ arm_m_exception_cache (struct frame_info *this_fram= e) process_stack_used =3D ((lr & (1 << 2)) !=3D 0); if (exc_return && process_stack_used) { - /* Thread (process) stack used. - Potentially this could be other register defined by target, but PSP - can be considered a standard name for the "Process Stack Pointer". - To be fully aware of system registers like MSP and PSP, these could - be added to a separate XML arm-m-system-profile that is valid for - ARMv6-M and ARMv7-M architectures. Also to be able to debug eg a - corefile off-line, then these registers must be defined by GDB, - and also be included in the corefile regsets. */ - - int psp_regnum =3D user_reg_map_name_to_regnum (gdbarch, "psp", -1); - if (psp_regnum =3D=3D -1) - { - /* Thread (process) stack could not be fetched, - give warning and exit. */ - - warning (_("no PSP thread stack unwinding supported.")); - - /* Terminate any further stack unwinding by refer to self. */ - cache->prev_sp =3D sp; - return cache; - } - else - { - /* Thread (process) stack used, use PSP as SP. */ - unwound_sp =3D get_frame_register_unsigned (this_frame, psp_regnum); - } + /* Thread (process) stack used, use PSP as SP. */ + unwound_sp =3D get_frame_register_unsigned (this_frame, tdep->m_prof= ile_psp_regnum); } else { /* Main stack used, use MSP as SP. */ - unwound_sp =3D sp; + unwound_sp =3D get_frame_register_unsigned (this_frame, tdep->m_prof= ile_msp_regnum); } =20 /* The hardware saves eight 32-bit words, comprising xPSR, @@ -9188,6 +9163,10 @@ arm_register_g_packet_guesses (struct gdbarch *gdbar= ch) register_remote_g_packet_guess (gdbarch, ARM_CORE_REGS_SIZE + ARM_VFP2_REGS_SIZE + ARM_INT_REGISTER_SIZE, tdesc); + + /* M-profile system (stack pointers). */ + tdesc =3D arm_read_mprofile_description (ARM_M_TYPE_SYSTEM); + register_remote_g_packet_guess (gdbarch, 2 * ARM_INT_REGISTER_SIZE, = tdesc); } =20 /* Otherwise we don't have a useful guess. */ @@ -9260,6 +9239,9 @@ arm_gdbarch_init (struct gdbarch_info info, struct gd= barch_list *arches) bool have_pacbti =3D false; int mve_vpr_regnum =3D -1; int register_count =3D ARM_NUM_REGS; + bool have_m_profile_msp =3D false; + int m_profile_msp_regnum =3D -1; + int m_profile_psp_regnum =3D -1; =20 /* If we have an object to base this architecture on, try to determine its ABI. */ @@ -9490,6 +9472,35 @@ arm_gdbarch_init (struct gdbarch_info info, struct g= dbarch_list *arches) if (!valid_p) return NULL; =20 + if (is_m) + { + feature =3D tdesc_find_feature (tdesc, + "org.gnu.gdb.arm.m-system"); + if (feature !=3D nullptr) + { + /* MSP */ + valid_p &=3D tdesc_numbered_register (feature, tdesc_data.get (), + register_count, "msp"); + if (!valid_p) + { + warning (_("M-profile m-system feature is missing required register ms= p.")); + return nullptr; + } + have_m_profile_msp =3D true; + m_profile_msp_regnum =3D register_count++; + + /* PSP */ + valid_p &=3D tdesc_numbered_register (feature, tdesc_data.get (), + register_count, "psp"); + if (!valid_p) + { + warning (_("M-profile m-system feature is missing required register ps= p.")); + return nullptr; + } + m_profile_psp_regnum =3D register_count++; + } + } + feature =3D tdesc_find_feature (tdesc, "org.gnu.gdb.arm.fpa"); if (feature !=3D NULL) @@ -9713,6 +9724,13 @@ arm_gdbarch_init (struct gdbarch_info info, struct g= dbarch_list *arches) /* Adjust the PACBTI feature settings. */ tdep->have_pacbti =3D have_pacbti; =20 + /* Adjust the M-profile stack pointers settings. */ + if (have_m_profile_msp) + { + tdep->m_profile_msp_regnum =3D m_profile_msp_regnum; + tdep->m_profile_psp_regnum =3D m_profile_psp_regnum; + } + arm_register_g_packet_guesses (gdbarch); =20 /* Breakpoints. */ @@ -9998,6 +10016,10 @@ arm_dump_tdep (struct gdbarch *gdbarch, struct ui_f= ile *file) tdep->mve_pseudo_base); gdb_printf (file, _("arm_dump_tdep: mve_pseudo_count =3D %i\n"), tdep->mve_pseudo_count); + gdb_printf (file, _("arm_dump_tdep: m_profile_msp_regnum =3D %i\n"), + tdep->m_profile_msp_regnum); + gdb_printf (file, _("arm_dump_tdep: m_profile_psp_regnum =3D %i\n"), + tdep->m_profile_psp_regnum); gdb_printf (file, _("arm_dump_tdep: Lowest pc =3D 0x%lx\n"), (unsigned long) tdep->lowest_pc); gdb_printf (file, _("arm_dump_tdep: have_pacbti =3D %s\n"), diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h index ae32fffcabf..40170673fde 100644 --- a/gdb/arm-tdep.h +++ b/gdb/arm-tdep.h @@ -125,6 +125,9 @@ struct arm_gdbarch_tdep : gdbarch_tdep register. */ int pacbti_pseudo_count =3D 0; /* Total number of PACBTI pseudo register= s. */ =20 + int m_profile_msp_regnum =3D 0; /* M-profile MSP register number. */ + int m_profile_psp_regnum =3D 0; /* M-profile PSP register number. */ + bool is_m =3D false; /* Does the target follow the "M" profile. */ CORE_ADDR lowest_pc =3D 0; /* Lowest address at which instructions will appear. */ diff --git a/gdb/features/Makefile b/gdb/features/Makefile index a2bb2a5922f..737d9cbd3db 100644 --- a/gdb/features/Makefile +++ b/gdb/features/Makefile @@ -206,6 +206,7 @@ FEATURE_XMLFILES =3D aarch64-core.xml \ arm/arm-fpa.xml \ arm/arm-m-profile.xml \ arm/arm-m-profile-mve.xml \ + arm/arm-m-system.xml \ arm/arm-m-profile-with-fpa.xml \ arm/arm-vfpv2.xml \ arm/arm-vfpv3.xml \ diff --git a/gdb/features/arm/arm-m-system.c b/gdb/features/arm/arm-m-syste= m.c new file mode 100644 index 00000000000..3fb20a57198 --- /dev/null +++ b/gdb/features/arm/arm-m-system.c @@ -0,0 +1,15 @@ +/* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: + Original: arm-m-system.xml */ + +#include "gdbsupport/tdesc.h" + +static int +create_feature_arm_arm_m_system (struct target_desc *result, long regnum) +{ + struct tdesc_feature *feature; + + feature =3D tdesc_create_feature (result, "org.gnu.gdb.arm.m-system"); + tdesc_create_reg (feature, "msp", regnum++, 1, NULL, 32, "data_ptr"); + tdesc_create_reg (feature, "psp", regnum++, 1, NULL, 32, "data_ptr"); + return regnum; +} diff --git a/gdb/features/arm/arm-m-system.xml b/gdb/features/arm/arm-m-sys= tem.xml new file mode 100644 index 00000000000..eb167adb21a --- /dev/null +++ b/gdb/features/arm/arm-m-system.xml @@ -0,0 +1,12 @@ + + + + + + + +