This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [RFA 4/5] New port: CR16: gdbserver


Hi,
Please find below an updated patch for the gdbserver port of the CR16 target.
This has been updated from my previous attempts of the same,
http://sourceware.org/ml/gdb-patches/2012-10/msg00064.html

The port has been updated based on feedback provided by Pedro in discussions
earlier this year in Jan,
http://sourceware.org/ml/gdb-patches/2013-01/msg00552.html

In addition to the comments, the port has been base-lined against latest sources
which needs the "initialize_low_arch" function.

The below gdbserver port has following changes,
1. Remove register pair access over remote protocol in the .dat file.
This allows for matching of the register numbers in the gdbserver with those
in linux-tdep.c. This was done by simplifying the PTRACE_GETREGS inside kernel
to read single registers.
2. Remove support for "r0r1_orig" register. This is a kernel internal register
and need not be user visible.
3. Set cr16_num_regs to 20 and PC_REGNUM to 16. This will now match the gdb port.
4. Add registers pc,usp,ra to the "expedite" set. 
5. Move the ptrace macro defines like PT_TEXT_ADDR from linux-low.c to the kernel's
ptrace.h

An updated gdb port for the same is also posted for this.

2013-06-19 Kaushik Phatak  <kaushik.phatak@kpitcummins.com>
	gdb/Changelog
	* regformats/reg-cr16.dat: New.

	gdb/gdbserver/Changelog
	* Makefile.in (clean): Remove reg-cr16.c.
	(linux-cr16-low.o, reg-cr16.o): New rules.
	* configure.srv: Add support for cr16-*-uclinux.
	* linux-cr16-low.c: New.

Index: gdb/gdbserver/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/Makefile.in,v
retrieving revision 1.153
diff -u -r1.153 Makefile.in
--- gdb/gdbserver/Makefile.in	7 Jun 2013 10:46:58 -0000	1.153
+++ gdb/gdbserver/Makefile.in	19 Jun 2013 12:05:16 -0000
@@ -138,6 +138,7 @@
 	$(srcdir)/remote-utils.c $(srcdir)/server.c $(srcdir)/target.c \
 	$(srcdir)/thread-db.c $(srcdir)/utils.c \
 	$(srcdir)/linux-arm-low.c $(srcdir)/linux-bfin-low.c \
+	$(srcdir)/linux-cr16-low.c \
 	$(srcdir)/linux-cris-low.c $(srcdir)/linux-crisv32-low.c \
 	${srcdir}/i386-low.c $(srcdir)/i387-fp.c \
 	$(srcdir)/linux-ia64-low.c $(srcdir)/linux-low.c \
@@ -319,7 +320,7 @@
 	rm -f aarch64.c
 	rm -f reg-arm.c reg-bfin.c i386.c reg-ia64.c reg-m32r.c reg-m68k.c
 	rm -f reg-sh.c reg-sparc.c reg-spu.c amd64.c i386-linux.c
-	rm -f reg-cris.c reg-crisv32.c amd64-linux.c reg-xtensa.c
+	rm -f reg-cr16.c reg-cris.c reg-crisv32.c amd64-linux.c reg-xtensa.c
 	rm -f reg-tilegx.c reg-tilegx32.c
 	rm -f arm-with-iwmmxt.c
 	rm -f arm-with-vfpv2.c arm-with-vfpv3.c arm-with-neon.c
@@ -584,6 +585,8 @@
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/arm-with-neon.dat arm-with-neon.c
 reg-bfin.c : $(srcdir)/../regformats/reg-bfin.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-bfin.dat reg-bfin.c
+reg-cr16.c : $(srcdir)/../regformats/reg-cr16.dat $(regdat_sh)
+	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-cr16.dat reg-cr16.c
 reg-cris.c : $(srcdir)/../regformats/reg-cris.dat $(regdat_sh)
 	$(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-cris.dat reg-cris.c
 reg-crisv32.c : $(srcdir)/../regformats/reg-crisv32.dat $(regdat_sh)
Index: gdb/gdbserver/configure.srv
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/configure.srv,v
retrieving revision 1.76
diff -u -r1.76 configure.srv
--- gdb/gdbserver/configure.srv	28 May 2013 10:41:17 -0000	1.76
+++ gdb/gdbserver/configure.srv	19 Jun 2013 12:05:16 -0000
@@ -88,6 +88,11 @@
 			srv_linux_usrregs=yes
 			srv_linux_thread_db=yes
 			;;
+  cr16-*-uclinux)	srv_regobj=reg-cr16.o
+			srv_tgtobj="linux-low.o linux-cr16-low.o"
+			srv_linux_usrregs=yes
+			srv_linux_thread_db=yes
+			;;
   crisv32-*-linux*)	srv_regobj=reg-crisv32.o
 			srv_tgtobj="linux-low.o linux-osdata.o linux-crisv32-low.o linux-procfs.o"
 			srv_tgtobj="${srv_tgtobj} linux-ptrace.o"
Index: gdb/gdbserver/cr16-linux-tdep.c
===================================================================
RCS file: gdb/gdbserver/linux-cr16-tdep.c
diff -N gdb/gdbserver/linux-cr16-tdep.c
--- /dev/null	2013-05-10 19:36:04.372328500 +0530
+++ ./gdb/gdbserver/linux-cr16-low.c	2013-06-19 17:44:04.000000000 +0530
@@ -0,0 +1,190 @@
+/* GNU/Linux/CR16 specific low level interface, for the remote server for GDB.
+
+   Copyright (C) 2012-2013 Free Software Foundation, Inc.
+   Contributed by Kaushik Phatak (kaushik.phatak@kpitcummins.com)
+   KPIT Cummins Infosystems Limited, Pune India. 
+   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>
+
+/* Defined in auto-generated file reg-cr16.c.  */
+void init_registers_cr16 (void);
+extern const struct target_desc *tdesc_cr16;
+
+/* CR16C  */
+#define cr16_num_regs 20
+#define PC_REGNUM 16
+
+/* Locations need to match <include/asm/arch/ptrace.h>.  */
+static int cr16_regmap[] = {
+  0,   2,  4,  6,  8,
+  10, 12, 14, 16, 18,
+  20, 22, 24, 28, 32,
+  36, 40, 44, 48, 52
+};
+
+static int
+cr16_cannot_store_register (int regno)
+{
+  if (cr16_regmap[regno] == -1)
+    return 1;
+
+  return (regno >= cr16_num_regs);
+}
+
+static int
+cr16_cannot_fetch_register (int regno)
+{
+  if (cr16_regmap[regno] == -1)
+    return 1;
+
+  return (regno >= cr16_num_regs);
+}
+
+static void
+cr16_set_pc (struct regcache *regcache, CORE_ADDR pc)
+{
+  unsigned long newpc = pc;
+
+  supply_register_by_name (regcache, "pc", &newpc);
+}
+
+static CORE_ADDR
+cr16_get_pc (struct regcache *regcache)
+{
+  unsigned long pc;
+
+  collect_register_by_name (regcache, "pc", &pc);
+  return pc;
+}
+
+static void
+cr16_collect_ptrace_register (struct regcache *regcache, int regno, char *buf)
+{
+  unsigned long pc;
+   
+  memset (buf, 0, sizeof (long));
+  collect_register_by_name (regcache, "pc", &pc);
+  if (regno == PC_REGNUM)
+    {
+      pc = pc >> 1;
+      cr16_set_pc (regcache, pc);
+    }
+  collect_register (regcache, regno, buf);
+}
+
+static void
+cr16_supply_ptrace_register (struct regcache *regcache,
+			     int regno, const char *buf)
+{
+  unsigned long pc;
+  int size = register_size (regcache->tdesc, regno);
+
+  supply_register (regcache, regno, buf);
+  collect_register_by_name (regcache, "pc", &pc);
+
+  /* For PC, leftshift the output as only top 21 bits are stored
+     This will make the value human readable for the host.  */
+  if (regno == PC_REGNUM)
+    {
+      pc = pc << 1;
+      cr16_set_pc (regcache, pc);
+    }
+}
+
+static const unsigned short cr16_breakpoint = 0xc700;
+#define cr16_breakpoint_len 2
+
+static int
+cr16_breakpoint_at (CORE_ADDR where)
+{
+  unsigned short insn;
+
+  (*the_target->read_memory) (where, (unsigned char *) &insn,
+			      cr16_breakpoint_len);
+  if (insn == cr16_breakpoint)
+    return 1;
+  /* If necessary, recognize more trap instructions here.  GDB only
+     uses the one.  */
+  return 0;
+}
+
+/* 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
+cr16_reinsert_addr (void)
+{
+  struct regcache *regcache = get_thread_regcache (current_inferior, 1);
+  unsigned long pc;
+
+  /* R14/Ra is return address register  */
+  collect_register_by_name (regcache, "ra", &pc);
+  return pc;
+}
+
+static void
+cr16_arch_setup (void)
+{
+  current_process ()->tdesc = tdesc_cr16;
+}
+
+static struct usrregs_info cr16_usrregs_info =
+  {
+    cr16_num_regs,
+    cr16_regmap,
+  };
+
+static struct regs_info regs_info =
+  {
+    NULL, /* regset_bitmap */
+    &cr16_usrregs_info,
+  };
+
+static const struct regs_info *
+cr16_regs_info (void)
+{
+  return &regs_info;
+}
+
+struct linux_target_ops the_low_target = {
+  cr16_arch_setup,
+  cr16_regs_info,
+  cr16_cannot_fetch_register,
+  cr16_cannot_store_register,
+  NULL,
+  cr16_get_pc,
+  cr16_set_pc,
+  (const unsigned char *) &cr16_breakpoint,
+  cr16_breakpoint_len,
+  cr16_reinsert_addr,
+  0,
+  cr16_breakpoint_at,
+  0,
+  0,
+  0,
+  0,
+  cr16_collect_ptrace_register,
+  cr16_supply_ptrace_register
+};
+
+void
+initialize_low_arch (void)
+{
+  init_registers_cr16 ();
+}
Index: gdb/regformats/reg-cr16.dat
===================================================================
RCS file: gdb/regformats/reg-cr16.dat
diff -N gdb/gdbserver/reg-cr16.dat
--- /dev/null	2013-05-10 19:36:04.372328500 +0530
+++ ./gdb/regformats/reg-cr16.dat	2013-06-18 15:10:23.000000000 +0530
@@ -0,0 +1,22 @@
+name:cr16
+expedite:psr,pc,usp,ra
+16:r0
+16:r1
+16:r2
+16:r3
+16:r4
+16:r5
+16:r6
+16:r7
+16:r8
+16:r9
+16:r10
+16:r11
+32:r12
+32:r13
+32:ra
+32:psr
+32:pc
+32:intbase
+32:usp
+32:cfg	

Attachment: cr16_gdbserver.diff
Description: cr16_gdbserver.diff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]