2003-06-27 19:34:32 +02:00
|
|
|
/*
|
|
|
|
* gdb server stub
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2005-07-02 16:31:34 +02:00
|
|
|
* Copyright (c) 2003-2005 Fabrice Bellard
|
2003-06-27 19:34:32 +02:00
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2006-06-17 20:30:42 +02:00
|
|
|
#include "config.h"
|
2005-04-17 21:16:13 +02:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2006-06-17 20:30:42 +02:00
|
|
|
#include <fcntl.h>
|
2005-04-17 21:16:13 +02:00
|
|
|
|
|
|
|
#include "qemu.h"
|
|
|
|
#else
|
2007-11-17 18:14:51 +01:00
|
|
|
#include "qemu-common.h"
|
|
|
|
#include "qemu-char.h"
|
|
|
|
#include "sysemu.h"
|
|
|
|
#include "gdbstub.h"
|
2005-04-17 21:16:13 +02:00
|
|
|
#endif
|
2004-04-01 01:37:16 +02:00
|
|
|
|
2006-06-14 17:21:14 +02:00
|
|
|
#include "qemu_socket.h"
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* XXX: these constants may be independent of the host ones even for Unix */
|
|
|
|
#ifndef SIGTRAP
|
|
|
|
#define SIGTRAP 5
|
|
|
|
#endif
|
|
|
|
#ifndef SIGINT
|
|
|
|
#define SIGINT 2
|
|
|
|
#endif
|
|
|
|
#else
|
2003-06-27 19:34:32 +02:00
|
|
|
#include <signal.h>
|
2006-06-14 17:21:14 +02:00
|
|
|
#endif
|
2003-06-27 19:34:32 +02:00
|
|
|
|
2003-07-26 20:01:58 +02:00
|
|
|
//#define DEBUG_GDB
|
2003-06-27 19:34:32 +02:00
|
|
|
|
2004-03-31 20:52:07 +02:00
|
|
|
enum RSState {
|
|
|
|
RS_IDLE,
|
|
|
|
RS_GETLINE,
|
|
|
|
RS_CHKSUM1,
|
|
|
|
RS_CHKSUM2,
|
2007-01-28 04:10:55 +01:00
|
|
|
RS_SYSCALL,
|
2004-03-31 20:52:07 +02:00
|
|
|
};
|
|
|
|
typedef struct GDBState {
|
2005-11-22 00:25:50 +01:00
|
|
|
CPUState *env; /* current CPU */
|
2005-04-24 12:07:11 +02:00
|
|
|
enum RSState state; /* parsing state */
|
2004-03-31 20:52:07 +02:00
|
|
|
char line_buf[4096];
|
|
|
|
int line_buf_index;
|
|
|
|
int line_csum;
|
2007-12-16 04:02:09 +01:00
|
|
|
uint8_t last_packet[4100];
|
2007-01-28 02:53:16 +01:00
|
|
|
int last_packet_len;
|
2008-05-18 00:20:53 +02:00
|
|
|
int signal;
|
2005-04-24 12:07:11 +02:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
2007-01-28 02:53:16 +01:00
|
|
|
int fd;
|
2005-04-24 12:07:11 +02:00
|
|
|
int running_state;
|
2007-01-28 02:53:16 +01:00
|
|
|
#else
|
|
|
|
CharDriverState *chr;
|
2005-04-24 12:07:11 +02:00
|
|
|
#endif
|
2004-03-31 20:52:07 +02:00
|
|
|
} GDBState;
|
2003-06-27 19:34:32 +02:00
|
|
|
|
2008-05-09 10:25:14 +02:00
|
|
|
/* By default use no IRQs and no timers while single stepping so as to
|
|
|
|
* make single stepping like an ICE HW step.
|
|
|
|
*/
|
|
|
|
static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER;
|
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
2007-01-28 02:53:16 +01:00
|
|
|
/* XXX: This is not thread safe. Do we care? */
|
|
|
|
static int gdbserver_fd = -1;
|
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
/* XXX: remove this hack. */
|
|
|
|
static GDBState gdbserver_state;
|
|
|
|
|
2004-03-31 20:52:07 +02:00
|
|
|
static int get_char(GDBState *s)
|
2003-06-27 19:34:32 +02:00
|
|
|
{
|
|
|
|
uint8_t ch;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for(;;) {
|
2006-06-14 17:21:14 +02:00
|
|
|
ret = recv(s->fd, &ch, 1, 0);
|
2003-06-27 19:34:32 +02:00
|
|
|
if (ret < 0) {
|
2008-05-18 00:20:53 +02:00
|
|
|
if (errno == ECONNRESET)
|
|
|
|
s->fd = -1;
|
2003-06-27 19:34:32 +02:00
|
|
|
if (errno != EINTR && errno != EAGAIN)
|
|
|
|
return -1;
|
|
|
|
} else if (ret == 0) {
|
2008-05-18 00:20:53 +02:00
|
|
|
close(s->fd);
|
|
|
|
s->fd = -1;
|
2003-06-27 19:34:32 +02:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ch;
|
|
|
|
}
|
2007-01-28 02:53:16 +01:00
|
|
|
#endif
|
2003-06-27 19:34:32 +02:00
|
|
|
|
2007-01-28 04:10:55 +01:00
|
|
|
/* GDB stub state for use by semihosting syscalls. */
|
|
|
|
static GDBState *gdb_syscall_state;
|
|
|
|
static gdb_syscall_complete_cb gdb_current_syscall_cb;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
GDB_SYS_UNKNOWN,
|
|
|
|
GDB_SYS_ENABLED,
|
|
|
|
GDB_SYS_DISABLED,
|
|
|
|
} gdb_syscall_mode;
|
|
|
|
|
|
|
|
/* If gdb is connected when the first semihosting syscall occurs then use
|
|
|
|
remote gdb syscalls. Otherwise use native file IO. */
|
|
|
|
int use_gdb_syscalls(void)
|
|
|
|
{
|
|
|
|
if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
|
|
|
|
gdb_syscall_mode = (gdb_syscall_state ? GDB_SYS_ENABLED
|
|
|
|
: GDB_SYS_DISABLED);
|
|
|
|
}
|
|
|
|
return gdb_syscall_mode == GDB_SYS_ENABLED;
|
|
|
|
}
|
|
|
|
|
2008-03-14 07:10:42 +01:00
|
|
|
/* Resume execution. */
|
|
|
|
static inline void gdb_continue(GDBState *s)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
s->running_state = 1;
|
|
|
|
#else
|
|
|
|
vm_start();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-03-31 20:52:07 +02:00
|
|
|
static void put_buffer(GDBState *s, const uint8_t *buf, int len)
|
2003-06-27 19:34:32 +02:00
|
|
|
{
|
2007-01-28 02:53:16 +01:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
2003-06-27 19:34:32 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
while (len > 0) {
|
2006-06-14 17:21:14 +02:00
|
|
|
ret = send(s->fd, buf, len, 0);
|
2003-06-27 19:34:32 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
if (errno != EINTR && errno != EAGAIN)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
buf += ret;
|
|
|
|
len -= ret;
|
|
|
|
}
|
|
|
|
}
|
2007-01-28 02:53:16 +01:00
|
|
|
#else
|
|
|
|
qemu_chr_write(s->chr, buf, len);
|
|
|
|
#endif
|
2003-06-27 19:34:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int fromhex(int v)
|
|
|
|
{
|
|
|
|
if (v >= '0' && v <= '9')
|
|
|
|
return v - '0';
|
|
|
|
else if (v >= 'A' && v <= 'F')
|
|
|
|
return v - 'A' + 10;
|
|
|
|
else if (v >= 'a' && v <= 'f')
|
|
|
|
return v - 'a' + 10;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int tohex(int v)
|
|
|
|
{
|
|
|
|
if (v < 10)
|
|
|
|
return v + '0';
|
|
|
|
else
|
|
|
|
return v - 10 + 'a';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void memtohex(char *buf, const uint8_t *mem, int len)
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
char *q;
|
|
|
|
q = buf;
|
|
|
|
for(i = 0; i < len; i++) {
|
|
|
|
c = mem[i];
|
|
|
|
*q++ = tohex(c >> 4);
|
|
|
|
*q++ = tohex(c & 0xf);
|
|
|
|
}
|
|
|
|
*q = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hextomem(uint8_t *mem, const char *buf, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < len; i++) {
|
|
|
|
mem[i] = (fromhex(buf[0]) << 4) | fromhex(buf[1]);
|
|
|
|
buf += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return -1 if error, 0 if OK */
|
2008-09-14 08:45:34 +02:00
|
|
|
static int put_packet(GDBState *s, const char *buf)
|
2003-06-27 19:34:32 +02:00
|
|
|
{
|
2007-01-28 02:53:16 +01:00
|
|
|
int len, csum, i;
|
2007-12-16 04:02:09 +01:00
|
|
|
uint8_t *p;
|
2003-06-27 19:34:32 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_GDB
|
|
|
|
printf("reply='%s'\n", buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(;;) {
|
2007-01-28 02:53:16 +01:00
|
|
|
p = s->last_packet;
|
|
|
|
*(p++) = '$';
|
2003-06-27 19:34:32 +02:00
|
|
|
len = strlen(buf);
|
2007-01-28 02:53:16 +01:00
|
|
|
memcpy(p, buf, len);
|
|
|
|
p += len;
|
2003-06-27 19:34:32 +02:00
|
|
|
csum = 0;
|
|
|
|
for(i = 0; i < len; i++) {
|
|
|
|
csum += buf[i];
|
|
|
|
}
|
2007-01-28 02:53:16 +01:00
|
|
|
*(p++) = '#';
|
|
|
|
*(p++) = tohex((csum >> 4) & 0xf);
|
|
|
|
*(p++) = tohex((csum) & 0xf);
|
2003-06-27 19:34:32 +02:00
|
|
|
|
2007-01-28 02:53:16 +01:00
|
|
|
s->last_packet_len = p - s->last_packet;
|
2007-12-16 04:16:05 +01:00
|
|
|
put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len);
|
2003-06-27 19:34:32 +02:00
|
|
|
|
2007-01-28 02:53:16 +01:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
i = get_char(s);
|
|
|
|
if (i < 0)
|
2003-06-27 19:34:32 +02:00
|
|
|
return -1;
|
2007-01-28 02:53:16 +01:00
|
|
|
if (i == '+')
|
2003-06-27 19:34:32 +02:00
|
|
|
break;
|
2007-01-28 02:53:16 +01:00
|
|
|
#else
|
|
|
|
break;
|
|
|
|
#endif
|
2003-06-27 19:34:32 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-09 10:50:01 +02:00
|
|
|
#if defined(TARGET_I386)
|
2008-05-09 16:40:22 +02:00
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
static const uint8_t gdb_x86_64_regs[16] = {
|
|
|
|
R_EAX, R_EBX, R_ECX, R_EDX, R_ESI, R_EDI, R_EBP, R_ESP,
|
|
|
|
8, 9, 10, 11, 12, 13, 14, 15,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2004-01-04 16:48:38 +01:00
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
2008-05-09 16:40:22 +02:00
|
|
|
int i, fpus, nb_regs;
|
|
|
|
uint8_t *p;
|
2007-10-31 01:21:35 +01:00
|
|
|
|
2008-05-09 16:40:22 +02:00
|
|
|
p = mem_buf;
|
2007-10-31 01:21:35 +01:00
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_CS64_MASK) {
|
2008-05-09 16:40:22 +02:00
|
|
|
nb_regs = 16;
|
|
|
|
for(i = 0; i < 16; i++) {
|
|
|
|
*(uint64_t *)p = tswap64(env->regs[gdb_x86_64_regs[i]]);
|
|
|
|
p += 8;
|
2007-10-31 01:21:35 +01:00
|
|
|
}
|
2008-05-09 16:40:22 +02:00
|
|
|
*(uint64_t *)p = tswap64(env->eip);
|
|
|
|
p += 8;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
nb_regs = 8;
|
2007-10-31 01:21:35 +01:00
|
|
|
for(i = 0; i < 8; i++) {
|
2008-05-09 16:40:22 +02:00
|
|
|
*(uint32_t *)p = tswap32(env->regs[i]);
|
|
|
|
p += 4;
|
2007-10-31 01:21:35 +01:00
|
|
|
}
|
2008-05-09 16:40:22 +02:00
|
|
|
*(uint32_t *)p = tswap32(env->eip);
|
|
|
|
p += 4;
|
2007-10-31 01:21:35 +01:00
|
|
|
}
|
2004-01-04 16:48:38 +01:00
|
|
|
|
2008-05-09 16:40:22 +02:00
|
|
|
*(uint32_t *)p = tswap32(env->eflags);
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = tswap32(env->segs[R_CS].selector);
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = tswap32(env->segs[R_SS].selector);
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = tswap32(env->segs[R_DS].selector);
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = tswap32(env->segs[R_ES].selector);
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = tswap32(env->segs[R_FS].selector);
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = tswap32(env->segs[R_GS].selector);
|
|
|
|
p += 4;
|
2004-01-04 16:48:38 +01:00
|
|
|
for(i = 0; i < 8; i++) {
|
2008-05-09 16:40:22 +02:00
|
|
|
/* XXX: convert floats */
|
|
|
|
#ifdef USE_X86LDOUBLE
|
|
|
|
memcpy(p, &env->fpregs[i], 10);
|
|
|
|
#else
|
|
|
|
memset(p, 0, 10);
|
|
|
|
#endif
|
|
|
|
p += 10;
|
2004-01-04 16:48:38 +01:00
|
|
|
}
|
2008-05-09 16:40:22 +02:00
|
|
|
*(uint32_t *)p = tswap32(env->fpuc); /* fctrl */
|
|
|
|
p += 4;
|
2004-01-04 16:48:38 +01:00
|
|
|
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
|
2008-05-09 16:40:22 +02:00
|
|
|
*(uint32_t *)p = tswap32(fpus); /* fstat */
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = 0; /* ftag */
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = 0; /* fiseg */
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = 0; /* fioff */
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = 0; /* foseg */
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = 0; /* fooff */
|
|
|
|
p += 4;
|
|
|
|
*(uint32_t *)p = 0; /* fop */
|
|
|
|
p += 4;
|
|
|
|
for(i = 0; i < nb_regs; i++) {
|
|
|
|
*(uint64_t *)p = tswap64(env->xmm_regs[i].XMM_Q(0));
|
|
|
|
p += 8;
|
|
|
|
*(uint64_t *)p = tswap64(env->xmm_regs[i].XMM_Q(1));
|
|
|
|
p += 8;
|
|
|
|
}
|
|
|
|
*(uint32_t *)p = tswap32(env->mxcsr);
|
|
|
|
p += 4;
|
|
|
|
return p - mem_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void cpu_gdb_load_seg(CPUState *env, const uint8_t **pp,
|
|
|
|
int sreg)
|
|
|
|
{
|
|
|
|
const uint8_t *p;
|
|
|
|
uint32_t sel;
|
|
|
|
p = *pp;
|
|
|
|
sel = tswap32(*(uint32_t *)p);
|
|
|
|
p += 4;
|
|
|
|
if (sel != env->segs[sreg].selector) {
|
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
cpu_x86_load_seg(env, sreg, sel);
|
|
|
|
#else
|
|
|
|
/* XXX: do it with a debug function which does not raise an
|
|
|
|
exception */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
*pp = p;
|
2004-01-04 16:48:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
2008-05-09 16:40:22 +02:00
|
|
|
const uint8_t *p = mem_buf;
|
|
|
|
int i, nb_regs;
|
|
|
|
uint16_t fpus;
|
2004-01-04 16:48:38 +01:00
|
|
|
|
2008-05-09 16:40:22 +02:00
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
if (env->hflags & HF_CS64_MASK) {
|
|
|
|
nb_regs = 16;
|
|
|
|
for(i = 0; i < 16; i++) {
|
|
|
|
env->regs[gdb_x86_64_regs[i]] = tswap64(*(uint64_t *)p);
|
|
|
|
p += 8;
|
|
|
|
}
|
|
|
|
env->eip = tswap64(*(uint64_t *)p);
|
|
|
|
p += 8;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
nb_regs = 8;
|
|
|
|
for(i = 0; i < 8; i++) {
|
|
|
|
env->regs[i] = tswap32(*(uint32_t *)p);
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
env->eip = tswap32(*(uint32_t *)p);
|
|
|
|
p += 4;
|
2004-01-04 16:48:38 +01:00
|
|
|
}
|
2008-05-09 16:40:22 +02:00
|
|
|
env->eflags = tswap32(*(uint32_t *)p);
|
|
|
|
p += 4;
|
|
|
|
cpu_gdb_load_seg(env, &p, R_CS);
|
|
|
|
cpu_gdb_load_seg(env, &p, R_SS);
|
|
|
|
cpu_gdb_load_seg(env, &p, R_DS);
|
|
|
|
cpu_gdb_load_seg(env, &p, R_ES);
|
|
|
|
cpu_gdb_load_seg(env, &p, R_FS);
|
|
|
|
cpu_gdb_load_seg(env, &p, R_GS);
|
|
|
|
|
|
|
|
/* FPU state */
|
|
|
|
for(i = 0; i < 8; i++) {
|
|
|
|
/* XXX: convert floats */
|
|
|
|
#ifdef USE_X86LDOUBLE
|
|
|
|
memcpy(&env->fpregs[i], p, 10);
|
2004-01-04 16:48:38 +01:00
|
|
|
#endif
|
2008-05-09 16:40:22 +02:00
|
|
|
p += 10;
|
|
|
|
}
|
|
|
|
env->fpuc = tswap32(*(uint32_t *)p); /* fctrl */
|
|
|
|
p += 4;
|
|
|
|
fpus = tswap32(*(uint32_t *)p);
|
|
|
|
p += 4;
|
|
|
|
env->fpstt = (fpus >> 11) & 7;
|
|
|
|
env->fpus = fpus & ~0x3800;
|
|
|
|
p += 4 * 6;
|
|
|
|
|
|
|
|
if (size >= ((p - mem_buf) + 16 * nb_regs + 4)) {
|
|
|
|
/* SSE state */
|
|
|
|
for(i = 0; i < nb_regs; i++) {
|
|
|
|
env->xmm_regs[i].XMM_Q(0) = tswap64(*(uint64_t *)p);
|
|
|
|
p += 8;
|
|
|
|
env->xmm_regs[i].XMM_Q(1) = tswap64(*(uint64_t *)p);
|
|
|
|
p += 8;
|
|
|
|
}
|
|
|
|
env->mxcsr = tswap32(*(uint32_t *)p);
|
|
|
|
p += 4;
|
|
|
|
}
|
2004-01-04 16:48:38 +01:00
|
|
|
}
|
|
|
|
|
2004-01-05 23:49:06 +01:00
|
|
|
#elif defined (TARGET_PPC)
|
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
2004-04-12 22:39:29 +02:00
|
|
|
uint32_t *registers = (uint32_t *)mem_buf, tmp;
|
2004-01-05 23:49:06 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* fill in gprs */
|
2004-04-12 22:39:29 +02:00
|
|
|
for(i = 0; i < 32; i++) {
|
2004-10-01 00:22:08 +02:00
|
|
|
registers[i] = tswapl(env->gpr[i]);
|
2004-01-05 23:49:06 +01:00
|
|
|
}
|
|
|
|
/* fill in fprs */
|
|
|
|
for (i = 0; i < 32; i++) {
|
2004-10-01 00:22:08 +02:00
|
|
|
registers[(i * 2) + 32] = tswapl(*((uint32_t *)&env->fpr[i]));
|
|
|
|
registers[(i * 2) + 33] = tswapl(*((uint32_t *)&env->fpr[i] + 1));
|
2004-01-05 23:49:06 +01:00
|
|
|
}
|
|
|
|
/* nip, msr, ccr, lnk, ctr, xer, mq */
|
2004-10-01 00:22:08 +02:00
|
|
|
registers[96] = tswapl(env->nip);
|
2007-10-25 23:35:50 +02:00
|
|
|
registers[97] = tswapl(env->msr);
|
2004-01-05 23:49:06 +01:00
|
|
|
tmp = 0;
|
|
|
|
for (i = 0; i < 8; i++)
|
2004-04-12 22:39:29 +02:00
|
|
|
tmp |= env->crf[i] << (32 - ((i + 1) * 4));
|
2004-10-01 00:22:08 +02:00
|
|
|
registers[98] = tswapl(tmp);
|
|
|
|
registers[99] = tswapl(env->lr);
|
|
|
|
registers[100] = tswapl(env->ctr);
|
2007-03-07 09:32:30 +01:00
|
|
|
registers[101] = tswapl(ppc_load_xer(env));
|
2004-10-01 00:22:08 +02:00
|
|
|
registers[102] = 0;
|
2004-04-12 22:39:29 +02:00
|
|
|
|
|
|
|
return 103 * 4;
|
2004-01-05 23:49:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
|
|
|
uint32_t *registers = (uint32_t *)mem_buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* fill in gprs */
|
|
|
|
for (i = 0; i < 32; i++) {
|
2004-10-01 00:22:08 +02:00
|
|
|
env->gpr[i] = tswapl(registers[i]);
|
2004-01-05 23:49:06 +01:00
|
|
|
}
|
|
|
|
/* fill in fprs */
|
|
|
|
for (i = 0; i < 32; i++) {
|
2004-10-01 00:22:08 +02:00
|
|
|
*((uint32_t *)&env->fpr[i]) = tswapl(registers[(i * 2) + 32]);
|
|
|
|
*((uint32_t *)&env->fpr[i] + 1) = tswapl(registers[(i * 2) + 33]);
|
2004-01-05 23:49:06 +01:00
|
|
|
}
|
|
|
|
/* nip, msr, ccr, lnk, ctr, xer, mq */
|
2004-10-01 00:22:08 +02:00
|
|
|
env->nip = tswapl(registers[96]);
|
2007-10-25 23:35:50 +02:00
|
|
|
ppc_store_msr(env, tswapl(registers[97]));
|
2004-10-01 00:22:08 +02:00
|
|
|
registers[98] = tswapl(registers[98]);
|
2004-01-05 23:49:06 +01:00
|
|
|
for (i = 0; i < 8; i++)
|
2004-04-12 22:39:29 +02:00
|
|
|
env->crf[i] = (registers[98] >> (32 - ((i + 1) * 4))) & 0xF;
|
2004-10-01 00:22:08 +02:00
|
|
|
env->lr = tswapl(registers[99]);
|
|
|
|
env->ctr = tswapl(registers[100]);
|
2007-03-07 09:32:30 +01:00
|
|
|
ppc_store_xer(env, tswapl(registers[101]));
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
|
|
|
#elif defined (TARGET_SPARC)
|
2008-06-07 10:03:05 +02:00
|
|
|
#ifdef TARGET_ABI32
|
|
|
|
#define tswap_abi(val) tswap32(val &0xffffffff)
|
|
|
|
#else
|
|
|
|
#define tswap_abi(val) tswapl(val)
|
|
|
|
#endif
|
2004-10-01 00:22:08 +02:00
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
2008-06-07 10:03:05 +02:00
|
|
|
#ifdef TARGET_ABI32
|
|
|
|
abi_ulong *registers = (abi_ulong *)mem_buf;
|
|
|
|
#else
|
2005-07-02 16:31:34 +02:00
|
|
|
target_ulong *registers = (target_ulong *)mem_buf;
|
2008-06-07 10:03:05 +02:00
|
|
|
#endif
|
2004-10-01 00:22:08 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* fill in g0..g7 */
|
2005-10-30 17:08:23 +01:00
|
|
|
for(i = 0; i < 8; i++) {
|
2008-06-07 10:03:05 +02:00
|
|
|
registers[i] = tswap_abi(env->gregs[i]);
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
|
|
|
/* fill in register window */
|
|
|
|
for(i = 0; i < 24; i++) {
|
2008-06-07 10:03:05 +02:00
|
|
|
registers[i + 8] = tswap_abi(env->regwptr[i]);
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
2008-06-07 10:03:05 +02:00
|
|
|
#if !defined(TARGET_SPARC64) || defined(TARGET_ABI32)
|
2004-10-01 00:22:08 +02:00
|
|
|
/* fill in fprs */
|
|
|
|
for (i = 0; i < 32; i++) {
|
2008-06-07 10:03:05 +02:00
|
|
|
registers[i + 32] = tswap_abi(*((uint32_t *)&env->fpr[i]));
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
|
|
|
/* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
|
2008-06-07 10:03:05 +02:00
|
|
|
registers[64] = tswap_abi(env->y);
|
2005-07-02 16:31:34 +02:00
|
|
|
{
|
2008-06-07 10:03:05 +02:00
|
|
|
uint32_t tmp;
|
2005-07-02 16:31:34 +02:00
|
|
|
|
2008-06-07 10:03:05 +02:00
|
|
|
tmp = GET_PSR(env);
|
|
|
|
registers[65] = tswap32(tmp);
|
2005-07-02 16:31:34 +02:00
|
|
|
}
|
2008-06-07 10:03:05 +02:00
|
|
|
registers[66] = tswap_abi(env->wim);
|
|
|
|
registers[67] = tswap_abi(env->tbr);
|
|
|
|
registers[68] = tswap_abi(env->pc);
|
|
|
|
registers[69] = tswap_abi(env->npc);
|
|
|
|
registers[70] = tswap_abi(env->fsr);
|
2004-10-01 00:22:08 +02:00
|
|
|
registers[71] = 0; /* csr */
|
|
|
|
registers[72] = 0;
|
2008-06-07 10:03:05 +02:00
|
|
|
return 73 * sizeof(uint32_t);
|
2005-07-02 16:31:34 +02:00
|
|
|
#else
|
2006-06-25 17:32:37 +02:00
|
|
|
/* fill in fprs */
|
|
|
|
for (i = 0; i < 64; i += 2) {
|
|
|
|
uint64_t tmp;
|
|
|
|
|
2007-04-14 18:15:48 +02:00
|
|
|
tmp = ((uint64_t)*(uint32_t *)&env->fpr[i]) << 32;
|
|
|
|
tmp |= *(uint32_t *)&env->fpr[i + 1];
|
|
|
|
registers[i / 2 + 32] = tswap64(tmp);
|
2005-07-02 16:31:34 +02:00
|
|
|
}
|
2006-06-25 17:32:37 +02:00
|
|
|
registers[64] = tswapl(env->pc);
|
|
|
|
registers[65] = tswapl(env->npc);
|
2007-07-07 22:53:22 +02:00
|
|
|
registers[66] = tswapl(((uint64_t)GET_CCR(env) << 32) |
|
|
|
|
((env->asi & 0xff) << 24) |
|
|
|
|
((env->pstate & 0xfff) << 8) |
|
|
|
|
GET_CWP64(env));
|
2006-06-25 17:32:37 +02:00
|
|
|
registers[67] = tswapl(env->fsr);
|
|
|
|
registers[68] = tswapl(env->fprs);
|
|
|
|
registers[69] = tswapl(env->y);
|
|
|
|
return 70 * sizeof(target_ulong);
|
2005-07-02 16:31:34 +02:00
|
|
|
#endif
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
2008-06-07 10:03:05 +02:00
|
|
|
#ifdef TARGET_ABI32
|
|
|
|
abi_ulong *registers = (abi_ulong *)mem_buf;
|
|
|
|
#else
|
2005-07-02 16:31:34 +02:00
|
|
|
target_ulong *registers = (target_ulong *)mem_buf;
|
2008-06-07 10:03:05 +02:00
|
|
|
#endif
|
2004-10-01 00:22:08 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* fill in g0..g7 */
|
|
|
|
for(i = 0; i < 7; i++) {
|
2008-06-07 10:03:05 +02:00
|
|
|
env->gregs[i] = tswap_abi(registers[i]);
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
|
|
|
/* fill in register window */
|
|
|
|
for(i = 0; i < 24; i++) {
|
2008-06-07 10:03:05 +02:00
|
|
|
env->regwptr[i] = tswap_abi(registers[i + 8]);
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
2008-06-07 10:03:05 +02:00
|
|
|
#if !defined(TARGET_SPARC64) || defined(TARGET_ABI32)
|
2004-10-01 00:22:08 +02:00
|
|
|
/* fill in fprs */
|
|
|
|
for (i = 0; i < 32; i++) {
|
2008-06-07 10:03:05 +02:00
|
|
|
*((uint32_t *)&env->fpr[i]) = tswap_abi(registers[i + 32]);
|
2004-10-01 00:22:08 +02:00
|
|
|
}
|
|
|
|
/* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
|
2008-06-07 10:03:05 +02:00
|
|
|
env->y = tswap_abi(registers[64]);
|
|
|
|
PUT_PSR(env, tswap_abi(registers[65]));
|
|
|
|
env->wim = tswap_abi(registers[66]);
|
|
|
|
env->tbr = tswap_abi(registers[67]);
|
|
|
|
env->pc = tswap_abi(registers[68]);
|
|
|
|
env->npc = tswap_abi(registers[69]);
|
|
|
|
env->fsr = tswap_abi(registers[70]);
|
2005-07-02 16:31:34 +02:00
|
|
|
#else
|
2006-06-25 17:32:37 +02:00
|
|
|
for (i = 0; i < 64; i += 2) {
|
2007-04-14 18:15:48 +02:00
|
|
|
uint64_t tmp;
|
|
|
|
|
|
|
|
tmp = tswap64(registers[i / 2 + 32]);
|
|
|
|
*((uint32_t *)&env->fpr[i]) = tmp >> 32;
|
|
|
|
*((uint32_t *)&env->fpr[i + 1]) = tmp & 0xffffffff;
|
2005-07-02 16:31:34 +02:00
|
|
|
}
|
2006-06-25 17:32:37 +02:00
|
|
|
env->pc = tswapl(registers[64]);
|
|
|
|
env->npc = tswapl(registers[65]);
|
2007-07-07 22:53:22 +02:00
|
|
|
{
|
|
|
|
uint64_t tmp = tswapl(registers[66]);
|
|
|
|
|
|
|
|
PUT_CCR(env, tmp >> 32);
|
|
|
|
env->asi = (tmp >> 24) & 0xff;
|
|
|
|
env->pstate = (tmp >> 8) & 0xfff;
|
|
|
|
PUT_CWP64(env, tmp & 0xff);
|
|
|
|
}
|
2006-06-25 17:32:37 +02:00
|
|
|
env->fsr = tswapl(registers[67]);
|
|
|
|
env->fprs = tswapl(registers[68]);
|
|
|
|
env->y = tswapl(registers[69]);
|
2005-07-02 16:31:34 +02:00
|
|
|
#endif
|
2004-01-05 23:49:06 +01:00
|
|
|
}
|
2008-06-07 10:03:05 +02:00
|
|
|
#undef tswap_abi
|
2005-04-17 21:16:13 +02:00
|
|
|
#elif defined (TARGET_ARM)
|
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
ptr = mem_buf;
|
|
|
|
/* 16 core integer registers (4 bytes each). */
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
*(uint32_t *)ptr = tswapl(env->regs[i]);
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
/* 8 FPA registers (12 bytes each), FPS (4 bytes).
|
|
|
|
Not yet implemented. */
|
|
|
|
memset (ptr, 0, 8 * 12 + 4);
|
|
|
|
ptr += 8 * 12 + 4;
|
|
|
|
/* CPSR (4 bytes). */
|
2005-11-26 11:38:39 +01:00
|
|
|
*(uint32_t *)ptr = tswapl (cpsr_read(env));
|
2005-04-17 21:16:13 +02:00
|
|
|
ptr += 4;
|
|
|
|
|
|
|
|
return ptr - mem_buf;
|
|
|
|
}
|
2004-01-04 16:48:38 +01:00
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
ptr = mem_buf;
|
|
|
|
/* Core integer registers. */
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
env->regs[i] = tswapl(*(uint32_t *)ptr);
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
/* Ignore FPA regs and scr. */
|
|
|
|
ptr += 8 * 12 + 4;
|
2005-11-26 11:38:39 +01:00
|
|
|
cpsr_write (env, tswapl(*(uint32_t *)ptr), 0xffffffff);
|
2005-04-17 21:16:13 +02:00
|
|
|
}
|
2006-10-22 02:18:54 +02:00
|
|
|
#elif defined (TARGET_M68K)
|
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t *ptr;
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
ptr = mem_buf;
|
|
|
|
/* D0-D7 */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
*(uint32_t *)ptr = tswapl(env->dregs[i]);
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
/* A0-A7 */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
*(uint32_t *)ptr = tswapl(env->aregs[i]);
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
*(uint32_t *)ptr = tswapl(env->sr);
|
|
|
|
ptr += 4;
|
|
|
|
*(uint32_t *)ptr = tswapl(env->pc);
|
|
|
|
ptr += 4;
|
|
|
|
/* F0-F7. The 68881/68040 have 12-bit extended precision registers.
|
|
|
|
ColdFire has 8-bit double precision registers. */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
u.d = env->fregs[i];
|
|
|
|
*(uint32_t *)ptr = tswap32(u.l.upper);
|
|
|
|
*(uint32_t *)ptr = tswap32(u.l.lower);
|
|
|
|
}
|
|
|
|
/* FP control regs (not implemented). */
|
|
|
|
memset (ptr, 0, 3 * 4);
|
|
|
|
ptr += 3 * 4;
|
|
|
|
|
|
|
|
return ptr - mem_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t *ptr;
|
|
|
|
CPU_DoubleU u;
|
|
|
|
|
|
|
|
ptr = mem_buf;
|
|
|
|
/* D0-D7 */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
env->dregs[i] = tswapl(*(uint32_t *)ptr);
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
/* A0-A7 */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
env->aregs[i] = tswapl(*(uint32_t *)ptr);
|
|
|
|
ptr += 4;
|
|
|
|
}
|
|
|
|
env->sr = tswapl(*(uint32_t *)ptr);
|
|
|
|
ptr += 4;
|
|
|
|
env->pc = tswapl(*(uint32_t *)ptr);
|
|
|
|
ptr += 4;
|
|
|
|
/* F0-F7. The 68881/68040 have 12-bit extended precision registers.
|
|
|
|
ColdFire has 8-bit double precision registers. */
|
|
|
|
for (i = 0; i < 8; i++) {
|
2007-09-16 23:08:06 +02:00
|
|
|
u.l.upper = tswap32(*(uint32_t *)ptr);
|
2006-10-22 02:18:54 +02:00
|
|
|
u.l.lower = tswap32(*(uint32_t *)ptr);
|
|
|
|
env->fregs[i] = u.d;
|
|
|
|
}
|
|
|
|
/* FP control regs (not implemented). */
|
|
|
|
ptr += 3 * 4;
|
|
|
|
}
|
2005-12-05 20:55:19 +01:00
|
|
|
#elif defined (TARGET_MIPS)
|
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
ptr = mem_buf;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
{
|
2008-06-27 12:02:35 +02:00
|
|
|
*(target_ulong *)ptr = tswapl(env->active_tc.gpr[i]);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
}
|
|
|
|
|
2007-10-25 23:30:37 +02:00
|
|
|
*(target_ulong *)ptr = (int32_t)tswap32(env->CP0_Status);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2008-06-27 12:02:35 +02:00
|
|
|
*(target_ulong *)ptr = tswapl(env->active_tc.LO[0]);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2008-06-27 12:02:35 +02:00
|
|
|
*(target_ulong *)ptr = tswapl(env->active_tc.HI[0]);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2007-06-01 15:18:19 +02:00
|
|
|
*(target_ulong *)ptr = tswapl(env->CP0_BadVAddr);
|
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2007-10-25 23:30:37 +02:00
|
|
|
*(target_ulong *)ptr = (int32_t)tswap32(env->CP0_Cause);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2008-06-27 12:02:35 +02:00
|
|
|
*(target_ulong *)ptr = tswapl(env->active_tc.PC);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2007-02-28 23:37:42 +01:00
|
|
|
if (env->CP0_Config1 & (1 << CP0C1_FP))
|
2006-12-11 20:22:27 +01:00
|
|
|
{
|
2007-02-28 23:37:42 +01:00
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
{
|
2007-10-25 23:30:37 +02:00
|
|
|
if (env->CP0_Status & (1 << CP0St_FR))
|
2008-09-18 13:57:27 +02:00
|
|
|
*(target_ulong *)ptr = tswapl(env->active_fpu.fpr[i].d);
|
2007-10-25 23:30:37 +02:00
|
|
|
else
|
2008-09-18 13:57:27 +02:00
|
|
|
*(target_ulong *)ptr = tswap32(env->active_fpu.fpr[i].w[FP_ENDIAN_IDX]);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2007-02-28 23:37:42 +01:00
|
|
|
}
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2008-09-18 13:57:27 +02:00
|
|
|
*(target_ulong *)ptr = (int32_t)tswap32(env->active_fpu.fcr31);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2008-09-18 13:57:27 +02:00
|
|
|
*(target_ulong *)ptr = (int32_t)tswap32(env->active_fpu.fcr0);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2007-02-28 23:37:42 +01:00
|
|
|
}
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2007-10-25 23:30:37 +02:00
|
|
|
/* "fp", pseudo frame pointer. Not yet implemented in gdb. */
|
|
|
|
*(target_ulong *)ptr = 0;
|
|
|
|
ptr += sizeof(target_ulong);
|
|
|
|
|
|
|
|
/* Registers for embedded use, we just pad them. */
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
*(target_ulong *)ptr = 0;
|
|
|
|
ptr += sizeof(target_ulong);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Processor ID. */
|
|
|
|
*(target_ulong *)ptr = (int32_t)tswap32(env->CP0_PRid);
|
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
|
|
|
return ptr - mem_buf;
|
|
|
|
}
|
|
|
|
|
2006-12-11 20:22:27 +01:00
|
|
|
/* convert MIPS rounding mode in FCR31 to IEEE library */
|
|
|
|
static unsigned int ieee_rm[] =
|
|
|
|
{
|
|
|
|
float_round_nearest_even,
|
|
|
|
float_round_to_zero,
|
|
|
|
float_round_up,
|
|
|
|
float_round_down
|
|
|
|
};
|
|
|
|
#define RESTORE_ROUNDING_MODE \
|
2008-09-18 13:57:27 +02:00
|
|
|
set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2005-12-05 20:55:19 +01:00
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
ptr = mem_buf;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
{
|
2008-06-27 12:02:35 +02:00
|
|
|
env->active_tc.gpr[i] = tswapl(*(target_ulong *)ptr);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
}
|
|
|
|
|
2007-06-01 15:18:19 +02:00
|
|
|
env->CP0_Status = tswapl(*(target_ulong *)ptr);
|
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2008-06-27 12:02:35 +02:00
|
|
|
env->active_tc.LO[0] = tswapl(*(target_ulong *)ptr);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2008-06-27 12:02:35 +02:00
|
|
|
env->active_tc.HI[0] = tswapl(*(target_ulong *)ptr);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2007-06-01 15:18:19 +02:00
|
|
|
env->CP0_BadVAddr = tswapl(*(target_ulong *)ptr);
|
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2007-06-01 15:18:19 +02:00
|
|
|
env->CP0_Cause = tswapl(*(target_ulong *)ptr);
|
|
|
|
ptr += sizeof(target_ulong);
|
2005-12-05 20:55:19 +01:00
|
|
|
|
2008-06-27 12:02:35 +02:00
|
|
|
env->active_tc.PC = tswapl(*(target_ulong *)ptr);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2007-02-28 23:37:42 +01:00
|
|
|
if (env->CP0_Config1 & (1 << CP0C1_FP))
|
2006-12-11 20:22:27 +01:00
|
|
|
{
|
2007-02-28 23:37:42 +01:00
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
{
|
2007-10-25 23:30:37 +02:00
|
|
|
if (env->CP0_Status & (1 << CP0St_FR))
|
2008-09-18 13:57:27 +02:00
|
|
|
env->active_fpu.fpr[i].d = tswapl(*(target_ulong *)ptr);
|
2007-10-25 23:30:37 +02:00
|
|
|
else
|
2008-09-18 13:57:27 +02:00
|
|
|
env->active_fpu.fpr[i].w[FP_ENDIAN_IDX] = tswapl(*(target_ulong *)ptr);
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2007-02-28 23:37:42 +01:00
|
|
|
}
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2008-09-18 13:57:27 +02:00
|
|
|
env->active_fpu.fcr31 = tswapl(*(target_ulong *)ptr) & 0xFF83FFFF;
|
2007-06-01 15:18:19 +02:00
|
|
|
ptr += sizeof(target_ulong);
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2007-10-25 23:30:37 +02:00
|
|
|
/* The remaining registers are assumed to be read-only. */
|
2006-12-11 20:22:27 +01:00
|
|
|
|
2007-02-28 23:37:42 +01:00
|
|
|
/* set rounding mode */
|
|
|
|
RESTORE_ROUNDING_MODE;
|
2006-12-11 20:22:27 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_SOFTFLOAT
|
2007-02-28 23:37:42 +01:00
|
|
|
/* no floating point exception for native float */
|
|
|
|
SET_FP_ENABLE(env->fcr31, 0);
|
2006-12-11 20:22:27 +01:00
|
|
|
#endif
|
2007-02-28 23:37:42 +01:00
|
|
|
}
|
2005-12-05 20:55:19 +01:00
|
|
|
}
|
2006-04-27 23:07:38 +02:00
|
|
|
#elif defined (TARGET_SH4)
|
2007-05-13 18:36:24 +02:00
|
|
|
|
|
|
|
/* Hint: Use "set architecture sh4" in GDB to see fpu registers */
|
|
|
|
|
2006-04-27 23:07:38 +02:00
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
|
|
|
uint32_t *ptr = (uint32_t *)mem_buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define SAVE(x) *ptr++=tswapl(x)
|
2006-06-18 21:12:54 +02:00
|
|
|
if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
|
|
|
|
for (i = 0; i < 8; i++) SAVE(env->gregs[i + 16]);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 8; i++) SAVE(env->gregs[i]);
|
|
|
|
}
|
|
|
|
for (i = 8; i < 16; i++) SAVE(env->gregs[i]);
|
2006-04-27 23:07:38 +02:00
|
|
|
SAVE (env->pc);
|
|
|
|
SAVE (env->pr);
|
|
|
|
SAVE (env->gbr);
|
|
|
|
SAVE (env->vbr);
|
|
|
|
SAVE (env->mach);
|
|
|
|
SAVE (env->macl);
|
|
|
|
SAVE (env->sr);
|
2007-05-13 18:36:24 +02:00
|
|
|
SAVE (env->fpul);
|
|
|
|
SAVE (env->fpscr);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
SAVE(env->fregs[i + ((env->fpscr & FPSCR_FR) ? 16 : 0)]);
|
|
|
|
SAVE (env->ssr);
|
|
|
|
SAVE (env->spc);
|
|
|
|
for (i = 0; i < 8; i++) SAVE(env->gregs[i]);
|
|
|
|
for (i = 0; i < 8; i++) SAVE(env->gregs[i + 16]);
|
2006-04-27 23:07:38 +02:00
|
|
|
return ((uint8_t *)ptr - mem_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
|
|
|
uint32_t *ptr = (uint32_t *)mem_buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define LOAD(x) (x)=*ptr++;
|
2006-06-18 21:12:54 +02:00
|
|
|
if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
|
|
|
|
for (i = 0; i < 8; i++) LOAD(env->gregs[i + 16]);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 8; i++) LOAD(env->gregs[i]);
|
|
|
|
}
|
|
|
|
for (i = 8; i < 16; i++) LOAD(env->gregs[i]);
|
2006-04-27 23:07:38 +02:00
|
|
|
LOAD (env->pc);
|
|
|
|
LOAD (env->pr);
|
|
|
|
LOAD (env->gbr);
|
|
|
|
LOAD (env->vbr);
|
|
|
|
LOAD (env->mach);
|
|
|
|
LOAD (env->macl);
|
|
|
|
LOAD (env->sr);
|
2007-05-13 18:36:24 +02:00
|
|
|
LOAD (env->fpul);
|
|
|
|
LOAD (env->fpscr);
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
LOAD(env->fregs[i + ((env->fpscr & FPSCR_FR) ? 16 : 0)]);
|
|
|
|
LOAD (env->ssr);
|
|
|
|
LOAD (env->spc);
|
|
|
|
for (i = 0; i < 8; i++) LOAD(env->gregs[i]);
|
|
|
|
for (i = 0; i < 8; i++) LOAD(env->gregs[i + 16]);
|
2006-04-27 23:07:38 +02:00
|
|
|
}
|
2007-10-08 15:16:14 +02:00
|
|
|
#elif defined (TARGET_CRIS)
|
|
|
|
|
|
|
|
static int cris_save_32 (unsigned char *d, uint32_t value)
|
|
|
|
{
|
|
|
|
*d++ = (value);
|
|
|
|
*d++ = (value >>= 8);
|
|
|
|
*d++ = (value >>= 8);
|
|
|
|
*d++ = (value >>= 8);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
static int cris_save_16 (unsigned char *d, uint32_t value)
|
|
|
|
{
|
|
|
|
*d++ = (value);
|
|
|
|
*d++ = (value >>= 8);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
static int cris_save_8 (unsigned char *d, uint32_t value)
|
|
|
|
{
|
|
|
|
*d++ = (value);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: this will bug on archs not supporting unaligned word accesses. */
|
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
|
|
|
uint8_t *ptr = mem_buf;
|
|
|
|
uint8_t srs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
ptr += cris_save_32 (ptr, env->regs[i]);
|
|
|
|
|
2008-02-28 09:28:32 +01:00
|
|
|
srs = env->pregs[PR_SRS];
|
2007-10-08 15:16:14 +02:00
|
|
|
|
|
|
|
ptr += cris_save_8 (ptr, env->pregs[0]);
|
|
|
|
ptr += cris_save_8 (ptr, env->pregs[1]);
|
|
|
|
ptr += cris_save_32 (ptr, env->pregs[2]);
|
|
|
|
ptr += cris_save_8 (ptr, srs);
|
|
|
|
ptr += cris_save_16 (ptr, env->pregs[4]);
|
|
|
|
|
|
|
|
for (i = 5; i < 16; i++)
|
|
|
|
ptr += cris_save_32 (ptr, env->pregs[i]);
|
|
|
|
|
|
|
|
ptr += cris_save_32 (ptr, env->pc);
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
ptr += cris_save_32 (ptr, env->sregs[srs][i]);
|
|
|
|
|
|
|
|
return ((uint8_t *)ptr - mem_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
|
|
|
uint32_t *ptr = (uint32_t *)mem_buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#define LOAD(x) (x)=*ptr++;
|
|
|
|
for (i = 0; i < 16; i++) LOAD(env->regs[i]);
|
|
|
|
LOAD (env->pc);
|
|
|
|
}
|
2005-04-17 21:16:13 +02:00
|
|
|
#else
|
2004-01-04 16:48:38 +01:00
|
|
|
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2003-06-27 19:34:32 +02:00
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
static int gdb_handle_packet(GDBState *s, CPUState *env, const char *line_buf)
|
2003-06-27 19:34:32 +02:00
|
|
|
{
|
|
|
|
const char *p;
|
2004-03-31 20:52:07 +02:00
|
|
|
int ch, reg_size, type;
|
2003-06-27 19:34:32 +02:00
|
|
|
char buf[4096];
|
2007-10-08 15:16:14 +02:00
|
|
|
uint8_t mem_buf[4096];
|
2003-06-27 19:34:32 +02:00
|
|
|
uint32_t *registers;
|
2006-06-25 17:32:37 +02:00
|
|
|
target_ulong addr, len;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2004-03-31 20:52:07 +02:00
|
|
|
#ifdef DEBUG_GDB
|
|
|
|
printf("command='%s'\n", line_buf);
|
|
|
|
#endif
|
|
|
|
p = line_buf;
|
|
|
|
ch = *p++;
|
|
|
|
switch(ch) {
|
|
|
|
case '?':
|
2005-04-17 21:16:13 +02:00
|
|
|
/* TODO: Make this return the correct value for user-mode. */
|
2004-03-31 20:52:07 +02:00
|
|
|
snprintf(buf, sizeof(buf), "S%02x", SIGTRAP);
|
|
|
|
put_packet(s, buf);
|
2008-05-17 20:58:29 +02:00
|
|
|
/* Remove all the breakpoints when this query is issued,
|
|
|
|
* because gdb is doing and initial connect and the state
|
|
|
|
* should be cleaned up.
|
|
|
|
*/
|
|
|
|
cpu_breakpoint_remove_all(env);
|
|
|
|
cpu_watchpoint_remove_all(env);
|
2004-03-31 20:52:07 +02:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (*p != '\0') {
|
2006-06-25 17:32:37 +02:00
|
|
|
addr = strtoull(p, (char **)&p, 16);
|
2003-07-26 14:06:08 +02:00
|
|
|
#if defined(TARGET_I386)
|
2004-03-31 20:52:07 +02:00
|
|
|
env->eip = addr;
|
2004-01-05 00:51:58 +01:00
|
|
|
#elif defined (TARGET_PPC)
|
2004-03-31 20:52:07 +02:00
|
|
|
env->nip = addr;
|
2004-10-04 23:23:09 +02:00
|
|
|
#elif defined (TARGET_SPARC)
|
|
|
|
env->pc = addr;
|
|
|
|
env->npc = addr + 4;
|
2005-11-26 11:38:39 +01:00
|
|
|
#elif defined (TARGET_ARM)
|
|
|
|
env->regs[15] = addr;
|
2006-04-27 23:07:38 +02:00
|
|
|
#elif defined (TARGET_SH4)
|
2007-07-12 12:05:07 +02:00
|
|
|
env->pc = addr;
|
|
|
|
#elif defined (TARGET_MIPS)
|
2008-06-27 12:02:35 +02:00
|
|
|
env->active_tc.PC = addr;
|
2007-10-08 15:16:14 +02:00
|
|
|
#elif defined (TARGET_CRIS)
|
|
|
|
env->pc = addr;
|
2003-07-26 14:06:08 +02:00
|
|
|
#endif
|
2004-03-31 20:52:07 +02:00
|
|
|
}
|
2008-03-14 07:10:42 +01:00
|
|
|
gdb_continue(s);
|
2005-04-24 12:07:11 +02:00
|
|
|
return RS_IDLE;
|
2008-05-18 00:20:53 +02:00
|
|
|
case 'C':
|
|
|
|
s->signal = strtoul(p, (char **)&p, 16);
|
|
|
|
gdb_continue(s);
|
|
|
|
return RS_IDLE;
|
2008-05-17 20:58:29 +02:00
|
|
|
case 'k':
|
|
|
|
/* Kill the target */
|
|
|
|
fprintf(stderr, "\nQEMU: Terminated via GDBstub\n");
|
|
|
|
exit(0);
|
|
|
|
case 'D':
|
|
|
|
/* Detach packet */
|
|
|
|
cpu_breakpoint_remove_all(env);
|
|
|
|
cpu_watchpoint_remove_all(env);
|
|
|
|
gdb_continue(s);
|
|
|
|
put_packet(s, "OK");
|
|
|
|
break;
|
2004-03-31 20:52:07 +02:00
|
|
|
case 's':
|
|
|
|
if (*p != '\0') {
|
2007-07-12 12:05:07 +02:00
|
|
|
addr = strtoull(p, (char **)&p, 16);
|
2003-07-29 22:50:33 +02:00
|
|
|
#if defined(TARGET_I386)
|
2004-03-31 20:52:07 +02:00
|
|
|
env->eip = addr;
|
2004-01-05 00:51:58 +01:00
|
|
|
#elif defined (TARGET_PPC)
|
2004-03-31 20:52:07 +02:00
|
|
|
env->nip = addr;
|
2004-10-04 23:23:09 +02:00
|
|
|
#elif defined (TARGET_SPARC)
|
|
|
|
env->pc = addr;
|
|
|
|
env->npc = addr + 4;
|
2005-11-26 11:38:39 +01:00
|
|
|
#elif defined (TARGET_ARM)
|
|
|
|
env->regs[15] = addr;
|
2006-04-27 23:07:38 +02:00
|
|
|
#elif defined (TARGET_SH4)
|
2007-07-12 12:05:07 +02:00
|
|
|
env->pc = addr;
|
|
|
|
#elif defined (TARGET_MIPS)
|
2008-06-27 12:02:35 +02:00
|
|
|
env->active_tc.PC = addr;
|
2007-10-08 15:16:14 +02:00
|
|
|
#elif defined (TARGET_CRIS)
|
|
|
|
env->pc = addr;
|
2003-07-29 22:50:33 +02:00
|
|
|
#endif
|
2004-03-31 20:52:07 +02:00
|
|
|
}
|
2008-05-09 10:25:14 +02:00
|
|
|
cpu_single_step(env, sstep_flags);
|
2008-03-14 07:10:42 +01:00
|
|
|
gdb_continue(s);
|
2005-04-24 12:07:11 +02:00
|
|
|
return RS_IDLE;
|
2007-01-28 04:10:55 +01:00
|
|
|
case 'F':
|
|
|
|
{
|
|
|
|
target_ulong ret;
|
|
|
|
target_ulong err;
|
|
|
|
|
|
|
|
ret = strtoull(p, (char **)&p, 16);
|
|
|
|
if (*p == ',') {
|
|
|
|
p++;
|
|
|
|
err = strtoull(p, (char **)&p, 16);
|
|
|
|
} else {
|
|
|
|
err = 0;
|
|
|
|
}
|
|
|
|
if (*p == ',')
|
|
|
|
p++;
|
|
|
|
type = *p;
|
|
|
|
if (gdb_current_syscall_cb)
|
|
|
|
gdb_current_syscall_cb(s->env, ret, err);
|
|
|
|
if (type == 'C') {
|
|
|
|
put_packet(s, "T02");
|
|
|
|
} else {
|
2008-03-14 07:10:42 +01:00
|
|
|
gdb_continue(s);
|
2007-01-28 04:10:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-03-31 20:52:07 +02:00
|
|
|
case 'g':
|
|
|
|
reg_size = cpu_gdb_read_registers(env, mem_buf);
|
|
|
|
memtohex(buf, mem_buf, reg_size);
|
|
|
|
put_packet(s, buf);
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
registers = (void *)mem_buf;
|
|
|
|
len = strlen(p) / 2;
|
|
|
|
hextomem((uint8_t *)registers, p, len);
|
|
|
|
cpu_gdb_write_registers(env, mem_buf, len);
|
|
|
|
put_packet(s, "OK");
|
|
|
|
break;
|
|
|
|
case 'm':
|
2006-06-25 17:32:37 +02:00
|
|
|
addr = strtoull(p, (char **)&p, 16);
|
2004-03-31 20:52:07 +02:00
|
|
|
if (*p == ',')
|
|
|
|
p++;
|
2006-06-25 17:32:37 +02:00
|
|
|
len = strtoull(p, NULL, 16);
|
2005-12-05 20:55:19 +01:00
|
|
|
if (cpu_memory_rw_debug(env, addr, mem_buf, len, 0) != 0) {
|
|
|
|
put_packet (s, "E14");
|
|
|
|
} else {
|
|
|
|
memtohex(buf, mem_buf, len);
|
|
|
|
put_packet(s, buf);
|
|
|
|
}
|
2004-03-31 20:52:07 +02:00
|
|
|
break;
|
|
|
|
case 'M':
|
2006-06-25 17:32:37 +02:00
|
|
|
addr = strtoull(p, (char **)&p, 16);
|
2004-03-31 20:52:07 +02:00
|
|
|
if (*p == ',')
|
|
|
|
p++;
|
2006-06-25 17:32:37 +02:00
|
|
|
len = strtoull(p, (char **)&p, 16);
|
2005-01-17 23:03:16 +01:00
|
|
|
if (*p == ':')
|
2004-03-31 20:52:07 +02:00
|
|
|
p++;
|
|
|
|
hextomem(mem_buf, p, len);
|
|
|
|
if (cpu_memory_rw_debug(env, addr, mem_buf, len, 1) != 0)
|
2005-04-26 23:09:55 +02:00
|
|
|
put_packet(s, "E14");
|
2004-03-31 20:52:07 +02:00
|
|
|
else
|
|
|
|
put_packet(s, "OK");
|
|
|
|
break;
|
|
|
|
case 'Z':
|
|
|
|
type = strtoul(p, (char **)&p, 16);
|
|
|
|
if (*p == ',')
|
|
|
|
p++;
|
2006-06-25 17:32:37 +02:00
|
|
|
addr = strtoull(p, (char **)&p, 16);
|
2004-03-31 20:52:07 +02:00
|
|
|
if (*p == ',')
|
|
|
|
p++;
|
2006-06-25 17:32:37 +02:00
|
|
|
len = strtoull(p, (char **)&p, 16);
|
2008-06-09 02:20:13 +02:00
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
2004-03-31 20:52:07 +02:00
|
|
|
if (cpu_breakpoint_insert(env, addr) < 0)
|
|
|
|
goto breakpoint_error;
|
|
|
|
put_packet(s, "OK");
|
2008-06-09 02:20:13 +02:00
|
|
|
break;
|
2007-03-17 00:58:11 +01:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2008-06-09 02:20:13 +02:00
|
|
|
case 2:
|
|
|
|
type = PAGE_WRITE;
|
|
|
|
goto insert_watchpoint;
|
|
|
|
case 3:
|
|
|
|
type = PAGE_READ;
|
|
|
|
goto insert_watchpoint;
|
|
|
|
case 4:
|
|
|
|
type = PAGE_READ | PAGE_WRITE;
|
|
|
|
insert_watchpoint:
|
|
|
|
if (cpu_watchpoint_insert(env, addr, type) < 0)
|
2007-03-17 00:58:11 +01:00
|
|
|
goto breakpoint_error;
|
|
|
|
put_packet(s, "OK");
|
2008-06-09 02:20:13 +02:00
|
|
|
break;
|
2007-03-17 00:58:11 +01:00
|
|
|
#endif
|
2008-06-09 02:20:13 +02:00
|
|
|
default:
|
|
|
|
put_packet(s, "");
|
|
|
|
break;
|
2004-03-31 20:52:07 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-09 02:20:13 +02:00
|
|
|
breakpoint_error:
|
|
|
|
put_packet(s, "E22");
|
|
|
|
break;
|
|
|
|
|
2004-03-31 20:52:07 +02:00
|
|
|
case 'z':
|
|
|
|
type = strtoul(p, (char **)&p, 16);
|
|
|
|
if (*p == ',')
|
|
|
|
p++;
|
2006-06-25 17:32:37 +02:00
|
|
|
addr = strtoull(p, (char **)&p, 16);
|
2004-03-31 20:52:07 +02:00
|
|
|
if (*p == ',')
|
|
|
|
p++;
|
2006-06-25 17:32:37 +02:00
|
|
|
len = strtoull(p, (char **)&p, 16);
|
2004-03-31 20:52:07 +02:00
|
|
|
if (type == 0 || type == 1) {
|
|
|
|
cpu_breakpoint_remove(env, addr);
|
|
|
|
put_packet(s, "OK");
|
2007-03-17 00:58:11 +01:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2008-06-09 02:20:13 +02:00
|
|
|
} else if (type >= 2 || type <= 4) {
|
2007-03-17 00:58:11 +01:00
|
|
|
cpu_watchpoint_remove(env, addr);
|
|
|
|
put_packet(s, "OK");
|
|
|
|
#endif
|
2004-03-31 20:52:07 +02:00
|
|
|
} else {
|
2008-06-09 02:20:13 +02:00
|
|
|
put_packet(s, "");
|
2004-03-31 20:52:07 +02:00
|
|
|
}
|
|
|
|
break;
|
2006-06-17 20:30:42 +02:00
|
|
|
case 'q':
|
2008-05-09 10:25:14 +02:00
|
|
|
case 'Q':
|
|
|
|
/* parse any 'q' packets here */
|
|
|
|
if (!strcmp(p,"qemu.sstepbits")) {
|
|
|
|
/* Query Breakpoint bit definitions */
|
2008-08-21 19:58:08 +02:00
|
|
|
snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x",
|
|
|
|
SSTEP_ENABLE,
|
|
|
|
SSTEP_NOIRQ,
|
|
|
|
SSTEP_NOTIMER);
|
2008-05-09 10:25:14 +02:00
|
|
|
put_packet(s, buf);
|
|
|
|
break;
|
|
|
|
} else if (strncmp(p,"qemu.sstep",10) == 0) {
|
|
|
|
/* Display or change the sstep_flags */
|
|
|
|
p += 10;
|
|
|
|
if (*p != '=') {
|
|
|
|
/* Display current setting */
|
2008-08-21 19:58:08 +02:00
|
|
|
snprintf(buf, sizeof(buf), "0x%x", sstep_flags);
|
2008-05-09 10:25:14 +02:00
|
|
|
put_packet(s, buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
type = strtoul(p, (char **)&p, 16);
|
|
|
|
sstep_flags = type;
|
|
|
|
put_packet(s, "OK");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_LINUX_USER
|
|
|
|
else if (strncmp(p, "Offsets", 7) == 0) {
|
2006-06-17 20:30:42 +02:00
|
|
|
TaskState *ts = env->opaque;
|
|
|
|
|
2008-08-21 19:58:08 +02:00
|
|
|
snprintf(buf, sizeof(buf),
|
|
|
|
"Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx
|
|
|
|
";Bss=" TARGET_ABI_FMT_lx,
|
|
|
|
ts->info->code_offset,
|
|
|
|
ts->info->data_offset,
|
|
|
|
ts->info->data_offset);
|
2006-06-17 20:30:42 +02:00
|
|
|
put_packet(s, buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2008-05-09 10:25:14 +02:00
|
|
|
/* Fall through. */
|
2004-03-31 20:52:07 +02:00
|
|
|
default:
|
|
|
|
/* put empty packet */
|
|
|
|
buf[0] = '\0';
|
|
|
|
put_packet(s, buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return RS_IDLE;
|
|
|
|
}
|
|
|
|
|
2005-01-04 00:34:06 +01:00
|
|
|
extern void tb_flush(CPUState *env);
|
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2004-03-31 20:52:07 +02:00
|
|
|
static void gdb_vm_stopped(void *opaque, int reason)
|
|
|
|
{
|
|
|
|
GDBState *s = opaque;
|
|
|
|
char buf[256];
|
|
|
|
int ret;
|
|
|
|
|
2007-01-28 04:10:55 +01:00
|
|
|
if (s->state == RS_SYSCALL)
|
|
|
|
return;
|
|
|
|
|
2004-03-31 20:52:07 +02:00
|
|
|
/* disable single step if it was enable */
|
2005-11-22 00:25:50 +01:00
|
|
|
cpu_single_step(s->env, 0);
|
2004-03-31 20:52:07 +02:00
|
|
|
|
2004-12-20 00:18:01 +01:00
|
|
|
if (reason == EXCP_DEBUG) {
|
2007-03-17 00:58:11 +01:00
|
|
|
if (s->env->watchpoint_hit) {
|
2007-04-15 00:35:50 +02:00
|
|
|
snprintf(buf, sizeof(buf), "T%02xwatch:" TARGET_FMT_lx ";",
|
|
|
|
SIGTRAP,
|
2007-03-17 00:58:11 +01:00
|
|
|
s->env->watchpoint[s->env->watchpoint_hit - 1].vaddr);
|
|
|
|
put_packet(s, buf);
|
|
|
|
s->env->watchpoint_hit = 0;
|
|
|
|
return;
|
|
|
|
}
|
2005-11-22 00:25:50 +01:00
|
|
|
tb_flush(s->env);
|
2004-03-31 20:52:07 +02:00
|
|
|
ret = SIGTRAP;
|
2006-04-23 20:42:15 +02:00
|
|
|
} else if (reason == EXCP_INTERRUPT) {
|
|
|
|
ret = SIGINT;
|
|
|
|
} else {
|
2004-03-31 20:52:07 +02:00
|
|
|
ret = 0;
|
2006-04-23 20:42:15 +02:00
|
|
|
}
|
2004-03-31 20:52:07 +02:00
|
|
|
snprintf(buf, sizeof(buf), "S%02x", ret);
|
|
|
|
put_packet(s, buf);
|
|
|
|
}
|
2005-04-17 21:16:13 +02:00
|
|
|
#endif
|
2004-03-31 20:52:07 +02:00
|
|
|
|
2007-01-28 04:10:55 +01:00
|
|
|
/* Send a gdb syscall request.
|
|
|
|
This accepts limited printf-style format specifiers, specifically:
|
2007-05-26 17:09:38 +02:00
|
|
|
%x - target_ulong argument printed in hex.
|
|
|
|
%lx - 64-bit argument printed in hex.
|
|
|
|
%s - string pointer (target_ulong) and length (int) pair. */
|
2008-09-14 08:45:34 +02:00
|
|
|
void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
|
2007-01-28 04:10:55 +01:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
char buf[256];
|
|
|
|
char *p;
|
|
|
|
target_ulong addr;
|
2007-05-26 17:09:38 +02:00
|
|
|
uint64_t i64;
|
2007-01-28 04:10:55 +01:00
|
|
|
GDBState *s;
|
|
|
|
|
|
|
|
s = gdb_syscall_state;
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
gdb_current_syscall_cb = cb;
|
|
|
|
s->state = RS_SYSCALL;
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
vm_stop(EXCP_DEBUG);
|
|
|
|
#endif
|
|
|
|
s->state = RS_IDLE;
|
|
|
|
va_start(va, fmt);
|
|
|
|
p = buf;
|
|
|
|
*(p++) = 'F';
|
|
|
|
while (*fmt) {
|
|
|
|
if (*fmt == '%') {
|
|
|
|
fmt++;
|
|
|
|
switch (*fmt++) {
|
|
|
|
case 'x':
|
|
|
|
addr = va_arg(va, target_ulong);
|
2008-08-21 19:58:08 +02:00
|
|
|
p += snprintf(p, &buf[sizeof(buf)] - p, TARGET_FMT_lx, addr);
|
2007-01-28 04:10:55 +01:00
|
|
|
break;
|
2007-05-26 17:09:38 +02:00
|
|
|
case 'l':
|
|
|
|
if (*(fmt++) != 'x')
|
|
|
|
goto bad_format;
|
|
|
|
i64 = va_arg(va, uint64_t);
|
2008-08-21 19:58:08 +02:00
|
|
|
p += snprintf(p, &buf[sizeof(buf)] - p, "%" PRIx64, i64);
|
2007-05-26 17:09:38 +02:00
|
|
|
break;
|
2007-01-28 04:10:55 +01:00
|
|
|
case 's':
|
|
|
|
addr = va_arg(va, target_ulong);
|
2008-08-21 19:58:08 +02:00
|
|
|
p += snprintf(p, &buf[sizeof(buf)] - p, TARGET_FMT_lx "/%x",
|
|
|
|
addr, va_arg(va, int));
|
2007-01-28 04:10:55 +01:00
|
|
|
break;
|
|
|
|
default:
|
2007-05-26 17:09:38 +02:00
|
|
|
bad_format:
|
2007-01-28 04:10:55 +01:00
|
|
|
fprintf(stderr, "gdbstub: Bad syscall format string '%s'\n",
|
|
|
|
fmt - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*(p++) = *(fmt++);
|
|
|
|
}
|
|
|
|
}
|
2007-08-06 15:19:15 +02:00
|
|
|
*p = 0;
|
2007-01-28 04:10:55 +01:00
|
|
|
va_end(va);
|
|
|
|
put_packet(s, buf);
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
gdb_handlesig(s->env, 0);
|
|
|
|
#else
|
|
|
|
cpu_interrupt(s->env, CPU_INTERRUPT_EXIT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-11-22 00:25:50 +01:00
|
|
|
static void gdb_read_byte(GDBState *s, int ch)
|
2004-03-31 20:52:07 +02:00
|
|
|
{
|
2005-11-22 00:25:50 +01:00
|
|
|
CPUState *env = s->env;
|
2004-03-31 20:52:07 +02:00
|
|
|
int i, csum;
|
2007-12-16 04:02:09 +01:00
|
|
|
uint8_t reply;
|
2004-03-31 20:52:07 +02:00
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2007-01-28 02:53:16 +01:00
|
|
|
if (s->last_packet_len) {
|
|
|
|
/* Waiting for a response to the last packet. If we see the start
|
|
|
|
of a new command then abandon the previous response. */
|
|
|
|
if (ch == '-') {
|
|
|
|
#ifdef DEBUG_GDB
|
|
|
|
printf("Got NACK, retransmitting\n");
|
|
|
|
#endif
|
2007-12-16 04:16:05 +01:00
|
|
|
put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len);
|
2007-01-28 02:53:16 +01:00
|
|
|
}
|
|
|
|
#ifdef DEBUG_GDB
|
|
|
|
else if (ch == '+')
|
|
|
|
printf("Got ACK\n");
|
|
|
|
else
|
|
|
|
printf("Got '%c' when expecting ACK/NACK\n", ch);
|
|
|
|
#endif
|
|
|
|
if (ch == '+' || ch == '$')
|
|
|
|
s->last_packet_len = 0;
|
|
|
|
if (ch != '$')
|
|
|
|
return;
|
|
|
|
}
|
2004-03-31 20:52:07 +02:00
|
|
|
if (vm_running) {
|
|
|
|
/* when the CPU is running, we cannot do anything except stop
|
|
|
|
it when receiving a char */
|
|
|
|
vm_stop(EXCP_INTERRUPT);
|
2007-09-16 23:08:06 +02:00
|
|
|
} else
|
2005-04-17 21:16:13 +02:00
|
|
|
#endif
|
2005-04-24 12:07:11 +02:00
|
|
|
{
|
2004-03-31 20:52:07 +02:00
|
|
|
switch(s->state) {
|
|
|
|
case RS_IDLE:
|
|
|
|
if (ch == '$') {
|
|
|
|
s->line_buf_index = 0;
|
|
|
|
s->state = RS_GETLINE;
|
2003-07-29 22:50:33 +02:00
|
|
|
}
|
2003-06-27 19:34:32 +02:00
|
|
|
break;
|
2004-03-31 20:52:07 +02:00
|
|
|
case RS_GETLINE:
|
|
|
|
if (ch == '#') {
|
|
|
|
s->state = RS_CHKSUM1;
|
|
|
|
} else if (s->line_buf_index >= sizeof(s->line_buf) - 1) {
|
|
|
|
s->state = RS_IDLE;
|
2003-07-26 14:06:08 +02:00
|
|
|
} else {
|
2004-03-31 20:52:07 +02:00
|
|
|
s->line_buf[s->line_buf_index++] = ch;
|
2003-07-26 14:06:08 +02:00
|
|
|
}
|
|
|
|
break;
|
2004-03-31 20:52:07 +02:00
|
|
|
case RS_CHKSUM1:
|
|
|
|
s->line_buf[s->line_buf_index] = '\0';
|
|
|
|
s->line_csum = fromhex(ch) << 4;
|
|
|
|
s->state = RS_CHKSUM2;
|
|
|
|
break;
|
|
|
|
case RS_CHKSUM2:
|
|
|
|
s->line_csum |= fromhex(ch);
|
|
|
|
csum = 0;
|
|
|
|
for(i = 0; i < s->line_buf_index; i++) {
|
|
|
|
csum += s->line_buf[i];
|
|
|
|
}
|
|
|
|
if (s->line_csum != (csum & 0xff)) {
|
2007-12-16 04:02:09 +01:00
|
|
|
reply = '-';
|
|
|
|
put_buffer(s, &reply, 1);
|
2004-03-31 20:52:07 +02:00
|
|
|
s->state = RS_IDLE;
|
2003-07-26 14:06:08 +02:00
|
|
|
} else {
|
2007-12-16 04:02:09 +01:00
|
|
|
reply = '+';
|
|
|
|
put_buffer(s, &reply, 1);
|
2005-04-17 21:16:13 +02:00
|
|
|
s->state = gdb_handle_packet(s, env, s->line_buf);
|
2003-07-26 14:06:08 +02:00
|
|
|
}
|
|
|
|
break;
|
2007-01-28 04:10:55 +01:00
|
|
|
default:
|
|
|
|
abort();
|
2004-03-31 20:52:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
int
|
|
|
|
gdb_handlesig (CPUState *env, int sig)
|
|
|
|
{
|
|
|
|
GDBState *s;
|
|
|
|
char buf[256];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
s = &gdbserver_state;
|
2008-05-18 00:20:53 +02:00
|
|
|
if (gdbserver_fd < 0 || s->fd < 0)
|
|
|
|
return sig;
|
2005-04-17 21:16:13 +02:00
|
|
|
|
|
|
|
/* disable single step if it was enabled */
|
|
|
|
cpu_single_step(env, 0);
|
|
|
|
tb_flush(env);
|
|
|
|
|
|
|
|
if (sig != 0)
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "S%02x", sig);
|
|
|
|
put_packet(s, buf);
|
|
|
|
}
|
2008-05-18 00:20:53 +02:00
|
|
|
/* put_packet() might have detected that the peer terminated the
|
|
|
|
connection. */
|
|
|
|
if (s->fd < 0)
|
|
|
|
return sig;
|
2005-04-17 21:16:13 +02:00
|
|
|
|
|
|
|
sig = 0;
|
|
|
|
s->state = RS_IDLE;
|
2005-04-24 12:07:11 +02:00
|
|
|
s->running_state = 0;
|
|
|
|
while (s->running_state == 0) {
|
2005-04-17 21:16:13 +02:00
|
|
|
n = read (s->fd, buf, 256);
|
|
|
|
if (n > 0)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
2005-11-22 00:25:50 +01:00
|
|
|
gdb_read_byte (s, buf[i]);
|
2005-04-17 21:16:13 +02:00
|
|
|
}
|
|
|
|
else if (n == 0 || errno != EAGAIN)
|
|
|
|
{
|
|
|
|
/* XXX: Connection closed. Should probably wait for annother
|
|
|
|
connection before continuing. */
|
|
|
|
return sig;
|
|
|
|
}
|
2005-04-24 12:07:11 +02:00
|
|
|
}
|
2008-05-18 00:20:53 +02:00
|
|
|
sig = s->signal;
|
|
|
|
s->signal = 0;
|
2005-04-17 21:16:13 +02:00
|
|
|
return sig;
|
|
|
|
}
|
2005-04-26 22:42:36 +02:00
|
|
|
|
|
|
|
/* Tell the remote gdb that the process has exited. */
|
|
|
|
void gdb_exit(CPUState *env, int code)
|
|
|
|
{
|
|
|
|
GDBState *s;
|
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
s = &gdbserver_state;
|
2008-05-18 00:20:53 +02:00
|
|
|
if (gdbserver_fd < 0 || s->fd < 0)
|
|
|
|
return;
|
2005-04-26 22:42:36 +02:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "W%02x", code);
|
|
|
|
put_packet(s, buf);
|
|
|
|
}
|
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
|
2005-11-15 23:16:05 +01:00
|
|
|
static void gdb_accept(void *opaque)
|
2004-03-31 20:52:07 +02:00
|
|
|
{
|
|
|
|
GDBState *s;
|
|
|
|
struct sockaddr_in sockaddr;
|
|
|
|
socklen_t len;
|
|
|
|
int val, fd;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
len = sizeof(sockaddr);
|
|
|
|
fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
|
|
|
|
if (fd < 0 && errno != EINTR) {
|
|
|
|
perror("accept");
|
|
|
|
return;
|
|
|
|
} else if (fd >= 0) {
|
2003-06-27 19:34:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-03-31 20:52:07 +02:00
|
|
|
|
|
|
|
/* set short latency */
|
|
|
|
val = 1;
|
2006-06-14 17:21:14 +02:00
|
|
|
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2005-04-17 21:16:13 +02:00
|
|
|
s = &gdbserver_state;
|
|
|
|
memset (s, 0, sizeof (GDBState));
|
2005-11-22 00:25:50 +01:00
|
|
|
s->env = first_cpu; /* XXX: allow to change CPU */
|
2004-03-31 20:52:07 +02:00
|
|
|
s->fd = fd;
|
|
|
|
|
2007-01-28 04:10:55 +01:00
|
|
|
gdb_syscall_state = s;
|
|
|
|
|
2004-03-31 20:52:07 +02:00
|
|
|
fcntl(fd, F_SETFL, O_NONBLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gdbserver_open(int port)
|
|
|
|
{
|
|
|
|
struct sockaddr_in sockaddr;
|
|
|
|
int fd, val, ret;
|
|
|
|
|
|
|
|
fd = socket(PF_INET, SOCK_STREAM, 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror("socket");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allow fast reuse */
|
|
|
|
val = 1;
|
2006-06-14 17:21:14 +02:00
|
|
|
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
|
2004-03-31 20:52:07 +02:00
|
|
|
|
|
|
|
sockaddr.sin_family = AF_INET;
|
|
|
|
sockaddr.sin_port = htons(port);
|
|
|
|
sockaddr.sin_addr.s_addr = 0;
|
|
|
|
ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
|
|
|
if (ret < 0) {
|
|
|
|
perror("bind");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = listen(fd, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
perror("listen");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gdbserver_start(int port)
|
|
|
|
{
|
|
|
|
gdbserver_fd = gdbserver_open(port);
|
|
|
|
if (gdbserver_fd < 0)
|
|
|
|
return -1;
|
|
|
|
/* accept connections */
|
2005-11-15 23:16:05 +01:00
|
|
|
gdb_accept (NULL);
|
2007-01-28 02:53:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 21:16:13 +02:00
|
|
|
#else
|
2007-07-12 00:48:58 +02:00
|
|
|
static int gdb_chr_can_receive(void *opaque)
|
2007-01-28 02:53:16 +01:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-07-12 00:48:58 +02:00
|
|
|
static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size)
|
2007-01-28 02:53:16 +01:00
|
|
|
{
|
|
|
|
GDBState *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
gdb_read_byte(s, buf[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gdb_chr_event(void *opaque, int event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case CHR_EVENT_RESET:
|
|
|
|
vm_stop(EXCP_INTERRUPT);
|
2007-01-28 04:10:55 +01:00
|
|
|
gdb_syscall_state = opaque;
|
2007-01-28 02:53:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-22 02:48:01 +01:00
|
|
|
int gdbserver_start(const char *port)
|
2007-01-28 02:53:16 +01:00
|
|
|
{
|
|
|
|
GDBState *s;
|
2007-02-22 02:48:01 +01:00
|
|
|
char gdbstub_port_name[128];
|
|
|
|
int port_num;
|
|
|
|
char *p;
|
|
|
|
CharDriverState *chr;
|
|
|
|
|
|
|
|
if (!port || !*port)
|
|
|
|
return -1;
|
2007-01-28 02:53:16 +01:00
|
|
|
|
2007-02-22 02:48:01 +01:00
|
|
|
port_num = strtol(port, &p, 10);
|
|
|
|
if (*p == 0) {
|
|
|
|
/* A numeric value is interpreted as a port number. */
|
|
|
|
snprintf(gdbstub_port_name, sizeof(gdbstub_port_name),
|
|
|
|
"tcp::%d,nowait,nodelay,server", port_num);
|
|
|
|
port = gdbstub_port_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
chr = qemu_chr_open(port);
|
2007-01-28 02:53:16 +01:00
|
|
|
if (!chr)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
s = qemu_mallocz(sizeof(GDBState));
|
|
|
|
if (!s) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
s->env = first_cpu; /* XXX: allow to change CPU */
|
|
|
|
s->chr = chr;
|
2007-07-12 00:48:58 +02:00
|
|
|
qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
|
2007-01-28 02:53:16 +01:00
|
|
|
gdb_chr_event, s);
|
|
|
|
qemu_add_vm_stop_handler(gdb_vm_stopped, s);
|
2003-06-27 19:34:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2007-01-28 02:53:16 +01:00
|
|
|
#endif
|