Re: [PATCH v2 5/5] target/tricore: Implement gdbstub

2020-05-29 Thread Alex Bennée


Bastian Koppelmann  writes:

> Signed-off-by: Bastian Koppelmann 

Acked-by: Alex Bennée 

-- 
Alex Bennée



[PATCH v2 5/5] target/tricore: Implement gdbstub

2020-05-29 Thread Bastian Koppelmann
Signed-off-by: Bastian Koppelmann 
---
v1 -> v2:
  - tricore_cpu_gdb_read_registers uses a GByteArray pointer for the mem_buf
argument

 target/tricore/Makefile.objs |   2 +-
 target/tricore/cpu.c |  10 +++
 target/tricore/cpu.h |   2 +
 target/tricore/gdbstub.c | 139 +++
 4 files changed, 152 insertions(+), 1 deletion(-)
 create mode 100644 target/tricore/gdbstub.c

diff --git a/target/tricore/Makefile.objs b/target/tricore/Makefile.objs
index 7a05670718..281b55f08d 100644
--- a/target/tricore/Makefile.objs
+++ b/target/tricore/Makefile.objs
@@ -1 +1 @@
-obj-y += translate.o helper.o cpu.o op_helper.o fpu_helper.o
+obj-y += translate.o helper.o cpu.o op_helper.o fpu_helper.o gdbstub.o
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index c8c1e9e7d5..2f2e5b029f 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -28,6 +28,11 @@ static inline void set_feature(CPUTriCoreState *env, int 
feature)
 env->features |= 1ULL << feature;
 }
 
+static gchar *tricore_gdb_arch_name(CPUState *cs)
+{
+return g_strdup("tricore");
+}
+
 static void tricore_cpu_set_pc(CPUState *cs, vaddr value)
 {
 TriCoreCPU *cpu = TRICORE_CPU(cs);
@@ -150,6 +155,11 @@ static void tricore_cpu_class_init(ObjectClass *c, void 
*data)
 cc->class_by_name = tricore_cpu_class_by_name;
 cc->has_work = tricore_cpu_has_work;
 
+cc->gdb_read_register = tricore_cpu_gdb_read_register;
+cc->gdb_write_register = tricore_cpu_gdb_write_register;
+cc->gdb_num_core_regs = 44;
+cc->gdb_arch_name = tricore_gdb_arch_name;
+
 cc->dump_state = tricore_cpu_dump_state;
 cc->set_pc = tricore_cpu_set_pc;
 cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb;
diff --git a/target/tricore/cpu.h b/target/tricore/cpu.h
index 8c014fad07..b82349d1b1 100644
--- a/target/tricore/cpu.h
+++ b/target/tricore/cpu.h
@@ -353,6 +353,8 @@ enum {
 
 uint32_t psw_read(CPUTriCoreState *env);
 void psw_write(CPUTriCoreState *env, uint32_t val);
+int tricore_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n);
+int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n);
 
 void fpu_set_state(CPUTriCoreState *env);
 
diff --git a/target/tricore/gdbstub.c b/target/tricore/gdbstub.c
new file mode 100644
index 00..0f4e612a04
--- /dev/null
+++ b/target/tricore/gdbstub.c
@@ -0,0 +1,139 @@
+/*
+ * TriCore gdb server stub
+ *
+ * Copyright (c) 2019 Bastian Koppelmann, Paderborn University
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "exec/gdbstub.h"
+
+
+#define LCX_REGNUM 32
+#define FCX_REGNUM 33
+#define PCXI_REGNUM34
+#define TRICORE_PSW_REGNUM 35
+#define TRICORE_PC_REGNUM  36
+#define ICR_REGNUM 37
+#define ISP_REGNUM 38
+#define BTV_REGNUM 39
+#define BIV_REGNUM 40
+#define SYSCON_REGNUM  41
+#define PMUCON0_REGNUM 42
+#define DMUCON_REGNUM  43
+
+static uint32_t tricore_cpu_gdb_read_csfr(CPUTriCoreState *env, int n)
+{
+switch (n) {
+case LCX_REGNUM:
+return env->LCX;
+case FCX_REGNUM:
+return env->FCX;
+case PCXI_REGNUM:
+return env->PCXI;
+case TRICORE_PSW_REGNUM:
+return psw_read(env);
+case TRICORE_PC_REGNUM:
+return env->PC;
+case ICR_REGNUM:
+return env->ICR;
+case ISP_REGNUM:
+return env->ISP;
+case BTV_REGNUM:
+return env->BTV;
+case BIV_REGNUM:
+return env->BIV;
+case SYSCON_REGNUM:
+return env->SYSCON;
+case PMUCON0_REGNUM:
+return 0; /* PMUCON0 */
+case DMUCON_REGNUM:
+return 0; /* DMUCON0 */
+default:
+return 0;
+}
+}
+
+static void tricore_cpu_gdb_write_csfr(CPUTriCoreState *env, int n,
+   uint32_t val)
+{
+switch (n) {
+case LCX_REGNUM:
+env->LCX = val;
+break;
+case FCX_REGNUM:
+env->FCX = val;
+break;
+case PCXI_REGNUM:
+env->PCXI = val;
+break;
+case TRICORE_PSW_REGNUM:
+psw_write(env, val);
+break;
+case TRICORE_PC_REGNUM:
+env->PC = val;
+break;
+case ICR_REGNUM:
+env->ICR = val;
+break;
+case ISP_REGNUM:
+env->ISP =