From c7b6b7f8bf31a6387e0bd1eab0d1ac9741999523 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 16 Nov 2020 21:54:23 +0300 Subject: [PATCH] target: e2k: initial gdb support --- linux-user/e2k/cpu_loop.c | 21 +++++++++++++++++ target/e2k/cpu.c | 4 ++++ target/e2k/cpu.h | 2 ++ target/e2k/gdbstub.c | 47 +++++++++++++++++++++++++++++++++++++++ target/e2k/meson.build | 1 + 5 files changed, 75 insertions(+) create mode 100644 target/e2k/gdbstub.c diff --git a/linux-user/e2k/cpu_loop.c b/linux-user/e2k/cpu_loop.c index e2112c7ee1..91ef2d244d 100644 --- a/linux-user/e2k/cpu_loop.c +++ b/linux-user/e2k/cpu_loop.c @@ -66,6 +66,27 @@ void cpu_loop(CPUE2KState *env) env->ip = env->nip; break; } + /* QEMU common interrupts */ + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_DEBUG: + { + target_siginfo_t info; + info.si_signo = TARGET_SIGTRAP; + info.si_errno = 0; + info.si_code = TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + break; + } + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + case EXCP_HLT: + case EXCP_HALTED: + case EXCP_YIELD: + fprintf(stderr, "Unhandled QEMU trap: 0x%x\n", trapnr); + break; default: fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr); cpu_dump_state(cs, stderr, 0); diff --git a/target/e2k/cpu.c b/target/e2k/cpu.c index 876af1dd2d..e6ffd860d4 100644 --- a/target/e2k/cpu.c +++ b/target/e2k/cpu.c @@ -224,6 +224,10 @@ static void e2k_cpu_class_init(ObjectClass *oc, void *data) cc->class_by_name = e2k_cpu_class_by_name; cc->disas_set_info = cpu_e2k_disas_set_info; cc->tcg_initialize = e2k_tcg_initialize; + + cc->gdb_read_register = e2k_cpu_gdb_read_register; + cc->gdb_write_register = e2k_cpu_gdb_write_register; + cc->gdb_num_core_regs = 300; /* TODO: bogus value, depends on e2k-linux-gdb */ } static const TypeInfo e2k_cpu_type_info = { diff --git a/target/e2k/cpu.h b/target/e2k/cpu.h index 4387caf505..ad652f316d 100644 --- a/target/e2k/cpu.h +++ b/target/e2k/cpu.h @@ -266,6 +266,8 @@ static inline void cpu_get_tb_cpu_state(CPUE2KState *env, target_ulong *pc, } int e2k_cpu_signal_handler(int host_signum, void *pinfo, void *puc); +int e2k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n); +int e2k_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n); #define cpu_signal_handler e2k_cpu_signal_handler diff --git a/target/e2k/gdbstub.c b/target/e2k/gdbstub.c new file mode 100644 index 0000000000..33b5d86bb4 --- /dev/null +++ b/target/e2k/gdbstub.c @@ -0,0 +1,47 @@ +/* + * Elbrus 2000 gdb server stub + * + * Copyright (c) 2003-2005 Fabrice Bellard + * Copyright (c) 2013 SUSE LINUX Products GmbH + * Copyright (c) 2020 Alibek Omarov + * + * 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 "cpu.h" +#include "exec/gdbstub.h" + +/* TODO: reverse engineer e2k-linux-gdb register ids */ + +int e2k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) +{ + E2KCPU *cpu = E2K_CPU(cs); + CPUClass *cc = CPU_GET_CLASS(cs); + CPUE2KState *env = &cpu->env; + + fprintf(stderr, "%s: unknown register %d\n", __FUNCTION__, n); + return 0; +} + +int e2k_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) +{ + E2KCPU *cpu = E2K_CPU(cs); + CPUClass *cc = CPU_GET_CLASS(cs); + CPUE2KState *env = &cpu->env; + + fprintf(stderr, "%s: unknown register %d\n", __FUNCTION__, n); + + /* TODO */ + return 0; +} diff --git a/target/e2k/meson.build b/target/e2k/meson.build index b400b79222..86927d4688 100644 --- a/target/e2k/meson.build +++ b/target/e2k/meson.build @@ -1,6 +1,7 @@ e2k_ss = ss.source_set() e2k_ss.add(files( 'cpu.c', + 'gdbstub.c', 'helper.c', 'helper_int.c', 'translate.c',