From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 64F093858D35 for ; Fri, 4 Feb 2022 08:42:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 64F093858D35 Received: by mail-wr1-x42f.google.com with SMTP id l25so9847852wrb.13 for ; Fri, 04 Feb 2022 00:42:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/yoAG+C9mWfoCg3iZa7+x+IBf92ckl2mhgDIzhbqCPY=; b=DRFVzn4W6/XoRTDOU/1pp9KAqNqg9mF0zDOvB6NnKazMZX3lDtFwoFZF6BFvE5MgTA Jis3dMdgcbW248QOFKbHwnhUfmAAterXZ5WWYFaHXljAeiaAhr9WuzdDpH08VvMd1C45 kEq3d1iMTNz1pPo74tdW6pzjzjqZrVv1FN53KZ2OVO9iCNjv5WX+tBE19soH0a8GRY+4 sRU3p9PAOk9LaN4gQrHA40XrX81BUW//3xO/DQTAbpGSPeFxrPkH6LtRKo5bGFeFQh5i 71dGZLH6Owyqhyv7Bq2Xbz8EepZJPeYkfPD9CRXNud1lF0qHZInXPvpA0gMgHTIoyvuG Ah9A== X-Gm-Message-State: AOAM532XFx+1U87NFBKt/QA9jq1tQiBd71UU8WMVEoKL0NLAnDOHmbRG 9SLS8lyOZZzrCfTa+bt7dT0x4G42fwrV2w== X-Google-Smtp-Source: ABdhPJzTHFt50b2iTeb81RRth7MSNCvA1LTdqMIAg5jQrHJoN/L6tEA6gkvdfQ4VswWx06kXb+fliQ== X-Received: by 2002:a5d:6f10:: with SMTP id ay16mr1565680wrb.205.1643964119140; Fri, 04 Feb 2022 00:41:59 -0800 (PST) Received: from babel.clyon.hd.free.fr ([2a01:e0a:203:b210:afd3:bde6:6149:fc73]) by smtp.gmail.com with ESMTPSA id y7sm1198617wrr.74.2022.02.04.00.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 00:41:58 -0800 (PST) From: christophe.lyon.oss@gmail.com X-Google-Original-From: christophe.lyon@gmail.com To: gdb-patches@sourceware.org Cc: torbjorn.svensson@st.com, Christophe Lyon Subject: [PATCH v3 2/5] gdb/arm: Define MSP and PSP registers for M-Profile Date: Fri, 4 Feb 2022 09:41:48 +0100 Message-Id: <20220204084151.14480-3-christophe.lyon@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204084151.14480-1-christophe.lyon@gmail.com> References: <20220204084151.14480-1-christophe.lyon@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Feb 2022 08:42:03 -0000 From: Christophe Lyon This patch removes the hardcoded access to PSP in arm_m_exception_cache() and relies on the definition with the XML descriptions. Signed-off-by: Christophe Lyon --- 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(-) create mode 100644 gdb/features/arm/arm-m-system.c create mode 100644 gdb/features/arm/arm-m-system.xml diff --git a/gdb/arch/arm.c b/gdb/arch/arm.c index a18b38b9d81..377baf677de 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" /* See arm.h. */ @@ -446,6 +447,11 @@ arm_create_mprofile_target_description (arm_m_profile_type m_type) regnum = create_feature_arm_arm_m_profile_mve (tdesc, regnum); break; + case ARM_M_TYPE_SYSTEM: + regnum = create_feature_arm_arm_m_profile (tdesc, regnum); + regnum = 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 eabcb434f1f..39e96910a4d 100644 --- a/gdb/arch/arm.h +++ b/gdb/arch/arm.h @@ -92,6 +92,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 }; diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 7d52d2d78f6..8533851eceb 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3014,9 +3014,9 @@ arm_m_exception_cache (struct frame_info *this_frame) { struct gdbarch *gdbarch = get_frame_arch (this_frame); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + arm_gdbarch_tdep *tdep = (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; @@ -3032,7 +3032,6 @@ arm_m_exception_cache (struct frame_info *this_frame) to the exception and if FPU is used (causing extended stack frame). */ lr = get_frame_register_unsigned (this_frame, ARM_LR_REGNUM); - sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); /* Check EXC_RETURN indicator bits. */ exc_return = (((lr >> 28) & 0xf) == 0xf); @@ -3041,37 +3040,13 @@ arm_m_exception_cache (struct frame_info *this_frame) process_stack_used = ((lr & (1 << 2)) != 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 = user_reg_map_name_to_regnum (gdbarch, "psp", -1); - if (psp_regnum == -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 = sp; - return cache; - } - else - { - /* Thread (process) stack used, use PSP as SP. */ - unwound_sp = get_frame_register_unsigned (this_frame, psp_regnum); - } + /* Thread (process) stack used, use PSP as SP. */ + unwound_sp = get_frame_register_unsigned (this_frame, tdep->m_profile_psp_regnum); } else { /* Main stack used, use MSP as SP. */ - unwound_sp = sp; + unwound_sp = get_frame_register_unsigned (this_frame, tdep->m_profile_msp_regnum); } /* The hardware saves eight 32-bit words, comprising xPSR, @@ -9038,6 +9013,10 @@ arm_register_g_packet_guesses (struct gdbarch *gdbarch) 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 = arm_read_mprofile_description (ARM_M_TYPE_SYSTEM); + register_remote_g_packet_guess (gdbarch, 2 * ARM_INT_REGISTER_SIZE, tdesc); } /* Otherwise we don't have a useful guess. */ @@ -9098,6 +9077,9 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) bool have_mve = false; int mve_vpr_regnum = -1; int register_count = ARM_NUM_REGS; + bool have_m_profile_sp = false; + int m_profile_msp_regnum = -1; + int m_profile_psp_regnum = -1; /* If we have an object to base this architecture on, try to determine its ABI. */ @@ -9300,6 +9282,35 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (!valid_p) return NULL; + if (is_m) + { + feature = tdesc_find_feature (tdesc, + "org.gnu.gdb.arm.m-system"); + if (feature != nullptr) + { + /* MSP */ + valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), + register_count, "msp"); + if (!valid_p) + { + warning (_("M-profile is missing required register msp.")); + return nullptr; + } + have_m_profile_sp = true; + m_profile_msp_regnum = register_count++; + + /* PSP */ + valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), + register_count, "psp"); + if (!valid_p) + { + warning (_("M-profile is missing required register psp.")); + return nullptr; + } + m_profile_psp_regnum = register_count++; + } + } + feature = tdesc_find_feature (tdesc, "org.gnu.gdb.arm.fpa"); if (feature != NULL) @@ -9499,6 +9510,13 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdep->mve_vpr_regnum = mve_vpr_regnum; } + /* Adjust the M-profile stack pointers settings. */ + if (have_m_profile_sp) + { + tdep->m_profile_msp_regnum = m_profile_msp_regnum; + tdep->m_profile_psp_regnum = m_profile_psp_regnum; + } + arm_register_g_packet_guesses (gdbarch); /* Breakpoints. */ @@ -9771,6 +9789,10 @@ arm_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) tdep->mve_pseudo_base); fprintf_unfiltered (file, _("arm_dump_tdep: mve_pseudo_count = %i\n"), tdep->mve_pseudo_count); + fprintf_unfiltered (file, _("arm_dump_tdep: m_profile_msp_regnum = %i\n"), + tdep->m_profile_msp_regnum); + fprintf_unfiltered (file, _("arm_dump_tdep: m_profile_psp_regnum = %i\n"), + tdep->m_profile_psp_regnum); fprintf_unfiltered (file, _("arm_dump_tdep: Lowest pc = 0x%lx\n"), (unsigned long) tdep->lowest_pc); } diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h index 9012b9da100..420af43a1fe 100644 --- a/gdb/arm-tdep.h +++ b/gdb/arm-tdep.h @@ -119,6 +119,9 @@ struct arm_gdbarch_tdep : gdbarch_tdep int mve_pseudo_base = 0; /* Number of the first MVE pseudo register. */ int mve_pseudo_count = 0; /* Total number of MVE pseudo registers. */ + int m_profile_msp_regnum = 0; /* M-profile MSP register number. */ + int m_profile_psp_regnum = 0; /* M-profile PSP register number. */ + bool is_m = false; /* Does the target follow the "M" profile. */ CORE_ADDR lowest_pc = 0; /* Lowest address at which instructions will appear. */ diff --git a/gdb/features/Makefile b/gdb/features/Makefile index 311176aba28..cb39f54e46e 100644 --- a/gdb/features/Makefile +++ b/gdb/features/Makefile @@ -205,6 +205,7 @@ FEATURE_XMLFILES = 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-system.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 = 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-system.xml new file mode 100644 index 00000000000..eb167adb21a --- /dev/null +++ b/gdb/features/arm/arm-m-system.xml @@ -0,0 +1,12 @@ + + + + + + + + -- 2.25.1