36 #include <netinet/in.h>
38 #include <sys/types.h>
48 static struct serial *sdi_desc = NULL;
50 #define SDI_TIMEOUT 30
65 #define MAX_BREAKPOINTS 1024
72 0x10, 0xe0, 0x70, 0x00
75 #define MAX_ACCESS_BREAKS 4
97 #define SDI_READ_CPU_REG 4
98 #define SDI_WRITE_CPU_REG 5
99 #define SDI_READ_MEMORY 6
100 #define SDI_WRITE_MEMORY 7
101 #define SDI_EXEC_CPU 8
102 #define SDI_STOP_CPU 9
103 #define SDI_WAIT_FOR_READY 10
104 #define SDI_GET_ATTR 11
105 #define SDI_SET_ATTR 12
106 #define SDI_STATUS 13
109 #define SDI_ATTR_NAME 1
110 #define SDI_ATTR_BRK 2
111 #define SDI_ATTR_ABRK 3
112 #define SDI_ATTR_CACHE 4
113 #define SDI_CACHE_TYPE_M32102 0
114 #define SDI_CACHE_TYPE_CHAOS 1
115 #define SDI_ATTR_MEM_ACCESS 5
116 #define SDI_MEM_ACCESS_DEBUG_DMA 0
117 #define SDI_MEM_ACCESS_MON_CODE 1
130 #define SDI_REG_R10 10
131 #define SDI_REG_R11 11
132 #define SDI_REG_R12 12
133 #define SDI_REG_FP 13
134 #define SDI_REG_LR 14
135 #define SDI_REG_SP 15
136 #define SDI_REG_PSW 16
137 #define SDI_REG_CBR 17
138 #define SDI_REG_SPI 18
139 #define SDI_REG_SPU 19
140 #define SDI_REG_CR4 20
141 #define SDI_REG_EVB 21
142 #define SDI_REG_BPC 22
143 #define SDI_REG_CR7 23
144 #define SDI_REG_BBPSW 24
145 #define SDI_REG_CR9 25
146 #define SDI_REG_CR10 26
147 #define SDI_REG_CR11 27
148 #define SDI_REG_CR12 28
149 #define SDI_REG_WR 29
150 #define SDI_REG_BBPC 30
151 #define SDI_REG_PBP 31
152 #define SDI_REG_ACCH 32
153 #define SDI_REG_ACCL 33
154 #define SDI_REG_ACC1H 34
155 #define SDI_REG_ACC1L 35
213 ((
unsigned char *) buf)[total++] = c;
224 memcpy (buf, &val, 4);
230 unsigned char buf[1];
239 unsigned char buf[2];
249 unsigned char buf[6];
261 unsigned char buf[13];
299 if ((val & 0xc0000000) == 0x80000000)
309 if ((val & 0xc0000000) == 0x80000000)
323 char *args,
char **env,
int from_tty)
328 error (
_(
"Cannot pass arguments to remote STDEBUG process"));
331 error (
_(
"No executable file specified"));
337 entry_pt = bfd_get_start_address (
exec_bfd);
363 struct hostent *host_ent;
364 struct sockaddr_in server_addr;
366 const char *port_str;
382 port_str = strchr (args,
':');
383 if (port_str == NULL)
386 xsnprintf (hostname,
sizeof (hostname),
"%s", args);
391 error (
_(
"Connection refused."));
394 error (
_(
"Cannot connect to SDI target."));
397 error (
_(
"Cannot connect to SDI target."));
456 unsigned long pc_addr, bp_addr, ab_addr;
458 unsigned char buf[13];
522 for (i = 0; i < ib_breakpoints; i++)
526 if (bp_addr == 0xffffffff)
545 if (bp_addr == 0xffffffff)
549 bp_addr &= 0x7fffffff;
555 if ((bp_addr & 2) == 0 && bp_addr != (pc_addr & 0xfffffffc))
576 if ((bp_addr & 2) == 0)
580 buf[11] =
bp_data[i][2] & 0x7f;
593 if ((bp_addr & 2) == 0)
596 buf[10] =
bp_data[i][1] & 0x7f;
617 if (ab_addr == 0x00000000)
705 unsigned long bp_addr, pc_addr;
708 unsigned char buf[13];
723 error (
_(
"Remote connection closed"));
729 error (
_(
"Remote connection closed"));
745 error (
_(
"Remote connection closed"));
752 status->
value.
sig = GDB_SIGNAL_TRAP;
755 signal (SIGINT, prev_sigint);
790 if ((pc_addr & 0x2) != 0)
794 if ((
bp_data[i][2] & 0x80) != 0)
803 if ((
bp_data[i][1] & 0x80) != 0)
816 for (i = 0; i < ib_breakpoints; i++)
826 if (bp_addr != 0xffffffff)
829 bp_addr &= 0x7fffffff;
852 if (c !=
'-' &&
recv_data (buf, 4) != -1)
856 if ((buf[3] & 0x1) == 0x1)
861 if ((buf[0] & 0x1) == 0x1)
925 unsigned long val, val2, regid;
946 val = ((0x00cf & val2) << 8) | ((0xcf00 & val) >> 8);
984 unsigned long psw, bbpsw;
992 tmp = (0x00cf & psw) | ((0x00cf & regval) << 8);
995 tmp = (0x0030 & bbpsw) | ((0xcf00 & regval) >> 8);
1005 regno, (
unsigned long) regval);
1026 const char *file =
"nothing";
1030 file = bfd_get_filename (
exec_bfd);
1043 unsigned long taddr;
1044 unsigned char buf[0x2000];
1051 if ((taddr & 0xa0000000) == 0x80000000)
1052 taddr &= 0x7fffffff;
1057 if (writebuf != NULL)
1067 if (writebuf != NULL)
1074 memcpy (buf + 9, writebuf, len);
1083 "m32r_xfer_memory() failed\n");
1102 if (c < 0 || c ==
'-')
1127 const char *annex,
gdb_byte *readbuf,
1138 readbuf, writebuf, offset, len,
1178 unsigned char buf[13];
1195 if (i >= ib_breakpoints)
1212 error (
_(
"Too many breakpoints"));
1250 struct timeval start_time, end_time;
1251 unsigned long data_count;
1259 while (*args !=
'\000')
1274 error (
_(
"Unknown option `%s'"), arg);
1285 if (!bfd_check_format (pbfd, bfd_object))
1286 error (
_(
"\"%s\" is not an object file: %s"), filename,
1287 bfd_errmsg (bfd_get_error ()));
1289 gettimeofday (&start_time, NULL);
1295 for (section = pbfd->sections; section; section = section->next)
1297 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD)
1299 bfd_vma section_address;
1300 bfd_size_type section_size;
1304 section_address = bfd_section_lma (pbfd, section);
1305 section_size = bfd_get_section_size (section);
1309 if ((section_address & 0xa0000000) == 0x80000000)
1310 section_address &= 0x7fffffff;
1315 bfd_get_section_name (pbfd, section),
1316 (
unsigned long) section_address,
1317 (
int) section_size);
1321 data_count += section_size;
1324 while (section_size > 0)
1326 char unsigned buf[0x1000 + 9];
1329 count =
min (section_size, 0x1000);
1335 bfd_get_section_contents (pbfd, section, buf + 9, fptr, count);
1337 error (
_(
"Error while downloading %s section."),
1338 bfd_get_section_name (pbfd, section));
1351 section_address += count;
1353 section_size -= count;
1374 signal (SIGINT, prev_sigint);
1376 gettimeofday (&end_time, NULL);
1396 entry = bfd_get_start_address (pbfd);
1400 (
unsigned long) entry);
1427 int type,
int cnt,
int othertype)
1458 error (
_(
"Too many watchpoints"));
1524 static char buf[64];
1528 xsnprintf (buf,
sizeof buf,
"Thread <main>");
1551 unsigned char buf[4096];
1561 for (i = 0; i < 4096; i++)
1578 unsigned char buf[3];
1590 unsigned char buf[3];
1601 unsigned char buf[3];
1645 m32r_ops.
to_doc =
"Use an M32R board using SDI debugging protocol.";
1701 _(
"Reset SDI connection."));
1704 _(
"Show status of SDI connection."));
1707 _(
"Debug M32R/Chaos."));
1710 _(
"Use debug DMA mem access."));
1712 _(
"Use mon code mem access."));
1715 _(
"Set breakpoints by IB break."));
1717 _(
"Set breakpoints by dbt."));
1721 remote_m32r_ptid =
ptid_build (42000, 0, 42000);
struct gdbarch * target_gdbarch(void)
void add_target(struct target_ops *t)
static int send_two_arg_cmd(unsigned char cmd, unsigned char arg1, unsigned long arg2)
static int use_ib_breakpoints
static void sdistatus_command(char *args, int from_tty)
#define SDI_CACHE_TYPE_CHAOS
static void m32r_load(struct target_ops *self, const char *args, int from_tty)
static unsigned int ab_type[MAX_ACCESS_BREAKS]
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
static unsigned long last_pc_addr
static void m32r_open(const char *args, int from_tty)
#define SDI_WRITE_CPU_REG
static void debug_chaos_command(char *args, int from_tty)
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
#define SDI_ATTR_MEM_ACCESS
static void use_debug_dma_command(char *args, int from_tty)
int(* to_has_memory)(struct target_ops *)
static int m32r_thread_alive(struct target_ops *ops, ptid_t ptid)
char *(* to_pid_to_str)(struct target_ops *, ptid_t) TARGET_DEFAULT_FUNC(default_pid_to_str)
static CORE_ADDR hit_watchpoint_addr
static void m32r_files_info(struct target_ops *target)
void init_wait_for_inferior(void)
int(* to_has_stack)(struct target_ops *)
void push_target(struct target_ops *t)
int(* to_insert_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_FUNC(memory_insert_breakpoint)
void delete_thread_silent(ptid_t)
char * plongest(LONGEST l)
struct target_ops m32r_ops
struct ui_file * gdb_stdout
int unpush_target(struct target_ops *t)
static int m32r_insert_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
static unsigned char recv_char_data(void)
void generic_mourn_inferior(void)
void(* to_close)(struct target_ops *)
#define SDI_MEM_ACCESS_MON_CODE
static int send_data(const void *buf, int len)
int serial_write(struct serial *scb, const void *buf, size_t count)
static void use_dbt_breakpoints_command(char *args, int from_tty)
int(* to_remove_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_FUNC(memory_remove_breakpoint)
int gdbarch_num_regs(struct gdbarch *gdbarch)
ptid_t(* to_wait)(struct target_ops *, ptid_t, struct target_waitstatus *, int TARGET_DEBUG_PRINTER(target_debug_print_options)) TARGET_DEFAULT_NORETURN(noprocess())
struct bfd * gdb_bfd_open(const char *name, const char *target, int fd)
void regcache_write_pc(struct regcache *regcache, CORE_ADDR pc)
static unsigned int ab_size[MAX_ACCESS_BREAKS]
struct regcache * get_current_regcache(void)
static void m32r_detach(struct target_ops *ops, const char *args, int from_tty)
void store_unsigned_integer(gdb_byte *, int, enum bfd_endian, ULONGEST)
void printf_filtered(const char *format,...)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
ptid_t ptid_build(int pid, long lwp, long tid)
void(* to_files_info)(struct target_ops *) TARGET_DEFAULT_IGNORE()
static void use_ib_breakpoints_command(char *args, int from_tty)
static enum target_xfer_status m32r_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
void null_cleanup(void *arg)
static int m32r_remove_watchpoint(struct target_ops *self, CORE_ADDR addr, int len, int type, struct expression *cond)
int(* to_insert_watchpoint)(struct target_ops *, CORE_ADDR, int, int, struct expression *) TARGET_DEFAULT_RETURN(-1)
static ptid_t remote_m32r_ptid
void serial_log_command(struct target_ops *self, const char *cmd)
static char chip_name[64]
static int m32r_insert_watchpoint(struct target_ops *self, CORE_ADDR addr, int len, int type, struct expression *cond)
static int m32r_stopped_data_address(struct target_ops *target, CORE_ADDR *addr_p)
static int send_one_arg_cmd(unsigned char cmd, unsigned char arg1)
static void m32r_mourn_inferior(struct target_ops *ops)
static void m32r_fetch_register(struct target_ops *ops, struct regcache *regcache, int regno)
struct target_ops current_target
void initialize_file_ftype(void)
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
static int recv_data(void *buf, int len)
int(* to_remove_watchpoint)(struct target_ops *, CORE_ADDR, int, int, struct expression *) TARGET_DEFAULT_RETURN(-1)
void target_terminal_inferior(void)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
void(* to_resume)(struct target_ops *, ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
static void m32r_prepare_to_store(struct target_ops *self, struct regcache *regcache)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
static void check_mmu_status(void)
static unsigned long ab_address[MAX_ACCESS_BREAKS]
union target_waitstatus::@161 value
int(* to_has_execution)(struct target_ops *, ptid_t)
static char * m32r_pid_to_str(struct target_ops *ops, ptid_t ptid)
void print_transfer_performance(struct ui_file *stream, unsigned long data_count, unsigned long write_count, const struct timeval *start_time, const struct timeval *end_time)
static void m32r_create_inferior(struct target_ops *ops, char *execfile, char *args, char **env, int from_tty)
static int startswith(const char *string, const char *pattern)
struct thread_info * add_thread_silent(ptid_t ptid)
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
static void m32r_stop(struct target_ops *self, ptid_t ptid)
void printf_unfiltered(const char *format,...)
void(* to_detach)(struct target_ops *ops, const char *, int) TARGET_DEFAULT_IGNORE()
static void m32r_kill(struct target_ops *ops)
static void m32r_close(struct target_ops *self)
struct cleanup * make_cleanup_bfd_unref(bfd *abfd)
struct ui_file * gdb_stdlog
static int max_ib_breakpoints
void serial_close(struct serial *scb)
static void gdb_cntrl_c(int signo)
char * normal_pid_to_str(ptid_t ptid)
struct serial * serial_open(const char *name)
void(* to_log_command)(struct target_ops *, const char *) TARGET_DEFAULT_IGNORE()
static void sdireset_command(char *args, int from_tty)
static int send_cmd(unsigned char cmd)
static int m32r_has_execution(struct target_ops *target, ptid_t the_ptid)
void target_terminal_init(void)
void clear_symtab_users(int add_flags)
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
void(* to_mourn_inferior)(struct target_ops *) TARGET_DEFAULT_FUNC(default_mourn_inferior)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
int(* to_can_use_hw_breakpoint)(struct target_ops *, int, int, int) TARGET_DEFAULT_RETURN(0)
static unsigned char bp_data[MAX_BREAKPOINTS][4]
void(* to_stop)(struct target_ops *, ptid_t) TARGET_DEFAULT_IGNORE()
static int m32r_return_one(struct target_ops *target)
int xsnprintf(char *str, size_t size, const char *format,...)
void clear_proceed_status(int step)
enum target_waitkind kind
static unsigned long recv_long_data(void)
void(* to_kill)(struct target_ops *) TARGET_DEFAULT_NORETURN(noprocess())
CORE_ADDR regcache_read_pc(struct regcache *regcache)
int remove_breakpoints(void)
void(* to_open)(const char *, int)
static int m32r_stopped_by_watchpoint(struct target_ops *ops)
void(* to_create_inferior)(struct target_ops *, char *, char *, char **, int)
int(* to_stopped_by_watchpoint)(struct target_ops *) TARGET_DEFAULT_RETURN(0)
char * extract_arg_const(const char **arg)
static int m32r_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
#define SDI_MEM_ACCESS_DEBUG_DMA
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
const char * to_shortname
static unsigned long bp_address[MAX_BREAKPOINTS]
initialize_file_ftype _initialize_remote_m32r
char * get_exec_file(int err)
static ptid_t m32r_wait(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options)
unsigned long long ULONGEST
static unsigned char last_pc_addr_data[2]
int(* to_has_all_memory)(struct target_ops *)
static int m32r_can_use_hw_watchpoint(struct target_ops *self, int type, int cnt, int othertype)
static const unsigned char dbt_bp_entry[]
static int max_access_breaks
int(* to_thread_alive)(struct target_ops *, ptid_t ptid) TARGET_DEFAULT_RETURN(0)
void target_preopen(int from_tty)
int serial_readchar(struct serial *scb, int timeout)
static void use_mon_code_command(char *args, int from_tty)
void gdb_flush(struct ui_file *file)
int(* to_stopped_data_address)(struct target_ops *, CORE_ADDR *) TARGET_DEFAULT_RETURN(0)
static void store_long_parameter(void *buf, long val)
#define SDI_WAIT_FOR_READY
static int get_reg_id(int regno)
static int send_three_arg_cmd(unsigned char cmd, unsigned long arg1, unsigned long arg2, unsigned long arg3)
void(* to_prepare_to_store)(struct target_ops *, struct regcache *) TARGET_DEFAULT_NORETURN(noprocess())
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
int(* to_has_registers)(struct target_ops *)
static void init_m32r_ops(void)
enum bfd_endian byte_order
void error(const char *fmt,...)
static enum target_xfer_status m32r_xfer_memory(gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST memaddr, ULONGEST len, ULONGEST *xfered_len)
static void m32r_store_register(struct target_ops *ops, struct regcache *regcache, int regno)
#define MAX_ACCESS_BREAKS
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
struct target_ops * beneath
void(* to_load)(struct target_ops *, const char *, int) TARGET_DEFAULT_NORETURN(tcomplain())
void do_cleanups(struct cleanup *old_chain)
static void m32r_resume(struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal sig)
const ULONGEST const LONGEST len