Skip to content

Commit

Permalink
cpu: Introduce CPUClass::gdb_{read,write}_register()
Browse files Browse the repository at this point in the history
Completes migration of target-specific code to new target-*/gdbstub.c.

Acked-by: Michael Walle <michael@walle.cc> (for lm32)
Acked-by: Max Filippov <jcmvbkbc@gmail.com> (for xtensa)
Signed-off-by: Andreas Färber <afaerber@suse.de>
  • Loading branch information
afaerber committed Jul 26, 2013
1 parent 986a299 commit 5b50e79
Show file tree
Hide file tree
Showing 60 changed files with 255 additions and 115 deletions.
80 changes: 7 additions & 73 deletions gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "cpu.h"
#include "qemu/sockets.h"
#include "sysemu/kvm.h"
#include "qemu/bitops.h"

static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
uint8_t *buf, int len, bool is_write)
Expand Down Expand Up @@ -316,10 +315,7 @@ static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER;

static GDBState *gdbserver_state;

/* This is an ugly hack to cope with both new and old gdb.
If gdb sends qXfer:features:read then assume we're talking to a newish
gdb that understands target descriptions. */
static int gdb_has_xml;
bool gdb_has_xml;

#ifdef CONFIG_USER_ONLY
/* XXX: This is not thread safe. Do we care? */
Expand Down Expand Up @@ -489,84 +485,22 @@ static int put_packet(GDBState *s, const char *buf)
return put_packet_binary(s, buf, strlen(buf));
}

#if defined(TARGET_I386)

#include "target-i386/gdbstub.c"

#elif defined (TARGET_PPC)
#if defined(TARGET_PPC)

#if defined (TARGET_PPC64)
#define GDB_CORE_XML "power64-core.xml"
#else
#define GDB_CORE_XML "power-core.xml"
#endif

#include "target-ppc/gdbstub.c"

#elif defined (TARGET_SPARC)

#include "target-sparc/gdbstub.c"

#elif defined (TARGET_ARM)

#define GDB_CORE_XML "arm-core.xml"

#include "target-arm/gdbstub.c"

#elif defined (TARGET_M68K)

#define GDB_CORE_XML "cf-core.xml"

#include "target-m68k/gdbstub.c"

#elif defined (TARGET_MIPS)

#include "target-mips/gdbstub.c"

#elif defined(TARGET_OPENRISC)

#include "target-openrisc/gdbstub.c"

#elif defined (TARGET_SH4)

#include "target-sh4/gdbstub.c"

#elif defined (TARGET_MICROBLAZE)

#include "target-microblaze/gdbstub.c"

#elif defined (TARGET_CRIS)

#include "target-cris/gdbstub.c"

#elif defined (TARGET_ALPHA)

#include "target-alpha/gdbstub.c"

#elif defined (TARGET_S390X)

#include "target-s390x/gdbstub.c"

#elif defined (TARGET_LM32)

#include "target-lm32/gdbstub.c"

#elif defined(TARGET_XTENSA)

#include "target-xtensa/gdbstub.c"

#else

static int cpu_gdb_read_register(CPUArchState *env, uint8_t *mem_buf, int n)
{
return 0;
}

static int cpu_gdb_write_register(CPUArchState *env, uint8_t *mem_buf, int n)
{
return 0;
}

#endif

#ifdef GDB_CORE_XML
Expand Down Expand Up @@ -642,7 +576,7 @@ static int gdb_read_register(CPUState *cpu, uint8_t *mem_buf, int reg)
GDBRegisterState *r;

if (reg < cc->gdb_num_core_regs) {
return cpu_gdb_read_register(env, mem_buf, reg);
return cc->gdb_read_register(cpu, mem_buf, reg);
}

for (r = cpu->gdb_regs; r; r = r->next) {
Expand All @@ -660,7 +594,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)
GDBRegisterState *r;

if (reg < cc->gdb_num_core_regs) {
return cpu_gdb_write_register(env, mem_buf, reg);
return cc->gdb_write_register(cpu, mem_buf, reg);
}

for (r = cpu->gdb_regs; r; r = r->next) {
Expand Down Expand Up @@ -1212,7 +1146,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
const char *xml;
target_ulong total_len;

gdb_has_xml = 1;
gdb_has_xml = true;
p += 19;
xml = get_feature_xml(p, &p);
if (!xml) {
Expand Down Expand Up @@ -1621,7 +1555,7 @@ static void gdb_accept(void)
s->c_cpu = first_cpu;
s->g_cpu = first_cpu;
s->fd = fd;
gdb_has_xml = 0;
gdb_has_xml = false;

gdbserver_state = s;

Expand Down Expand Up @@ -1707,7 +1641,7 @@ static void gdb_chr_event(void *opaque, int event)
switch (event) {
case CHR_EVENT_OPENED:
vm_stop(RUN_STATE_PAUSED);
gdb_has_xml = 0;
gdb_has_xml = false;
break;
default:
break;
Expand Down
8 changes: 8 additions & 0 deletions include/exec/gdbstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ int gdbserver_start(int);
int gdbserver_start(const char *port);
#endif

/**
* gdb_has_xml:
* This is an ugly hack to cope with both new and old gdb.
* If gdb sends qXfer:features:read then assume we're talking to a newish
* gdb that understands target descriptions.
*/
extern bool gdb_has_xml;

/* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */
extern const char *const xml_builtin[][2];

Expand Down
4 changes: 4 additions & 0 deletions include/qom/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ struct TranslationBlock;
* @synchronize_from_tb: Callback for synchronizing state from a TCG
* #TranslationBlock.
* @get_phys_page_debug: Callback for obtaining a physical address.
* @gdb_read_register: Callback for letting GDB read a register.
* @gdb_write_register: Callback for letting GDB write a register.
* @vmsd: State description for migration.
* @gdb_num_core_regs: Number of core registers accessible to GDB.
*
Expand Down Expand Up @@ -109,6 +111,8 @@ typedef struct CPUClass {
void (*set_pc)(CPUState *cpu, vaddr value);
void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);

int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
int cpuid, void *opaque);
Expand Down
13 changes: 13 additions & 0 deletions qom/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ static int cpu_common_write_elf64_note(WriteCoreDumpFunction f,
}


static int cpu_common_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg)
{
return 0;
}

static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg)
{
return 0;
}


void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
int flags)
{
Expand Down Expand Up @@ -253,6 +264,8 @@ static void cpu_class_init(ObjectClass *klass, void *data)
k->write_elf32_note = cpu_common_write_elf32_note;
k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
k->write_elf64_note = cpu_common_write_elf64_note;
k->gdb_read_register = cpu_common_gdb_read_register;
k->gdb_write_register = cpu_common_gdb_write_register;
dc->realize = cpu_common_realizefn;
dc->no_user = 1;
}
Expand Down
1 change: 1 addition & 0 deletions target-alpha/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
obj-$(CONFIG_SOFTMMU) += machine.o
obj-y += translate.o helper.o cpu.o
obj-y += int_helper.o fpu_helper.o sys_helper.o mem_helper.o
obj-y += gdbstub.o
2 changes: 2 additions & 0 deletions target-alpha/cpu-qom.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ void alpha_cpu_do_interrupt(CPUState *cpu);
void alpha_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
int flags);
hwaddr alpha_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
int alpha_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
int alpha_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);

#endif
2 changes: 2 additions & 0 deletions target-alpha/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
cc->do_interrupt = alpha_cpu_do_interrupt;
cc->dump_state = alpha_cpu_dump_state;
cc->set_pc = alpha_cpu_set_pc;
cc->gdb_read_register = alpha_cpu_gdb_read_register;
cc->gdb_write_register = alpha_cpu_gdb_write_register;
#ifndef CONFIG_USER_ONLY
cc->do_unassigned_access = alpha_cpu_unassigned_access;
cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug;
Expand Down
11 changes: 9 additions & 2 deletions target-alpha/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "qemu-common.h"
#include "exec/gdbstub.h"

static int cpu_gdb_read_register(CPUAlphaState *env, uint8_t *mem_buf, int n)
int alpha_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
{
AlphaCPU *cpu = ALPHA_CPU(cs);
CPUAlphaState *env = &cpu->env;
uint64_t val;
CPU_DoubleU d;

Expand Down Expand Up @@ -52,8 +57,10 @@ static int cpu_gdb_read_register(CPUAlphaState *env, uint8_t *mem_buf, int n)
return gdb_get_regl(mem_buf, val);
}

static int cpu_gdb_write_register(CPUAlphaState *env, uint8_t *mem_buf, int n)
int alpha_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
{
AlphaCPU *cpu = ALPHA_CPU(cs);
CPUAlphaState *env = &cpu->env;
target_ulong tmp = ldtul_p(mem_buf);
CPU_DoubleU d;

Expand Down
1 change: 1 addition & 0 deletions target-arm/Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ obj-$(CONFIG_KVM) += kvm.o
obj-$(CONFIG_NO_KVM) += kvm-stub.o
obj-y += translate.o op_helper.o helper.o cpu.o
obj-y += neon_helper.o iwmmxt_helper.o
obj-y += gdbstub.o
3 changes: 3 additions & 0 deletions target-arm/cpu-qom.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,7 @@ void arm_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,

hwaddr arm_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);

int arm_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);

#endif
2 changes: 2 additions & 0 deletions target-arm/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
cc->do_interrupt = arm_cpu_do_interrupt;
cc->dump_state = arm_cpu_dump_state;
cc->set_pc = arm_cpu_set_pc;
cc->gdb_read_register = arm_cpu_gdb_read_register;
cc->gdb_write_register = arm_cpu_gdb_write_register;
#ifndef CONFIG_USER_ONLY
cc->get_phys_page_debug = arm_cpu_get_phys_page_debug;
cc->vmsd = &vmstate_arm_cpu;
Expand Down
12 changes: 10 additions & 2 deletions target-arm/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "qemu-common.h"
#include "exec/gdbstub.h"

/* Old gdb always expect FPA registers. Newer (xml-aware) gdb only expect
whatever the target description contains. Due to a historical mishap
the FPA registers appear in between core integer regs and the CPSR.
We hack round this by giving the FPA regs zero size when talking to a
newer gdb. */

static int cpu_gdb_read_register(CPUARMState *env, uint8_t *mem_buf, int n)
int arm_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
{
ARMCPU *cpu = ARM_CPU(cs);
CPUARMState *env = &cpu->env;

if (n < 16) {
/* Core integer register. */
return gdb_get_reg32(mem_buf, env->regs[n]);
Expand Down Expand Up @@ -53,8 +59,10 @@ static int cpu_gdb_read_register(CPUARMState *env, uint8_t *mem_buf, int n)
return 0;
}

static int cpu_gdb_write_register(CPUARMState *env, uint8_t *mem_buf, int n)
int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
{
ARMCPU *cpu = ARM_CPU(cs);
CPUARMState *env = &cpu->env;
uint32_t tmp;

tmp = ldl_p(mem_buf);
Expand Down
1 change: 1 addition & 0 deletions target-cris/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
obj-y += translate.o op_helper.o helper.o cpu.o
obj-y += gdbstub.o
obj-$(CONFIG_SOFTMMU) += mmu.o machine.o
3 changes: 3 additions & 0 deletions target-cris/cpu-qom.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,

hwaddr cris_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);

int cris_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
int cris_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);

#endif
2 changes: 2 additions & 0 deletions target-cris/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
cc->do_interrupt = cris_cpu_do_interrupt;
cc->dump_state = cris_cpu_dump_state;
cc->set_pc = cris_cpu_set_pc;
cc->gdb_read_register = cris_cpu_gdb_read_register;
cc->gdb_write_register = cris_cpu_gdb_write_register;
#ifndef CONFIG_USER_ONLY
cc->get_phys_page_debug = cris_cpu_get_phys_page_debug;
#endif
Expand Down
11 changes: 9 additions & 2 deletions target-cris/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "qemu-common.h"
#include "exec/gdbstub.h"

static int
read_register_crisv10(CPUCRISState *env, uint8_t *mem_buf, int n)
Expand Down Expand Up @@ -48,8 +51,10 @@ read_register_crisv10(CPUCRISState *env, uint8_t *mem_buf, int n)
return 0;
}

static int cpu_gdb_read_register(CPUCRISState *env, uint8_t *mem_buf, int n)
int cris_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
{
CRISCPU *cpu = CRIS_CPU(cs);
CPUCRISState *env = &cpu->env;
uint8_t srs;

if (env->pregs[PR_VR] < 32) {
Expand Down Expand Up @@ -85,8 +90,10 @@ static int cpu_gdb_read_register(CPUCRISState *env, uint8_t *mem_buf, int n)
return 0;
}

static int cpu_gdb_write_register(CPUCRISState *env, uint8_t *mem_buf, int n)
int cris_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
{
CRISCPU *cpu = CRIS_CPU(cs);
CPUCRISState *env = &cpu->env;
uint32_t tmp;

if (n > 49) {
Expand Down
1 change: 1 addition & 0 deletions target-i386/Makefile.objs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
obj-y += translate.o helper.o cpu.o
obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o
obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o
obj-y += gdbstub.o
obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o
obj-$(CONFIG_KVM) += kvm.o hyperv.o
obj-$(CONFIG_NO_KVM) += kvm-stub.o
Expand Down
3 changes: 3 additions & 0 deletions target-i386/cpu-qom.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,

hwaddr x86_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);

int x86_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);

#endif
2 changes: 2 additions & 0 deletions target-i386/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,8 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
cc->dump_state = x86_cpu_dump_state;
cc->set_pc = x86_cpu_set_pc;
cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
cc->gdb_read_register = x86_cpu_gdb_read_register;
cc->gdb_write_register = x86_cpu_gdb_write_register;
cc->get_arch_id = x86_cpu_get_arch_id;
cc->get_paging_enabled = x86_cpu_get_paging_enabled;
#ifndef CONFIG_USER_ONLY
Expand Down
Loading

0 comments on commit 5b50e79

Please sign in to comment.