From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1936) id F0E0D3857C49; Wed, 18 May 2022 20:38:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0E0D3857C49 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: John Baldwin To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use aarch64_features to describe register features in target descriptions. X-Act-Checkin: binutils-gdb X-Git-Author: John Baldwin X-Git-Refname: refs/heads/master X-Git-Oldrev: 04dfe7aa52171d110db813bce67c0eea5f4b18cd X-Git-Newrev: 0ee6b1c511c0e2a6793568692d2e5418cd6bc10d Message-Id: <20220518203813.F0E0D3857C49@sourceware.org> Date: Wed, 18 May 2022 20:38:13 +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, 18 May 2022 20:38:14 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0ee6b1c511c0= e2a6793568692d2e5418cd6bc10d commit 0ee6b1c511c0e2a6793568692d2e5418cd6bc10d Author: John Baldwin Date: Wed May 18 13:32:04 2022 -0700 Use aarch64_features to describe register features in target descriptio= ns. =20 Replace the sve bool member of aarch64_features with a vq member that holds the vector quotient. It is zero if SVE is not present. =20 Add std::hash<> specialization and operator=3D=3D so that aarch64_featu= res can be used as a key with std::unordered_map<>. =20 Change the various functions that create or lookup aarch64 target descriptions to accept a const aarch64_features object rather than a growing number of arguments. =20 Replace the multi-dimension tdesc_aarch64_list arrays used to cache target descriptions with unordered_maps indexed by aarch64_feature. Diff: --- gdb/aarch64-fbsd-nat.c | 5 +++-- gdb/aarch64-fbsd-tdep.c | 5 ++++- gdb/aarch64-linux-nat.c | 10 ++++++---- gdb/aarch64-linux-tdep.c | 11 +++++++---- gdb/aarch64-tdep.c | 21 +++++++++++++-------- gdb/aarch64-tdep.h | 3 +-- gdb/arch/aarch64.c | 13 ++++++------- gdb/arch/aarch64.h | 40 ++++++++++++++++++++++++++++++------= ---- gdbserver/linux-aarch64-ipa.cc | 4 ++-- gdbserver/linux-aarch64-low.cc | 11 ++++------- gdbserver/linux-aarch64-tdesc.cc | 18 +++++++++--------- gdbserver/linux-aarch64-tdesc.h | 6 ++++-- gdbserver/netbsd-aarch64-low.cc | 2 +- 13 files changed, 90 insertions(+), 59 deletions(-) diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c index 910bf5bb190..fb7a29b5afb 100644 --- a/gdb/aarch64-fbsd-nat.c +++ b/gdb/aarch64-fbsd-nat.c @@ -149,8 +149,9 @@ aarch64_fbsd_nat_target::store_registers (struct regcac= he *regcache, const struct target_desc * aarch64_fbsd_nat_target::read_description () { - bool tls =3D have_regset (inferior_ptid, NT_ARM_TLS) !=3D 0; - return aarch64_read_description (0, false, false, tls); + aarch64_features features; + features.tls =3D have_regset (inferior_ptid, NT_ARM_TLS) !=3D 0; + return aarch64_read_description (features); } =20 #ifdef HAVE_DBREG diff --git a/gdb/aarch64-fbsd-tdep.c b/gdb/aarch64-fbsd-tdep.c index fdf0795b9bf..891546b3c64 100644 --- a/gdb/aarch64-fbsd-tdep.c +++ b/gdb/aarch64-fbsd-tdep.c @@ -178,7 +178,10 @@ aarch64_fbsd_core_read_description (struct gdbarch *gd= barch, { asection *tls =3D bfd_get_section_by_name (abfd, ".reg-aarch-tls"); =20 - return aarch64_read_description (0, false, false, tls !=3D nullptr); + aarch64_features features; + features.tls =3D tls !=3D nullptr; + + return aarch64_read_description (features); } =20 /* Implement the get_thread_local_address gdbarch method. */ diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 10b0ca10984..9cde72b247b 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -709,11 +709,13 @@ aarch64_linux_nat_target::read_description () CORE_ADDR hwcap =3D linux_get_hwcap (this); CORE_ADDR hwcap2 =3D linux_get_hwcap2 (this); =20 - bool pauth_p =3D hwcap & AARCH64_HWCAP_PACA; - bool mte_p =3D hwcap2 & HWCAP2_MTE; + aarch64_features features; + features.vq =3D aarch64_sve_get_vq (tid); + features.pauth =3D hwcap & AARCH64_HWCAP_PACA; + features.mte =3D hwcap2 & HWCAP2_MTE; + features.tls =3D true; =20 - return aarch64_read_description (aarch64_sve_get_vq (tid), pauth_p, mte_= p, - true); + return aarch64_read_description (features); } =20 /* Convert a native/host siginfo object, into/from the siginfo in the diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index dbebcd4f0e0..453692df2f4 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -779,10 +779,13 @@ aarch64_linux_core_read_description (struct gdbarch *= gdbarch, CORE_ADDR hwcap =3D linux_get_hwcap (target); CORE_ADDR hwcap2 =3D linux_get_hwcap2 (target); =20 - bool pauth_p =3D hwcap & AARCH64_HWCAP_PACA; - bool mte_p =3D hwcap2 & HWCAP2_MTE; - return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, ab= fd), - pauth_p, mte_p, tls !=3D nullptr); + aarch64_features features; + features.vq =3D aarch64_linux_core_read_vq (gdbarch, abfd); + features.pauth =3D hwcap & AARCH64_HWCAP_PACA; + features.mte =3D hwcap2 & HWCAP2_MTE; + features.tls =3D tls !=3D nullptr; + + return aarch64_read_description (features); } =20 /* Implementation of `gdbarch_stap_is_single_operand', as defined in diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index c3abd3a4256..e35c083454d 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -52,13 +52,14 @@ =20 #include "opcode/aarch64.h" #include +#include =20 /* A Homogeneous Floating-Point or Short-Vector Aggregate may have at most four members. */ #define HA_MAX_NUM_FLDS 4 =20 /* All possible aarch64 target descriptors. */ -static target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1][2/*pauth*/]= [2 /* mte */][2 /* tls */]; +static std::unordered_map tdesc_aarch64_= map; =20 /* The standard register names, and all the valid aliases for them. */ static const struct @@ -3332,18 +3333,18 @@ aarch64_displaced_step_hw_singlestep (struct gdbarc= h *gdbarch) TLS_P indicates the presence of the Thread Local Storage feature. */ =20 const target_desc * -aarch64_read_description (uint64_t vq, bool pauth_p, bool mte_p, bool tls_= p) +aarch64_read_description (const aarch64_features &features) { - if (vq > AARCH64_MAX_SVE_VQ) - error (_("VQ is %" PRIu64 ", maximum supported value is %d"), vq, + if (features.vq > AARCH64_MAX_SVE_VQ) + error (_("VQ is %" PRIu64 ", maximum supported value is %d"), features= .vq, AARCH64_MAX_SVE_VQ); =20 - struct target_desc *tdesc =3D tdesc_aarch64_list[vq][pauth_p][mte_p][tls= _p]; + struct target_desc *tdesc =3D tdesc_aarch64_map[features]; =20 if (tdesc =3D=3D NULL) { - tdesc =3D aarch64_create_target_description (vq, pauth_p, mte_p, tls= _p); - tdesc_aarch64_list[vq][pauth_p][mte_p][tls_p] =3D tdesc; + tdesc =3D aarch64_create_target_description (features); + tdesc_aarch64_map[features] =3D tdesc; } =20 return tdesc; @@ -3450,7 +3451,11 @@ aarch64_gdbarch_init (struct gdbarch_info info, stru= ct gdbarch_list *arches) value. */ const struct target_desc *tdesc =3D info.target_desc; if (!tdesc_has_registers (tdesc) || vq !=3D aarch64_get_tdesc_vq (tdesc)) - tdesc =3D aarch64_read_description (vq, false, false, false); + { + aarch64_features features; + features.vq =3D vq; + tdesc =3D aarch64_read_description (features); + } gdb_assert (tdesc); =20 feature_core =3D tdesc_find_feature (tdesc,"org.gnu.gdb.aarch64.core"); diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h index 8efacd5de0f..b85a3d33cc9 100644 --- a/gdb/aarch64-tdep.h +++ b/gdb/aarch64-tdep.h @@ -120,8 +120,7 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep } }; =20 -const target_desc *aarch64_read_description (uint64_t vq, bool pauth_p, - bool mte_p, bool tls_p); +const target_desc *aarch64_read_description (const aarch64_features &featu= res); =20 extern int aarch64_process_record (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr); diff --git a/gdb/arch/aarch64.c b/gdb/arch/aarch64.c index 733a3fd6d2a..0f73286f145 100644 --- a/gdb/arch/aarch64.c +++ b/gdb/arch/aarch64.c @@ -29,8 +29,7 @@ /* See arch/aarch64.h. */ =20 target_desc * -aarch64_create_target_description (uint64_t vq, bool pauth_p, bool mte_p, - bool tls_p) +aarch64_create_target_description (const aarch64_features &features) { target_desc_up tdesc =3D allocate_target_description (); =20 @@ -42,19 +41,19 @@ aarch64_create_target_description (uint64_t vq, bool pa= uth_p, bool mte_p, =20 regnum =3D create_feature_aarch64_core (tdesc.get (), regnum); =20 - if (vq =3D=3D 0) + if (features.vq =3D=3D 0) regnum =3D create_feature_aarch64_fpu (tdesc.get (), regnum); else - regnum =3D create_feature_aarch64_sve (tdesc.get (), regnum, vq); + regnum =3D create_feature_aarch64_sve (tdesc.get (), regnum, features.= vq); =20 - if (pauth_p) + if (features.pauth) regnum =3D create_feature_aarch64_pauth (tdesc.get (), regnum); =20 /* Memory tagging extension registers. */ - if (mte_p) + if (features.mte) regnum =3D create_feature_aarch64_mte (tdesc.get (), regnum); =20 - if (tls_p) + if (features.tls) regnum =3D create_feature_aarch64_tls (tdesc.get (), regnum); =20 return tdesc.release (); diff --git a/gdb/arch/aarch64.h b/gdb/arch/aarch64.h index 8496a0341f7..72ec4193eba 100644 --- a/gdb/arch/aarch64.h +++ b/gdb/arch/aarch64.h @@ -26,23 +26,43 @@ used to select register sets. */ struct aarch64_features { - bool sve =3D false; + /* A non zero VQ value indicates both the presence of SVE and the + Vector Quotient - the number of 128bit chunks in an SVE Z + register. */ + uint64_t vq =3D 0; + bool pauth =3D false; bool mte =3D false; bool tls =3D false; }; =20 -/* Create the aarch64 target description. A non zero VQ value indicates b= oth - the presence of SVE and the Vector Quotient - the number of 128bit chun= ks in - an SVE Z register. HAS_PAUTH_P indicates the presence of the PAUTH - feature. - - MTE_P indicates the presence of the Memory Tagging Extension feature. +inline bool operator=3D=3D(const aarch64_features &lhs, const aarch64_feat= ures &rhs) +{ + return lhs.vq =3D=3D rhs.vq + && lhs.pauth =3D=3D rhs.pauth + && lhs.mte =3D=3D rhs.mte + && lhs.tls =3D=3D rhs.tls; +} + +template<> +struct std::hash +{ + std::size_t operator()(const aarch64_features &features) const noexcept + { + std::size_t h; + + h =3D features.vq; + h =3D h << 1 | features.pauth; + h =3D h << 1 | features.mte; + h =3D h << 1 | features.tls; + return h; + } +}; =20 - TLS_P indicates the presence of the Thread Local Storage feature. */ +/* Create the aarch64 target description. */ =20 -target_desc *aarch64_create_target_description (uint64_t vq, bool has_paut= h_p, - bool mte_p, bool tls_p); +target_desc * + aarch64_create_target_description (const aarch64_features &features); =20 /* Register numbers of various important registers. Note that on SVE, the Z registers reuse the V register numbers and the V diff --git a/gdbserver/linux-aarch64-ipa.cc b/gdbserver/linux-aarch64-ipa.cc index dc907d3ff88..918f85f6ea9 100644 --- a/gdbserver/linux-aarch64-ipa.cc +++ b/gdbserver/linux-aarch64-ipa.cc @@ -152,7 +152,7 @@ get_raw_reg (const unsigned char *raw_regs, int regnum) const struct target_desc * get_ipa_tdesc (int idx) { - return aarch64_linux_read_description (0, false, false, false); + return aarch64_linux_read_description ({}); } =20 /* Allocate buffer for the jump pads. The branch instruction has a reach @@ -205,5 +205,5 @@ void initialize_low_tracepoint (void) { /* SVE, pauth, MTE and TLS not yet supported. */ - aarch64_linux_read_description (0, false, false, false); + aarch64_linux_read_description ({}); } diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index ba0a810e0f9..db508696261 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -779,11 +779,11 @@ aarch64_adjust_register_sets (const struct aarch64_fe= atures &features) break; case NT_FPREGSET: /* This is unavailable when SVE is present. */ - if (!features.sve) + if (features.vq =3D=3D 0) regset->size =3D sizeof (struct user_fpsimd_state); break; case NT_ARM_SVE: - if (features.sve) + if (features.vq > 0) regset->size =3D SVE_PT_SIZE (AARCH64_MAX_SVE_VQ, SVE_PT_REGS_SVE); break; case NT_ARM_PAC_MASK: @@ -824,17 +824,14 @@ aarch64_target::low_arch_setup () { struct aarch64_features features; =20 - uint64_t vq =3D aarch64_sve_get_vq (tid); - features.sve =3D (vq > 0); + features.vq =3D aarch64_sve_get_vq (tid); /* A-profile PAC is 64-bit only. */ features.pauth =3D linux_get_hwcap (8) & AARCH64_HWCAP_PACA; /* A-profile MTE is 64-bit only. */ features.mte =3D linux_get_hwcap2 (8) & HWCAP2_MTE; features.tls =3D true; =20 - current_process ()->tdesc - =3D aarch64_linux_read_description (vq, features.pauth, features.mte, - features.tls); + current_process ()->tdesc =3D aarch64_linux_read_description (featur= es); =20 /* Adjust the register sets we should use for this particular set of features. */ diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-tde= sc.cc index be96612d571..93f2bedde0d 100644 --- a/gdbserver/linux-aarch64-tdesc.cc +++ b/gdbserver/linux-aarch64-tdesc.cc @@ -25,36 +25,36 @@ #include "arch/aarch64.h" #include "linux-aarch32-low.h" #include +#include =20 /* All possible aarch64 target descriptors. */ -struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1][2/*pauth*/]= [2 /* mte */][2 /* tls */]; +static std::unordered_map tdesc_aarch64_m= ap; =20 /* Create the aarch64 target description. */ =20 const target_desc * -aarch64_linux_read_description (uint64_t vq, bool pauth_p, bool mte_p, - bool tls_p) +aarch64_linux_read_description (const aarch64_features &features) { - if (vq > AARCH64_MAX_SVE_VQ) - error (_("VQ is %" PRIu64 ", maximum supported value is %d"), vq, + if (features.vq > AARCH64_MAX_SVE_VQ) + error (_("VQ is %" PRIu64 ", maximum supported value is %d"), features= .vq, AARCH64_MAX_SVE_VQ); =20 - struct target_desc *tdesc =3D tdesc_aarch64_list[vq][pauth_p][mte_p][tls= _p]; + struct target_desc *tdesc =3D tdesc_aarch64_map[features]; =20 if (tdesc =3D=3D NULL) { - tdesc =3D aarch64_create_target_description (vq, pauth_p, mte_p, tls= _p); + tdesc =3D aarch64_create_target_description (features); =20 static const char *expedite_regs_aarch64[] =3D { "x29", "sp", "pc", = NULL }; static const char *expedite_regs_aarch64_sve[] =3D { "x29", "sp", "p= c", "vg", NULL }; =20 - if (vq =3D=3D 0) + if (features.vq =3D=3D 0) init_target_desc (tdesc, expedite_regs_aarch64); else init_target_desc (tdesc, expedite_regs_aarch64_sve); =20 - tdesc_aarch64_list[vq][pauth_p][mte_p][tls_p] =3D tdesc; + tdesc_aarch64_map[features] =3D tdesc; } =20 return tdesc; diff --git a/gdbserver/linux-aarch64-tdesc.h b/gdbserver/linux-aarch64-tdes= c.h index 4ab658447a2..30bcd24d13d 100644 --- a/gdbserver/linux-aarch64-tdesc.h +++ b/gdbserver/linux-aarch64-tdesc.h @@ -20,7 +20,9 @@ #ifndef GDBSERVER_LINUX_AARCH64_TDESC_H #define GDBSERVER_LINUX_AARCH64_TDESC_H =20 -const target_desc * aarch64_linux_read_description (uint64_t vq, bool paut= h_p, - bool mte_p, bool tls_p); +#include "arch/aarch64.h" + +const target_desc * + aarch64_linux_read_description (const aarch64_features &features); =20 #endif /* GDBSERVER_LINUX_AARCH64_TDESC_H */ diff --git a/gdbserver/netbsd-aarch64-low.cc b/gdbserver/netbsd-aarch64-low= .cc index b371e599232..f8447b0d1ee 100644 --- a/gdbserver/netbsd-aarch64-low.cc +++ b/gdbserver/netbsd-aarch64-low.cc @@ -96,7 +96,7 @@ void netbsd_aarch64_target::low_arch_setup () { target_desc *tdesc - =3D aarch64_create_target_description (0, false, false, false); + =3D aarch64_create_target_description ({}); =20 static const char *expedite_regs_aarch64[] =3D { "x29", "sp", "pc", NULL= }; init_target_desc (tdesc, expedite_regs_aarch64);