From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73572 invoked by alias); 4 Aug 2015 09:52:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 73560 invoked by uid 89); 4 Aug 2015 09:52:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f46.google.com Received: from mail-pa0-f46.google.com (HELO mail-pa0-f46.google.com) (209.85.220.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 04 Aug 2015 09:52:15 +0000 Received: by pasy3 with SMTP id y3so4582352pas.2 for ; Tue, 04 Aug 2015 02:52:13 -0700 (PDT) X-Received: by 10.68.232.104 with SMTP id tn8mr5845880pbc.155.1438681933300; Tue, 04 Aug 2015 02:52:13 -0700 (PDT) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id nd6sm760188pbc.65.2015.08.04.02.52.09 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 04 Aug 2015 02:52:12 -0700 (PDT) From: Yao Qi To: Pedro Alves Cc: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH 2/7] New regs_info for aarch32 References: <1438355801-25798-1-git-send-email-yao.qi@linaro.org> <1438355801-25798-3-git-send-email-yao.qi@linaro.org> <55BF7383.5030304@redhat.com> <55BF980F.5010306@gmail.com> <55BFA0AD.5000408@redhat.com> Date: Tue, 04 Aug 2015 09:52:00 -0000 In-Reply-To: <55BFA0AD.5000408@redhat.com> (Pedro Alves's message of "Mon, 03 Aug 2015 18:11:09 +0100") Message-ID: <86614ve5z5.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-08/txt/msg00065.txt.bz2 Pedro Alves writes: > Let me try putting it another way then. > > Why are some init_registers_arm_XXX calls done in > linux-aarch32-low.c:initialize_low_arch_aarch32 but others > in linux-arm-low.c:initialize_low_arch? > > If we already end up with __aarch64__ #ifdefs, shouldn't the resulting > code end like this? > > void > initialize_low_arch_aarch32 (void) > { > #ifndef __aarch64__ > init_registers_arm (); > init_registers_arm_with_iwmmxt (); > init_registers_arm_with_vfpv2 (); > init_registers_arm_with_vfpv3 (); > #endif > init_registers_arm_with_neon (); > } > > Isn't aarch32 the term used for all 32-bit execution state, > including pre-ARMv8? Otherwise, going forward, what is the > guideline to know where to put a new > init_registers_arm_xxx call? aarch32 means armv7+neon, so ideally we only need call init_registers_arm_with_neon for aarch32. However, arm_store_vfpregset and arm_fill_vfpregset need to check tdesc_arm_with_vfpv3 and tdesc_arm_with_vfpv2, so we need to call init_registers_arm_with_vfpv2 and init_registers_arm_with_vfpv3 to init them. That is the reason I call them inside initialize_low_arch_aarch32. I agree the "#ifndef __aarch64__" is confusing, and let me remove that block out of initialize_low_arch_aarch32. The patch below is updated to initialize arm_with_neon target description in linux-aarch32-low.c:initialize_low_arch_aarch32, and leave vfpv2 and vfpv3 target descriptions inside linux-arm-low.c. This is cleaner than the previous version. As a result, patch 3/7 is cleaner too, because "#ifndef __aarch64__" is not needed anymore. The guideline of adding new arm targets in my mind is if new arm target can be run on aarch32 (32-bit mode on aarch64), it should be initialized in initialize_low_arch_aarch32. If new arm target can't be run on 32-bit mode on aarch64, it should be initialized in linux-arm-low.c:initialize_low_arch. --=20 Yao (=E9=BD=90=E5=B0=A7) Subject: [PATCH 2/7] New regs_info for aarch32 This patch adds a new regs_info regs_info_aarch32 for aarch32, which can be used by both aarch64 and arm backend. gdb/gdbserver: 2015-08-04 Yao Qi * configure.srv (srv_tgtobj): Add linux-aarch32-low.o. * linux-aarch32-low.c: New file. * linux-aarch32-low.h: New file. * linux-arm-low.c (arm_fill_gregset): Move it to linux-aarch32-low.c. (arm_store_gregset): Likewise. (arm_fill_vfpregset): Call arm_fill_vfpregset_num (arm_store_vfpregset): Call arm_store_vfpregset_num. (arm_arch_setup): Check if PTRACE_GETREGSET works. (regs_info): Rename to regs_info_arm. (arm_regs_info): Return regs_info_aarch32 if have_ptrace_getregset is 1 and target description is arm_with_neon or arm_with_vfpv3. (initialize_low_arch): Don't call init_registers_arm_with_neon. Call initialize_low_arch_aarch32 instead. --- gdb/gdbserver/configure.srv | 1 + gdb/gdbserver/linux-aarch32-low.c | 140 ++++++++++++++++++++++++++++++++++= ++++ gdb/gdbserver/linux-aarch32-low.h | 29 ++++++++ gdb/gdbserver/linux-arm-low.c | 78 +++++++++------------ 4 files changed, 201 insertions(+), 47 deletions(-) create mode 100644 gdb/gdbserver/linux-aarch32-low.c create mode 100644 gdb/gdbserver/linux-aarch32-low.h diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv index 9a04aac..1a8361a 100644 --- a/gdb/gdbserver/configure.srv +++ b/gdb/gdbserver/configure.srv @@ -62,6 +62,7 @@ case "${target}" in srv_regobj=3D"${srv_regobj} arm-with-vfpv3.o" srv_regobj=3D"${srv_regobj} arm-with-neon.o" srv_tgtobj=3D"$srv_linux_obj linux-arm-low.o" + srv_tgtobj=3D"$srv_tgtobj linux-aarch32-low.o" srv_xmlfiles=3D"arm-with-iwmmxt.xml" srv_xmlfiles=3D"${srv_xmlfiles} arm-with-vfpv2.xml" srv_xmlfiles=3D"${srv_xmlfiles} arm-with-vfpv3.xml" diff --git a/gdb/gdbserver/linux-aarch32-low.c b/gdb/gdbserver/linux-aarch3= 2-low.c new file mode 100644 index 0000000..7f3b985 --- /dev/null +++ b/gdb/gdbserver/linux-aarch32-low.c @@ -0,0 +1,140 @@ +/* Copyright (C) 1995-2015 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . = */ + +#include "server.h" +#include "arch/arm.h" +#include "linux-low.h" +#include "linux-aarch32-low.h" + +#include +/* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h. + On Bionic elf.h and linux/elf.h have conflicting definitions. */ +#ifndef ELFMAG0 +#include +#endif + +/* Collect GP registers from REGCACHE to buffer BUF. */ + +void +arm_fill_gregset (struct regcache *regcache, void *buf) +{ + int i; + uint32_t *regs =3D buf; + + for (i =3D ARM_A1_REGNUM; i <=3D ARM_PC_REGNUM; i++) + collect_register (regcache, i, ®s[i]); + + collect_register (regcache, ARM_PS_REGNUM, ®s[16]); +} + +/* Supply GP registers contents, stored in BUF, to REGCACHE. */ + +void +arm_store_gregset (struct regcache *regcache, const void *buf) +{ + int i; + char zerobuf[8]; + const uint32_t *regs =3D buf; + + memset (zerobuf, 0, 8); + for (i =3D ARM_A1_REGNUM; i <=3D ARM_PC_REGNUM; i++) + supply_register (regcache, i, ®s[i]); + + for (; i < ARM_PS_REGNUM; i++) + supply_register (regcache, i, zerobuf); + + supply_register (regcache, ARM_PS_REGNUM, ®s[16]); +} + +/* Collect NUM number of VFP registers from REGCACHE to buffer BUF. */ + +void +arm_fill_vfpregset_num (struct regcache *regcache, void *buf, int num) +{ + int i, base; + + gdb_assert (num =3D=3D 16 || num =3D=3D 32); + + base =3D find_regno (regcache->tdesc, "d0"); + for (i =3D 0; i < num; i++) + collect_register (regcache, base + i, (char *) buf + i * 8); + + collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8); +} + +/* Supply NUM number of VFP registers contents, stored in BUF, to + REGCACHE. */ + +void +arm_store_vfpregset_num (struct regcache *regcache, const void *buf, int n= um) +{ + int i, base; + + gdb_assert (num =3D=3D 16 || num =3D=3D 32); + + base =3D find_regno (regcache->tdesc, "d0"); + for (i =3D 0; i < num; i++) + supply_register (regcache, base + i, (char *) buf + i * 8); + + supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8); +} + +static void +arm_fill_vfpregset (struct regcache *regcache, void *buf) +{ + arm_fill_vfpregset_num (regcache, buf, 32); +} + +static void +arm_store_vfpregset (struct regcache *regcache, const void *buf) +{ + arm_store_vfpregset_num (regcache, buf, 32); +} + +/* Register sets with using PTRACE_GETREGSET. */ + +static struct regset_info aarch32_regsets[] =3D { + { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_PRSTATUS, 18 * 4, + GENERAL_REGS, + arm_fill_gregset, arm_store_gregset }, + { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_ARM_VFP, 32 * 8 + 4, + EXTENDED_REGS, + arm_fill_vfpregset, arm_store_vfpregset }, + { 0, 0, 0, -1, -1, NULL, NULL } +}; + +static struct regsets_info aarch32_regsets_info =3D + { + aarch32_regsets, /* regsets */ + 0, /* num_regsets */ + NULL, /* disabled_regsets */ + }; + +struct regs_info regs_info_aarch32 =3D + { + NULL, /* regset_bitmap */ + NULL, /* usrregs */ + &aarch32_regsets_info + }; + +void +initialize_low_arch_aarch32 (void) +{ + init_registers_arm_with_neon (); + + initialize_regsets_info (&aarch32_regsets_info); +} diff --git a/gdb/gdbserver/linux-aarch32-low.h b/gdb/gdbserver/linux-aarch3= 2-low.h new file mode 100644 index 0000000..6682f0a --- /dev/null +++ b/gdb/gdbserver/linux-aarch32-low.h @@ -0,0 +1,29 @@ +/* Copyright (C) 1995-2015 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . = */ + +extern struct regs_info regs_info_aarch32; + +void arm_fill_gregset (struct regcache *regcache, void *buf); +void arm_store_gregset (struct regcache *regcache, const void *buf); +void arm_fill_vfpregset_num (struct regcache *regcache, void *buf, int num= ); +void arm_store_vfpregset_num (struct regcache *regcache, const void *buf, + int num); + +void initialize_low_arch_aarch32 (void); + +void init_registers_arm_with_neon (void); +extern const struct target_desc *tdesc_arm_with_neon; diff --git a/gdb/gdbserver/linux-arm-low.c b/gdb/gdbserver/linux-arm-low.c index 3c5956b..6a27e6e 100644 --- a/gdb/gdbserver/linux-arm-low.c +++ b/gdb/gdbserver/linux-arm-low.c @@ -19,7 +19,9 @@ #include "server.h" #include "linux-low.h" #include "arch/arm.h" +#include "linux-aarch32-low.h" =20 +#include /* Don't include elf.h if linux/elf.h got included by gdb_proc_service.h. On Bionic elf.h and linux/elf.h have conflicting definitions. */ #ifndef ELFMAG0 @@ -41,9 +43,6 @@ extern const struct target_desc *tdesc_arm_with_vfpv2; void init_registers_arm_with_vfpv3 (void); extern const struct target_desc *tdesc_arm_with_vfpv3; =20 -void init_registers_arm_with_neon (void); -extern const struct target_desc *tdesc_arm_with_neon; - #ifndef PTRACE_GET_THREAD_AREA #define PTRACE_GET_THREAD_AREA 22 #endif @@ -150,35 +149,6 @@ arm_cannot_fetch_register (int regno) } =20 static void -arm_fill_gregset (struct regcache *regcache, void *buf) -{ - int i; - uint32_t *regs =3D buf; - - for (i =3D ARM_A1_REGNUM; i <=3D ARM_PC_REGNUM; i++) - collect_register (regcache, i, ®s[i]); - - collect_register (regcache, ARM_PS_REGNUM, ®s[16]); -} - -static void -arm_store_gregset (struct regcache *regcache, const void *buf) -{ - int i; - char zerobuf[8]; - const uint32_t *regs =3D buf; - - memset (zerobuf, 0, 8); - for (i =3D ARM_A1_REGNUM; i <=3D ARM_PC_REGNUM; i++) - supply_register (regcache, i, ®s[i]); - - for (; i < ARM_PS_REGNUM; i++) - supply_register (regcache, i, zerobuf); - - supply_register (regcache, ARM_PS_REGNUM, ®s[16]); -} - -static void arm_fill_wmmxregset (struct regcache *regcache, void *buf) { int i; @@ -215,7 +185,7 @@ arm_store_wmmxregset (struct regcache *regcache, const = void *buf) static void arm_fill_vfpregset (struct regcache *regcache, void *buf) { - int i, num, base; + int num; =20 if (regcache->tdesc =3D=3D tdesc_arm_with_neon || regcache->tdesc =3D=3D tdesc_arm_with_vfpv3) @@ -225,17 +195,13 @@ arm_fill_vfpregset (struct regcache *regcache, void *= buf) else return; =20 - base =3D find_regno (regcache->tdesc, "d0"); - for (i =3D 0; i < num; i++) - collect_register (regcache, base + i, (char *) buf + i * 8); - - collect_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8); + arm_fill_vfpregset_num (regcache, buf, num); } =20 static void arm_store_vfpregset (struct regcache *regcache, const void *buf) { - int i, num, base; + int num; =20 if (regcache->tdesc =3D=3D tdesc_arm_with_neon || regcache->tdesc =3D=3D tdesc_arm_with_vfpv3) @@ -245,11 +211,7 @@ arm_store_vfpregset (struct regcache *regcache, const = void *buf) else return; =20 - base =3D find_regno (regcache->tdesc, "d0"); - for (i =3D 0; i < num; i++) - supply_register (regcache, base + i, (char *) buf + i * 8); - - supply_register_by_name (regcache, "fpscr", (char *) buf + 32 * 8); + arm_store_vfpregset_num (regcache, buf, num); } =20 extern int debug_threads; @@ -888,9 +850,24 @@ arm_read_description (void) static void arm_arch_setup (void) { + int tid =3D lwpid_of (current_thread); + int gpregs[18]; + struct iovec iov; + current_process ()->tdesc =3D arm_read_description (); + + iov.iov_base =3D gpregs; + iov.iov_len =3D sizeof (gpregs); + + /* Check if PTRACE_GETREGSET works. */ + if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov) =3D=3D 0) + have_ptrace_getregset =3D 1; + else + have_ptrace_getregset =3D 0; } =20 +/* Register sets without using PTRACE_GETREGSET. */ + static struct regset_info arm_regsets[] =3D { { PTRACE_GETREGS, PTRACE_SETREGS, 0, 18 * 4, GENERAL_REGS, @@ -917,7 +894,7 @@ static struct usrregs_info arm_usrregs_info =3D arm_regmap, }; =20 -static struct regs_info regs_info =3D +static struct regs_info regs_info_arm =3D { NULL, /* regset_bitmap */ &arm_usrregs_info, @@ -927,7 +904,13 @@ static struct regs_info regs_info =3D static const struct regs_info * arm_regs_info (void) { - return ®s_info; + const struct target_desc *tdesc =3D current_process ()->tdesc; + + if (have_ptrace_getregset =3D=3D 1 + && (tdesc =3D=3D tdesc_arm_with_neon || tdesc =3D=3D tdesc_arm_with_= vfpv3)) + return ®s_info_aarch32; + else + return ®s_info_arm; } =20 struct linux_target_ops the_low_target =3D { @@ -975,7 +958,8 @@ initialize_low_arch (void) init_registers_arm_with_iwmmxt (); init_registers_arm_with_vfpv2 (); init_registers_arm_with_vfpv3 (); - init_registers_arm_with_neon (); + + initialize_low_arch_aarch32 (); =20 initialize_regsets_info (&arm_regsets_info); } --=20 1.9.1