home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gdb-4.12-src.lha
/
GNU
/
src
/
amiga
/
gdb-4.12
/
gdb
/
remote-mips.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-03
|
40KB
|
1,431 lines
/* Remote debugging interface for MIPS remote debugging protocol.
Copyright 1993, 1994 Free Software Foundation, Inc.
Contributed by Cygnus Support. Written by Ian Lance Taylor
<ian@cygnus.com>.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "defs.h"
#include "inferior.h"
#include "bfd.h"
#include "symfile.h"
#include "wait.h"
#include "gdbcmd.h"
#include "gdbcore.h"
#include "serial.h"
#include "target.h"
#include "remote-utils.h"
#include <signal.h>
#include <varargs.h>
/* Prototypes for local functions. */
static int
mips_readchar PARAMS ((int timeout));
static int
mips_receive_header PARAMS ((unsigned char *hdr, int *pgarbage, int ch,
int timeout));
static int
mips_receive_trailer PARAMS ((unsigned char *trlr, int *pgarbage, int *pch,
int timeout));
static int mips_cksum PARAMS ((const unsigned char *hdr,
const unsigned char *data,
int len));
static void
mips_send_packet PARAMS ((const char *s, int get_ack));
static int mips_receive_packet PARAMS ((char *buff, int throw_error,
int timeout));
static int
mips_request PARAMS ((char cmd, unsigned int addr, unsigned int data,
int *perr, int timeout));
static void
mips_initialize PARAMS ((void));
static void
mips_open PARAMS ((char *name, int from_tty));
static void
mips_close PARAMS ((int quitting));
static void
mips_detach PARAMS ((char *args, int from_tty));
static void mips_resume PARAMS ((int pid, int step,
enum target_signal siggnal));
static int
mips_wait PARAMS ((int pid, struct target_waitstatus *status));
static int
mips_map_regno PARAMS ((int regno));
static void
mips_fetch_registers PARAMS ((int regno));
static void
mips_prepare_to_store PARAMS ((void));
static void
mips_store_registers PARAMS ((int regno));
static int
mips_fetch_word PARAMS ((CORE_ADDR addr));
static void
mips_store_word PARAMS ((CORE_ADDR addr, int value));
static int
mips_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, int len,
int write, struct target_ops *ignore));
static void
mips_files_info PARAMS ((struct target_ops *ignore));
static void
mips_load PARAMS ((char *args, int from_tty));
static void
mips_create_inferior PARAMS ((char *execfile, char *args, char **env));
static void
mips_mourn_inferior PARAMS ((void));
/* A forward declaration. */
extern struct target_ops mips_ops;
/* The MIPS remote debugging interface is built on top of a simple
packet protocol. Each packet is organized as follows:
SYN The first character is always a SYN (ASCII 026, or ^V). SYN
may not appear anywhere else in the packet. Any time a SYN is
seen, a new packet should be assumed to have begun.
TYPE_LEN
This byte contains the upper five bits of the logical length
of the data section, plus a single bit indicating whether this
is a data packet or an acknowledgement. The documentation
indicates that this bit is 1 for a data packet, but the actual
board uses 1 for an acknowledgement. The value of the byte is
0x40 + (ack ? 0x20 : 0) + (len >> 6)
(we always have 0 <= len < 1024). Acknowledgement packets do
not carry data, and must have a data length of 0.
LEN1 This byte contains the lower six bits of the logical length of
the data section. The value is
0x40 + (len & 0x3f)
SEQ This byte contains the six bit sequence number of the packet.
The value is
0x40 + seq
An acknowlegment packet contains the sequence number of the
packet being acknowledged plus 1 module 64. Data packets are
transmitted in sequence. There may only be one outstanding
unacknowledged data packet at a time. The sequence numbers
are independent in each direction. If an acknowledgement for
the previous packet is received (i.e., an acknowledgement with
the sequence number of the packet just sent) the packet just
sent should be retransmitted. If no acknowledgement is
received within a timeout period, the packet should be
retransmitted. This has an unfortunate failure condition on a
high-latency line, as a delayed acknowledgement may lead to an
endless series of duplicate packets.
DATA The actual data bytes follow. The following characters are
escaped inline with DLE (ASCII 020, or ^P):
SYN (026) DLE S
DLE (020) DLE D
^C (003) DLE C
^S (023) DLE s
^Q (021) DLE q
The additional DLE characters are not counted in the logical
length stored in the TYPE_LEN and LEN1 bytes.
CSUM1
CSUM2
CSUM3
These bytes contain an 18 bit checksum of the complete
contents of the packet excluding the SEQ byte and the
CSUM[123] bytes. The checksum is simply the twos complement
addition of all the bytes treated as unsigned characters. The
values of the checksum bytes are:
CSUM1: 0x40 + ((cksum >> 12) & 0x3f)
CSUM2: 0x40 + ((cksum >> 6) & 0x3f)
CSUM3: 0x40 + (cksum & 0x3f)
It happens that the MIPS remote debugging protocol always
communicates with ASCII strings. Because of this, this
implementation doesn't bother to handle the DLE quoting mechanism,
since it will never be required. */
/* The SYN character which starts each packet. */
#define SYN '\026'
/* The 0x40 used to offset each packet (this value ensures that all of
the header and trailer bytes, other than SYN, are printable ASCII
characters). */
#define HDR_OFFSET 0x40
/* The indices of the bytes in the packet header. */
#define HDR_INDX_SYN 0
#define HDR_INDX_TYPE_LEN 1
#define HDR_INDX_LEN1 2
#define HDR_INDX_SEQ 3
#define HDR_LENGTH 4
/* The data/ack bit in the TYPE_LEN header byte. */
#define TYPE_LEN_DA_BIT 0x20
#define TYPE_LEN_DATA 0
#define TYPE_LEN_ACK TYPE_LEN_DA_BIT
/* How to compute the header bytes. */
#define HDR_SET_SYN(data, len, seq) (SYN)
#define HDR_SET_TYPE_LEN(data, len, seq) \
(HDR_OFFSET \
+ ((data) ? TYPE_LEN_DATA : TYPE_LEN_ACK) \
+ (((len) >> 6) & 0x1f))
#define HDR_SET_LEN1(data, len, seq) (HDR_OFFSET + ((len) & 0x3f))
#define HDR_SET_SEQ(data, len, seq) (HDR_OFFSET + (seq))
/* Check that a header byte is reasonable. */
#define HDR_CHECK(ch) (((ch) & HDR_OFFSET) == HDR_OFFSET)
/* Get data from the header. These macros evaluate their argument
multiple times. */
#define HDR_IS_DATA(hdr) \
(((hdr)[HDR_INDX_TYPE_LEN] & TYPE_LEN_DA_BIT) == TYPE_LEN_DATA)
#define HDR_GET_LEN(hdr) \
((((hdr)[HDR_INDX_TYPE_LEN] & 0x1f) << 6) + (((hdr)[HDR_INDX_LEN1] & 0x3f)))
#define HDR_GET_SEQ(hdr) ((hdr)[HDR_INDX_SEQ] & 0x3f)
/* The maximum data length. */
#define DATA_MAXLEN 1023
/* The trailer offset. */
#define TRLR_OFFSET HDR_OFFSET
/* The indices of the bytes in the packet trailer. */
#define TRLR_INDX_CSUM1 0
#define TRLR_INDX_CSUM2 1
#define TRLR_INDX_CSUM3 2
#define TRLR_LENGTH 3
/* How to compute the trailer bytes. */
#define TRLR_SET_CSUM1(cksum) (TRLR_OFFSET + (((cksum) >> 12) & 0x3f))
#define TRLR_SET_CSUM2(cksum) (TRLR_OFFSET + (((cksum) >> 6) & 0x3f))
#define TRLR_SET_CSUM3(cksum) (TRLR_OFFSET + (((cksum) ) & 0x3f))
/* Check that a trailer byte is reasonable. */
#define TRLR_CHECK(ch) (((ch) & TRLR_OFFSET) == TRLR_OFFSET)
/* Get data from the trailer. This evaluates its argument multiple
times. */
#define TRLR_GET_CKSUM(trlr) \
((((trlr)[TRLR_INDX_CSUM1] & 0x3f) << 12) \
+ (((trlr)[TRLR_INDX_CSUM2] & 0x3f) << 6) \
+ ((trlr)[TRLR_INDX_CSUM3] & 0x3f))
/* The sequence number modulos. */
#define SEQ_MODULOS (64)
/* Set to 1 if the target is open. */
static int mips_is_open;
/* Set to 1 while the connection is being initialized. */
static int mips_initializing;
/* The next sequence number