Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch 3/4] Nios II gdbserver support
@ 2013-04-22 13:31 Sandra Loosemore
  2013-04-23  2:45 ` Joseph S. Myers
       [not found] ` <20130426064547.GQ3525@adacore.com>
  0 siblings, 2 replies; 8+ messages in thread
From: Sandra Loosemore @ 2013-04-22 13:31 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 424 bytes --]

This part of the Altera Nios II port includes the gdbserver support for 
GNU/Linux target.  OK to commit?

-Sandra

2013-04-21  Sandra Loosemore  <sandra@codesourcery.com>
	    Andrew Jenner  <andrew@codesourcery.com>

	gdb/gdbserver/
	* Makefile.in (SFILES): Add linux-nios2-low.c.
	(clean): Add action to delete nios2-linux.c.
	(nios2-linux.c): New rule.
	* configure.srv: Add nios2*-*-linux*.
	* linux-nios2-low.c: New.


[-- Attachment #2: gdb-3.patch --]
[-- Type: text/x-patch, Size: 8802 bytes --]

Index: gdb/gdbserver/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v
retrieving revision 1.149
diff -u -p -r1.149 Makefile.in
--- gdb/gdbserver/Makefile.in	17 Apr 2013 09:58:15 -0000	1.149
+++ gdb/gdbserver/Makefile.in	20 Apr 2013 21:32:50 -0000
@@ -143,6 +143,7 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/
 	$(srcdir)/linux-ia64-low.c $(srcdir)/linux-low.c \
 	$(srcdir)/linux-m32r-low.c \
 	$(srcdir)/linux-m68k-low.c $(srcdir)/linux-mips-low.c \
+	$(srcdir)/linux-nios2-low.c \
 	$(srcdir)/linux-ppc-low.c \
 	$(srcdir)/linux-s390-low.c \
 	$(srcdir)/linux-sh-low.c $(srcdir)/linux-sparc-low.c \
@@ -322,6 +323,7 @@ clean:
 	rm -f arm-with-iwmmxt.c
 	rm -f arm-with-vfpv2.c arm-with-vfpv3.c arm-with-neon.c
 	rm -f mips-linux.c mips64-linux.c
+	rm -f nios2-linux.c
 	rm -f powerpc-32.c powerpc-32l.c powerpc-64l.c powerpc-e500l.c
 	rm -f powerpc-altivec32l.c powerpc-cell32l.c powerpc-vsx32l.c
 	rm -f powerpc-altivec64l.c powerpc-cell64l.c powerpc-vsx64l.c
@@ -609,6 +611,8 @@ mips64-linux.c : $(srcdir)/../regformats
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/mips64-linux.dat mips64-linux.c
 mips64-dsp-linux.c : $(srcdir)/../regformats/mips64-dsp-linux.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/mips64-dsp-linux.dat mips64-dsp-linux.c
+nios2-linux.c :	$(srcdir)/../regformats/nios2-linux.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/nios2-linux.dat nios2-linux.c
 powerpc-32.c : $(srcdir)/../regformats/rs6000/powerpc-32.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/rs6000/powerpc-32.dat powerpc-32.c
 powerpc-32l.c : $(srcdir)/../regformats/rs6000/powerpc-32l.dat $(regdat_sh)
Index: gdb/gdbserver/configure.srv
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.srv,v
retrieving revision 1.74
diff -u -p -r1.74 configure.srv
--- gdb/gdbserver/configure.srv	11 Mar 2013 08:35:11 -0000	1.74
+++ gdb/gdbserver/configure.srv	20 Apr 2013 21:32:50 -0000
@@ -201,6 +201,15 @@ case "${target}" in
 			srv_linux_usrregs=yes
 			srv_linux_thread_db=yes
 			;;
+  nios2*-*-linux*)	srv_regobj="nios2-linux.o"
+			srv_tgtobj="linux-low.o linux-osdata.o linux-nios2-low.o linux-procfs.o"
+			srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
+			srv_xmlfiles="nios2-linux.xml"
+			srv_xmlfiles="${srv_xmlfiles} nios2-cpu.xml"
+			srv_linux_regsets=yes
+			srv_linux_usrregs=yes
+			srv_linux_thread_db=yes
+			;;
   powerpc*-*-linux*)	srv_regobj="powerpc-32l.o"
 			srv_regobj="${srv_regobj} powerpc-altivec32l.o"
 			srv_regobj="${srv_regobj} powerpc-cell32l.o"
Index: gdb/gdbserver/linux-nios2-low.c
===================================================================
RCS file: gdb/gdbserver/linux-nios2-low.c
diff -N gdb/gdbserver/linux-nios2-low.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/gdbserver/linux-nios2-low.c	20 Apr 2013 21:32:50 -0000
@@ -0,0 +1,230 @@
+/* GNU/Linux/Nios II specific low level interface, for the remote server for
+   GDB.
+   Copyright (C) 2008, 2012, 2013
+   Free Software Foundation, Inc.
+
+   Contributed by Mentor Graphics, 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 <http://www.gnu.org/licenses/>.  */
+
+#include "server.h"
+#include "linux-low.h"
+#include <sys/ptrace.h>
+#include <endian.h>
+#include "gdb_proc_service.h"
+#include <asm/ptrace.h>
+
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+
+/* The following definition must agree with the number of registers defined in
+   "struct user_regs" in GLIBC
+   (ports/sysdeps/unix/sysv/linux/nios2/sys/user.h), and also with
+   NIOS2_NUM_REGS in GDB proper.  */
+
+#define nios2_num_regs 49
+
+/* Defined in auto-generated file nios2-linux.c.  */
+
+void init_registers_nios2_linux (void);
+
+union nios2_register
+{
+  unsigned char buf[4];
+  int reg32;
+};
+
+/* Return the ptrace ``address'' of register REGNO. */
+
+static int nios2_regmap[] = {
+  -1,  1,  2,  3,  4,  5,  6,  7,
+  8,  9,  10, 11, 12, 13, 14, 15,
+  16, 17, 18, 19, 20, 21, 22, 23,
+  24, 25, 26, 27, 28, 29, 30, 31,
+  32, 33, 34, 35, 36, 37, 38, 39,
+  40, 41, 42, 43, 44, 45, 46, 47,
+  48,
+
+  0
+};
+
+/* Nothing to do here but call the autogenerated register setup hook.  */
+
+static void
+nios2_arch_setup (void)
+{
+  init_registers_nios2_linux ();
+}
+
+/* Pseudo registers cannot be read by ptrace, and there's no point
+   in reading or setting r0, the zero register.  */
+
+static int
+nios2_cannot_fetch_register (int regno)
+{
+  if (nios2_regmap[regno] == -1)
+    return 1;
+  if (find_regno ("r0") == regno)
+    return 1;
+
+  return 0;
+}
+
+static int
+nios2_cannot_store_register (int regno)
+{
+  if (nios2_regmap[regno] == -1)
+    return 1;
+  if (find_regno ("r0") == regno)
+    return 1;
+
+  return 0;
+}
+
+/* Get/store the PC.  */
+
+static CORE_ADDR
+nios2_get_pc (struct regcache *regcache)
+{
+  union nios2_register pc;
+  collect_register_by_name (regcache, "pc", pc.buf);
+  return pc.reg32;
+}
+
+static void
+nios2_set_pc (struct regcache *regcache, CORE_ADDR pc)
+{
+  union nios2_register newpc;
+  newpc.reg32 = pc;
+  supply_register_by_name (regcache, "pc", newpc.buf);
+}
+
+/* Breakpoint support.  */
+
+static const unsigned int nios2_breakpoint = 0x003b6ffa;
+#define nios2_breakpoint_len 4
+
+/* We only place breakpoints in empty marker functions, and thread locking
+   is outside of the function.  So rather than importing software single-step,
+   we can just run until exit.  */
+
+static CORE_ADDR
+nios2_reinsert_addr (void)
+{
+  union nios2_register ra;
+  struct regcache *regcache = get_thread_regcache (current_inferior, 1);
+
+  collect_register_by_name (regcache, "r31", ra.buf);
+  return ra.reg32;
+}
+
+static int
+nios2_breakpoint_at (CORE_ADDR where)
+{
+  unsigned int insn;
+
+  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  if (insn == nios2_breakpoint)
+    return 1;
+  return 0;
+}
+
+/* Fetch the thread-local storage pointer for libthread_db.  */
+
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+                    lwpid_t lwpid, int idx, void **base)
+{
+  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+    return PS_ERR;
+
+  /* IDX is the bias from the thread pointer to the beginning of the
+     thread descriptor.  It has to be subtracted due to implementation
+     quirks in libthread_db.  */
+  *base = (void *) ((char *)*base - idx);
+
+  return PS_OK;
+}
+
+#ifdef HAVE_PTRACE_GETREGS
+
+/* Helper functions to collect/supply a single register REGNO.  */
+
+static void
+nios2_collect_register (struct regcache *regcache, int regno,
+			union nios2_register *reg)
+{
+  union nios2_register tmp_reg;
+
+  collect_register (regcache, regno, &tmp_reg.reg32);
+  reg->reg32 = tmp_reg.reg32;
+}
+
+static void
+nios2_supply_register (struct regcache *regcache, int regno,
+		       const union nios2_register *reg)
+{
+  supply_register (regcache, regno, reg->buf);
+}
+
+/* We have only a single register set on Nios II.  */
+
+static void
+nios2_fill_gregset (struct regcache *regcache, void *buf)
+{
+  union nios2_register *regset = buf;
+  int i;
+
+  for (i = 1; i < nios2_num_regs; i++)
+    nios2_collect_register (regcache, i, regset + i);
+}
+
+static void
+nios2_store_gregset (struct regcache *regcache, const void *buf)
+{
+  const union nios2_register *regset = buf;
+  int i;
+
+  for (i = 0; i < nios2_num_regs; i++)
+    nios2_supply_register (regcache, i, regset + i);
+}
+#endif /* HAVE_PTRACE_GETREGS */
+
+struct regset_info target_regsets[] = {
+#ifdef HAVE_PTRACE_GETREGS
+  { PTRACE_GETREGS, PTRACE_SETREGS, 0, nios2_num_regs * 4, GENERAL_REGS,
+    nios2_fill_gregset, nios2_store_gregset },
+#endif /* HAVE_PTRACE_GETREGS */
+  { 0, 0, 0, -1, -1, NULL, NULL }
+};
+
+struct linux_target_ops the_low_target = {
+  nios2_arch_setup,
+  nios2_num_regs,
+  nios2_regmap,
+  NULL,
+  nios2_cannot_fetch_register,
+  nios2_cannot_store_register,
+  NULL,
+  nios2_get_pc,
+  nios2_set_pc,
+  (const unsigned char *) &nios2_breakpoint,
+  nios2_breakpoint_len,
+  nios2_reinsert_addr,
+  0,
+  nios2_breakpoint_at,
+};

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/4] Nios II gdbserver support
  2013-04-22 13:31 [patch 3/4] Nios II gdbserver support Sandra Loosemore
@ 2013-04-23  2:45 ` Joseph S. Myers
  2013-04-23  9:33   ` Sandra Loosemore
       [not found] ` <20130426064547.GQ3525@adacore.com>
  1 sibling, 1 reply; 8+ messages in thread
From: Joseph S. Myers @ 2013-04-23  2:45 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: gdb-patches

On Sun, 21 Apr 2013, Sandra Loosemore wrote:

> +   Copyright (C) 2008, 2012, 2013
> +   Free Software Foundation, Inc.

GDB now uses copyright year ranges, so

   Copyright (C) 2008-2013 Free Software Foundation, Inc.

(all on one line) and likewise for any other new files in this patch 
series.

> +#ifndef PTRACE_GET_THREAD_AREA
> +#define PTRACE_GET_THREAD_AREA 25
> +#endif

The same comment I made on the AArch64 port applies here: for native code 
in new ports, as opposed to use of new definitions in existing ports, you 
should just be able to assume recent-enough headers (at least until the 
Linux kernel port goes upstream, at which point the first upstream release 
with the code can be the minimum version of kernel headers supported) 
rather than having such #if conditionals.

-- 
Joseph S. Myers
joseph@codesourcery.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/4] Nios II gdbserver support
  2013-04-23  2:45 ` Joseph S. Myers
@ 2013-04-23  9:33   ` Sandra Loosemore
  2013-04-24  0:00     ` Joseph S. Myers
  0 siblings, 1 reply; 8+ messages in thread
From: Sandra Loosemore @ 2013-04-23  9:33 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gdb-patches

On 04/22/2013 03:05 PM, Joseph S. Myers wrote:
> On Sun, 21 Apr 2013, Sandra Loosemore wrote:
>
>> +   Copyright (C) 2008, 2012, 2013
>> +   Free Software Foundation, Inc.
>
> GDB now uses copyright year ranges, so
>
>     Copyright (C) 2008-2013 Free Software Foundation, Inc.
>
> (all on one line) and likewise for any other new files in this patch
> series.

Hmmm, I thought the year range was only acceptable when there were 
actually modifications to the file in all of those years?

>> +#ifndef PTRACE_GET_THREAD_AREA
>> +#define PTRACE_GET_THREAD_AREA 25
>> +#endif
>
> The same comment I made on the AArch64 port applies here: for native code
> in new ports, as opposed to use of new definitions in existing ports, you
> should just be able to assume recent-enough headers (at least until the
> Linux kernel port goes upstream, at which point the first upstream release
> with the code can be the minimum version of kernel headers supported)
> rather than having such #if conditionals.

I'm not sure what change you want here.  If I remove that block of code, 
the file fails to compile with the kernel headers currently being 
provided by Altera, which do not define PTRACE_GET_THREAD_AREA.

-Sandra


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/4] Nios II gdbserver support
  2013-04-23  9:33   ` Sandra Loosemore
@ 2013-04-24  0:00     ` Joseph S. Myers
  0 siblings, 0 replies; 8+ messages in thread
From: Joseph S. Myers @ 2013-04-24  0:00 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: gdb-patches

On Mon, 22 Apr 2013, Sandra Loosemore wrote:

> >     Copyright (C) 2008-2013 Free Software Foundation, Inc.
> > 
> > (all on one line) and likewise for any other new files in this patch
> > series.
> 
> Hmmm, I thought the year range was only acceptable when there were actually
> modifications to the file in all of those years?

No, modifications to the package as a whole (presuming it had public 
version control, or a public release, for each year in question), not to 
the individual file.

> > > +#ifndef PTRACE_GET_THREAD_AREA
> > > +#define PTRACE_GET_THREAD_AREA 25
> > > +#endif
> > 
> > The same comment I made on the AArch64 port applies here: for native code
> > in new ports, as opposed to use of new definitions in existing ports, you
> > should just be able to assume recent-enough headers (at least until the
> > Linux kernel port goes upstream, at which point the first upstream release
> > with the code can be the minimum version of kernel headers supported)
> > rather than having such #if conditionals.
> 
> I'm not sure what change you want here.  If I remove that block of code, the
> file fails to compile with the kernel headers currently being provided by
> Altera, which do not define PTRACE_GET_THREAD_AREA.

That sounds like the kernel headers need to be fixed before the kernel 
port goes upstream, at which point GDB can depend on the first kernel 
version to go upstream rather than allowing for old kernel header versions 
(which will be ABI-incompatible with the upstream version anyway because 
of not using the generic syscall ABI).

-- 
Joseph S. Myers
joseph@codesourcery.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/4] Nios II gdbserver support, version 2
       [not found] ` <20130426064547.GQ3525@adacore.com>
@ 2013-05-03  3:45   ` Sandra Loosemore
  2013-05-03 18:09     ` Pedro Alves
  0 siblings, 1 reply; 8+ messages in thread
From: Sandra Loosemore @ 2013-05-03  3:45 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker, Pedro Alves

[-- Attachment #1: Type: text/plain, Size: 333 bytes --]

Here is a revised version of the gdbserver parts of the Nios II port. 
I've tweaked the copyright dates, comments, and formatting similarly to 
what I did to the GDB-side patches.  I also made a few cleanups to the 
register-handling code to be consistent with the technical changes I 
made on the GDB side.

OK to commit?

-Sandra


[-- Attachment #2: gdb2-3.log --]
[-- Type: text/x-log, Size: 307 bytes --]

2013-05-02  Sandra Loosemore  <sandra@codesourcery.com>
	    Andrew Jenner  <andrew@codesourcery.com>

	gdb/gdbserver/
	* Makefile.in (SFILES): Add linux-nios2-low.c.
	(clean): Add action to delete nios2-linux.c.
	(nios2-linux.c): New rule.
	* configure.srv: Add nios2*-*-linux*.
	* linux-nios2-low.c: New.

[-- Attachment #3: gdb2-3.patch --]
[-- Type: text/x-patch, Size: 8824 bytes --]

Index: gdb/gdbserver/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v
retrieving revision 1.150
diff -u -p -r1.150 Makefile.in
--- gdb/gdbserver/Makefile.in	22 Apr 2013 16:46:15 -0000	1.150
+++ gdb/gdbserver/Makefile.in	2 May 2013 23:00:10 -0000
@@ -143,6 +143,7 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/
 	$(srcdir)/linux-ia64-low.c $(srcdir)/linux-low.c \
 	$(srcdir)/linux-m32r-low.c \
 	$(srcdir)/linux-m68k-low.c $(srcdir)/linux-mips-low.c \
+	$(srcdir)/linux-nios2-low.c \
 	$(srcdir)/linux-ppc-low.c \
 	$(srcdir)/linux-s390-low.c \
 	$(srcdir)/linux-sh-low.c $(srcdir)/linux-sparc-low.c \
@@ -323,6 +324,7 @@ clean:
 	rm -f arm-with-iwmmxt.c
 	rm -f arm-with-vfpv2.c arm-with-vfpv3.c arm-with-neon.c
 	rm -f mips-linux.c mips64-linux.c
+	rm -f nios2-linux.c
 	rm -f powerpc-32.c powerpc-32l.c powerpc-64l.c powerpc-e500l.c
 	rm -f powerpc-altivec32l.c powerpc-cell32l.c powerpc-vsx32l.c
 	rm -f powerpc-altivec64l.c powerpc-cell64l.c powerpc-vsx64l.c
@@ -613,6 +615,8 @@ mips64-linux.c : $(srcdir)/../regformats
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/mips64-linux.dat mips64-linux.c
 mips64-dsp-linux.c : $(srcdir)/../regformats/mips64-dsp-linux.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/mips64-dsp-linux.dat mips64-dsp-linux.c
+nios2-linux.c :	$(srcdir)/../regformats/nios2-linux.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/nios2-linux.dat nios2-linux.c
 powerpc-32.c : $(srcdir)/../regformats/rs6000/powerpc-32.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/rs6000/powerpc-32.dat powerpc-32.c
 powerpc-32l.c : $(srcdir)/../regformats/rs6000/powerpc-32l.dat $(regdat_sh)
Index: gdb/gdbserver/configure.srv
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.srv,v
retrieving revision 1.74
diff -u -p -r1.74 configure.srv
--- gdb/gdbserver/configure.srv	11 Mar 2013 08:35:11 -0000	1.74
+++ gdb/gdbserver/configure.srv	2 May 2013 23:00:10 -0000
@@ -201,6 +201,15 @@ case "${target}" in
 			srv_linux_usrregs=yes
 			srv_linux_thread_db=yes
 			;;
+  nios2*-*-linux*)	srv_regobj="nios2-linux.o"
+			srv_tgtobj="linux-low.o linux-osdata.o linux-nios2-low.o linux-procfs.o"
+			srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
+			srv_xmlfiles="nios2-linux.xml"
+			srv_xmlfiles="${srv_xmlfiles} nios2-cpu.xml"
+			srv_linux_regsets=yes
+			srv_linux_usrregs=yes
+			srv_linux_thread_db=yes
+			;;
   powerpc*-*-linux*)	srv_regobj="powerpc-32l.o"
 			srv_regobj="${srv_regobj} powerpc-altivec32l.o"
 			srv_regobj="${srv_regobj} powerpc-cell32l.o"
Index: gdb/gdbserver/linux-nios2-low.c
===================================================================
RCS file: gdb/gdbserver/linux-nios2-low.c
diff -N gdb/gdbserver/linux-nios2-low.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/gdbserver/linux-nios2-low.c	2 May 2013 23:00:10 -0000
@@ -0,0 +1,230 @@
+/* GNU/Linux/Nios II specific low level interface, for the remote server for
+   GDB.
+   Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+   Contributed by Mentor Graphics, 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 <http://www.gnu.org/licenses/>.  */
+
+#include "server.h"
+#include "linux-low.h"
+#include <sys/ptrace.h>
+#include <endian.h>
+#include "gdb_proc_service.h"
+#include <asm/ptrace.h>
+
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+
+/* The following definition must agree with the number of registers
+   defined in "struct user_regs" in GLIBC
+   (ports/sysdeps/unix/sysv/linux/nios2/sys/user.h), and also with
+   NIOS2_NUM_REGS in GDB proper.  */
+
+#define nios2_num_regs 49
+
+/* Defined in auto-generated file nios2-linux.c.  */
+
+void init_registers_nios2_linux (void);
+
+/* This union is used to convert between int and byte buffer
+   representations of register contents.  */
+
+union nios2_register
+{
+  unsigned char buf[4];
+  int reg32;
+};
+
+/* Return the ptrace ``address'' of register REGNO. */
+
+static int nios2_regmap[] = {
+  -1,  1,  2,  3,  4,  5,  6,  7,
+  8,  9,  10, 11, 12, 13, 14, 15,
+  16, 17, 18, 19, 20, 21, 22, 23,
+  24, 25, 26, 27, 28, 29, 30, 31,
+  32, 33, 34, 35, 36, 37, 38, 39,
+  40, 41, 42, 43, 44, 45, 46, 47,
+  48,
+  0
+};
+
+/* Implement the arch_setup linux_target_ops method.  */
+
+static void
+nios2_arch_setup (void)
+{
+  init_registers_nios2_linux ();
+}
+
+/* Implement the cannot_fetch_register linux_target_ops method.  */
+
+static int
+nios2_cannot_fetch_register (int regno)
+{
+  if (nios2_regmap[regno] == -1)
+    return 1;
+
+  return 0;
+}
+
+/* Implement the cannot_store_register linux_target_ops method.  */
+
+static int
+nios2_cannot_store_register (int regno)
+{
+  if (nios2_regmap[regno] == -1)
+    return 1;
+
+  return 0;
+}
+
+/* Implement the get_pc linux_target_ops method.  */
+
+static CORE_ADDR
+nios2_get_pc (struct regcache *regcache)
+{
+  union nios2_register pc;
+  collect_register_by_name (regcache, "pc", pc.buf);
+  return pc.reg32;
+}
+
+/* Implement the set_pc linux_target_ops method.  */
+
+static void
+nios2_set_pc (struct regcache *regcache, CORE_ADDR pc)
+{
+  union nios2_register newpc;
+  newpc.reg32 = pc;
+  supply_register_by_name (regcache, "pc", newpc.buf);
+}
+
+/* Breakpoint support.  */
+
+static const unsigned int nios2_breakpoint = 0x003b6ffa;
+#define nios2_breakpoint_len 4
+
+/* Implement the breakpoint_reinsert_addr linux_target_ops method.  */
+
+static CORE_ADDR
+nios2_reinsert_addr (void)
+{
+  union nios2_register ra;
+  struct regcache *regcache = get_thread_regcache (current_inferior, 1);
+
+  collect_register_by_name (regcache, "ra", ra.buf);
+  return ra.reg32;
+}
+
+/* Implement the breakpoint_at linux_target_ops method.  */
+
+static int
+nios2_breakpoint_at (CORE_ADDR where)
+{
+  unsigned int insn;
+
+  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  if (insn == nios2_breakpoint)
+    return 1;
+  return 0;
+}
+
+/* Fetch the thread-local storage pointer for libthread_db.  */
+
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+                    lwpid_t lwpid, int idx, void **base)
+{
+  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+    return PS_ERR;
+
+  /* IDX is the bias from the thread pointer to the beginning of the
+     thread descriptor.  It has to be subtracted due to implementation
+     quirks in libthread_db.  */
+  *base = (void *) ((char *)*base - idx);
+
+  return PS_OK;
+}
+
+#ifdef HAVE_PTRACE_GETREGS
+
+/* Helper functions to collect/supply a single register REGNO.  */
+
+static void
+nios2_collect_register (struct regcache *regcache, int regno,
+			union nios2_register *reg)
+{
+  union nios2_register tmp_reg;
+
+  collect_register (regcache, regno, &tmp_reg.reg32);
+  reg->reg32 = tmp_reg.reg32;
+}
+
+static void
+nios2_supply_register (struct regcache *regcache, int regno,
+		       const union nios2_register *reg)
+{
+  supply_register (regcache, regno, reg->buf);
+}
+
+/* We have only a single register set on Nios II.  */
+
+static void
+nios2_fill_gregset (struct regcache *regcache, void *buf)
+{
+  union nios2_register *regset = buf;
+  int i;
+
+  for (i = 1; i < nios2_num_regs; i++)
+    nios2_collect_register (regcache, i, regset + i);
+}
+
+static void
+nios2_store_gregset (struct regcache *regcache, const void *buf)
+{
+  const union nios2_register *regset = buf;
+  int i;
+
+  for (i = 0; i < nios2_num_regs; i++)
+    nios2_supply_register (regcache, i, regset + i);
+}
+#endif /* HAVE_PTRACE_GETREGS */
+
+struct regset_info target_regsets[] = {
+#ifdef HAVE_PTRACE_GETREGS
+  { PTRACE_GETREGS, PTRACE_SETREGS, 0, nios2_num_regs * 4, GENERAL_REGS,
+    nios2_fill_gregset, nios2_store_gregset },
+#endif /* HAVE_PTRACE_GETREGS */
+  { 0, 0, 0, -1, -1, NULL, NULL }
+};
+
+struct linux_target_ops the_low_target = {
+  nios2_arch_setup,
+  nios2_num_regs,
+  nios2_regmap,
+  NULL,
+  nios2_cannot_fetch_register,
+  nios2_cannot_store_register,
+  NULL,
+  nios2_get_pc,
+  nios2_set_pc,
+  (const unsigned char *) &nios2_breakpoint,
+  nios2_breakpoint_len,
+  nios2_reinsert_addr,
+  0,
+  nios2_breakpoint_at,
+};

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/4] Nios II gdbserver support, version 2
  2013-05-03  3:45   ` [patch 3/4] Nios II gdbserver support, version 2 Sandra Loosemore
@ 2013-05-03 18:09     ` Pedro Alves
  2013-05-05  2:16       ` [patch 3/4] Nios II gdbserver support, version 3 Sandra Loosemore
  0 siblings, 1 reply; 8+ messages in thread
From: Pedro Alves @ 2013-05-03 18:09 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: gdb-patches, Joel Brobecker

On 05/03/2013 04:45 AM, Sandra Loosemore wrote:
> Here is a revised version of the gdbserver parts of the Nios II port. I've tweaked the copyright dates, comments, and formatting similarly to what I did to the GDB-side patches.  I also made a few cleanups to the register-handling code to be consistent with the technical changes I made on the GDB side.
> 
> OK to commit?

Okay with nits below addressed.

> +static CORE_ADDR
> +nios2_get_pc (struct regcache *regcache)
> +{
> +  union nios2_register pc;

Could you add an empty line after declarations (throughout),
please?

> +ps_err_e
> +ps_get_thread_area (const struct ps_prochandle *ph,
> +                    lwpid_t lwpid, int idx, void **base)
> +{
> +  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
> +    return PS_ERR;
> +
> +  /* IDX is the bias from the thread pointer to the beginning of the
> +     thread descriptor.  It has to be subtracted due to implementation
> +     quirks in libthread_db.  */
> +  *base = (void *) ((char *)*base - idx);

Missing space: '(char *) *base'

> +struct regset_info target_regsets[] = {

Put { on next line.

> +struct linux_target_ops the_low_target = {

Ditto.

Thanks,
-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/4] Nios II gdbserver support, version 3
  2013-05-03 18:09     ` Pedro Alves
@ 2013-05-05  2:16       ` Sandra Loosemore
  2013-05-06  9:15         ` Pedro Alves
  0 siblings, 1 reply; 8+ messages in thread
From: Sandra Loosemore @ 2013-05-05  2:16 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches, Joel Brobecker

[-- Attachment #1: Type: text/plain, Size: 153 bytes --]

On 05/03/2013 12:09 PM, Pedro Alves wrote:
>
> Okay with nits below addressed.
> [snip]

All fixed, I think.  Is the third time the charm?  :-)

-Sandra

[-- Attachment #2: gdb3-3.log --]
[-- Type: text/x-log, Size: 307 bytes --]

2013-05-04  Sandra Loosemore  <sandra@codesourcery.com>
	    Andrew Jenner  <andrew@codesourcery.com>

	gdb/gdbserver/
	* Makefile.in (SFILES): Add linux-nios2-low.c.
	(clean): Add action to delete nios2-linux.c.
	(nios2-linux.c): New rule.
	* configure.srv: Add nios2*-*-linux*.
	* linux-nios2-low.c: New.

[-- Attachment #3: gdb3-3.patch --]
[-- Type: text/x-patch, Size: 8831 bytes --]

Index: gdb/gdbserver/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v
retrieving revision 1.150
diff -u -p -r1.150 Makefile.in
--- gdb/gdbserver/Makefile.in	22 Apr 2013 16:46:15 -0000	1.150
+++ gdb/gdbserver/Makefile.in	5 May 2013 02:00:15 -0000
@@ -143,6 +143,7 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/
 	$(srcdir)/linux-ia64-low.c $(srcdir)/linux-low.c \
 	$(srcdir)/linux-m32r-low.c \
 	$(srcdir)/linux-m68k-low.c $(srcdir)/linux-mips-low.c \
+	$(srcdir)/linux-nios2-low.c \
 	$(srcdir)/linux-ppc-low.c \
 	$(srcdir)/linux-s390-low.c \
 	$(srcdir)/linux-sh-low.c $(srcdir)/linux-sparc-low.c \
@@ -323,6 +324,7 @@ clean:
 	rm -f arm-with-iwmmxt.c
 	rm -f arm-with-vfpv2.c arm-with-vfpv3.c arm-with-neon.c
 	rm -f mips-linux.c mips64-linux.c
+	rm -f nios2-linux.c
 	rm -f powerpc-32.c powerpc-32l.c powerpc-64l.c powerpc-e500l.c
 	rm -f powerpc-altivec32l.c powerpc-cell32l.c powerpc-vsx32l.c
 	rm -f powerpc-altivec64l.c powerpc-cell64l.c powerpc-vsx64l.c
@@ -613,6 +615,8 @@ mips64-linux.c : $(srcdir)/../regformats
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/mips64-linux.dat mips64-linux.c
 mips64-dsp-linux.c : $(srcdir)/../regformats/mips64-dsp-linux.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/mips64-dsp-linux.dat mips64-dsp-linux.c
+nios2-linux.c :	$(srcdir)/../regformats/nios2-linux.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/nios2-linux.dat nios2-linux.c
 powerpc-32.c : $(srcdir)/../regformats/rs6000/powerpc-32.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/rs6000/powerpc-32.dat powerpc-32.c
 powerpc-32l.c : $(srcdir)/../regformats/rs6000/powerpc-32l.dat $(regdat_sh)
Index: gdb/gdbserver/configure.srv
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.srv,v
retrieving revision 1.74
diff -u -p -r1.74 configure.srv
--- gdb/gdbserver/configure.srv	11 Mar 2013 08:35:11 -0000	1.74
+++ gdb/gdbserver/configure.srv	5 May 2013 02:00:15 -0000
@@ -201,6 +201,15 @@ case "${target}" in
 			srv_linux_usrregs=yes
 			srv_linux_thread_db=yes
 			;;
+  nios2*-*-linux*)	srv_regobj="nios2-linux.o"
+			srv_tgtobj="linux-low.o linux-osdata.o linux-nios2-low.o linux-procfs.o"
+			srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
+			srv_xmlfiles="nios2-linux.xml"
+			srv_xmlfiles="${srv_xmlfiles} nios2-cpu.xml"
+			srv_linux_regsets=yes
+			srv_linux_usrregs=yes
+			srv_linux_thread_db=yes
+			;;
   powerpc*-*-linux*)	srv_regobj="powerpc-32l.o"
 			srv_regobj="${srv_regobj} powerpc-altivec32l.o"
 			srv_regobj="${srv_regobj} powerpc-cell32l.o"
Index: gdb/gdbserver/linux-nios2-low.c
===================================================================
RCS file: gdb/gdbserver/linux-nios2-low.c
diff -N gdb/gdbserver/linux-nios2-low.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gdb/gdbserver/linux-nios2-low.c	5 May 2013 02:00:15 -0000
@@ -0,0 +1,234 @@
+/* GNU/Linux/Nios II specific low level interface, for the remote server for
+   GDB.
+   Copyright (C) 2008-2013 Free Software Foundation, Inc.
+
+   Contributed by Mentor Graphics, 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 <http://www.gnu.org/licenses/>.  */
+
+#include "server.h"
+#include "linux-low.h"
+#include <sys/ptrace.h>
+#include <endian.h>
+#include "gdb_proc_service.h"
+#include <asm/ptrace.h>
+
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+
+/* The following definition must agree with the number of registers
+   defined in "struct user_regs" in GLIBC
+   (ports/sysdeps/unix/sysv/linux/nios2/sys/user.h), and also with
+   NIOS2_NUM_REGS in GDB proper.  */
+
+#define nios2_num_regs 49
+
+/* Defined in auto-generated file nios2-linux.c.  */
+
+void init_registers_nios2_linux (void);
+
+/* This union is used to convert between int and byte buffer
+   representations of register contents.  */
+
+union nios2_register
+{
+  unsigned char buf[4];
+  int reg32;
+};
+
+/* Return the ptrace ``address'' of register REGNO. */
+
+static int nios2_regmap[] = {
+  -1,  1,  2,  3,  4,  5,  6,  7,
+  8,  9,  10, 11, 12, 13, 14, 15,
+  16, 17, 18, 19, 20, 21, 22, 23,
+  24, 25, 26, 27, 28, 29, 30, 31,
+  32, 33, 34, 35, 36, 37, 38, 39,
+  40, 41, 42, 43, 44, 45, 46, 47,
+  48,
+  0
+};
+
+/* Implement the arch_setup linux_target_ops method.  */
+
+static void
+nios2_arch_setup (void)
+{
+  init_registers_nios2_linux ();
+}
+
+/* Implement the cannot_fetch_register linux_target_ops method.  */
+
+static int
+nios2_cannot_fetch_register (int regno)
+{
+  if (nios2_regmap[regno] == -1)
+    return 1;
+
+  return 0;
+}
+
+/* Implement the cannot_store_register linux_target_ops method.  */
+
+static int
+nios2_cannot_store_register (int regno)
+{
+  if (nios2_regmap[regno] == -1)
+    return 1;
+
+  return 0;
+}
+
+/* Implement the get_pc linux_target_ops method.  */
+
+static CORE_ADDR
+nios2_get_pc (struct regcache *regcache)
+{
+  union nios2_register pc;
+
+  collect_register_by_name (regcache, "pc", pc.buf);
+  return pc.reg32;
+}
+
+/* Implement the set_pc linux_target_ops method.  */
+
+static void
+nios2_set_pc (struct regcache *regcache, CORE_ADDR pc)
+{
+  union nios2_register newpc;
+
+  newpc.reg32 = pc;
+  supply_register_by_name (regcache, "pc", newpc.buf);
+}
+
+/* Breakpoint support.  */
+
+static const unsigned int nios2_breakpoint = 0x003b6ffa;
+#define nios2_breakpoint_len 4
+
+/* Implement the breakpoint_reinsert_addr linux_target_ops method.  */
+
+static CORE_ADDR
+nios2_reinsert_addr (void)
+{
+  union nios2_register ra;
+  struct regcache *regcache = get_thread_regcache (current_inferior, 1);
+
+  collect_register_by_name (regcache, "ra", ra.buf);
+  return ra.reg32;
+}
+
+/* Implement the breakpoint_at linux_target_ops method.  */
+
+static int
+nios2_breakpoint_at (CORE_ADDR where)
+{
+  unsigned int insn;
+
+  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  if (insn == nios2_breakpoint)
+    return 1;
+  return 0;
+}
+
+/* Fetch the thread-local storage pointer for libthread_db.  */
+
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+                    lwpid_t lwpid, int idx, void **base)
+{
+  if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0)
+    return PS_ERR;
+
+  /* IDX is the bias from the thread pointer to the beginning of the
+     thread descriptor.  It has to be subtracted due to implementation
+     quirks in libthread_db.  */
+  *base = (void *) ((char *) *base - idx);
+
+  return PS_OK;
+}
+
+#ifdef HAVE_PTRACE_GETREGS
+
+/* Helper functions to collect/supply a single register REGNO.  */
+
+static void
+nios2_collect_register (struct regcache *regcache, int regno,
+			union nios2_register *reg)
+{
+  union nios2_register tmp_reg;
+
+  collect_register (regcache, regno, &tmp_reg.reg32);
+  reg->reg32 = tmp_reg.reg32;
+}
+
+static void
+nios2_supply_register (struct regcache *regcache, int regno,
+		       const union nios2_register *reg)
+{
+  supply_register (regcache, regno, reg->buf);
+}
+
+/* We have only a single register set on Nios II.  */
+
+static void
+nios2_fill_gregset (struct regcache *regcache, void *buf)
+{
+  union nios2_register *regset = buf;
+  int i;
+
+  for (i = 1; i < nios2_num_regs; i++)
+    nios2_collect_register (regcache, i, regset + i);
+}
+
+static void
+nios2_store_gregset (struct regcache *regcache, const void *buf)
+{
+  const union nios2_register *regset = buf;
+  int i;
+
+  for (i = 0; i < nios2_num_regs; i++)
+    nios2_supply_register (regcache, i, regset + i);
+}
+#endif /* HAVE_PTRACE_GETREGS */
+
+struct regset_info target_regsets[] =
+{
+#ifdef HAVE_PTRACE_GETREGS
+  { PTRACE_GETREGS, PTRACE_SETREGS, 0, nios2_num_regs * 4, GENERAL_REGS,
+    nios2_fill_gregset, nios2_store_gregset },
+#endif /* HAVE_PTRACE_GETREGS */
+  { 0, 0, 0, -1, -1, NULL, NULL }
+};
+
+struct linux_target_ops the_low_target =
+{
+  nios2_arch_setup,
+  nios2_num_regs,
+  nios2_regmap,
+  NULL,
+  nios2_cannot_fetch_register,
+  nios2_cannot_store_register,
+  NULL,
+  nios2_get_pc,
+  nios2_set_pc,
+  (const unsigned char *) &nios2_breakpoint,
+  nios2_breakpoint_len,
+  nios2_reinsert_addr,
+  0,
+  nios2_breakpoint_at,
+};

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch 3/4] Nios II gdbserver support, version 3
  2013-05-05  2:16       ` [patch 3/4] Nios II gdbserver support, version 3 Sandra Loosemore
@ 2013-05-06  9:15         ` Pedro Alves
  0 siblings, 0 replies; 8+ messages in thread
From: Pedro Alves @ 2013-05-06  9:15 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: gdb-patches, Joel Brobecker

On 05/05/2013 03:16 AM, Sandra Loosemore wrote:
> On 05/03/2013 12:09 PM, Pedro Alves wrote:
>>
>> Okay with nits below addressed.
>> [snip]
> 
> All fixed, I think.  Is the third time the charm?  :-)

Yep.  :-)

OK.

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-05-06  9:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-22 13:31 [patch 3/4] Nios II gdbserver support Sandra Loosemore
2013-04-23  2:45 ` Joseph S. Myers
2013-04-23  9:33   ` Sandra Loosemore
2013-04-24  0:00     ` Joseph S. Myers
     [not found] ` <20130426064547.GQ3525@adacore.com>
2013-05-03  3:45   ` [patch 3/4] Nios II gdbserver support, version 2 Sandra Loosemore
2013-05-03 18:09     ` Pedro Alves
2013-05-05  2:16       ` [patch 3/4] Nios II gdbserver support, version 3 Sandra Loosemore
2013-05-06  9:15         ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox