This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 4/5] New port: CR16: gdbserver
- From: Kaushik Phatak <Kaushik dot Phatak at kpitcummins dot com>
- To: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Thu, 4 Oct 2012 10:23:00 +0000
- Subject: [RFA 4/5] New port: CR16: gdbserver
Hi,
This patch adds gdbserver support for the National Semiconductor cr16 target.
This currently still has a limitation related to -fPIC usage and global variables.
However, I am hoping that major portions of this patch which have been tested
and are working well get accepted here.
Regards,
Kaushik
2012-10-04 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.
* linux-low.c (PT_TEXT_ADDR, PT_DATA_ADDR, PT_TEXT_END_ADDR): Define.
diff -uprN gdb-7.5/gdb/gdbserver/configure.srv ./gdb-7.5_working/gdb/gdbserver/configure.srv
--- gdb-7.5/gdb/gdbserver/configure.srv 2012-05-31 01:13:15.000000000 +0530
+++ ./gdb-7.5_working/gdb/gdbserver/configure.srv 2012-10-04 14:18:33.000000000 +0530
@@ -74,6 +74,11 @@ case "${target}" in
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"
diff -uprN gdb-7.5/gdb/gdbserver/linux-cr16-low.c ./gdb-7.5_working/gdb/gdbserver/linux-cr16-low.c
--- gdb-7.5/gdb/gdbserver/linux-cr16-low.c 1970-01-01 05:30:00.000000000 +0530
+++ ./gdb-7.5_working/gdb/gdbserver/linux-cr16-low.c 2012-10-01 15:28:08.000000000 +0530
@@ -0,0 +1,159 @@
+/* GNU/Linux/CR16 specific low level interface, for the remote server for GDB.
+
+ Copyright (C) 2010-2012 Free Software Foundation, Inc.
+ Contributed by Kaushik Phatak (kaushik.pahatk@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);
+
+/* CR16C */
+/* Locations need to match <include/asm/arch/ptrace.h>. */
+#define cr16_num_regs 16
+#define PC_REGNUM 11
+
+static int cr16_regmap[] = {
+ 0, 4, 8, 12,
+ 16, 20, 24, 28,
+ 32, 36, 40, 44,
+ 48, 52, 56, 60
+};
+
+extern int debug_threads;
+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;
+ 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;
+}
+struct linux_target_ops the_low_target = {
+ init_registers_cr16,
+ cr16_num_regs,
+ cr16_regmap,
+ NULL,
+ 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,
+};
diff -uprN gdb-7.5/gdb/gdbserver/linux-low.c ./gdb-7.5_working/gdb/gdbserver/linux-low.c
--- gdb-7.5/gdb/gdbserver/linux-low.c 2012-07-07 17:43:57.000000000 +0530
+++ ./gdb-7.5_working/gdb/gdbserver/linux-low.c 2012-10-01 16:21:48.000000000 +0530
@@ -4809,7 +4810,7 @@ linux_stopped_data_address (void)
#if ! (defined(PT_TEXT_ADDR) \
|| defined(PT_DATA_ADDR) \
|| defined(PT_TEXT_END_ADDR))
-#if defined(__mcoldfire__)
+#if defined(__mcoldfire__) || (__CR16__)
/* These should really be defined in the kernel's ptrace.h header. */
#define PT_TEXT_ADDR 49*4
#define PT_DATA_ADDR 50*4
diff -uprN gdb-7.5/gdb/gdbserver/Makefile.in ./gdb-7.5_working/gdb/gdbserver/Makefile.in
--- gdb-7.5/gdb/gdbserver/Makefile.in 2012-07-02 20:59:38.000000000 +0530
+++ ./gdb-7.5_working/gdb/gdbserver/Makefile.in 2012-09-13 14:42:51.000000000 +0530
@@ -126,6 +126,7 @@ SFILES= $(srcdir)/gdbreplay.c $(srcdir)/
$(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 \
@@ -307,7 +308,7 @@ clean:
rm -f $(IPA_LIB)
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-cris.c reg-cr16.c reg-crisv32.c amd64-linux.c reg-xtensa.c
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
@@ -546,6 +547,7 @@ linux-low.o: linux-low.c $(linux_low_h)
linux-arm-low.o: linux-arm-low.c $(linux_low_h) $(server_h) \
$(gdb_proc_service_h)
linux-bfin-low.o: linux-bfin-low.c $(linux_low_h) $(server_h)
+linux-cr16-low.o: linux-cr16-low.c $(linux_low_h) $(server_h)
linux-cris-low.o: linux-cris-low.c $(linux_low_h) $(server_h)
linux-crisv32-low.o: linux-crisv32-low.c $(linux_low_h) $(server_h)
linux-ia64-low.o: linux-ia64-low.c $(linux_low_h) $(server_h)
@@ -593,6 +595,9 @@ arm-with-neon.c : $(srcdir)/../regformat
reg-bfin.o : reg-bfin.c $(regdef_h)
reg-bfin.c : $(srcdir)/../regformats/reg-bfin.dat $(regdat_sh)
$(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-bfin.dat reg-bfin.c
+reg-cr16.o : reg-cr16.c $(regdef_h)
+reg-cr16.c : $(srcdir)/../regformats/reg-cr16.dat $(regdat_sh)
+ $(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-cr16.dat reg-cr16.c
reg-cris.o : reg-cris.c $(regdef_h)
reg-cris.c : $(srcdir)/../regformats/reg-cris.dat $(regdat_sh)
$(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-cris.dat reg-cris.c
diff -uprN gdb-7.5/gdb/regformats/reg-cr16.dat ./gdb-7.5_working/gdb/regformats/reg-cr16.dat
--- gdb-7.5/gdb/regformats/reg-cr16.dat 1970-01-01 05:30:00.000000000 +0530
+++ ./gdb-7.5_working/gdb/regformats/reg-cr16.dat 2012-09-13 14:45:02.000000000 +0530
@@ -0,0 +1,18 @@
+name:cr16
+expedite:psr
+32:r0and1
+32:r2and3
+32:r4and5
+32:r6and7
+32:r8and9
+32:r10and11
+32:r12
+32:r13
+32:ra
+16:psr
+16:pad
+32:pc
+32:orig_r0and1
+32:intbase
+32:usp
+32:cfg