1 |
39 |
julius |
/*$$HEADER*/
|
2 |
|
|
/******************************************************************************/
|
3 |
|
|
/* */
|
4 |
|
|
/* H E A D E R I N F O R M A T I O N */
|
5 |
|
|
/* */
|
6 |
|
|
/******************************************************************************/
|
7 |
|
|
|
8 |
|
|
// Project Name : OpenRISC Debug Proxy
|
9 |
|
|
// File Name : gdb.c
|
10 |
|
|
// Prepared By : jb, rmd
|
11 |
|
|
// Project Start : 2008-10-01
|
12 |
|
|
|
13 |
|
|
/*$$COPYRIGHT NOTICE*/
|
14 |
|
|
/******************************************************************************/
|
15 |
|
|
/* */
|
16 |
|
|
/* C O P Y R I G H T N O T I C E */
|
17 |
|
|
/* */
|
18 |
|
|
/******************************************************************************/
|
19 |
|
|
/*
|
20 |
|
|
This library is free software; you can redistribute it and/or
|
21 |
|
|
modify it under the terms of the GNU Lesser General Public
|
22 |
|
|
License as published by the Free Software Foundation;
|
23 |
|
|
version 2.1 of the License, a copy of which is available from
|
24 |
|
|
http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
|
25 |
|
|
|
26 |
|
|
This library is distributed in the hope that it will be useful,
|
27 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
29 |
|
|
Lesser General Public License for more details.
|
30 |
|
|
|
31 |
|
|
You should have received a copy of the GNU Lesser General Public
|
32 |
|
|
License along with this library; if not, write to the Free Software
|
33 |
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
34 |
|
|
*/
|
35 |
|
|
|
36 |
|
|
/*$$DESCRIPTION*/
|
37 |
|
|
/******************************************************************************/
|
38 |
|
|
/* */
|
39 |
|
|
/* D E S C R I P T I O N */
|
40 |
|
|
/* */
|
41 |
|
|
/******************************************************************************/
|
42 |
|
|
//
|
43 |
|
|
// Implements GDB stub for OpenRISC debug proxy.
|
44 |
|
|
//
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
/*$$CHANGE HISTORY*/
|
48 |
|
|
/******************************************************************************/
|
49 |
|
|
/* */
|
50 |
|
|
/* C H A N G E H I S T O R Y */
|
51 |
|
|
/* */
|
52 |
|
|
/******************************************************************************/
|
53 |
|
|
|
54 |
|
|
// Date Version Description
|
55 |
|
|
//------------------------------------------------------------------------
|
56 |
|
|
// 081101 Imported code from "jp" project jb
|
57 |
|
|
// 090219 Adapted code from Jeremy Bennett's RSP server
|
58 |
|
|
// for the or1ksim project. rmb
|
59 |
|
|
// 090304 Finished RSP server code import, added extra
|
60 |
|
|
// functions, adding stability when debugging on
|
61 |
|
|
// a remote target. jb
|
62 |
|
|
// 090505 Remove PPC polling - caused intermittent errors
|
63 |
|
|
// in or1k jb
|
64 |
46 |
julius |
// 090828 Fixed byte/non-aligned accesses. Removed legacy
|
65 |
|
|
// "remote JTAG" protocol. jb
|
66 |
39 |
julius |
#ifdef CYGWIN_COMPILE
|
67 |
|
|
|
68 |
|
|
#else
|
69 |
|
|
// linux includes
|
70 |
|
|
#include <time.h>
|
71 |
|
|
#include <sched.h>
|
72 |
|
|
#endif
|
73 |
|
|
|
74 |
|
|
#include <stdio.h>
|
75 |
|
|
#include <ctype.h>
|
76 |
|
|
#include <string.h>
|
77 |
|
|
#include <stdlib.h>
|
78 |
|
|
#include <unistd.h>
|
79 |
|
|
#include <stdarg.h>
|
80 |
|
|
|
81 |
|
|
/* Libraries for JTAG proxy server. */
|
82 |
|
|
#include <sys/stat.h>
|
83 |
|
|
#include <sys/types.h>
|
84 |
|
|
#include <sys/socket.h>
|
85 |
|
|
#include <netinet/in.h>
|
86 |
|
|
#include <sys/ioctl.h>
|
87 |
|
|
#include <sys/select.h>
|
88 |
|
|
#include <sys/poll.h>
|
89 |
|
|
#include <fcntl.h>
|
90 |
|
|
#include <netdb.h>
|
91 |
|
|
#include <netinet/tcp.h>
|
92 |
|
|
#include <signal.h>
|
93 |
|
|
#include <inttypes.h>
|
94 |
|
|
#include <errno.h>
|
95 |
|
|
#include <arpa/inet.h>
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
/*! Name of the Or1ksim RSP service */
|
99 |
|
|
#define OR1KSIM_RSP_SERVICE "or1ksim-rsp"
|
100 |
|
|
|
101 |
|
|
#include "gdb.h" /* partially copied from gdb/config/or1k */
|
102 |
|
|
#include "or_debug_proxy.h"
|
103 |
|
|
|
104 |
|
|
#define MAX_GPRS (32)
|
105 |
|
|
|
106 |
|
|
/* Indices of GDB registers that are not GPRs. Must match GDB settings! */
|
107 |
|
|
#define PPC_REGNUM (MAX_GPRS + 0) /*!< Previous PC */
|
108 |
|
|
#define NPC_REGNUM (MAX_GPRS + 1) /*!< Next PC */
|
109 |
|
|
#define SR_REGNUM (MAX_GPRS + 2) /*!< Supervision Register */
|
110 |
|
|
#define NUM_REGS (MAX_GPRS + 3) /*!< Total GDB registers */
|
111 |
|
|
|
112 |
|
|
/* OR1k CPU registers address */
|
113 |
|
|
#define NPC_CPU_REG_ADD 0x10 /* Next PC */
|
114 |
|
|
#define SR_CPU_REG_ADD 0x11 /* Supervision Register */
|
115 |
|
|
#define PPC_CPU_REG_ADD 0x12 /* Previous PC */
|
116 |
|
|
#define DMR1_CPU_REG_ADD ((6 << 11) + 16) /* Debug Mode Register 1 (DMR1) 0x3010 */
|
117 |
|
|
#define DMR2_CPU_REG_ADD ((6 << 11) + 17) /* Debug Mode Register 2 (DMR2) 0x3011 */
|
118 |
|
|
#define DSR_CPU_REG_ADD ((6 << 11) + 20) /* Debug Stop Register (DSR) 0x3014 */
|
119 |
|
|
#define DRR_CPU_REG_ADD ((6 << 11) + 21) /* Debug Reason Register (DRR) 0x3015 */
|
120 |
|
|
|
121 |
|
|
/*! Trap instruction for OR32 */
|
122 |
|
|
#define OR1K_TRAP_INSTR 0x21000001
|
123 |
|
|
|
124 |
|
|
/*! The maximum number of characters in inbound/outbound buffers. The largest
|
125 |
|
|
packets are the 'G' packet, which must hold the 'G' and all the registers
|
126 |
|
|
with two hex digits per byte and the 'g' reply, which must hold all the
|
127 |
|
|
registers, and (in our implementation) an end-of-string (0)
|
128 |
|
|
character. Adding the EOS allows us to print out the packet as a
|
129 |
|
|
string. So at least NUMREGBYTES*2 + 1 (for the 'G' or the EOS) are needed
|
130 |
|
|
for register packets */
|
131 |
47 |
julius |
//#define GDB_BUF_MAX ((NUM_REGS) * 8 + 1)
|
132 |
|
|
#define GDB_BUF_MAX 4096
|
133 |
|
|
#define GDB_BUF_MAX_TIMES_TWO (GDB_BUF_MAX*2)
|
134 |
39 |
julius |
|
135 |
|
|
/*! Size of the matchpoint hash table. Largest prime < 2^10 */
|
136 |
|
|
#define MP_HASH_SIZE 1021
|
137 |
|
|
|
138 |
|
|
/* Definition of special-purpose registers (SPRs). */
|
139 |
|
|
#define MAX_SPRS (0x10000)
|
140 |
|
|
|
141 |
|
|
#define SPR_DMR1_ST 0x00400000 /* Single-step trace*/
|
142 |
|
|
#define SPR_DMR2_WGB 0x003ff000 /* Watchpoints generating breakpoint */
|
143 |
|
|
#define SPR_DSR_TE 0x00002000 /* Trap exception */
|
144 |
|
|
|
145 |
|
|
#define WORDSBIGENDIAN_N
|
146 |
|
|
|
147 |
|
|
/* Definition of OR1K exceptions */
|
148 |
|
|
#define EXCEPT_NONE 0x0000
|
149 |
|
|
#define EXCEPT_RESET 0x0100
|
150 |
|
|
#define EXCEPT_BUSERR 0x0200
|
151 |
|
|
#define EXCEPT_DPF 0x0300
|
152 |
|
|
#define EXCEPT_IPF 0x0400
|
153 |
|
|
#define EXCEPT_TICK 0x0500
|
154 |
|
|
#define EXCEPT_ALIGN 0x0600
|
155 |
|
|
#define EXCEPT_ILLEGAL 0x0700
|
156 |
|
|
#define EXCEPT_INT 0x0800
|
157 |
|
|
#define EXCEPT_DTLBMISS 0x0900
|
158 |
|
|
#define EXCEPT_ITLBMISS 0x0a00
|
159 |
|
|
#define EXCEPT_RANGE 0x0b00
|
160 |
|
|
#define EXCEPT_SYSCALL 0x0c00
|
161 |
|
|
#define EXCEPT_FPE 0x0d00
|
162 |
|
|
#define EXCEPT_TRAP 0x0e00
|
163 |
|
|
|
164 |
|
|
// Changed to #defines from static const int's due to compile error
|
165 |
|
|
// DRR (Debug Reason Register) Bits
|
166 |
|
|
#define SPR_DRR_RSTE 0x00000001 //!< Reset
|
167 |
|
|
#define SPR_DRR_BUSEE 0x00000002 //!< Bus error
|
168 |
|
|
#define SPR_DRR_DPFE 0x00000004 //!< Data page fault
|
169 |
|
|
#define SPR_DRR_IPFE 0x00000008 //!< Insn page fault
|
170 |
|
|
#define SPR_DRR_TTE 0x00000010 //!< Tick timer
|
171 |
|
|
#define SPR_DRR_AE 0x00000020 //!< Alignment
|
172 |
|
|
#define SPR_DRR_IIE 0x00000040 //!< Illegal instruction
|
173 |
|
|
#define SPR_DRR_IE 0x00000080 //!< Interrupt
|
174 |
|
|
#define SPR_DRR_DME 0x00000100 //!< DTLB miss
|
175 |
|
|
#define SPR_DRR_IME 0x00000200 //!< ITLB miss
|
176 |
|
|
#define SPR_DRR_RE 0x00000400 //!< Range fault
|
177 |
|
|
#define SPR_DRR_SCE 0x00000800 //!< System call
|
178 |
|
|
#define SPR_DRR_FPE 0x00001000 //!< Floating point
|
179 |
|
|
#define SPR_DRR_TE 0x00002000 //!< Trap
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
/*! Definition of GDB target signals. Data taken from the GDB 6.8
|
183 |
|
|
source. Only those we use defined here. The exact meaning of
|
184 |
|
|
signal number is defined by the header `include/gdb/signals.h'
|
185 |
|
|
in the GDB source code. For an explanation of what each signal
|
186 |
|
|
means, see target_signal_to_string.*/
|
187 |
|
|
enum target_signal {
|
188 |
|
|
TARGET_SIGNAL_NONE = 0,
|
189 |
|
|
TARGET_SIGNAL_INT = 2,
|
190 |
|
|
TARGET_SIGNAL_ILL = 4,
|
191 |
|
|
TARGET_SIGNAL_TRAP = 5,
|
192 |
|
|
TARGET_SIGNAL_FPE = 8,
|
193 |
|
|
TARGET_SIGNAL_BUS = 10,
|
194 |
|
|
TARGET_SIGNAL_SEGV = 11,
|
195 |
|
|
TARGET_SIGNAL_ALRM = 14,
|
196 |
|
|
TARGET_SIGNAL_USR2 = 31,
|
197 |
|
|
TARGET_SIGNAL_PWR = 32
|
198 |
|
|
};
|
199 |
|
|
|
200 |
|
|
/*! String to map hex digits to chars */
|
201 |
|
|
static const char hexchars[]="0123456789abcdef";
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
//! Is the NPC cached?
|
205 |
|
|
|
206 |
|
|
//! Setting the NPC flushes the pipeline, so subsequent reads will return
|
207 |
|
|
//! zero until the processor has refilled the pipeline. This will not be
|
208 |
|
|
//! happening if the processor is stalled (as it is when GDB had control),
|
209 |
|
|
//! so we must cache the NPC. As soon as the processor is unstalled, this
|
210 |
|
|
//! cached value becomes invalid. So we must track the stall state, and if
|
211 |
|
|
//! appropriate cache the NPC.
|
212 |
|
|
enum stallStates {
|
213 |
|
|
STALLED,
|
214 |
|
|
UNSTALLED,
|
215 |
|
|
UNKNOWN
|
216 |
|
|
} stallState;
|
217 |
|
|
|
218 |
|
|
int npcIsCached; //!< Is the NPC cached - should be bool
|
219 |
|
|
uint32_t npcCachedValue; //!< Cached value of the NPC
|
220 |
|
|
|
221 |
46 |
julius |
/* OR32 Linux kernel debugging hacks */
|
222 |
|
|
/* If we're operating in virtual memory space, currently the standard VM base
|
223 |
|
|
is 0xc0000000, since the GDB we're currently using is bare-metal we will
|
224 |
|
|
do a translation of these VM addresses to their physical address - although
|
225 |
|
|
not with any sophistication, we simply map all 0xc0000000 based addresses
|
226 |
|
|
to 0x0. This allows GDB to read/wite the addresses the PC and NPC point to,
|
227 |
|
|
access VM data areas, etc. */
|
228 |
|
|
/* Define OR32_KERNEL_DBUG_COMPAT=1 when compiling to enable this */
|
229 |
|
|
#define OR32_KERNEL_DBG_COMPAT 1
|
230 |
|
|
#define OR32_LINUX_VM_OFFSET 0xc0000000
|
231 |
|
|
#define OR32_LINUX_VM_MASK 0xf0000000
|
232 |
39 |
julius |
|
233 |
46 |
julius |
#define IS_VM_ADDR(adr) ((adr & OR32_LINUX_VM_MASK) == OR32_LINUX_VM_OFFSET)
|
234 |
39 |
julius |
|
235 |
|
|
|
236 |
46 |
julius |
|
237 |
|
|
|
238 |
39 |
julius |
/************************
|
239 |
|
|
JTAG Server Routines
|
240 |
|
|
************************/
|
241 |
|
|
int serverIP = 0;
|
242 |
|
|
int serverPort = 0;
|
243 |
|
|
int server_fd = 0;
|
244 |
|
|
int gdb_fd = 0;
|
245 |
|
|
|
246 |
|
|
static int tcp_level = 0;
|
247 |
|
|
|
248 |
|
|
/* global to store what chain the debug unit is currently connected to
|
249 |
|
|
(not the JTAG TAP, but the onchip debug module has selected) */
|
250 |
|
|
int gdb_chain = -1;
|
251 |
|
|
|
252 |
|
|
/*! Data structure for RSP buffers. Can't be null terminated, since it may
|
253 |
|
|
include zero bytes */
|
254 |
|
|
struct rsp_buf
|
255 |
|
|
{
|
256 |
47 |
julius |
char data[GDB_BUF_MAX_TIMES_TWO];
|
257 |
39 |
julius |
int len;
|
258 |
|
|
};
|
259 |
|
|
|
260 |
|
|
/*! Enumeration of different types of matchpoint. These have explicit values
|
261 |
|
|
matching the second digit of 'z' and 'Z' packets. */
|
262 |
|
|
enum mp_type {
|
263 |
|
|
BP_MEMORY = 0, // software-breakpoint Z0 break
|
264 |
|
|
BP_HARDWARE = 1, // hardware-breakpoint Z1 hbreak
|
265 |
|
|
WP_WRITE = 2, // write-watchpoint Z2 watch
|
266 |
|
|
WP_READ = 3, // read-watchpoint Z3 rwatch
|
267 |
|
|
WP_ACCESS = 4 // access-watchpoint Z4 awatch
|
268 |
|
|
};
|
269 |
|
|
|
270 |
|
|
/*! Data structure for a matchpoint hash table entry */
|
271 |
|
|
struct mp_entry
|
272 |
|
|
{
|
273 |
|
|
enum mp_type type; /*!< Type of matchpoint */
|
274 |
|
|
uint32_t addr; /*!< Address with the matchpoint */
|
275 |
|
|
uint32_t instr; /*!< Substituted instruction */
|
276 |
|
|
struct mp_entry *next; /*!< Next entry with this hash */
|
277 |
|
|
};
|
278 |
|
|
|
279 |
|
|
/*! Central data for the RSP connection */
|
280 |
|
|
static struct
|
281 |
|
|
{
|
282 |
|
|
int client_waiting; /*!< Is client waiting a response? */
|
283 |
|
|
// Not used int proto_num; /*!< Number of the protocol used */
|
284 |
|
|
int client_fd; /*!< FD for talking to GDB */
|
285 |
|
|
int sigval; /*!< GDB signal for any exception */
|
286 |
|
|
uint32_t start_addr; /*!< Start of last run */
|
287 |
|
|
struct mp_entry *mp_hash[MP_HASH_SIZE]; /*!< Matchpoint hash table */
|
288 |
|
|
} rsp;
|
289 |
|
|
|
290 |
|
|
/* Forward declarations of static functions */
|
291 |
|
|
static char *printTime(void);
|
292 |
|
|
static int gdb_read(void*, int);
|
293 |
|
|
static int gdb_write(void*, int);
|
294 |
|
|
static void rsp_interrupt();
|
295 |
|
|
static char rsp_peek();
|
296 |
|
|
static struct rsp_buf *get_packet (void);
|
297 |
|
|
static void rsp_init (void);
|
298 |
|
|
static void set_npc (uint32_t addr);
|
299 |
|
|
static uint32_t get_npc();
|
300 |
|
|
static void rsp_check_for_exception();
|
301 |
|
|
static int check_for_exception_vector(uint32_t ppc);
|
302 |
|
|
static void rsp_exception (uint32_t except);
|
303 |
|
|
static int get_rsp_char (void);
|
304 |
|
|
static int hex (int c);
|
305 |
|
|
static void rsp_get_client (void);
|
306 |
|
|
static void rsp_client_request (void);
|
307 |
|
|
static void rsp_client_close (void);
|
308 |
|
|
static void client_close (char err);
|
309 |
46 |
julius |
static void put_str_packet (const char *str);
|
310 |
39 |
julius |
static void rsp_report_exception (void);
|
311 |
|
|
static void put_packet (struct rsp_buf *p_buf);
|
312 |
|
|
static void send_rsp_str (unsigned char *data, int len);
|
313 |
|
|
static void rsp_query (struct rsp_buf *p_buf);
|
314 |
|
|
static void rsp_vpkt (struct rsp_buf *p_buf);
|
315 |
46 |
julius |
static void rsp_step (struct rsp_buf *p_buf);
|
316 |
|
|
static void rsp_step_with_signal (struct rsp_buf *p_buf);
|
317 |
|
|
static void rsp_step_generic (uint32_t addr, uint32_t except);
|
318 |
39 |
julius |
static void rsp_continue (struct rsp_buf *p_buf);
|
319 |
46 |
julius |
static void rsp_continue_with_signal (struct rsp_buf *p_buf);
|
320 |
|
|
static void rsp_continue_generic (uint32_t addr, uint32_t except);
|
321 |
39 |
julius |
static void rsp_read_all_regs (void);
|
322 |
|
|
static void rsp_write_all_regs (struct rsp_buf *p_buf);
|
323 |
|
|
static void rsp_read_mem (struct rsp_buf *p_buf);
|
324 |
|
|
static void rsp_write_mem (struct rsp_buf *p_buf);
|
325 |
|
|
static void rsp_write_mem_bin (struct rsp_buf *p_buf);
|
326 |
|
|
static int rsp_unescape (char *data, int len);
|
327 |
|
|
static void rsp_read_reg (struct rsp_buf *p_buf);
|
328 |
|
|
static void rsp_write_reg (struct rsp_buf *p_buf);
|
329 |
|
|
static void mp_hash_init (void);
|
330 |
46 |
julius |
static void mp_hash_add (enum mp_type type, uint32_t addr, uint32_t instr);
|
331 |
39 |
julius |
static struct mp_entry * mp_hash_lookup (enum mp_type type, uint32_t addr);
|
332 |
|
|
static struct mp_entry * mp_hash_delete (enum mp_type type, uint32_t addr);
|
333 |
|
|
static void rsp_remove_matchpoint (struct rsp_buf *p_buf);
|
334 |
|
|
static void rsp_insert_matchpoint (struct rsp_buf *p_buf);
|
335 |
|
|
static void rsp_command (struct rsp_buf *p_buf);
|
336 |
|
|
static void rsp_set (struct rsp_buf *p_buf);
|
337 |
|
|
static void rsp_restart (void);
|
338 |
|
|
static void ascii2hex (char *dest,char *src);
|
339 |
|
|
static void hex2ascii (char *dest, char *src);
|
340 |
|
|
static uint32_t hex2reg (char *p_buf);
|
341 |
|
|
static void reg2hex (uint32_t val, char *p_buf);
|
342 |
|
|
static void swap_buf(char* p_buf, int len);
|
343 |
|
|
static void set_stall_state (int state);
|
344 |
|
|
static void reset_or1k (void);
|
345 |
|
|
static void gdb_ensure_or1k_stalled();
|
346 |
|
|
static int gdb_set_chain(int chain);
|
347 |
46 |
julius |
static int gdb_write_byte(uint32_t adr, uint8_t data);
|
348 |
39 |
julius |
static int gdb_write_reg(uint32_t adr, uint32_t data);
|
349 |
|
|
static int gdb_read_reg(uint32_t adr, uint32_t *data);
|
350 |
|
|
static int gdb_write_block(uint32_t adr, uint32_t *data, int len);
|
351 |
|
|
static int gdb_read_block(uint32_t adr, uint32_t *data, int len);
|
352 |
|
|
|
353 |
|
|
char *printTime(void)
|
354 |
|
|
{
|
355 |
|
|
time_t tid;
|
356 |
|
|
struct tm *strtm;
|
357 |
|
|
static char timeBuf[20];
|
358 |
|
|
|
359 |
|
|
time(&tid);
|
360 |
|
|
strtm = localtime(&tid);
|
361 |
|
|
sprintf(timeBuf,"[%.02d:%.02d:%.02d] ",strtm->tm_hour,strtm->tm_min,strtm->tm_sec);
|
362 |
|
|
return timeBuf;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
/*---------------------------------------------------------------------------*/
|
366 |
|
|
/*!Initialize the Remote Serial Protocol connection
|
367 |
|
|
|
368 |
|
|
Set up the central data structures. */
|
369 |
|
|
/*---------------------------------------------------------------------------*/
|
370 |
|
|
void
|
371 |
|
|
rsp_init (void)
|
372 |
|
|
{
|
373 |
|
|
/* Clear out the central data structure */
|
374 |
|
|
rsp.client_waiting = 0; /* GDB client is not waiting for us */
|
375 |
|
|
rsp.client_fd = -1; /* i.e. invalid */
|
376 |
|
|
rsp.sigval = 0; /* No exception */
|
377 |
|
|
rsp.start_addr = EXCEPT_RESET; /* Default restart point */
|
378 |
|
|
|
379 |
|
|
/* Set up the matchpoint hash table */
|
380 |
|
|
mp_hash_init ();
|
381 |
|
|
|
382 |
|
|
/* RSP always starts stalled as though we have just reset the processor. */
|
383 |
|
|
rsp_exception (EXCEPT_TRAP);
|
384 |
|
|
|
385 |
|
|
/* Setup the NPC caching variables */
|
386 |
|
|
stallState = STALLED;
|
387 |
|
|
// Force a caching of the NPC
|
388 |
|
|
npcIsCached = 0;
|
389 |
|
|
get_npc();
|
390 |
|
|
|
391 |
|
|
} /* rsp_init () */
|
392 |
|
|
|
393 |
|
|
/*---------------------------------------------------------------------------*/
|
394 |
|
|
/*!Look for action on RSP
|
395 |
|
|
|
396 |
|
|
This function is called when the processor has stalled, which, except for
|
397 |
|
|
initialization, must be due to an interrupt.
|
398 |
|
|
|
399 |
|
|
If we have no RSP client, we get one. We can make no progress until the
|
400 |
|
|
client is available.
|
401 |
|
|
|
402 |
|
|
Then if the cause is an exception following a step or continue command, and
|
403 |
|
|
the exception not been notified to GDB, a packet reporting the cause of the
|
404 |
|
|
exception is sent.
|
405 |
|
|
|
406 |
|
|
The next client request is then processed. */
|
407 |
|
|
/*---------------------------------------------------------------------------*/
|
408 |
|
|
void
|
409 |
|
|
handle_rsp (void)
|
410 |
|
|
{
|
411 |
|
|
uint32_t temp_uint32;
|
412 |
|
|
|
413 |
|
|
rsp_init();
|
414 |
|
|
|
415 |
|
|
while (1){
|
416 |
|
|
/* If we have no RSP client, wait until we get one. */
|
417 |
|
|
while (-1 == rsp.client_fd)
|
418 |
|
|
{
|
419 |
|
|
rsp_get_client ();
|
420 |
|
|
rsp.client_waiting = 0; /* No longer waiting */
|
421 |
|
|
}
|
422 |
|
|
|
423 |
|
|
/* If we have an unacknowledged exception tell the GDB client. If this
|
424 |
|
|
exception was a trap due to a memory breakpoint, then adjust the NPC. */
|
425 |
|
|
if (rsp.client_waiting)
|
426 |
|
|
{
|
427 |
|
|
|
428 |
|
|
// Check for exception
|
429 |
|
|
rsp_check_for_exception();
|
430 |
|
|
|
431 |
|
|
if(stallState == STALLED)
|
432 |
|
|
// Get the PPC if we're stalled
|
433 |
|
|
gdb_read_reg(PPC_CPU_REG_ADD, &temp_uint32);
|
434 |
|
|
|
435 |
|
|
|
436 |
|
|
if ((TARGET_SIGNAL_TRAP == rsp.sigval) && (NULL != mp_hash_lookup (BP_MEMORY, temp_uint32)))
|
437 |
|
|
{
|
438 |
|
|
if (stallState != STALLED)
|
439 |
79 |
julius |
// This is a quick fix for a strange situation seen in some of
|
440 |
|
|
// the simulators where the sw bp would be detected, but the
|
441 |
|
|
// stalled state variable wasn't updated correctly indicating
|
442 |
|
|
// that last time it checked, it wasn't set but the processor
|
443 |
|
|
// had hit the breakpoint. So run rsp_check_for_exception() to
|
444 |
|
|
// bring everything up to date.
|
445 |
39 |
julius |
rsp_check_for_exception();
|
446 |
|
|
|
447 |
|
|
if(DEBUG_GDB) printf("Software breakpoint hit at 0x%08x. Rolling back NPC to this instruction\n", temp_uint32);
|
448 |
|
|
|
449 |
|
|
set_npc (temp_uint32);
|
450 |
|
|
|
451 |
|
|
rsp_report_exception();
|
452 |
|
|
rsp.client_waiting = 0; /* No longer waiting */
|
453 |
|
|
}
|
454 |
|
|
else if(stallState == STALLED) {
|
455 |
|
|
// If we're here, the thing has stalled, but not because of a breakpoint we set
|
456 |
|
|
// report back the exception
|
457 |
|
|
|
458 |
|
|
rsp_report_exception();
|
459 |
|
|
rsp.client_waiting = 0; /* No longer waiting */
|
460 |
|
|
|
461 |
|
|
}
|
462 |
|
|
|
463 |
|
|
if (rsp.client_waiting)
|
464 |
|
|
#ifdef CYGWIN_COMPILE
|
465 |
|
|
sleep(1);
|
466 |
|
|
#else
|
467 |
46 |
julius |
usleep(10000);
|
468 |
39 |
julius |
sched_yield();
|
469 |
|
|
#endif
|
470 |
|
|
|
471 |
|
|
|
472 |
|
|
}
|
473 |
|
|
|
474 |
|
|
// See if there's any incoming data from the client by peeking at the socket
|
475 |
|
|
if (rsp_peek() > 0)
|
476 |
|
|
{
|
477 |
|
|
if (rsp_peek() == 0x03 && (stallState != STALLED)) // ETX, end of text control char
|
478 |
|
|
{
|
479 |
|
|
// Got an interrupt command from GDB, this function should
|
480 |
|
|
// pull the packet off the socket and stall the processor.
|
481 |
|
|
// and then send a stop reply packet with signal TARGET_SIGNAL_NONE
|
482 |
|
|
rsp_interrupt();
|
483 |
|
|
rsp.client_waiting = 0;
|
484 |
|
|
}
|
485 |
|
|
else if (rsp.client_waiting == 0)
|
486 |
|
|
{
|
487 |
|
|
// Default handling of data from the client:
|
488 |
|
|
/* Get a RSP client request */
|
489 |
|
|
rsp_client_request ();
|
490 |
|
|
}
|
491 |
|
|
} /* end if (rsp_peek() > 0) */
|
492 |
|
|
else
|
493 |
|
|
#ifdef CYGWIN_COMPILE
|
494 |
|
|
sleep(1);
|
495 |
|
|
#else
|
496 |
|
|
{
|
497 |
46 |
julius |
usleep(10000);
|
498 |
39 |
julius |
sched_yield();
|
499 |
|
|
}
|
500 |
|
|
#endif
|
501 |
|
|
|
502 |
|
|
}
|
503 |
|
|
|
504 |
|
|
} /* handle_rsp () */
|
505 |
|
|
|
506 |
|
|
|
507 |
|
|
/*
|
508 |
|
|
Check if processor is stalled - if it is, read the DRR
|
509 |
|
|
and return the target signal code
|
510 |
|
|
*/
|
511 |
|
|
static void rsp_check_for_exception()
|
512 |
|
|
{
|
513 |
|
|
|
514 |
|
|
unsigned char stalled;
|
515 |
|
|
uint32_t drr;
|
516 |
46 |
julius |
err = dbg_cpu0_read_ctrl(0, &stalled); /* check if we're stalled */
|
517 |
|
|
|
518 |
39 |
julius |
if (!(stalled & 0x01))
|
519 |
|
|
{
|
520 |
|
|
// Processor not stalled. Just return;
|
521 |
|
|
return;
|
522 |
|
|
}
|
523 |
|
|
|
524 |
|
|
if (DEBUG_GDB) printf("rsp_check_for_exception() detected processor was stalled\nChecking DRR\n");
|
525 |
|
|
|
526 |
|
|
// We're stalled
|
527 |
|
|
stallState = STALLED;
|
528 |
|
|
npcIsCached = 0;
|
529 |
|
|
|
530 |
|
|
gdb_set_chain(SC_RISC_DEBUG);
|
531 |
|
|
|
532 |
|
|
// Now read the DRR (Debug Reason Register)
|
533 |
|
|
gdb_read_reg(DRR_CPU_REG_ADD, &drr);
|
534 |
|
|
|
535 |
|
|
if (DEBUG_GDB) printf("DRR: 0x%08x\n", drr);
|
536 |
|
|
|
537 |
|
|
switch ((int)(drr&0xffffffff))
|
538 |
|
|
{
|
539 |
|
|
case SPR_DRR_RSTE: rsp.sigval = TARGET_SIGNAL_PWR; break;
|
540 |
|
|
case SPR_DRR_BUSEE: rsp.sigval = TARGET_SIGNAL_BUS; break;
|
541 |
|
|
case SPR_DRR_DPFE: rsp.sigval = TARGET_SIGNAL_SEGV; break;
|
542 |
|
|
case SPR_DRR_IPFE: rsp.sigval = TARGET_SIGNAL_SEGV; break;
|
543 |
|
|
case SPR_DRR_TTE: rsp.sigval = TARGET_SIGNAL_ALRM; break;
|
544 |
|
|
case SPR_DRR_AE: rsp.sigval = TARGET_SIGNAL_BUS; break;
|
545 |
|
|
case SPR_DRR_IIE: rsp.sigval = TARGET_SIGNAL_ILL; break;
|
546 |
|
|
case SPR_DRR_IE: rsp.sigval = TARGET_SIGNAL_INT; break;
|
547 |
|
|
case SPR_DRR_DME: rsp.sigval = TARGET_SIGNAL_SEGV; break;
|
548 |
|
|
case SPR_DRR_IME: rsp.sigval = TARGET_SIGNAL_SEGV; break;
|
549 |
|
|
case SPR_DRR_RE: rsp.sigval = TARGET_SIGNAL_FPE; break;
|
550 |
|
|
case SPR_DRR_SCE: rsp.sigval = TARGET_SIGNAL_USR2; break;
|
551 |
|
|
case SPR_DRR_FPE: rsp.sigval = TARGET_SIGNAL_FPE; break;
|
552 |
|
|
case SPR_DRR_TE: rsp.sigval = TARGET_SIGNAL_TRAP; break;
|
553 |
|
|
|
554 |
|
|
default:
|
555 |
|
|
// This must be the case of single step (which does not set DRR)
|
556 |
|
|
rsp.sigval = TARGET_SIGNAL_TRAP; break;
|
557 |
|
|
}
|
558 |
|
|
|
559 |
|
|
if (DEBUG_GDB) printf("rsp.sigval: 0x%x\n", rsp.sigval);
|
560 |
|
|
|
561 |
|
|
return;
|
562 |
|
|
}
|
563 |
|
|
|
564 |
|
|
/*---------------------------------------------------------------------------*/
|
565 |
|
|
/*!Check if PPC is in an exception vector that halts program flow
|
566 |
|
|
|
567 |
|
|
Compare the provided PPC with known exception vectors that are fatal
|
568 |
|
|
to a program's execution. Call rsp_exception(ppc) to set the appropriate
|
569 |
|
|
sigval and return.
|
570 |
|
|
|
571 |
|
|
@param[in] ppc Value of current PPC, as read from debug unit
|
572 |
|
|
@return: 1 if we set a sigval and should return control to GDB, else 0 */
|
573 |
|
|
/*---------------------------------------------------------------------------*/
|
574 |
|
|
static int
|
575 |
|
|
check_for_exception_vector(uint32_t ppc)
|
576 |
|
|
{
|
577 |
|
|
switch(ppc)
|
578 |
|
|
{
|
579 |
|
|
// The following should return sigvals to GDB for processing
|
580 |
|
|
case EXCEPT_BUSERR:
|
581 |
|
|
case EXCEPT_ALIGN:
|
582 |
|
|
case EXCEPT_ILLEGAL:
|
583 |
|
|
case EXCEPT_TRAP: if(DEBUG_GDB)
|
584 |
|
|
printf("PPC at exception address\n");
|
585 |
|
|
rsp_exception(ppc);
|
586 |
|
|
return 1;
|
587 |
|
|
|
588 |
|
|
default:
|
589 |
|
|
return 0;
|
590 |
|
|
}
|
591 |
|
|
return 1;
|
592 |
|
|
}
|
593 |
|
|
|
594 |
|
|
/*---------------------------------------------------------------------------*/
|
595 |
|
|
/*!Note an exception for future processing
|
596 |
|
|
|
597 |
|
|
The simulator has encountered an exception. Record it here, so that a
|
598 |
|
|
future call to handle_exception will report it back to the client. The
|
599 |
|
|
signal is supplied in Or1ksim form and recorded in GDB form.
|
600 |
|
|
|
601 |
|
|
We flag up a warning if an exception is already pending, and ignore the
|
602 |
|
|
earlier exception.
|
603 |
|
|
|
604 |
|
|
@param[in] except The exception (Or1ksim form) */
|
605 |
|
|
/*---------------------------------------------------------------------------*/
|
606 |
|
|
void
|
607 |
|
|
rsp_exception (uint32_t except)
|
608 |
|
|
{
|
609 |
|
|
int sigval; /* GDB signal equivalent to exception */
|
610 |
|
|
|
611 |
|
|
switch (except)
|
612 |
|
|
{
|
613 |
|
|
case EXCEPT_RESET: sigval = TARGET_SIGNAL_PWR; break;
|
614 |
|
|
case EXCEPT_BUSERR: sigval = TARGET_SIGNAL_BUS; break;
|
615 |
|
|
case EXCEPT_DPF: sigval = TARGET_SIGNAL_SEGV; break;
|
616 |
|
|
case EXCEPT_IPF: sigval = TARGET_SIGNAL_SEGV; break;
|
617 |
|
|
case EXCEPT_TICK: sigval = TARGET_SIGNAL_ALRM; break;
|
618 |
|
|
case EXCEPT_ALIGN: sigval = TARGET_SIGNAL_BUS; break;
|
619 |
|
|
case EXCEPT_ILLEGAL: sigval = TARGET_SIGNAL_ILL; break;
|
620 |
|
|
case EXCEPT_INT: sigval = TARGET_SIGNAL_INT; break;
|
621 |
|
|
case EXCEPT_DTLBMISS: sigval = TARGET_SIGNAL_SEGV; break;
|
622 |
|
|
case EXCEPT_ITLBMISS: sigval = TARGET_SIGNAL_SEGV; break;
|
623 |
|
|
case EXCEPT_RANGE: sigval = TARGET_SIGNAL_FPE; break;
|
624 |
|
|
case EXCEPT_SYSCALL: sigval = TARGET_SIGNAL_USR2; break;
|
625 |
|
|
case EXCEPT_FPE: sigval = TARGET_SIGNAL_FPE; break;
|
626 |
|
|
case EXCEPT_TRAP: sigval = TARGET_SIGNAL_TRAP; break;
|
627 |
|
|
|
628 |
|
|
default:
|
629 |
|
|
fprintf (stderr, "Warning: Unknown RSP exception %u: Ignored\n", except);
|
630 |
|
|
return;
|
631 |
|
|
}
|
632 |
|
|
|
633 |
|
|
if ((0 != rsp.sigval) && (sigval != rsp.sigval))
|
634 |
|
|
{
|
635 |
|
|
fprintf (stderr, "Warning: RSP signal %d received while signal "
|
636 |
|
|
"%d pending: Pending exception replaced\n", sigval, rsp.sigval);
|
637 |
|
|
}
|
638 |
|
|
|
639 |
|
|
rsp.sigval = sigval; /* Save the signal value */
|
640 |
|
|
|
641 |
|
|
} /* rsp_exception () */
|
642 |
|
|
|
643 |
|
|
|
644 |
|
|
/*---------------------------------------------------------------------------*/
|
645 |
|
|
/*!Get a new client connection.
|
646 |
|
|
|
647 |
|
|
Blocks until the client connection is available.
|
648 |
|
|
|
649 |
|
|
A lot of this code is copied from remote_open in gdbserver remote-utils.c.
|
650 |
|
|
|
651 |
|
|
This involves setting up a socket to listen on a socket for attempted
|
652 |
|
|
connections from a single GDB instance (we couldn't be talking to multiple
|
653 |
|
|
GDBs at once!).
|
654 |
|
|
|
655 |
|
|
The service is specified either as a port number in the Or1ksim configuration
|
656 |
|
|
(parameter rsp_port in section debug, default 51000) or as a service name
|
657 |
|
|
in the constant OR1KSIM_RSP_SERVICE.
|
658 |
|
|
|
659 |
|
|
The protocol used for communication is specified in OR1KSIM_RSP_PROTOCOL. */
|
660 |
|
|
/*---------------------------------------------------------------------------*/
|
661 |
|
|
static void
|
662 |
|
|
rsp_get_client (void)
|
663 |
|
|
{
|
664 |
|
|
int tmp_fd; /* Temporary descriptor for socket */
|
665 |
|
|
int optval; /* Socket options */
|
666 |
|
|
struct sockaddr_in sock_addr; /* Socket address */
|
667 |
|
|
socklen_t len; /* Size of the socket address */
|
668 |
|
|
|
669 |
|
|
/* 0 is used as the RSP port number to indicate that we should use the
|
670 |
|
|
service name instead. */
|
671 |
|
|
if (0 == serverPort)
|
672 |
|
|
{
|
673 |
|
|
struct servent *service = getservbyname (OR1KSIM_RSP_SERVICE, "tcp");
|
674 |
|
|
if (NULL == service)
|
675 |
|
|
{
|
676 |
|
|
fprintf (stderr, "Warning: RSP unable to find service \"%s\": %s\n",
|
677 |
|
|
OR1KSIM_RSP_SERVICE, strerror (errno));
|
678 |
|
|
return;
|
679 |
|
|
}
|
680 |
|
|
serverPort = ntohs (service->s_port);
|
681 |
|
|
}
|
682 |
|
|
|
683 |
|
|
/* Open a socket on which we'll listen for clients */
|
684 |
|
|
tmp_fd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
685 |
|
|
if (tmp_fd < 0)
|
686 |
|
|
{
|
687 |
|
|
fprintf (stderr, "ERROR: Cannot open RSP socket\n");
|
688 |
|
|
exit (0);
|
689 |
|
|
}
|
690 |
|
|
|
691 |
|
|
/* Allow rapid reuse of the port on this socket */
|
692 |
|
|
optval = 1;
|
693 |
|
|
setsockopt (tmp_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&optval,
|
694 |
|
|
sizeof (optval));
|
695 |
|
|
|
696 |
|
|
/* Bind the port to the socket */
|
697 |
|
|
sock_addr.sin_family = PF_INET;
|
698 |
|
|
sock_addr.sin_port = htons (serverPort);
|
699 |
|
|
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
700 |
|
|
if (bind (tmp_fd, (struct sockaddr *) &sock_addr, sizeof (sock_addr)))
|
701 |
|
|
{
|
702 |
|
|
fprintf (stderr, "ERROR: Cannot bind to RSP socket\n");
|
703 |
|
|
exit (0);
|
704 |
|
|
}
|
705 |
|
|
|
706 |
|
|
/* Listen for (at most one) client */
|
707 |
|
|
if (0 != listen (tmp_fd, 1))
|
708 |
|
|
{
|
709 |
|
|
fprintf (stderr, "ERROR: Cannot listen on RSP socket\n");
|
710 |
|
|
exit (0);
|
711 |
|
|
}
|
712 |
|
|
|
713 |
|
|
printf("Waiting for gdb connection on localhost:%d\n", serverPort);
|
714 |
|
|
fflush (stdout);
|
715 |
|
|
|
716 |
|
|
printf("Press CTRL+c to exit.\n");
|
717 |
|
|
fflush (stdout);
|
718 |
|
|
|
719 |
|
|
/* Accept a client which connects */
|
720 |
|
|
len = sizeof (sock_addr);
|
721 |
|
|
rsp.client_fd = accept (tmp_fd, (struct sockaddr *)&sock_addr, &len);
|
722 |
|
|
|
723 |
|
|
if (-1 == rsp.client_fd)
|
724 |
|
|
{
|
725 |
|
|
fprintf (stderr, "Warning: Failed to accept RSP client\n");
|
726 |
|
|
return;
|
727 |
|
|
}
|
728 |
|
|
|
729 |
|
|
/* Enable TCP keep alive process */
|
730 |
|
|
optval = 1;
|
731 |
|
|
setsockopt (rsp.client_fd, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval,
|
732 |
|
|
sizeof (optval));
|
733 |
|
|
|
734 |
|
|
int flags;
|
735 |
|
|
|
736 |
|
|
/* If they have O_NONBLOCK, use the Posix way to do it */
|
737 |
|
|
|
738 |
|
|
#if defined(O_NONBLOCK)
|
739 |
|
|
/* Fixme: O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */
|
740 |
|
|
if (-1 == (flags = fcntl(rsp.client_fd, F_GETFL, 0)))
|
741 |
|
|
flags = 0;
|
742 |
|
|
|
743 |
|
|
fcntl(rsp.client_fd, F_SETFL, flags | O_NONBLOCK);
|
744 |
|
|
#else
|
745 |
|
|
/* Otherwise, use the old way of doing it */
|
746 |
|
|
flags = 1;
|
747 |
79 |
julius |
ioctl(rsp.client_fd, FIOBIO, &flags);
|
748 |
39 |
julius |
#endif
|
749 |
|
|
|
750 |
79 |
julius |
/* Set socket to be non-blocking.
|
751 |
39 |
julius |
|
752 |
79 |
julius |
We do this because when we're given a continue, or step
|
753 |
|
|
instruction,command we set the processor stall off, then instantly check
|
754 |
39 |
julius |
if it's stopped. If it hasn't then we drop through and wait for input
|
755 |
|
|
from GDB. Obviously this will cause problems when it will stop after we
|
756 |
79 |
julius |
do the check. So now, rsp_peek() been implemented to simply check if
|
757 |
|
|
there's an incoming command from GDB (although, mainly interested in
|
758 |
|
|
int. commands), otherwise it returns back to poll the processor's
|
759 |
39 |
julius |
stall bit. It can only do this if the socket is non-blocking.
|
760 |
|
|
|
761 |
|
|
At first test, simply adding this line appeared to give no problems with
|
762 |
|
|
the existing code. No "simulation" of blocking behaviour on the
|
763 |
|
|
non-blocking socket was required (in the event that a read/write throws
|
764 |
|
|
back a EWOULDBLOCK error, as was looked to be the case in the previous
|
765 |
|
|
GDB handling code) -- Julius
|
766 |
|
|
*/
|
767 |
79 |
julius |
|
768 |
39 |
julius |
if (ioctl(rsp.client_fd, FIONBIO, (char *)&optval) > 0 )
|
769 |
|
|
{
|
770 |
|
|
perror("ioctl() failed");
|
771 |
|
|
close(rsp.client_fd);
|
772 |
|
|
close(tmp_fd);
|
773 |
|
|
exit(0);
|
774 |
|
|
}
|
775 |
|
|
|
776 |
|
|
|
777 |
|
|
/* Don't delay small packets, for better interactive response (disable
|
778 |
|
|
Nagel's algorithm) */
|
779 |
|
|
optval = 1;
|
780 |
|
|
setsockopt (rsp.client_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&optval,
|
781 |
|
|
sizeof (optval));
|
782 |
|
|
|
783 |
|
|
/* Socket is no longer needed */
|
784 |
|
|
close (tmp_fd); /* No longer need this */
|
785 |
|
|
signal (SIGPIPE, SIG_IGN); /* So we don't exit if client dies */
|
786 |
|
|
|
787 |
|
|
printf ("Remote debugging from host %s\n", inet_ntoa (sock_addr.sin_addr));
|
788 |
|
|
} /* rsp_get_client () */
|
789 |
|
|
|
790 |
|
|
|
791 |
|
|
/*---------------------------------------------------------------------------*/
|
792 |
|
|
/*!Deal with a request from the GDB client session
|
793 |
|
|
|
794 |
|
|
In general, apart from the simplest requests, this function replies on
|
795 |
|
|
other functions to implement the functionality. */
|
796 |
|
|
/*---------------------------------------------------------------------------*/
|
797 |
|
|
static void rsp_client_request (void)
|
798 |
|
|
{
|
799 |
|
|
struct rsp_buf *p_buf = get_packet (); /* Message sent to us */
|
800 |
|
|
|
801 |
|
|
// Null packet means we hit EOF or the link was closed for some other
|
802 |
|
|
// reason. Close the client and return
|
803 |
|
|
if (NULL == p_buf)
|
804 |
|
|
{
|
805 |
|
|
rsp_client_close ();
|
806 |
|
|
return;
|
807 |
|
|
}
|
808 |
|
|
|
809 |
|
|
if (DEBUG_GDB){
|
810 |
|
|
printf("%s-----------------------------------------------------\n", printTime());
|
811 |
|
|
printf ("Packet received %s: %d chars\n", p_buf->data, p_buf->len );
|
812 |
|
|
fflush (stdout);
|
813 |
|
|
}
|
814 |
|
|
|
815 |
|
|
switch (p_buf->data[0])
|
816 |
|
|
{
|
817 |
|
|
case '!':
|
818 |
|
|
/* Request for extended remote mode */
|
819 |
|
|
put_str_packet ("OK"); // OK = supports and has enabled extended mode.
|
820 |
|
|
return;
|
821 |
|
|
|
822 |
|
|
case '?':
|
823 |
|
|
/* Return last signal ID */
|
824 |
|
|
rsp_report_exception();
|
825 |
|
|
return;
|
826 |
|
|
|
827 |
|
|
case 'A':
|
828 |
|
|
/* Initialization of argv not supported */
|
829 |
|
|
fprintf (stderr, "Warning: RSP 'A' packet not supported: ignored\n");
|
830 |
|
|
put_str_packet ("E01");
|
831 |
|
|
return;
|
832 |
|
|
|
833 |
|
|
case 'b':
|
834 |
|
|
/* Setting baud rate is deprecated */
|
835 |
|
|
fprintf (stderr, "Warning: RSP 'b' packet is deprecated and not "
|
836 |
|
|
"supported: ignored\n");
|
837 |
|
|
return;
|
838 |
|
|
|
839 |
|
|
case 'B':
|
840 |
|
|
/* Breakpoints should be set using Z packets */
|
841 |
|
|
fprintf (stderr, "Warning: RSP 'B' packet is deprecated (use 'Z'/'z' "
|
842 |
|
|
"packets instead): ignored\n");
|
843 |
|
|
return;
|
844 |
|
|
|
845 |
|
|
case 'c':
|
846 |
|
|
/* Continue */
|
847 |
|
|
rsp_continue (p_buf);
|
848 |
|
|
return;
|
849 |
|
|
|
850 |
|
|
case 'C':
|
851 |
|
|
/* Continue with signal */
|
852 |
|
|
rsp_continue_with_signal (p_buf);
|
853 |
|
|
return;
|
854 |
|
|
|
855 |
|
|
case 'd':
|
856 |
|
|
/* Disable debug using a general query */
|
857 |
|
|
fprintf (stderr, "Warning: RSP 'd' packet is deprecated (define a 'Q' "
|
858 |
|
|
"packet instead: ignored\n");
|
859 |
|
|
return;
|
860 |
|
|
|
861 |
|
|
case 'D':
|
862 |
|
|
/* Detach GDB. Do this by closing the client. The rules say that
|
863 |
|
|
execution should continue. TODO. Is this really then intended
|
864 |
|
|
meaning? Or does it just mean that only vAttach will be recognized
|
865 |
|
|
after this? */
|
866 |
|
|
put_str_packet ("OK");
|
867 |
|
|
rsp_client_close ();
|
868 |
|
|
reset_or1k ();
|
869 |
|
|
set_stall_state (0);
|
870 |
|
|
return;
|
871 |
|
|
|
872 |
|
|
case 'F':
|
873 |
|
|
/* File I/O is not currently supported */
|
874 |
|
|
fprintf (stderr, "Warning: RSP file I/O not currently supported: 'F' "
|
875 |
|
|
"packet ignored\n");
|
876 |
|
|
return;
|
877 |
|
|
|
878 |
|
|
case 'g':
|
879 |
|
|
rsp_read_all_regs ();
|
880 |
|
|
return;
|
881 |
|
|
|
882 |
|
|
case 'G':
|
883 |
|
|
rsp_write_all_regs (p_buf);
|
884 |
|
|
return;
|
885 |
|
|
|
886 |
|
|
case 'H':
|
887 |
|
|
/* Set the thread number of subsequent operations. For now ignore
|
888 |
|
|
silently and just reply "OK" */
|
889 |
|
|
put_str_packet ("OK");
|
890 |
|
|
return;
|
891 |
|
|
|
892 |
|
|
case 'i':
|
893 |
|
|
/* Single instruction step */
|
894 |
|
|
fprintf (stderr, "Warning: RSP cycle stepping not supported: target "
|
895 |
|
|
"stopped immediately\n");
|
896 |
|
|
rsp.client_waiting = 1; /* Stop reply will be sent */
|
897 |
|
|
return;
|
898 |
|
|
|
899 |
|
|
case 'I':
|
900 |
|
|
/* Single instruction step with signal */
|
901 |
|
|
fprintf (stderr, "Warning: RSP cycle stepping not supported: target "
|
902 |
|
|
"stopped immediately\n");
|
903 |
|
|
rsp.client_waiting = 1; /* Stop reply will be sent */
|
904 |
|
|
return;
|
905 |
|
|
|
906 |
|
|
case 'k':
|
907 |
|
|
/* Kill request. Do nothing for now. */
|
908 |
|
|
return;
|
909 |
|
|
|
910 |
|
|
case 'm':
|
911 |
|
|
/* Read memory (symbolic) */
|
912 |
|
|
rsp_read_mem (p_buf);
|
913 |
|
|
return;
|
914 |
|
|
|
915 |
|
|
case 'M':
|
916 |
|
|
/* Write memory (symbolic) */
|
917 |
|
|
rsp_write_mem (p_buf);
|
918 |
|
|
return;
|
919 |
|
|
|
920 |
|
|
case 'p':
|
921 |
|
|
/* Read a register */
|
922 |
|
|
rsp_read_reg (p_buf);
|
923 |
|
|
return;
|
924 |
|
|
|
925 |
|
|
case 'P':
|
926 |
|
|
/* Write a register */
|
927 |
|
|
rsp_write_reg (p_buf);
|
928 |
|
|
return;
|
929 |
|
|
|
930 |
|
|
case 'q':
|
931 |
|
|
/* Any one of a number of query packets */
|
932 |
|
|
rsp_query (p_buf);
|
933 |
|
|
return;
|
934 |
|
|
|
935 |
|
|
case 'Q':
|
936 |
|
|
/* Any one of a number of set packets */
|
937 |
|
|
rsp_set (p_buf);
|
938 |
|
|
return;
|
939 |
|
|
|
940 |
|
|
case 'r':
|
941 |
|
|
/* Reset the system. Deprecated (use 'R' instead) */
|
942 |
|
|
fprintf (stderr, "Warning: RSP 'r' packet is deprecated (use 'R' "
|
943 |
|
|
"packet instead): ignored\n");
|
944 |
|
|
return;
|
945 |
|
|
|
946 |
|
|
case 'R':
|
947 |
|
|
/* Restart the program being debugged. */
|
948 |
|
|
rsp_restart ();
|
949 |
|
|
return;
|
950 |
|
|
|
951 |
|
|
case 's':
|
952 |
|
|
/* Single step (one high level instruction). This could be hard without
|
953 |
|
|
DWARF2 info */
|
954 |
|
|
rsp_step (p_buf);
|
955 |
|
|
return;
|
956 |
|
|
|
957 |
|
|
case 'S':
|
958 |
|
|
/* Single step (one high level instruction) with signal. This could be
|
959 |
|
|
hard without DWARF2 info */
|
960 |
|
|
rsp_step_with_signal (p_buf);
|
961 |
|
|
return;
|
962 |
|
|
|
963 |
|
|
case 't':
|
964 |
|
|
/* Search. This is not well defined in the manual and for now we don't
|
965 |
|
|
support it. No response is defined. */
|
966 |
|
|
fprintf (stderr, "Warning: RSP 't' packet not supported: ignored\n");
|
967 |
|
|
return;
|
968 |
|
|
|
969 |
|
|
case 'T':
|
970 |
|
|
/* Is the thread alive. We are bare metal, so don't have a thread
|
971 |
|
|
context. The answer is always "OK". */
|
972 |
|
|
put_str_packet ("OK");
|
973 |
|
|
return;
|
974 |
|
|
|
975 |
|
|
case 'v':
|
976 |
|
|
/* Any one of a number of packets to control execution */
|
977 |
|
|
rsp_vpkt (p_buf);
|
978 |
|
|
return;
|
979 |
|
|
|
980 |
|
|
case 'X':
|
981 |
|
|
/* Write memory (binary) */
|
982 |
|
|
rsp_write_mem_bin (p_buf);
|
983 |
|
|
return;
|
984 |
|
|
|
985 |
|
|
case 'z':
|
986 |
|
|
/* Remove a breakpoint/watchpoint. */
|
987 |
|
|
rsp_remove_matchpoint (p_buf);
|
988 |
|
|
return;
|
989 |
|
|
|
990 |
|
|
case 'Z':
|
991 |
|
|
/* Insert a breakpoint/watchpoint. */
|
992 |
|
|
rsp_insert_matchpoint (p_buf);
|
993 |
|
|
return;
|
994 |
|
|
|
995 |
|
|
default:
|
996 |
|
|
/* Unknown commands are ignored */
|
997 |
|
|
fprintf (stderr, "Warning: Unknown RSP request %s\n", p_buf->data);
|
998 |
|
|
return;
|
999 |
|
|
}
|
1000 |
|
|
} /* rsp_client_request () */
|
1001 |
|
|
|
1002 |
|
|
|
1003 |
|
|
/*---------------------------------------------------------------------------*/
|
1004 |
|
|
/*!Close the connection to the client if it is open */
|
1005 |
|
|
/*---------------------------------------------------------------------------*/
|
1006 |
|
|
static void
|
1007 |
|
|
rsp_client_close (void)
|
1008 |
|
|
{
|
1009 |
|
|
if (-1 != rsp.client_fd)
|
1010 |
|
|
{
|
1011 |
|
|
close (rsp.client_fd);
|
1012 |
|
|
rsp.client_fd = -1;
|
1013 |
|
|
}
|
1014 |
|
|
} /* rsp_client_close () */
|
1015 |
|
|
|
1016 |
|
|
|
1017 |
|
|
/*---------------------------------------------------------------------------*/
|
1018 |
|
|
/*!Send a packet to the GDB client
|
1019 |
|
|
|
1020 |
|
|
Modeled on the stub version supplied with GDB. Put out the data preceded by
|
1021 |
|
|
a '$', followed by a '#' and a one byte checksum. '$', '#', '*' and '}' are
|
1022 |
|
|
escaped by preceding them with '}' and then XORing the character with
|
1023 |
|
|
0x20.
|
1024 |
|
|
|
1025 |
|
|
@param[in] p_buf The data to send */
|
1026 |
|
|
/*---------------------------------------------------------------------------*/
|
1027 |
|
|
static void
|
1028 |
|
|
put_packet (struct rsp_buf *p_buf)
|
1029 |
|
|
{
|
1030 |
|
|
unsigned char data[GDB_BUF_MAX * 2];
|
1031 |
|
|
int len;
|
1032 |
|
|
int ch; /* Ack char */
|
1033 |
|
|
|
1034 |
|
|
/* Construct $<packet info>#<checksum>. Repeat until the GDB client
|
1035 |
|
|
acknowledges satisfactory receipt. */
|
1036 |
|
|
do
|
1037 |
|
|
{
|
1038 |
|
|
unsigned char checksum = 0; /* Computed checksum */
|
1039 |
|
|
int count = 0; /* Index into the buffer */
|
1040 |
|
|
|
1041 |
|
|
if (DEBUG_GDB_DUMP_DATA){
|
1042 |
|
|
printf ("Putting %s\n\n", p_buf->data);
|
1043 |
|
|
fflush (stdout);
|
1044 |
|
|
}
|
1045 |
|
|
|
1046 |
|
|
len = 0;
|
1047 |
|
|
data[len++] = '$'; /* Start char */
|
1048 |
|
|
|
1049 |
|
|
/* Body of the packet */
|
1050 |
|
|
for (count = 0; count < p_buf->len; count++)
|
1051 |
|
|
{
|
1052 |
|
|
unsigned char ch = p_buf->data[count];
|
1053 |
|
|
|
1054 |
|
|
/* Check for escaped chars */
|
1055 |
|
|
if (('$' == ch) || ('#' == ch) || ('*' == ch) || ('}' == ch))
|
1056 |
|
|
{
|
1057 |
|
|
ch ^= 0x20;
|
1058 |
|
|
checksum += (unsigned char)'}';
|
1059 |
|
|
data[len++] = '}';
|
1060 |
|
|
}
|
1061 |
|
|
|
1062 |
|
|
checksum += ch;
|
1063 |
|
|
data[len++] = ch;
|
1064 |
|
|
}
|
1065 |
|
|
|
1066 |
|
|
data[len++] = '#'; /* End char */
|
1067 |
|
|
|
1068 |
|
|
/* Computed checksum */
|
1069 |
|
|
data[len++] = (hexchars[checksum >> 4]);
|
1070 |
|
|
data[len++] = (hexchars[checksum % 16]);
|
1071 |
|
|
|
1072 |
|
|
send_rsp_str ((unsigned char *) &data, len);
|
1073 |
|
|
|
1074 |
|
|
/* Check for ack of connection failure */
|
1075 |
|
|
ch = get_rsp_char ();
|
1076 |
|
|
if (0 > ch)
|
1077 |
|
|
{
|
1078 |
|
|
return; /* Fail the put silently. */
|
1079 |
|
|
}
|
1080 |
|
|
}
|
1081 |
|
|
while ('+' != ch);
|
1082 |
|
|
|
1083 |
|
|
} /* put_packet () */
|
1084 |
|
|
|
1085 |
|
|
|
1086 |
|
|
/*---------------------------------------------------------------------------*/
|
1087 |
|
|
/*!Convenience to put a constant string packet
|
1088 |
|
|
|
1089 |
|
|
param[in] str The text of the packet */
|
1090 |
|
|
/*---------------------------------------------------------------------------*/
|
1091 |
|
|
static void
|
1092 |
|
|
put_str_packet (const char *str)
|
1093 |
|
|
{
|
1094 |
|
|
struct rsp_buf buffer;
|
1095 |
|
|
int len = strlen (str);
|
1096 |
|
|
|
1097 |
|
|
/* Construct the packet to send, so long as string is not too big,
|
1098 |
|
|
otherwise truncate. Add EOS at the end for convenient debug printout */
|
1099 |
|
|
|
1100 |
|
|
if (len >= GDB_BUF_MAX)
|
1101 |
|
|
{
|
1102 |
|
|
fprintf (stderr, "Warning: String %s too large for RSP packet: "
|
1103 |
|
|
"truncated\n", str);
|
1104 |
|
|
len = GDB_BUF_MAX - 1;
|
1105 |
|
|
}
|
1106 |
|
|
|
1107 |
|
|
strncpy (buffer.data, str, len);
|
1108 |
|
|
buffer.data[len] = 0;
|
1109 |
|
|
buffer.len = len;
|
1110 |
|
|
|
1111 |
|
|
put_packet (&buffer);
|
1112 |
|
|
|
1113 |
|
|
} /* put_str_packet () */
|
1114 |
|
|
|
1115 |
|
|
|
1116 |
|
|
/*---------------------------------------------------------------------------*/
|
1117 |
|
|
/*!Get a packet from the GDB client
|
1118 |
|
|
|
1119 |
|
|
Modeled on the stub version supplied with GDB. The data is in a static
|
1120 |
|
|
buffer. The data should be copied elsewhere if it is to be preserved across
|
1121 |
|
|
a subsequent call to get_packet().
|
1122 |
|
|
|
1123 |
|
|
Unlike the reference implementation, we don't deal with sequence
|
1124 |
|
|
numbers. GDB has never used them, and this implementation is only intended
|
1125 |
|
|
for use with GDB 6.8 or later. Sequence numbers were removed from the RSP
|
1126 |
|
|
standard at GDB 5.0.
|
1127 |
|
|
|
1128 |
|
|
@return A pointer to the static buffer containing the data */
|
1129 |
|
|
/*---------------------------------------------------------------------------*/
|
1130 |
|
|
static struct rsp_buf *
|
1131 |
|
|
get_packet (void)
|
1132 |
|
|
{
|
1133 |
|
|
static struct rsp_buf buf; /* Survives the return */
|
1134 |
|
|
|
1135 |
|
|
/* Keep getting packets, until one is found with a valid checksum */
|
1136 |
|
|
while (1)
|
1137 |
|
|
{
|
1138 |
|
|
unsigned char checksum; /* The checksum we have computed */
|
1139 |
|
|
int count; /* Index into the buffer */
|
1140 |
|
|
int ch; /* Current character */
|
1141 |
|
|
|
1142 |
|
|
/* Wait around for the start character ('$'). Ignore all other
|
1143 |
|
|
characters */
|
1144 |
|
|
ch = get_rsp_char ();
|
1145 |
|
|
|
1146 |
|
|
while (ch != '$')
|
1147 |
|
|
{
|
1148 |
|
|
if (-1 == ch)
|
1149 |
|
|
{
|
1150 |
|
|
return NULL; /* Connection failed */
|
1151 |
|
|
}
|
1152 |
|
|
|
1153 |
|
|
ch = get_rsp_char ();
|
1154 |
|
|
|
1155 |
|
|
// Potentially handle an interrupt character (0x03) here
|
1156 |
|
|
}
|
1157 |
|
|
|
1158 |
|
|
/* Read until a '#' or end of buffer is found */
|
1159 |
|
|
checksum = 0;
|
1160 |
|
|
count = 0;
|
1161 |
|
|
while (count < GDB_BUF_MAX - 1)
|
1162 |
|
|
{
|
1163 |
|
|
ch = get_rsp_char ();
|
1164 |
|
|
|
1165 |
|
|
if(rsp.client_waiting && DEBUG_GDB)
|
1166 |
|
|
{
|
1167 |
|
|
printf("%x\n",ch);
|
1168 |
|
|
}
|
1169 |
|
|
|
1170 |
|
|
|
1171 |
|
|
/* Check for connection failure */
|
1172 |
|
|
if (0 > ch)
|
1173 |
|
|
{
|
1174 |
|
|
return NULL;
|
1175 |
|
|
}
|
1176 |
|
|
|
1177 |
|
|
/* If we hit a start of line char begin all over again */
|
1178 |
|
|
if ('$' == ch)
|
1179 |
|
|
{
|
1180 |
|
|
checksum = 0;
|
1181 |
|
|
count = 0;
|
1182 |
|
|
|
1183 |
|
|
continue;
|
1184 |
|
|
}
|
1185 |
|
|
|
1186 |
|
|
/* Break out if we get the end of line char */
|
1187 |
|
|
if ('#' == ch)
|
1188 |
|
|
{
|
1189 |
|
|
break;
|
1190 |
|
|
}
|
1191 |
|
|
|
1192 |
|
|
/* Update the checksum and add the char to the buffer */
|
1193 |
|
|
|
1194 |
|
|
checksum = checksum + (unsigned char)ch;
|
1195 |
|
|
buf.data[count] = (char)ch;
|
1196 |
|
|
count = count + 1;
|
1197 |
|
|
}
|
1198 |
|
|
|
1199 |
|
|
/* Mark the end of the buffer with EOS - it's convenient for non-binary
|
1200 |
|
|
data to be valid strings. */
|
1201 |
|
|
buf.data[count] = 0;
|
1202 |
|
|
buf.len = count;
|
1203 |
|
|
|
1204 |
|
|
/* If we have a valid end of packet char, validate the checksum */
|
1205 |
|
|
if ('#' == ch)
|
1206 |
|
|
{
|
1207 |
|
|
unsigned char xmitcsum; /* The checksum in the packet */
|
1208 |
|
|
|
1209 |
|
|
ch = get_rsp_char ();
|
1210 |
|
|
if (0 > ch)
|
1211 |
|
|
{
|
1212 |
|
|
return NULL; /* Connection failed */
|
1213 |
|
|
}
|
1214 |
|
|
xmitcsum = hex (ch) << 4;
|
1215 |
|
|
|
1216 |
|
|
ch = get_rsp_char ();
|
1217 |
|
|
if (0 > ch)
|
1218 |
|
|
{
|
1219 |
|
|
return NULL; /* Connection failed */
|
1220 |
|
|
}
|
1221 |
|
|
|
1222 |
|
|
xmitcsum += hex (ch);
|
1223 |
|
|
|
1224 |
|
|
/* If the checksums don't match print a warning, and put the
|
1225 |
|
|
negative ack back to the client. Otherwise put a positive ack. */
|
1226 |
|
|
if (checksum != xmitcsum)
|
1227 |
|
|
{
|
1228 |
|
|
fprintf (stderr, "Warning: Bad RSP checksum: Computed "
|
1229 |
|
|
"0x%02x, received 0x%02x\n", checksum, xmitcsum);
|
1230 |
|
|
|
1231 |
|
|
ch = '-';
|
1232 |
|
|
send_rsp_str ((unsigned char *) &ch, 1); /* Failed checksum */
|
1233 |
|
|
}
|
1234 |
|
|
else
|
1235 |
|
|
{
|
1236 |
|
|
ch = '+';
|
1237 |
|
|
send_rsp_str ((unsigned char *) &ch, 1); /* successful transfer */
|
1238 |
|
|
break;
|
1239 |
|
|
}
|
1240 |
|
|
}
|
1241 |
|
|
else
|
1242 |
|
|
{
|
1243 |
|
|
fprintf (stderr, "Warning: RSP packet overran buffer\n");
|
1244 |
|
|
}
|
1245 |
|
|
}
|
1246 |
|
|
return &buf; /* Success */
|
1247 |
|
|
} /* get_packet () */
|
1248 |
|
|
|
1249 |
|
|
|
1250 |
|
|
/*---------------------------------------------------------------------------*/
|
1251 |
|
|
/*!Put a single character out onto the client socket
|
1252 |
|
|
|
1253 |
|
|
This should only be called if the client is open, but we check for safety.
|
1254 |
|
|
|
1255 |
|
|
@param[in] c The character to put out */
|
1256 |
|
|
/*---------------------------------------------------------------------------*/
|
1257 |
|
|
static void
|
1258 |
|
|
send_rsp_str (unsigned char *data, int len)
|
1259 |
|
|
{
|
1260 |
|
|
if (-1 == rsp.client_fd)
|
1261 |
|
|
{
|
1262 |
|
|
fprintf (stderr, "Warning: Attempt to write '%s' to unopened RSP "
|
1263 |
|
|
"client: Ignored\n", data);
|
1264 |
|
|
return;
|
1265 |
|
|
}
|
1266 |
|
|
|
1267 |
|
|
/* Write until successful (we retry after interrupts) or catastrophic
|
1268 |
|
|
failure. */
|
1269 |
|
|
while (1)
|
1270 |
|
|
{
|
1271 |
|
|
switch (write (rsp.client_fd, data, len))
|
1272 |
|
|
{
|
1273 |
|
|
case -1:
|
1274 |
|
|
/* Error: only allow interrupts or would block */
|
1275 |
|
|
if ((EAGAIN != errno) && (EINTR != errno))
|
1276 |
|
|
{
|
1277 |
|
|
fprintf (stderr, "Warning: Failed to write to RSP client: "
|
1278 |
|
|
"Closing client connection: %s\n",
|
1279 |
|
|
strerror (errno));
|
1280 |
|
|
rsp_client_close ();
|
1281 |
|
|
return;
|
1282 |
|
|
}
|
1283 |
|
|
|
1284 |
|
|
break;
|
1285 |
|
|
|
1286 |
|
|
case 0:
|
1287 |
|
|
break; /* Nothing written! Try again */
|
1288 |
|
|
|
1289 |
|
|
default:
|
1290 |
|
|
return; /* Success, we can return */
|
1291 |
|
|
}
|
1292 |
|
|
}
|
1293 |
|
|
} /* send_rsp_str () */
|
1294 |
|
|
|
1295 |
|
|
|
1296 |
|
|
/*---------------------------------------------------------------------------*/
|
1297 |
|
|
/*!Get a single character from the client socket
|
1298 |
|
|
|
1299 |
|
|
This should only be called if the client is open, but we check for safety.
|
1300 |
|
|
|
1301 |
|
|
@return The character read, or -1 on failure */
|
1302 |
|
|
/*---------------------------------------------------------------------------*/
|
1303 |
|
|
static int
|
1304 |
|
|
get_rsp_char ()
|
1305 |
|
|
{
|
1306 |
|
|
if (-1 == rsp.client_fd)
|
1307 |
|
|
{
|
1308 |
|
|
fprintf (stderr, "Warning: Attempt to read from unopened RSP "
|
1309 |
|
|
"client: Ignored\n");
|
1310 |
|
|
return -1;
|
1311 |
|
|
}
|
1312 |
|
|
|
1313 |
|
|
/* Non-blocking read until successful (we retry after interrupts) or
|
1314 |
|
|
catastrophic failure. */
|
1315 |
|
|
while (1)
|
1316 |
|
|
{
|
1317 |
|
|
unsigned char c;
|
1318 |
|
|
|
1319 |
|
|
switch (read (rsp.client_fd, &c, sizeof (c)))
|
1320 |
|
|
{
|
1321 |
|
|
case -1:
|
1322 |
|
|
/* Error: only allow interrupts */
|
1323 |
|
|
if ((EAGAIN != errno) && (EINTR != errno))
|
1324 |
|
|
{
|
1325 |
|
|
fprintf (stderr, "Warning: Failed to read from RSP client: "
|
1326 |
|
|
"Closing client connection: %s\n",
|
1327 |
|
|
strerror (errno));
|
1328 |
|
|
rsp_client_close ();
|
1329 |
|
|
return -1;
|
1330 |
|
|
}
|
1331 |
|
|
|
1332 |
|
|
break;
|
1333 |
|
|
|
1334 |
|
|
case 0:
|
1335 |
|
|
// EOF
|
1336 |
|
|
rsp_client_close ();
|
1337 |
|
|
return -1;
|
1338 |
|
|
|
1339 |
|
|
default:
|
1340 |
|
|
return c & 0xff; /* Success, we can return (no sign extend!) */
|
1341 |
|
|
}
|
1342 |
|
|
}
|
1343 |
|
|
} /* get_rsp_char () */
|
1344 |
|
|
|
1345 |
|
|
/*---------------------------------------------------------------------------*/
|
1346 |
|
|
/* !Peek at data coming into server from GDB
|
1347 |
|
|
|
1348 |
|
|
Useful for polling for ETX (0x3) chars being sent when GDB wants to
|
1349 |
|
|
interrupt
|
1350 |
|
|
|
1351 |
|
|
@return the char we peeked, 0 otherwise */
|
1352 |
|
|
/*---------------------------------------------------------------------------*/
|
1353 |
|
|
static char
|
1354 |
|
|
rsp_peek()
|
1355 |
|
|
{
|
1356 |
|
|
/*
|
1357 |
|
|
if (-1 == rsp.client_fd)
|
1358 |
|
|
{
|
1359 |
|
|
fprintf (stderr, "Warning: Attempt to read from unopened RSP "
|
1360 |
|
|
"client: Ignored\n");
|
1361 |
|
|
return -1;
|
1362 |
|
|
}
|
1363 |
|
|
*/
|
1364 |
|
|
char c;
|
1365 |
|
|
int n;
|
1366 |
|
|
// Using recv here instead of read becuase we can pass the MSG_PEEK
|
1367 |
|
|
// flag, which lets us look at what's on the socket, without actually
|
1368 |
|
|
// taking it off
|
1369 |
|
|
|
1370 |
|
|
//if (DEBUG_GDB)
|
1371 |
|
|
// printf("peeking at GDB socket...\n");
|
1372 |
|
|
|
1373 |
|
|
n = recv (rsp.client_fd, &c, sizeof (c), MSG_PEEK);
|
1374 |
|
|
|
1375 |
|
|
//if (DEBUG_GDB)
|
1376 |
|
|
// printf("peeked, got n=%d, c=0x%x\n",n, c);
|
1377 |
|
|
|
1378 |
|
|
if (n > 0)
|
1379 |
|
|
return c;
|
1380 |
|
|
else
|
1381 |
|
|
return '\0';
|
1382 |
|
|
|
1383 |
|
|
}
|
1384 |
|
|
|
1385 |
|
|
/*---------------------------------------------------------------------------*/
|
1386 |
|
|
/*!Handle an interrupt from GDB
|
1387 |
|
|
|
1388 |
|
|
Detect an interrupt from GDB and stall the processor */
|
1389 |
|
|
/*---------------------------------------------------------------------------*/
|
1390 |
|
|
static void
|
1391 |
|
|
rsp_interrupt()
|
1392 |
|
|
{
|
1393 |
|
|
unsigned char c;
|
1394 |
|
|
|
1395 |
|
|
if (read (rsp.client_fd, &c, sizeof (c)) <= 0)
|
1396 |
|
|
{
|
1397 |
|
|
// Had issues, just return
|
1398 |
|
|
return;
|
1399 |
|
|
}
|
1400 |
|
|
|
1401 |
|
|
// Ensure this is a ETX control char (0x3), currently, we only call this
|
1402 |
|
|
// function when we've peeked and seen it, otherwise, ignore, return and pray
|
1403 |
|
|
// things go back to normal...
|
1404 |
|
|
if (c != 0x03)
|
1405 |
|
|
{
|
1406 |
|
|
printf("Warning: Interrupt character expected but not found on socket.\n");
|
1407 |
|
|
return;
|
1408 |
|
|
}
|
1409 |
|
|
|
1410 |
|
|
// Otherwise, it's an interrupt packet, stall the processor, and upon return
|
1411 |
|
|
// to the main handle_rsp() loop, it will inform GDB.
|
1412 |
|
|
|
1413 |
|
|
if (DEBUG_GDB) printf("Interrupt received from GDB. Stalling processor.\n");
|
1414 |
|
|
|
1415 |
|
|
set_stall_state (1);
|
1416 |
|
|
|
1417 |
|
|
// Send a stop reply response, manually set rsp.sigval to TARGET_SIGNAL_NONE
|
1418 |
|
|
rsp.sigval = TARGET_SIGNAL_NONE;
|
1419 |
|
|
rsp_report_exception();
|
1420 |
|
|
rsp.client_waiting = 0; /* No longer waiting */
|
1421 |
|
|
|
1422 |
|
|
return;
|
1423 |
|
|
|
1424 |
|
|
}
|
1425 |
|
|
|
1426 |
|
|
|
1427 |
|
|
/*---------------------------------------------------------------------------*/
|
1428 |
|
|
/*!"Unescape" RSP binary data
|
1429 |
|
|
|
1430 |
|
|
'#', '$' and '}' are escaped by preceding them by '}' and oring with 0x20.
|
1431 |
|
|
|
1432 |
|
|
This function reverses that, modifying the data in place.
|
1433 |
|
|
|
1434 |
|
|
@param[in] data The array of bytes to convert
|
1435 |
|
|
@para[in] len The number of bytes to be converted
|
1436 |
|
|
|
1437 |
|
|
@return The number of bytes AFTER conversion */
|
1438 |
|
|
/*---------------------------------------------------------------------------*/
|
1439 |
|
|
static int
|
1440 |
|
|
rsp_unescape (char *data,
|
1441 |
|
|
int len)
|
1442 |
|
|
{
|
1443 |
|
|
int from_off = 0; /* Offset to source char */
|
1444 |
|
|
int to_off = 0; /* Offset to dest char */
|
1445 |
|
|
|
1446 |
|
|
while (from_off < len)
|
1447 |
|
|
{
|
1448 |
|
|
/* Is it escaped */
|
1449 |
|
|
if ( '}' == data[from_off])
|
1450 |
|
|
{
|
1451 |
|
|
from_off++;
|
1452 |
|
|
data[to_off] = data[from_off] ^ 0x20;
|
1453 |
|
|
}
|
1454 |
|
|
else
|
1455 |
|
|
{
|
1456 |
|
|
data[to_off] = data[from_off];
|
1457 |
|
|
}
|
1458 |
|
|
|
1459 |
|
|
from_off++;
|
1460 |
|
|
to_off++;
|
1461 |
|
|
}
|
1462 |
|
|
|
1463 |
|
|
return to_off;
|
1464 |
|
|
|
1465 |
|
|
} /* rsp_unescape () */
|
1466 |
|
|
|
1467 |
|
|
|
1468 |
|
|
/*---------------------------------------------------------------------------*/
|
1469 |
|
|
/*!Initialize the matchpoint hash table
|
1470 |
|
|
|
1471 |
|
|
This is an open hash table, so this function clears all the links to
|
1472 |
|
|
NULL. */
|
1473 |
|
|
/*---------------------------------------------------------------------------*/
|
1474 |
|
|
static void
|
1475 |
|
|
mp_hash_init (void)
|
1476 |
|
|
{
|
1477 |
|
|
int i;
|
1478 |
|
|
|
1479 |
|
|
for (i = 0; i < MP_HASH_SIZE; i++)
|
1480 |
|
|
{
|
1481 |
|
|
rsp.mp_hash[i] = NULL;
|
1482 |
|
|
}
|
1483 |
|
|
} /* mp_hash_init () */
|
1484 |
|
|
|
1485 |
|
|
|
1486 |
|
|
/*---------------------------------------------------------------------------*/
|
1487 |
|
|
/*!Add an entry to the matchpoint hash table
|
1488 |
|
|
|
1489 |
|
|
Add the entry if it wasn't already there. If it was there do nothing. The
|
1490 |
|
|
match just be on type and addr. The instr need not match, since if this is
|
1491 |
|
|
a duplicate insertion (perhaps due to a lost packet) they will be
|
1492 |
|
|
different.
|
1493 |
|
|
|
1494 |
|
|
@param[in] type The type of matchpoint
|
1495 |
|
|
@param[in] addr The address of the matchpoint
|
1496 |
|
|
@para[in] instr The instruction to associate with the address */
|
1497 |
|
|
/*---------------------------------------------------------------------------*/
|
1498 |
|
|
static void
|
1499 |
|
|
mp_hash_add (enum mp_type type,
|
1500 |
|
|
uint32_t addr,
|
1501 |
|
|
uint32_t instr)
|
1502 |
|
|
{
|
1503 |
|
|
int hv = addr % MP_HASH_SIZE;
|
1504 |
|
|
struct mp_entry *curr;
|
1505 |
|
|
|
1506 |
|
|
/* See if we already have the entry */
|
1507 |
|
|
for(curr = rsp.mp_hash[hv]; NULL != curr; curr = curr->next)
|
1508 |
|
|
{
|
1509 |
|
|
if ((type == curr->type) && (addr == curr->addr))
|
1510 |
|
|
{
|
1511 |
|
|
return; /* We already have the entry */
|
1512 |
|
|
}
|
1513 |
|
|
}
|
1514 |
|
|
|
1515 |
|
|
/* Insert the new entry at the head of the chain */
|
1516 |
|
|
curr = (struct mp_entry*) malloc (sizeof (*curr));
|
1517 |
|
|
|
1518 |
|
|
curr->type = type;
|
1519 |
|
|
curr->addr = addr;
|
1520 |
|
|
curr->instr = instr;
|
1521 |
|
|
curr->next = rsp.mp_hash[hv];
|
1522 |
|
|
|
1523 |
|
|
rsp.mp_hash[hv] = curr;
|
1524 |
|
|
|
1525 |
|
|
} /* mp_hash_add () */
|
1526 |
|
|
|
1527 |
|
|
|
1528 |
|
|
/*---------------------------------------------------------------------------*/
|
1529 |
|
|
/*!Look up an entry in the matchpoint hash table
|
1530 |
|
|
|
1531 |
|
|
The match must be on type AND addr.
|
1532 |
|
|
|
1533 |
|
|
@param[in] type The type of matchpoint
|
1534 |
|
|
@param[in] addr The address of the matchpoint
|
1535 |
|
|
|
1536 |
|
|
@return The entry deleted, or NULL if the entry was not found */
|
1537 |
|
|
/*---------------------------------------------------------------------------*/
|
1538 |
|
|
static struct mp_entry * mp_hash_lookup (enum mp_type type, uint32_t addr)
|
1539 |
|
|
{
|
1540 |
|
|
int hv = addr % MP_HASH_SIZE;
|
1541 |
|
|
struct mp_entry *curr;
|
1542 |
|
|
|
1543 |
|
|
/* Search */
|
1544 |
|
|
for (curr = rsp.mp_hash[hv]; NULL != curr; curr = curr->next)
|
1545 |
|
|
{
|
1546 |
|
|
if ((type == curr->type) && (addr == curr->addr))
|
1547 |
|
|
{
|
1548 |
|
|
return curr; /* The entry found */
|
1549 |
|
|
}
|
1550 |
|
|
}
|
1551 |
|
|
|
1552 |
|
|
/* Not found */
|
1553 |
|
|
return NULL;
|
1554 |
|
|
|
1555 |
|
|
} /* mp_hash_lookup () */
|
1556 |
|
|
|
1557 |
|
|
|
1558 |
|
|
/*---------------------------------------------------------------------------*/
|
1559 |
|
|
/*!Delete an entry from the matchpoint hash table
|
1560 |
|
|
|
1561 |
|
|
If it is there the entry is deleted from the hash table. If it is not
|
1562 |
|
|
there, no action is taken. The match must be on type AND addr.
|
1563 |
|
|
|
1564 |
|
|
The usual fun and games tracking the previous entry, so we can delete
|
1565 |
|
|
things.
|
1566 |
|
|
|
1567 |
|
|
@note The deletion DOES NOT free the memory associated with the entry,
|
1568 |
|
|
since that is returned. The caller should free the memory when they
|
1569 |
|
|
have used the information.
|
1570 |
|
|
|
1571 |
|
|
@param[in] type The type of matchpoint
|
1572 |
|
|
@param[in] addr The address of the matchpoint
|
1573 |
|
|
|
1574 |
|
|
@return The entry deleted, or NULL if the entry was not found */
|
1575 |
|
|
/*---------------------------------------------------------------------------*/
|
1576 |
|
|
static struct mp_entry *
|
1577 |
|
|
mp_hash_delete (enum mp_type type,
|
1578 |
|
|
uint32_t addr)
|
1579 |
|
|
{
|
1580 |
|
|
int hv = addr % MP_HASH_SIZE;
|
1581 |
|
|
struct mp_entry *prev = NULL;
|
1582 |
|
|
struct mp_entry *curr;
|
1583 |
|
|
|
1584 |
|
|
/* Search */
|
1585 |
|
|
for (curr = rsp.mp_hash[hv]; NULL != curr; curr = curr->next)
|
1586 |
|
|
{
|
1587 |
|
|
if ((type == curr->type) && (addr == curr->addr))
|
1588 |
|
|
{
|
1589 |
|
|
/* Found - delete. Method depends on whether we are the head of
|
1590 |
|
|
chain. */
|
1591 |
|
|
if (NULL == prev)
|
1592 |
|
|
{
|
1593 |
|
|
rsp.mp_hash[hv] = curr->next;
|
1594 |
|
|
}
|
1595 |
|
|
else
|
1596 |
|
|
{
|
1597 |
|
|
prev->next = curr->next;
|
1598 |
|
|
}
|
1599 |
|
|
|
1600 |
|
|
return curr; /* The entry deleted */
|
1601 |
|
|
}
|
1602 |
|
|
|
1603 |
|
|
prev = curr;
|
1604 |
|
|
}
|
1605 |
|
|
|
1606 |
|
|
/* Not found */
|
1607 |
|
|
return NULL;
|
1608 |
|
|
|
1609 |
|
|
} /* mp_hash_delete () */
|
1610 |
|
|
|
1611 |
|
|
|
1612 |
|
|
/*---------------------------------------------------------------------------*/
|
1613 |
|
|
/*!Utility to give the value of a hex char
|
1614 |
|
|
|
1615 |
|
|
@param[in] ch A character representing a hexadecimal digit. Done as -1,
|
1616 |
|
|
for consistency with other character routines, which can use
|
1617 |
|
|
-1 as EOF.
|
1618 |
|
|
|
1619 |
|
|
@return The value of the hex character, or -1 if the character is
|
1620 |
|
|
invalid. */
|
1621 |
|
|
/*---------------------------------------------------------------------------*/
|
1622 |
|
|
static int hex (int c)
|
1623 |
|
|
{
|
1624 |
|
|
return ((c >= 'a') && (c <= 'f')) ? c - 'a' + 10 :
|
1625 |
|
|
((c >= '0') && (c <= '9')) ? c - '0' :
|
1626 |
|
|
((c >= 'A') && (c <= 'F')) ? c - 'A' + 10 : -1;
|
1627 |
|
|
|
1628 |
|
|
} /* hex () */
|
1629 |
|
|
|
1630 |
|
|
|
1631 |
|
|
/*---------------------------------------------------------------------------*/
|
1632 |
|
|
/*!Convert a register to a hex digit string
|
1633 |
|
|
|
1634 |
|
|
The supplied 32-bit value is converted to an 8 digit hex string according
|
1635 |
|
|
the target endianism. It is null terminated for convenient printing.
|
1636 |
|
|
|
1637 |
|
|
@param[in] val The value to convert
|
1638 |
|
|
@param[out] p_buf The buffer for the text string */
|
1639 |
|
|
/*---------------------------------------------------------------------------*/
|
1640 |
|
|
static void
|
1641 |
|
|
reg2hex (uint32_t val, char *p_buf)
|
1642 |
|
|
{
|
1643 |
|
|
int n; /* Counter for digits */
|
1644 |
|
|
int nyb_shift;
|
1645 |
|
|
|
1646 |
|
|
for (n = 0; n < 8; n++)
|
1647 |
|
|
{
|
1648 |
|
|
#ifdef WORDSBIGENDIAN
|
1649 |
|
|
if(n%2==0){
|
1650 |
|
|
nyb_shift = n * 4 + 4;
|
1651 |
|
|
}
|
1652 |
|
|
else{
|
1653 |
|
|
nyb_shift = n * 4 - 4;
|
1654 |
|
|
}
|
1655 |
|
|
#else
|
1656 |
|
|
nyb_shift = 28 - (n * 4);
|
1657 |
|
|
#endif
|
1658 |
|
|
p_buf[n] = hexchars[(val >> nyb_shift) & 0xf];
|
1659 |
|
|
}
|
1660 |
|
|
|
1661 |
|
|
p_buf[8] = 0; /* Useful to terminate as string */
|
1662 |
|
|
|
1663 |
|
|
} /* reg2hex () */
|
1664 |
|
|
|
1665 |
|
|
|
1666 |
|
|
/*---------------------------------------------------------------------------*/
|
1667 |
|
|
/*!Convert a hex digit string to a register value
|
1668 |
|
|
|
1669 |
|
|
The supplied 8 digit hex string is converted to a 32-bit value according
|
1670 |
|
|
the target endianism
|
1671 |
|
|
|
1672 |
|
|
@param[in] p_buf The buffer with the hex string
|
1673 |
|
|
|
1674 |
|
|
@return The value to convert */
|
1675 |
|
|
/*---------------------------------------------------------------------------*/
|
1676 |
|
|
static uint32_t
|
1677 |
|
|
hex2reg (char *p_buf)
|
1678 |
|
|
{
|
1679 |
|
|
int n; /* Counter for digits */
|
1680 |
|
|
uint32_t val = 0; /* The result */
|
1681 |
|
|
|
1682 |
|
|
for (n = 0; n < 8; n++)
|
1683 |
|
|
{
|
1684 |
|
|
#ifdef WORDSBIGENDIAN
|
1685 |
|
|
int nyb_shift = n * 4;
|
1686 |
|
|
#else
|
1687 |
|
|
int nyb_shift = 28 - (n * 4);
|
1688 |
|
|
#endif
|
1689 |
|
|
val |= hex (p_buf[n]) << nyb_shift;
|
1690 |
|
|
}
|
1691 |
|
|
|
1692 |
|
|
return val;
|
1693 |
|
|
|
1694 |
|
|
} /* hex2reg () */
|
1695 |
|
|
|
1696 |
|
|
|
1697 |
|
|
/*---------------------------------------------------------------------------*/
|
1698 |
|
|
/*!Convert an ASCII character string to pairs of hex digits
|
1699 |
|
|
|
1700 |
|
|
Both source and destination are null terminated.
|
1701 |
|
|
|
1702 |
|
|
@param[out] dest Buffer to store the hex digit pairs (null terminated)
|
1703 |
|
|
@param[in] src The ASCII string (null terminated) */
|
1704 |
|
|
/*---------------------------------------------------------------------------*/
|
1705 |
|
|
static void ascii2hex (char *dest,
|
1706 |
|
|
char *src)
|
1707 |
|
|
{
|
1708 |
|
|
int i;
|
1709 |
|
|
|
1710 |
|
|
/* Step through converting the source string */
|
1711 |
|
|
for (i = 0; src[i] != '\0'; i++)
|
1712 |
|
|
{
|
1713 |
|
|
char ch = src[i];
|
1714 |
|
|
|
1715 |
|
|
dest[i * 2] = hexchars[ch >> 4 & 0xf];
|
1716 |
|
|
dest[i * 2 + 1] = hexchars[ch & 0xf];
|
1717 |
|
|
}
|
1718 |
|
|
|
1719 |
|
|
dest[i * 2] = '\0';
|
1720 |
|
|
|
1721 |
|
|
} /* ascii2hex () */
|
1722 |
|
|
|
1723 |
|
|
|
1724 |
|
|
/*---------------------------------------------------------------------------*/
|
1725 |
|
|
/*!Convert pairs of hex digits to an ASCII character string
|
1726 |
|
|
|
1727 |
|
|
Both source and destination are null terminated.
|
1728 |
|
|
|
1729 |
|
|
@param[out] dest The ASCII string (null terminated)
|
1730 |
|
|
@param[in] src Buffer holding the hex digit pairs (null terminated) */
|
1731 |
|
|
/*---------------------------------------------------------------------------*/
|
1732 |
|
|
static void hex2ascii (char *dest,
|
1733 |
|
|
char *src)
|
1734 |
|
|
{
|
1735 |
|
|
int i;
|
1736 |
|
|
|
1737 |
|
|
/* Step through convering the source hex digit pairs */
|
1738 |
|
|
for (i = 0; src[i * 2] != '\0' && src[i * 2 + 1] != '\0'; i++)
|
1739 |
|
|
{
|
1740 |
|
|
dest[i] = ((hex (src[i * 2]) & 0xf) << 4) | (hex (src[i * 2 + 1]) & 0xf);
|
1741 |
|
|
}
|
1742 |
|
|
|
1743 |
|
|
dest[i] = '\0';
|
1744 |
|
|
|
1745 |
|
|
} /* hex2ascii () */
|
1746 |
|
|
|
1747 |
|
|
|
1748 |
|
|
/*---------------------------------------------------------------------------*/
|
1749 |
|
|
/*!Set the program counter
|
1750 |
|
|
|
1751 |
|
|
This sets the value in the NPC SPR. Not completely trivial, since this is
|
1752 |
|
|
actually cached in cpu_state.pc. Any reset of the NPC also involves
|
1753 |
|
|
clearing the delay state and setting the pcnext global.
|
1754 |
|
|
|
1755 |
|
|
Only actually do this if the requested address is different to the current
|
1756 |
|
|
NPC (avoids clearing the delay pipe).
|
1757 |
|
|
|
1758 |
|
|
@param[in] addr The address to use */
|
1759 |
|
|
/*---------------------------------------------------------------------------*/
|
1760 |
|
|
static void
|
1761 |
|
|
set_npc (uint32_t addr)
|
1762 |
|
|
{
|
1763 |
|
|
|
1764 |
|
|
// First set the chain
|
1765 |
|
|
gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
1766 |
|
|
|
1767 |
|
|
|
1768 |
|
|
if (addr != get_npc())
|
1769 |
|
|
{
|
1770 |
|
|
|
1771 |
|
|
gdb_write_reg(NPC_CPU_REG_ADD, addr);
|
1772 |
|
|
|
1773 |
|
|
if (STALLED == stallState)
|
1774 |
|
|
{
|
1775 |
|
|
if (DEBUG_GDB) printf("set_npc(): New NPC value (0x%08x) written and locally cached \n", addr);
|
1776 |
|
|
npcCachedValue = addr;
|
1777 |
|
|
npcIsCached = 1;
|
1778 |
|
|
}
|
1779 |
|
|
else
|
1780 |
|
|
{
|
1781 |
|
|
if (DEBUG_GDB) printf("set_npc(): New NPC value (0x%08x) written \n", addr);
|
1782 |
|
|
npcIsCached = 0;
|
1783 |
|
|
}
|
1784 |
|
|
|
1785 |
|
|
|
1786 |
|
|
}
|
1787 |
|
|
else
|
1788 |
|
|
return;
|
1789 |
|
|
|
1790 |
|
|
|
1791 |
|
|
} /* set_npc () */
|
1792 |
|
|
|
1793 |
|
|
|
1794 |
|
|
//! Read the value of the Next Program Counter (a SPR)
|
1795 |
|
|
|
1796 |
|
|
//! Setting the NPC flushes the pipeline, so subsequent reads will return
|
1797 |
|
|
//! zero until the processor has refilled the pipeline. This will not be
|
1798 |
|
|
//! happening if the processor is stalled (as it is when GDB had control),
|
1799 |
|
|
//! so we must cache the NPC. As soon as the processor is unstalled, this
|
1800 |
|
|
//! cached value becomes invalid.
|
1801 |
|
|
|
1802 |
|
|
//! If we are stalled and the value has been cached, use it. If we are stalled
|
1803 |
|
|
//! and the value has not been cached, cache it (for efficiency) and use
|
1804 |
|
|
//! it. Otherwise read the corresponding SPR.
|
1805 |
|
|
|
1806 |
|
|
//! @return The value of the NPC
|
1807 |
|
|
static uint32_t get_npc ()
|
1808 |
|
|
{
|
1809 |
|
|
uint32_t current_npc;
|
1810 |
|
|
|
1811 |
|
|
if (STALLED == stallState)
|
1812 |
|
|
{
|
1813 |
|
|
if (npcIsCached == 0)
|
1814 |
|
|
{
|
1815 |
|
|
err = gdb_set_chain(SC_RISC_DEBUG);
|
1816 |
|
|
err = gdb_read_reg(NPC_CPU_REG_ADD, &npcCachedValue);
|
1817 |
|
|
if(err > 0){
|
1818 |
|
|
printf("Error %d reading NPC\n", err);
|
1819 |
|
|
rsp_client_close ();
|
1820 |
|
|
return 0;
|
1821 |
|
|
}
|
1822 |
|
|
if (DEBUG_GDB) printf("get_npc(): caching newly read NPC value (0x%08x)\n",npcCachedValue);
|
1823 |
|
|
|
1824 |
|
|
|
1825 |
|
|
npcIsCached = 1;
|
1826 |
|
|
}
|
1827 |
|
|
else
|
1828 |
|
|
if (DEBUG_GDB) printf("get_npc(): reading cached NPC value (0x%08x)\n",npcCachedValue);
|
1829 |
|
|
|
1830 |
|
|
return npcCachedValue;
|
1831 |
|
|
}
|
1832 |
|
|
else
|
1833 |
|
|
{
|
1834 |
|
|
err = gdb_read_reg(NPC_CPU_REG_ADD, ¤t_npc);
|
1835 |
|
|
if(err > 0){
|
1836 |
|
|
printf("Error %d reading NPC\n", err);
|
1837 |
|
|
rsp_client_close ();
|
1838 |
|
|
return 0;
|
1839 |
|
|
}
|
1840 |
|
|
return current_npc;
|
1841 |
|
|
|
1842 |
|
|
}
|
1843 |
|
|
} // get_npc ()
|
1844 |
|
|
|
1845 |
|
|
|
1846 |
|
|
|
1847 |
|
|
/*---------------------------------------------------------------------------*/
|
1848 |
|
|
/*!Send a packet acknowledging an exception has occurred
|
1849 |
|
|
|
1850 |
|
|
This is only called if there is a client FD to talk to */
|
1851 |
|
|
/*---------------------------------------------------------------------------*/
|
1852 |
|
|
static void
|
1853 |
|
|
rsp_report_exception (void)
|
1854 |
|
|
{
|
1855 |
|
|
struct rsp_buf buffer;
|
1856 |
|
|
|
1857 |
|
|
/* Construct a signal received packet */
|
1858 |
|
|
buffer.data[0] = 'S';
|
1859 |
|
|
buffer.data[1] = hexchars[rsp.sigval >> 4];
|
1860 |
|
|
buffer.data[2] = hexchars[rsp.sigval % 16];
|
1861 |
|
|
buffer.data[3] = 0;
|
1862 |
|
|
buffer.len = strlen (buffer.data);
|
1863 |
|
|
|
1864 |
|
|
put_packet (&buffer);
|
1865 |
|
|
|
1866 |
|
|
} /* rsp_report_exception () */
|
1867 |
|
|
|
1868 |
|
|
|
1869 |
|
|
/*---------------------------------------------------------------------------*/
|
1870 |
|
|
/*!Handle a RSP continue request
|
1871 |
|
|
|
1872 |
|
|
Parse the command to see if there is an address. Uses the underlying
|
1873 |
|
|
generic continue function, with EXCEPT_NONE.
|
1874 |
|
|
|
1875 |
|
|
@param[in] p_buf The full continue packet */
|
1876 |
|
|
/*---------------------------------------------------------------------------*/
|
1877 |
|
|
static void
|
1878 |
|
|
rsp_continue (struct rsp_buf *p_buf)
|
1879 |
|
|
{
|
1880 |
|
|
uint32_t addr; /* Address to continue from, if any */
|
1881 |
|
|
|
1882 |
|
|
// First set the chain
|
1883 |
|
|
err = gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
1884 |
|
|
|
1885 |
|
|
// Make sure the processor is stalled
|
1886 |
|
|
gdb_ensure_or1k_stalled();
|
1887 |
|
|
|
1888 |
|
|
if(err > 0){
|
1889 |
|
|
printf("Error %d to set RISC Debug Interface chain in the CONTINUE command 'c'\n", err);
|
1890 |
|
|
rsp_client_close ();
|
1891 |
|
|
return;
|
1892 |
|
|
}
|
1893 |
|
|
|
1894 |
|
|
if (0 == strcmp ("c", p_buf->data))
|
1895 |
|
|
{
|
1896 |
|
|
// Arc Sim Code --> addr = cpu_state.pc; /* Default uses current NPC */
|
1897 |
|
|
/* ---------- NPC ---------- */
|
1898 |
|
|
addr = get_npc();
|
1899 |
|
|
}
|
1900 |
|
|
else if (1 != sscanf (p_buf->data, "c%x", &addr))
|
1901 |
|
|
{
|
1902 |
|
|
fprintf (stderr,
|
1903 |
|
|
"Warning: RSP continue address %s not recognized: ignored\n",
|
1904 |
|
|
p_buf->data);
|
1905 |
|
|
|
1906 |
|
|
// Arc Sim Code --> addr = cpu_state.pc; /* Default uses current NPC */
|
1907 |
|
|
/* ---------- NPC ---------- */
|
1908 |
|
|
addr = get_npc();
|
1909 |
|
|
}
|
1910 |
|
|
|
1911 |
|
|
if (DEBUG_GDB) printf("rsp_continue() --> Read NPC = 0x%08x\n", addr);
|
1912 |
|
|
|
1913 |
|
|
rsp_continue_generic (addr, EXCEPT_NONE);
|
1914 |
|
|
|
1915 |
|
|
} /* rsp_continue () */
|
1916 |
|
|
|
1917 |
|
|
|
1918 |
|
|
/*---------------------------------------------------------------------------*/
|
1919 |
|
|
/*!Handle a RSP continue with signal request
|
1920 |
|
|
|
1921 |
|
|
Currently null. Will use the underlying generic continue function.
|
1922 |
|
|
|
1923 |
|
|
@param[in] p_buf The full continue with signal packet */
|
1924 |
|
|
/*---------------------------------------------------------------------------*/
|
1925 |
|
|
static void
|
1926 |
|
|
rsp_continue_with_signal (struct rsp_buf *p_buf)
|
1927 |
|
|
{
|
1928 |
|
|
printf ("RSP continue with signal '%s' received\n", p_buf->data);
|
1929 |
|
|
|
1930 |
|
|
} /* rsp_continue_with_signal () */
|
1931 |
|
|
|
1932 |
|
|
|
1933 |
|
|
/*---------------------------------------------------------------------------*/
|
1934 |
|
|
/*!Generic processing of a continue request
|
1935 |
|
|
|
1936 |
|
|
The signal may be EXCEPT_NONE if there is no exception to be
|
1937 |
|
|
handled. Currently the exception is ignored.
|
1938 |
|
|
|
1939 |
|
|
The single step flag is cleared in the debug registers and then the
|
1940 |
|
|
processor is unstalled.
|
1941 |
|
|
|
1942 |
|
|
@param[in] addr Address from which to step
|
1943 |
|
|
@param[in] except The exception to use (if any) */
|
1944 |
|
|
/*---------------------------------------------------------------------------*/
|
1945 |
|
|
static void
|
1946 |
|
|
rsp_continue_generic (uint32_t addr,
|
1947 |
|
|
uint32_t except)
|
1948 |
|
|
{
|
1949 |
|
|
uint32_t temp_uint32;
|
1950 |
|
|
|
1951 |
|
|
/* Set the address as the value of the next program counter */
|
1952 |
|
|
set_npc (addr);
|
1953 |
|
|
|
1954 |
|
|
/* Clear Debug Reason Register (DRR) 0x3015 */
|
1955 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DRR] = 0;
|
1956 |
|
|
if(gdb_write_reg(DRR_CPU_REG_ADD, 0)) printf("Error write to DRR register\n");
|
1957 |
|
|
|
1958 |
|
|
/* Clear watchpoint break generation in Debug Mode Register 2 (DMR2) 0x3011 */
|
1959 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DMR2] &= ~SPR_DMR2_WGB;
|
1960 |
|
|
if(gdb_read_reg(DMR2_CPU_REG_ADD, &temp_uint32)) printf("Error read from DMR2 register\n");
|
1961 |
|
|
temp_uint32 &= ~SPR_DMR2_WGB;
|
1962 |
|
|
if(gdb_write_reg(DMR2_CPU_REG_ADD, temp_uint32)) printf("Error write to DMR2 register\n");
|
1963 |
|
|
|
1964 |
|
|
/* Clear the single step trigger in Debug Mode Register 1 (DMR1) Register 0x3010 */
|
1965 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DMR1] &= ~SPR_DMR1_ST;
|
1966 |
|
|
if(gdb_read_reg(DMR1_CPU_REG_ADD, &temp_uint32)) printf("Error read from DMR1 register\n");
|
1967 |
|
|
temp_uint32 &= ~SPR_DMR1_ST;
|
1968 |
|
|
if(gdb_write_reg(DMR1_CPU_REG_ADD, temp_uint32)) printf("Error write to DMR1 register\n");
|
1969 |
|
|
|
1970 |
|
|
/* Set traps to be handled by the debug unit in the Debug Stop Register (DSR) Register 0x3014 */
|
1971 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DSR] |= SPR_DSR_TE;
|
1972 |
|
|
if(gdb_read_reg(DSR_CPU_REG_ADD, &temp_uint32)) printf("Error read from DSR register\n");
|
1973 |
|
|
temp_uint32 |= SPR_DSR_TE;
|
1974 |
|
|
if(gdb_write_reg(DSR_CPU_REG_ADD, temp_uint32)) printf("Error write to DSR register\n");
|
1975 |
|
|
|
1976 |
|
|
/* Unstall the processor */
|
1977 |
|
|
set_stall_state (0);
|
1978 |
|
|
|
1979 |
|
|
/* Note the GDB client is now waiting for a reply. */
|
1980 |
|
|
rsp.client_waiting = 1;
|
1981 |
|
|
|
1982 |
|
|
} /* rsp_continue_generic () */
|
1983 |
|
|
|
1984 |
|
|
|
1985 |
|
|
/*---------------------------------------------------------------------------*/
|
1986 |
|
|
/*!Handle a RSP read all registers request
|
1987 |
|
|
|
1988 |
|
|
The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PPC
|
1989 |
|
|
(i.e. SPR PPC), NPC (i.e. SPR NPC) and SR (i.e. SPR SR). Each register is
|
1990 |
|
|
returned as a sequence of bytes in target endian order.
|
1991 |
|
|
|
1992 |
|
|
Each byte is packed as a pair of hex digits. */
|
1993 |
|
|
/*---------------------------------------------------------------------------*/
|
1994 |
|
|
static void
|
1995 |
|
|
rsp_read_all_regs (void)
|
1996 |
|
|
{
|
1997 |
|
|
struct rsp_buf buffer; /* Buffer for the reply */
|
1998 |
|
|
int r; /* Register index */
|
1999 |
|
|
uint32_t temp_uint32;
|
2000 |
|
|
|
2001 |
|
|
// Make sure the processor is stalled
|
2002 |
|
|
gdb_ensure_or1k_stalled();
|
2003 |
|
|
|
2004 |
|
|
// First set the chain
|
2005 |
|
|
gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2006 |
|
|
|
2007 |
|
|
|
2008 |
|
|
// Read all GPRs
|
2009 |
|
|
for (r = 0; r < MAX_GPRS; r++){
|
2010 |
|
|
|
2011 |
|
|
err = gdb_read_reg(0x400 + r, &temp_uint32);
|
2012 |
|
|
if(err > 0){
|
2013 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_read_reg at reg. %d\n", err, r);
|
2014 |
|
|
put_str_packet ("E01");
|
2015 |
|
|
return;
|
2016 |
|
|
}
|
2017 |
|
|
reg2hex (temp_uint32, &(buffer.data[r * 8]));
|
2018 |
|
|
|
2019 |
|
|
if (DEBUG_GDB_DUMP_DATA){
|
2020 |
|
|
switch(r % 4)
|
2021 |
|
|
{
|
2022 |
|
|
case 0:
|
2023 |
|
|
printf("gpr%02d 0x%08x ", r, temp_uint32);
|
2024 |
|
|
break;
|
2025 |
|
|
case 1:
|
2026 |
|
|
case 2:
|
2027 |
|
|
printf("0x%08x ", temp_uint32);
|
2028 |
|
|
break;
|
2029 |
|
|
case 3:
|
2030 |
|
|
printf("0x%08x\n", temp_uint32);
|
2031 |
|
|
break;
|
2032 |
|
|
default:
|
2033 |
|
|
break;
|
2034 |
|
|
}
|
2035 |
|
|
}
|
2036 |
|
|
|
2037 |
|
|
}
|
2038 |
|
|
/* ---------- PPC ---------- */
|
2039 |
|
|
err = gdb_read_reg(PPC_CPU_REG_ADD, &temp_uint32);
|
2040 |
|
|
if(err > 0){
|
2041 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_read_reg read --> PPC\n", err);
|
2042 |
|
|
put_str_packet ("E01");
|
2043 |
|
|
return;
|
2044 |
|
|
}
|
2045 |
|
|
reg2hex (temp_uint32, &(buffer.data[PPC_REGNUM * 8]));
|
2046 |
|
|
if (DEBUG_GDB_DUMP_DATA) printf("PPC 0x%08x\n", temp_uint32);
|
2047 |
|
|
/* ---------- NPC ---------- */
|
2048 |
|
|
temp_uint32 = get_npc();
|
2049 |
|
|
/*
|
2050 |
|
|
err = gdb_read_reg(NPC_CPU_REG_ADD, &temp_uint32);
|
2051 |
|
|
if(err > 0){
|
2052 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_read_reg read --> NPC\n", err);
|
2053 |
|
|
put_str_packet ("E01");
|
2054 |
|
|
return;
|
2055 |
|
|
}
|
2056 |
|
|
*/
|
2057 |
|
|
reg2hex (temp_uint32, &(buffer.data[NPC_REGNUM * 8]));
|
2058 |
|
|
if (DEBUG_GDB_DUMP_DATA) printf("NPC 0x%08x\n", temp_uint32);
|
2059 |
|
|
/* ---------- SR ---------- */
|
2060 |
|
|
err = gdb_read_reg(SR_CPU_REG_ADD, &temp_uint32);
|
2061 |
|
|
if(err > 0){
|
2062 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_read_reg read --> SP\n", err);
|
2063 |
|
|
put_str_packet ("E01");
|
2064 |
|
|
return;
|
2065 |
|
|
}
|
2066 |
|
|
reg2hex (temp_uint32, &(buffer.data[SR_REGNUM * 8]));
|
2067 |
|
|
if (DEBUG_GDB_DUMP_DATA) printf("SR 0x%08x\n", temp_uint32);
|
2068 |
|
|
|
2069 |
|
|
/* Finalize the packet and send it */
|
2070 |
|
|
buffer.data[NUM_REGS * 8] = 0;
|
2071 |
|
|
buffer.len = NUM_REGS * 8;
|
2072 |
|
|
|
2073 |
|
|
put_packet (&buffer);
|
2074 |
|
|
return;
|
2075 |
|
|
} /* rsp_read_all_regs () */
|
2076 |
|
|
|
2077 |
|
|
|
2078 |
|
|
/*---------------------------------------------------------------------------*/
|
2079 |
|
|
/*!Handle a RSP write all registers request
|
2080 |
|
|
|
2081 |
|
|
The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PPC
|
2082 |
|
|
(i.e. SPR PPC), NPC (i.e. SPR NPC) and SR (i.e. SPR SR). Each register is
|
2083 |
|
|
supplied as a sequence of bytes in target endian order.
|
2084 |
|
|
|
2085 |
|
|
Each byte is packed as a pair of hex digits.
|
2086 |
|
|
|
2087 |
|
|
@todo There is no error checking at present. Non-hex chars will generate a
|
2088 |
|
|
warning message, but there is no other check that the right amount
|
2089 |
|
|
of data is present. The result is always "OK".
|
2090 |
|
|
|
2091 |
|
|
@param[in] p_buf The original packet request. */
|
2092 |
|
|
/*---------------------------------------------------------------------------*/
|
2093 |
|
|
static void
|
2094 |
|
|
rsp_write_all_regs (struct rsp_buf *p_buf)
|
2095 |
|
|
{
|
2096 |
|
|
uint32_t regnum; /* Register index */
|
2097 |
|
|
// char valstr[9]; /* Allow for EOS on the string */
|
2098 |
|
|
|
2099 |
|
|
// /* Check for valid data */
|
2100 |
|
|
// if (0 != (strcmp ("G", p_buf->data)) && (GDB_BUF_MAX != strlen(p_buf->data)))
|
2101 |
|
|
// {
|
2102 |
|
|
// fprintf (stderr, "Warning: Failed to recognize RSP write register "
|
2103 |
|
|
// "command: %s\n", p_buf->data);
|
2104 |
|
|
// // put_str_packet ("E01");
|
2105 |
|
|
// return;
|
2106 |
|
|
// }
|
2107 |
|
|
|
2108 |
|
|
// Make sure the processor is stalled
|
2109 |
|
|
gdb_ensure_or1k_stalled();
|
2110 |
|
|
|
2111 |
|
|
// First set the chain
|
2112 |
|
|
err = gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2113 |
|
|
if(err > 0){
|
2114 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_set_chain\n", err);
|
2115 |
|
|
put_str_packet ("E01");
|
2116 |
|
|
return;
|
2117 |
|
|
}
|
2118 |
|
|
|
2119 |
|
|
/* ---------- GPRS ---------- */
|
2120 |
|
|
for (regnum = 0; regnum < MAX_GPRS; regnum++)
|
2121 |
|
|
{
|
2122 |
|
|
err = gdb_write_reg(0x400 + regnum, hex2reg (&p_buf->data[regnum * 8 + 1]));
|
2123 |
|
|
if(err > 0){
|
2124 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> GPRS\n", err);
|
2125 |
|
|
put_str_packet ("E01");
|
2126 |
|
|
return;
|
2127 |
|
|
}
|
2128 |
|
|
}
|
2129 |
|
|
|
2130 |
|
|
/* ---------- PPC ---------- */
|
2131 |
|
|
err = gdb_write_reg(PPC_CPU_REG_ADD, hex2reg (&p_buf->data[PPC_REGNUM * 8 + 1]));
|
2132 |
|
|
if(err > 0){
|
2133 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> PPC\n", err);
|
2134 |
|
|
put_str_packet ("E01");
|
2135 |
|
|
return;
|
2136 |
|
|
}
|
2137 |
|
|
/* ---------- SR ---------- */
|
2138 |
|
|
err = gdb_write_reg(SR_CPU_REG_ADD, hex2reg (&p_buf->data[SR_REGNUM * 8 + 1]));
|
2139 |
|
|
if(err > 0){
|
2140 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> SR\n", err);
|
2141 |
|
|
put_str_packet ("E01");
|
2142 |
|
|
return;
|
2143 |
|
|
}
|
2144 |
|
|
/* ---------- NPC ---------- */
|
2145 |
|
|
set_npc(hex2reg (&p_buf->data[NPC_REGNUM * 8 + 1]));
|
2146 |
|
|
/*
|
2147 |
|
|
err = gdb_write_reg(NPC_CPU_REG_ADD, hex2reg (&p_buf->data[NPC_REGNUM * 8 + 1]));
|
2148 |
|
|
if(err > 0){
|
2149 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> NPC\n", err);
|
2150 |
|
|
put_str_packet ("E01");
|
2151 |
|
|
return;
|
2152 |
|
|
}
|
2153 |
|
|
*/
|
2154 |
|
|
/* Acknowledge. TODO: We always succeed at present, even if the data was
|
2155 |
|
|
defective. */
|
2156 |
|
|
put_str_packet ("OK");
|
2157 |
|
|
} /* rsp_write_all_regs () */
|
2158 |
|
|
|
2159 |
|
|
|
2160 |
|
|
/*---------------------------------------------------------------------------*/
|
2161 |
|
|
/* Handle a RSP read memory (symbolic) request
|
2162 |
|
|
|
2163 |
|
|
Syntax is:
|
2164 |
|
|
|
2165 |
|
|
m<addr>,<length>:
|
2166 |
|
|
|
2167 |
|
|
The response is the bytes, lowest address first, encoded as pairs of hex
|
2168 |
|
|
digits.
|
2169 |
|
|
|
2170 |
|
|
The length given is the number of bytes to be read.
|
2171 |
|
|
|
2172 |
|
|
@note This function reuses p_buf, so trashes the original command.
|
2173 |
|
|
|
2174 |
|
|
@param[in] p_buf The command received */
|
2175 |
|
|
/*---------------------------------------------------------------------------*/
|
2176 |
|
|
static void rsp_read_mem (struct rsp_buf *p_buf)
|
2177 |
|
|
{
|
2178 |
|
|
unsigned int addr; /* Where to read the memory */
|
2179 |
|
|
int len; /* Number of bytes to read */
|
2180 |
|
|
int off; /* Offset into the memory */
|
2181 |
46 |
julius |
uint32_t temp_uint32 = 0;
|
2182 |
|
|
char *rec_buf, *rec_buf_ptr;
|
2183 |
|
|
int bytes_per_word = 4; /* Current OR implementation is 4-byte words */
|
2184 |
|
|
int i;
|
2185 |
|
|
int len_cpy;
|
2186 |
|
|
/* Couple of temps we might need when doing aligning/leftover accesses */
|
2187 |
|
|
uint32_t tmp_word;
|
2188 |
|
|
char *tmp_word_ptr = (char*) &tmp_word;
|
2189 |
|
|
|
2190 |
39 |
julius |
|
2191 |
|
|
|
2192 |
|
|
if (2 != sscanf (p_buf->data, "m%x,%x:", &addr, &len))
|
2193 |
|
|
{
|
2194 |
|
|
fprintf (stderr, "Warning: Failed to recognize RSP read memory "
|
2195 |
|
|
"command: %s\n", p_buf->data);
|
2196 |
|
|
put_str_packet ("E01");
|
2197 |
|
|
return;
|
2198 |
|
|
}
|
2199 |
|
|
|
2200 |
|
|
/* Make sure we won't overflow the buffer (2 chars per byte) */
|
2201 |
47 |
julius |
if ((len * 2) >= GDB_BUF_MAX_TIMES_TWO)
|
2202 |
39 |
julius |
{
|
2203 |
|
|
fprintf (stderr, "Warning: Memory read %s too large for RSP packet: "
|
2204 |
|
|
"truncated\n", p_buf->data);
|
2205 |
|
|
len = (GDB_BUF_MAX - 1) / 2;
|
2206 |
|
|
}
|
2207 |
|
|
|
2208 |
|
|
if(!(rec_buf = (char*)malloc(len))) {
|
2209 |
|
|
put_str_packet ("E01");
|
2210 |
|
|
return;
|
2211 |
|
|
}
|
2212 |
|
|
|
2213 |
|
|
// Make sure the processor is stalled
|
2214 |
|
|
gdb_ensure_or1k_stalled();
|
2215 |
|
|
|
2216 |
|
|
// Set chain 5 --> Wishbone Memory chain
|
2217 |
|
|
err = gdb_set_chain(SC_WISHBONE);
|
2218 |
|
|
if(err){
|
2219 |
46 |
julius |
if (DEBUG_GDB) printf("Error %d in gdb_set_chain\n", err);
|
2220 |
|
|
put_str_packet ("E01");
|
2221 |
39 |
julius |
return;
|
2222 |
46 |
julius |
}
|
2223 |
|
|
|
2224 |
|
|
len_cpy = len;
|
2225 |
|
|
rec_buf_ptr = rec_buf; // Need to save a copy of pointer
|
2226 |
|
|
|
2227 |
|
|
if (addr & 0x3) // address not aligned at the start
|
2228 |
|
|
{
|
2229 |
|
|
// Have to read from the word-aligned address first and fetch the bytes
|
2230 |
|
|
// we need.
|
2231 |
|
|
if (DEBUG_GDB)
|
2232 |
|
|
printf("rsp_read_mem: unaligned address read - reading before bytes\n",
|
2233 |
|
|
err);
|
2234 |
|
|
int num_bytes_to_align = bytes_per_word - (addr & 0x3);
|
2235 |
|
|
uint32_t aligned_addr = addr & ~0x3;
|
2236 |
|
|
|
2237 |
|
|
if (DEBUG_GDB)
|
2238 |
|
|
printf("rsp_read_mem: reading first %d of %d overall, from 0x%.8x\n",
|
2239 |
|
|
num_bytes_to_align, len_cpy, aligned_addr);
|
2240 |
|
|
|
2241 |
|
|
err = gdb_read_reg(aligned_addr, &tmp_word);
|
2242 |
|
|
|
2243 |
|
|
if (DEBUG_GDB) printf("rsp_read_mem: first word 0x%.8x\n", tmp_word);
|
2244 |
|
|
|
2245 |
|
|
if(err){
|
2246 |
|
|
put_str_packet ("E01");
|
2247 |
|
|
return;
|
2248 |
|
|
}
|
2249 |
|
|
|
2250 |
|
|
// Pack these bytes in first
|
2251 |
|
|
if (num_bytes_to_align > len_cpy) num_bytes_to_align = len_cpy;
|
2252 |
|
|
|
2253 |
|
|
// Data returns back in big endian format.
|
2254 |
|
|
if (DEBUG_GDB_BLOCK_DATA)printf("rsp_read_mem: packing first bytes ");
|
2255 |
|
|
i=addr&0x3; int buf_ctr = 0;
|
2256 |
|
|
while (buf_ctr < num_bytes_to_align)
|
2257 |
|
|
{
|
2258 |
|
|
rec_buf_ptr[buf_ctr] = tmp_word_ptr[i];
|
2259 |
|
|
if (DEBUG_GDB_BLOCK_DATA)printf("i=%d=0x%x, ", i,
|
2260 |
|
|
tmp_word_ptr[bytes_per_word-1-i]);
|
2261 |
|
|
i++;
|
2262 |
|
|
buf_ctr++;
|
2263 |
39 |
julius |
}
|
2264 |
46 |
julius |
|
2265 |
|
|
if (DEBUG_GDB_BLOCK_DATA)printf("\n");
|
2266 |
|
|
|
2267 |
|
|
// Adjust our status
|
2268 |
|
|
len_cpy -= num_bytes_to_align; addr += num_bytes_to_align;
|
2269 |
|
|
rec_buf_ptr += num_bytes_to_align;
|
2270 |
|
|
}
|
2271 |
|
|
if (len_cpy/bytes_per_word) // Now perform all full word accesses
|
2272 |
|
|
{
|
2273 |
|
|
int words_to_read = len_cpy/bytes_per_word; // Full words to read
|
2274 |
|
|
if (DEBUG_GDB) printf("rsp_read_mem: reading %d words from 0x%.8x\n",
|
2275 |
|
|
words_to_read, addr);
|
2276 |
|
|
// Read full data words from Wishbone Memory chain
|
2277 |
|
|
err = gdb_read_block(addr, (uint32_t*)rec_buf_ptr,
|
2278 |
|
|
words_to_read*bytes_per_word);
|
2279 |
|
|
|
2280 |
|
|
if(err){
|
2281 |
|
|
put_str_packet ("E01");
|
2282 |
|
|
return;
|
2283 |
|
|
}
|
2284 |
39 |
julius |
|
2285 |
46 |
julius |
// Adjust our status
|
2286 |
|
|
len_cpy -= (words_to_read*bytes_per_word);
|
2287 |
|
|
addr += (words_to_read*bytes_per_word);
|
2288 |
|
|
rec_buf_ptr += (words_to_read*bytes_per_word);
|
2289 |
|
|
}
|
2290 |
|
|
if (len_cpy) // Leftover bytes
|
2291 |
|
|
{
|
2292 |
|
|
if (DEBUG_GDB)
|
2293 |
|
|
printf("rsp_read_mem: reading %d left-over bytes from 0x%.8x\n",
|
2294 |
|
|
len_cpy, addr);
|
2295 |
|
|
|
2296 |
|
|
err = gdb_read_reg(addr, &tmp_word);
|
2297 |
|
|
|
2298 |
|
|
// Big endian - top byte first!
|
2299 |
|
|
for(i=0;i<len_cpy;i++)
|
2300 |
|
|
rec_buf_ptr[i] = tmp_word_ptr[i];
|
2301 |
|
|
|
2302 |
|
|
}
|
2303 |
|
|
|
2304 |
|
|
if (DEBUG_GDB)
|
2305 |
|
|
printf("rsp_read_mem: err: %d\n",err);
|
2306 |
|
|
|
2307 |
|
|
|
2308 |
39 |
julius |
if(err){
|
2309 |
46 |
julius |
put_str_packet ("E01");
|
2310 |
|
|
return;
|
2311 |
|
|
}
|
2312 |
39 |
julius |
|
2313 |
|
|
/* Refill the buffer with the reply */
|
2314 |
|
|
for( off = 0 ; off < len ; off ++ ) {
|
2315 |
46 |
julius |
;
|
2316 |
|
|
p_buf->data[(2*off)] = hexchars[((rec_buf[off]&0xf0)>>4)];
|
2317 |
|
|
p_buf->data[(2*off)+1] = hexchars[(rec_buf[off]&0x0f)];
|
2318 |
39 |
julius |
}
|
2319 |
46 |
julius |
|
2320 |
39 |
julius |
if (DEBUG_GDB && (err > 0)) printf("\nError %x\n", err);fflush (stdout);
|
2321 |
|
|
free(rec_buf);
|
2322 |
|
|
p_buf->data[off * 2] = 0; /* End of string */
|
2323 |
|
|
p_buf->len = strlen (p_buf->data);
|
2324 |
46 |
julius |
if (DEBUG_GDB_BLOCK_DATA){
|
2325 |
|
|
printf("rsp_read_mem: adr 0x%.8x data: ", addr);
|
2326 |
|
|
for(i=0;i<len*2;i++)
|
2327 |
|
|
printf("%c",p_buf->data[i]);
|
2328 |
|
|
printf("\n");
|
2329 |
|
|
}
|
2330 |
|
|
|
2331 |
39 |
julius |
put_packet (p_buf);
|
2332 |
46 |
julius |
|
2333 |
39 |
julius |
} /* rsp_read_mem () */
|
2334 |
|
|
|
2335 |
|
|
|
2336 |
|
|
/*---------------------------------------------------------------------------*/
|
2337 |
|
|
/*!Handle a RSP write memory (symbolic) request ("M")
|
2338 |
|
|
|
2339 |
|
|
Syntax is:
|
2340 |
|
|
|
2341 |
|
|
M<addr>,<length>:<data>
|
2342 |
|
|
|
2343 |
|
|
Example: M4015cc,2:c320#
|
2344 |
|
|
(Write the value 0xc320 to address 0x4015cc.)
|
2345 |
|
|
|
2346 |
|
|
An example target response:
|
2347 |
|
|
+ $OK#
|
2348 |
|
|
|
2349 |
|
|
The data is the bytes, lowest address first, encoded as pairs of hex
|
2350 |
|
|
digits.
|
2351 |
|
|
|
2352 |
|
|
The length given is the number of bytes to be written.
|
2353 |
|
|
|
2354 |
|
|
@note This function reuses p_buf, so trashes the original command.
|
2355 |
|
|
|
2356 |
|
|
@param[in] p_buf The command received */
|
2357 |
|
|
/*---------------------------------------------------------------------------*/
|
2358 |
|
|
static void
|
2359 |
|
|
rsp_write_mem (struct rsp_buf *p_buf)
|
2360 |
|
|
{
|
2361 |
|
|
unsigned int addr; /* Where to write the memory */
|
2362 |
|
|
int len; /* Number of bytes to write */
|
2363 |
|
|
char *symdat; /* Pointer to the symboli data */
|
2364 |
|
|
int datlen; /* Number of digits in symbolic data */
|
2365 |
|
|
int off; /* Offset into the memory */
|
2366 |
|
|
int nibc; /* Nibbel counter */
|
2367 |
|
|
uint32_t val;
|
2368 |
|
|
|
2369 |
|
|
if (2 != sscanf (p_buf->data, "M%x,%x:", &addr, &len))
|
2370 |
|
|
{
|
2371 |
|
|
fprintf (stderr, "Warning: Failed to recognize RSP write memory "
|
2372 |
|
|
"command: %s\n", p_buf->data);
|
2373 |
|
|
put_str_packet ("E01");
|
2374 |
|
|
return;
|
2375 |
|
|
}
|
2376 |
|
|
|
2377 |
|
|
/* Find the start of the data and check there is the amount we expect. */
|
2378 |
|
|
symdat = (char*) memchr ((const void *)p_buf->data, ':', GDB_BUF_MAX) + 1;
|
2379 |
|
|
datlen = p_buf->len - (symdat - p_buf->data);
|
2380 |
|
|
|
2381 |
|
|
/* Sanity check */
|
2382 |
|
|
if (len * 2 != datlen)
|
2383 |
|
|
{
|
2384 |
|
|
fprintf (stderr, "Warning: Write of %d digits requested, but %d digits "
|
2385 |
|
|
"supplied: packet ignored\n", len * 2, datlen );
|
2386 |
|
|
put_str_packet ("E01");
|
2387 |
|
|
return;
|
2388 |
|
|
}
|
2389 |
|
|
|
2390 |
|
|
// Make sure the processor is stalled
|
2391 |
|
|
gdb_ensure_or1k_stalled();
|
2392 |
|
|
|
2393 |
|
|
|
2394 |
|
|
// Set chain 5 --> Wishbone Memory chain
|
2395 |
|
|
err = gdb_set_chain(SC_WISHBONE);
|
2396 |
|
|
if(err){
|
2397 |
|
|
put_str_packet ("E01");
|
2398 |
|
|
return;
|
2399 |
|
|
}
|
2400 |
|
|
|
2401 |
|
|
val = 0;
|
2402 |
|
|
off = 0;
|
2403 |
|
|
/* Write the bytes to memory */
|
2404 |
|
|
for (nibc = 0; nibc < datlen; nibc++)
|
2405 |
|
|
{
|
2406 |
|
|
val |= 0x0000000f & hex (symdat[nibc]);
|
2407 |
|
|
if(nibc % 8 == 7){
|
2408 |
|
|
err = gdb_write_block(addr + off, &val, 4);
|
2409 |
|
|
if (DEBUG_GDB) printf("Error %x\n", err);fflush (stdout);
|
2410 |
|
|
if(err){
|
2411 |
|
|
put_str_packet ("E01");
|
2412 |
|
|
return;
|
2413 |
|
|
}
|
2414 |
|
|
val = 0;
|
2415 |
|
|
off += 4;
|
2416 |
|
|
}
|
2417 |
|
|
val <<= 4;
|
2418 |
|
|
}
|
2419 |
|
|
put_str_packet ("OK");
|
2420 |
|
|
} /* rsp_write_mem () */
|
2421 |
|
|
|
2422 |
|
|
|
2423 |
|
|
/*---------------------------------------------------------------------------*/
|
2424 |
|
|
/*!Read a single register
|
2425 |
|
|
|
2426 |
|
|
The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PC
|
2427 |
|
|
(i.e. SPR NPC) and SR (i.e. SPR SR). The register is returned as a
|
2428 |
|
|
sequence of bytes in target endian order.
|
2429 |
|
|
|
2430 |
|
|
Each byte is packed as a pair of hex digits.
|
2431 |
|
|
|
2432 |
|
|
@param[in] p_buf The original packet request. Reused for the reply. */
|
2433 |
|
|
/*---------------------------------------------------------------------------*/
|
2434 |
|
|
static void
|
2435 |
|
|
rsp_read_reg (struct rsp_buf *p_buf)
|
2436 |
|
|
{
|
2437 |
|
|
unsigned int regnum;
|
2438 |
|
|
uint32_t temp_uint32;
|
2439 |
|
|
|
2440 |
|
|
/* Break out the fields from the data */
|
2441 |
|
|
if (1 != sscanf (p_buf->data, "p%x", ®num))
|
2442 |
|
|
{
|
2443 |
|
|
fprintf (stderr, "Warning: Failed to recognize RSP read register "
|
2444 |
|
|
"command: %s\n", p_buf->data);
|
2445 |
|
|
put_str_packet ("E01");
|
2446 |
|
|
return;
|
2447 |
|
|
}
|
2448 |
|
|
|
2449 |
|
|
// Make sure the processor is stalled
|
2450 |
|
|
gdb_ensure_or1k_stalled();
|
2451 |
|
|
|
2452 |
|
|
// First set the chain
|
2453 |
|
|
err = gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2454 |
|
|
if(err > 0){
|
2455 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_set_chain\n", err);
|
2456 |
|
|
put_str_packet ("E01");
|
2457 |
|
|
return;
|
2458 |
|
|
}
|
2459 |
46 |
julius |
|
2460 |
39 |
julius |
/* Get the relevant register */
|
2461 |
|
|
if (regnum < MAX_GPRS)
|
2462 |
|
|
{
|
2463 |
46 |
julius |
err = gdb_read_reg(0x400 + regnum, &temp_uint32);
|
2464 |
|
|
if(err > 0){
|
2465 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_read_reg at reg. %d \n", err, regnum);
|
2466 |
|
|
put_str_packet ("E01");
|
2467 |
|
|
return;
|
2468 |
|
|
}
|
2469 |
|
|
reg2hex (temp_uint32, p_buf->data);
|
2470 |
39 |
julius |
}
|
2471 |
|
|
else if (PPC_REGNUM == regnum) /* ---------- PPC ---------- */
|
2472 |
|
|
{
|
2473 |
46 |
julius |
err = gdb_read_reg(PPC_CPU_REG_ADD, &temp_uint32);
|
2474 |
|
|
if(err > 0){
|
2475 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_read_reg read --> PPC\n", err);
|
2476 |
|
|
put_str_packet ("E01");
|
2477 |
|
|
return;
|
2478 |
|
|
}
|
2479 |
|
|
reg2hex (temp_uint32, p_buf->data);
|
2480 |
39 |
julius |
}
|
2481 |
|
|
else if (NPC_REGNUM == regnum) /* ---------- NPC ---------- */
|
2482 |
|
|
{
|
2483 |
|
|
temp_uint32 = get_npc();
|
2484 |
|
|
/*
|
2485 |
46 |
julius |
err = gdb_read_reg(NPC_CPU_REG_ADD, &temp_uint32);
|
2486 |
|
|
if(err > 0){
|
2487 |
39 |
julius |
if (DEBUG_GDB) printf("Error %d in rsp_read_reg read --> PPC\n", err);
|
2488 |
|
|
put_str_packet ("E01");
|
2489 |
|
|
return;
|
2490 |
46 |
julius |
}
|
2491 |
39 |
julius |
*/
|
2492 |
|
|
reg2hex (temp_uint32, p_buf->data);
|
2493 |
|
|
}
|
2494 |
|
|
else if (SR_REGNUM == regnum) /* ---------- SR ---------- */
|
2495 |
|
|
{
|
2496 |
|
|
err = gdb_read_reg(SR_CPU_REG_ADD, &temp_uint32);
|
2497 |
|
|
if(err > 0){
|
2498 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_read_reg read --> PPC\n", err);
|
2499 |
|
|
put_str_packet ("E01");
|
2500 |
|
|
return;
|
2501 |
|
|
}
|
2502 |
|
|
reg2hex (temp_uint32, p_buf->data);
|
2503 |
|
|
}
|
2504 |
|
|
else
|
2505 |
|
|
{
|
2506 |
|
|
/* Error response if we don't know the register */
|
2507 |
|
|
fprintf (stderr, "Warning: Attempt to read unknown register 0x%x: "
|
2508 |
|
|
"ignored\n", regnum);
|
2509 |
|
|
put_str_packet ("E01");
|
2510 |
|
|
return;
|
2511 |
|
|
}
|
2512 |
|
|
|
2513 |
|
|
p_buf->len = strlen (p_buf->data);
|
2514 |
|
|
put_packet (p_buf);
|
2515 |
|
|
|
2516 |
|
|
} /* rsp_read_reg () */
|
2517 |
|
|
|
2518 |
|
|
|
2519 |
|
|
/*---------------------------------------------------------------------------*/
|
2520 |
|
|
/*!Write a single register
|
2521 |
|
|
|
2522 |
|
|
The registers follow the GDB sequence for OR1K: GPR0 through GPR31, PC
|
2523 |
|
|
(i.e. SPR NPC) and SR (i.e. SPR SR). The register is specified as a
|
2524 |
|
|
sequence of bytes in target endian order.
|
2525 |
|
|
|
2526 |
|
|
Each byte is packed as a pair of hex digits.
|
2527 |
|
|
|
2528 |
|
|
@param[in] p_buf The original packet request. */
|
2529 |
|
|
/*---------------------------------------------------------------------------*/
|
2530 |
|
|
static void
|
2531 |
|
|
rsp_write_reg (struct rsp_buf *p_buf)
|
2532 |
|
|
{
|
2533 |
|
|
unsigned int regnum;
|
2534 |
|
|
char valstr[9]; /* Allow for EOS on the string */
|
2535 |
|
|
// int err = 0;
|
2536 |
|
|
|
2537 |
|
|
/* Break out the fields from the data */
|
2538 |
|
|
if (2 != sscanf (p_buf->data, "P%x=%8s", ®num, valstr))
|
2539 |
|
|
{
|
2540 |
|
|
fprintf (stderr, "Warning: Failed to recognize RSP write register "
|
2541 |
|
|
"command: %s\n", p_buf->data);
|
2542 |
|
|
put_str_packet ("E01");
|
2543 |
|
|
return;
|
2544 |
|
|
}
|
2545 |
|
|
|
2546 |
|
|
// Make sure the processor is stalled
|
2547 |
|
|
gdb_ensure_or1k_stalled();
|
2548 |
|
|
|
2549 |
|
|
// First set the chain
|
2550 |
|
|
err = gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2551 |
|
|
if(err > 0){
|
2552 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_set_chain\n", err);
|
2553 |
|
|
put_str_packet ("E01");
|
2554 |
|
|
return;
|
2555 |
|
|
}
|
2556 |
|
|
|
2557 |
|
|
/* Set the relevant register */
|
2558 |
|
|
if (regnum < MAX_GPRS) /* ---------- GPRS ---------- */
|
2559 |
46 |
julius |
{
|
2560 |
39 |
julius |
err = gdb_write_reg(0x400 + regnum, hex2reg (valstr));
|
2561 |
46 |
julius |
if(err > 0){
|
2562 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> GPRS\n", err);
|
2563 |
|
|
put_str_packet ("E01");
|
2564 |
|
|
return;
|
2565 |
|
|
}
|
2566 |
39 |
julius |
}
|
2567 |
|
|
else if (PPC_REGNUM == regnum) /* ---------- PPC ---------- */
|
2568 |
|
|
{
|
2569 |
|
|
err = gdb_write_reg(PPC_CPU_REG_ADD, hex2reg (valstr));
|
2570 |
46 |
julius |
if(err > 0){
|
2571 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> PPC\n", err);
|
2572 |
|
|
put_str_packet ("E01");
|
2573 |
|
|
return;
|
2574 |
|
|
}
|
2575 |
39 |
julius |
}
|
2576 |
|
|
else if (NPC_REGNUM == regnum) /* ---------- NPC ---------- */
|
2577 |
|
|
{
|
2578 |
|
|
set_npc(hex2reg (valstr));
|
2579 |
|
|
/*
|
2580 |
|
|
err = gdb_write_reg(NPC_CPU_REG_ADD, hex2reg (valstr));
|
2581 |
|
|
if(err > 0){
|
2582 |
46 |
julius |
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> NPC\n", err);
|
2583 |
|
|
put_str_packet ("E01");
|
2584 |
|
|
return;
|
2585 |
39 |
julius |
}
|
2586 |
|
|
*/
|
2587 |
|
|
}
|
2588 |
|
|
else if (SR_REGNUM == regnum) /* ---------- SR ---------- */
|
2589 |
|
|
{
|
2590 |
|
|
err = gdb_write_reg(SR_CPU_REG_ADD, hex2reg (valstr));
|
2591 |
46 |
julius |
if(err > 0){
|
2592 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_write_reg write --> SR\n", err);
|
2593 |
|
|
put_str_packet ("E01");
|
2594 |
|
|
return;
|
2595 |
39 |
julius |
}
|
2596 |
|
|
}
|
2597 |
|
|
else
|
2598 |
|
|
{
|
2599 |
|
|
/* Error response if we don't know the register */
|
2600 |
|
|
fprintf (stderr, "Warning: Attempt to write unknown register 0x%x: "
|
2601 |
|
|
"ignored\n", regnum);
|
2602 |
|
|
put_str_packet ("E01");
|
2603 |
|
|
return;
|
2604 |
|
|
}
|
2605 |
46 |
julius |
|
2606 |
39 |
julius |
put_str_packet ("OK");
|
2607 |
46 |
julius |
|
2608 |
39 |
julius |
} /* rsp_write_reg () */
|
2609 |
|
|
|
2610 |
|
|
|
2611 |
|
|
/*---------------------------------------------------------------------------*/
|
2612 |
|
|
/*!Handle a RSP query request
|
2613 |
|
|
|
2614 |
|
|
@param[in] p_buf The request */
|
2615 |
|
|
/*---------------------------------------------------------------------------*/
|
2616 |
|
|
static void
|
2617 |
|
|
rsp_query (struct rsp_buf *p_buf)
|
2618 |
|
|
{
|
2619 |
|
|
if (0 == strcmp ("qC", p_buf->data))
|
2620 |
|
|
{
|
2621 |
|
|
/* Return the current thread ID (unsigned hex). A null response
|
2622 |
|
|
indicates to use the previously selected thread. Since we do not
|
2623 |
|
|
support a thread concept, this is the appropriate response. */
|
2624 |
|
|
put_str_packet ("");
|
2625 |
|
|
}
|
2626 |
|
|
else if (0 == strncmp ("qCRC", p_buf->data, strlen ("qCRC")))
|
2627 |
|
|
{
|
2628 |
|
|
/* Return CRC of memory area */
|
2629 |
|
|
fprintf (stderr, "Warning: RSP CRC query not supported\n");
|
2630 |
|
|
put_str_packet ("E01");
|
2631 |
|
|
}
|
2632 |
|
|
else if (0 == strcmp ("qfThreadInfo", p_buf->data))
|
2633 |
|
|
{
|
2634 |
|
|
/* Return info about active threads. We return just '-1' */
|
2635 |
|
|
put_str_packet ("m-1");
|
2636 |
|
|
}
|
2637 |
|
|
else if (0 == strcmp ("qsThreadInfo", p_buf->data))
|
2638 |
|
|
{
|
2639 |
|
|
/* Return info about more active threads. We have no more, so return the
|
2640 |
|
|
end of list marker, 'l' */
|
2641 |
|
|
put_str_packet ("l");
|
2642 |
|
|
}
|
2643 |
|
|
else if (0 == strncmp ("qGetTLSAddr:", p_buf->data, strlen ("qGetTLSAddr:")))
|
2644 |
|
|
{
|
2645 |
|
|
/* We don't support this feature */
|
2646 |
|
|
put_str_packet ("");
|
2647 |
|
|
}
|
2648 |
|
|
else if (0 == strncmp ("qL", p_buf->data, strlen ("qL")))
|
2649 |
|
|
{
|
2650 |
|
|
/* Deprecated and replaced by 'qfThreadInfo' */
|
2651 |
|
|
fprintf (stderr, "Warning: RSP qL deprecated: no info returned\n");
|
2652 |
|
|
put_str_packet ("qM001");
|
2653 |
|
|
}
|
2654 |
|
|
else if (0 == strcmp ("qOffsets", p_buf->data))
|
2655 |
|
|
{
|
2656 |
|
|
/* Report any relocation */
|
2657 |
|
|
put_str_packet ("Text=0;Data=0;Bss=0");
|
2658 |
|
|
}
|
2659 |
|
|
else if (0 == strncmp ("qP", p_buf->data, strlen ("qP")))
|
2660 |
|
|
{
|
2661 |
|
|
/* Deprecated and replaced by 'qThreadExtraInfo' */
|
2662 |
|
|
fprintf (stderr, "Warning: RSP qP deprecated: no info returned\n");
|
2663 |
|
|
put_str_packet ("");
|
2664 |
|
|
}
|
2665 |
|
|
else if (0 == strncmp ("qRcmd,", p_buf->data, strlen ("qRcmd,")))
|
2666 |
|
|
{
|
2667 |
|
|
/* This is used to interface to commands to do "stuff" */
|
2668 |
|
|
rsp_command (p_buf);
|
2669 |
|
|
}
|
2670 |
|
|
else if (0 == strncmp ("qSupported", p_buf->data, strlen ("qSupported")))
|
2671 |
|
|
{
|
2672 |
|
|
/* Report a list of the features we support. For now we just ignore any
|
2673 |
|
|
supplied specific feature queries, but in the future these may be
|
2674 |
|
|
supported as well. Note that the packet size allows for 'G' + all the
|
2675 |
|
|
registers sent to us, or a reply to 'g' with all the registers and an
|
2676 |
|
|
EOS so the buffer is a well formed string. */
|
2677 |
|
|
setup_or32(); // setup cpu
|
2678 |
|
|
char reply[GDB_BUF_MAX];
|
2679 |
|
|
sprintf (reply, "PacketSize=%x", GDB_BUF_MAX);
|
2680 |
|
|
put_str_packet (reply);
|
2681 |
|
|
}
|
2682 |
|
|
else if (0 == strncmp ("qSymbol:", p_buf->data, strlen ("qSymbol:")))
|
2683 |
|
|
{
|
2684 |
|
|
/* Offer to look up symbols. Nothing we want (for now). TODO. This just
|
2685 |
|
|
ignores any replies to symbols we looked up, but we didn't want to
|
2686 |
|
|
do that anyway! */
|
2687 |
|
|
put_str_packet ("OK");
|
2688 |
|
|
}
|
2689 |
|
|
else if (0 == strncmp ("qThreadExtraInfo,", p_buf->data,
|
2690 |
|
|
strlen ("qThreadExtraInfo,")))
|
2691 |
|
|
{
|
2692 |
|
|
/* Report that we are runnable, but the text must be hex ASCI
|
2693 |
|
|
digits. For now do this by steam, reusing the original packet */
|
2694 |
|
|
sprintf (p_buf->data, "%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
2695 |
|
|
'R', 'u', 'n', 'n', 'a', 'b', 'l', 'e', 0);
|
2696 |
|
|
p_buf->len = strlen (p_buf->data);
|
2697 |
|
|
put_packet (p_buf);
|
2698 |
|
|
}
|
2699 |
|
|
else if (0 == strncmp ("qXfer:", p_buf->data, strlen ("qXfer:")))
|
2700 |
|
|
{
|
2701 |
|
|
/* For now we support no 'qXfer' requests, but these should not be
|
2702 |
|
|
expected, since they were not reported by 'qSupported' */
|
2703 |
|
|
fprintf (stderr, "Warning: RSP 'qXfer' not supported: ignored\n");
|
2704 |
|
|
put_str_packet ("");
|
2705 |
|
|
}
|
2706 |
|
|
else
|
2707 |
|
|
{
|
2708 |
|
|
fprintf (stderr, "Unrecognized RSP query: ignored\n");
|
2709 |
|
|
}
|
2710 |
|
|
} /* rsp_query () */
|
2711 |
|
|
|
2712 |
|
|
|
2713 |
|
|
/*---------------------------------------------------------------------------*/
|
2714 |
|
|
/*!Handle a RSP qRcmd request
|
2715 |
|
|
|
2716 |
|
|
The actual command follows the "qRcmd," in ASCII encoded to hex
|
2717 |
|
|
|
2718 |
|
|
@param[in] p_buf The request in full */
|
2719 |
|
|
/*---------------------------------------------------------------------------*/
|
2720 |
|
|
static void
|
2721 |
|
|
rsp_command (struct rsp_buf *p_buf)
|
2722 |
|
|
{
|
2723 |
|
|
char cmd[GDB_BUF_MAX];
|
2724 |
|
|
unsigned int regno;
|
2725 |
|
|
uint32_t temp_uint32;
|
2726 |
|
|
|
2727 |
|
|
hex2ascii (cmd, &(p_buf->data[strlen ("qRcmd,")]));
|
2728 |
|
|
|
2729 |
|
|
/* Work out which command it is */
|
2730 |
|
|
if (0 == strncmp ("readspr ", cmd, strlen ("readspr")))
|
2731 |
|
|
{
|
2732 |
|
|
/* Parse and return error if we fail */
|
2733 |
|
|
if( 1 != sscanf (cmd, "readspr %4x", ®no))
|
2734 |
|
|
{
|
2735 |
|
|
fprintf (stderr, "Warning: qRcmd %s not recognized: ignored\n", cmd);
|
2736 |
|
|
put_str_packet ("E01");
|
2737 |
|
|
return;
|
2738 |
|
|
}
|
2739 |
|
|
|
2740 |
|
|
/* SPR out of range */
|
2741 |
|
|
if (regno > MAX_SPRS)
|
2742 |
|
|
{
|
2743 |
|
|
fprintf (stderr, "Warning: qRcmd readspr %x too large: ignored\n",
|
2744 |
|
|
regno);
|
2745 |
|
|
put_str_packet ("E01");
|
2746 |
|
|
return;
|
2747 |
|
|
}
|
2748 |
|
|
|
2749 |
|
|
/* Construct the reply */
|
2750 |
|
|
|
2751 |
|
|
// Make sure the processor is stalled
|
2752 |
|
|
gdb_ensure_or1k_stalled();
|
2753 |
|
|
|
2754 |
|
|
// First set the chain
|
2755 |
|
|
gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2756 |
|
|
|
2757 |
|
|
// special case for NPC
|
2758 |
|
|
if(regno == NPC_CPU_REG_ADD)
|
2759 |
|
|
temp_uint32 = get_npc();
|
2760 |
|
|
else
|
2761 |
|
|
{
|
2762 |
|
|
err = gdb_read_reg(regno, &temp_uint32);
|
2763 |
|
|
if(err > 0){
|
2764 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_command at reg. %x \n", err, regno);
|
2765 |
|
|
}
|
2766 |
|
|
else{
|
2767 |
|
|
reg2hex (temp_uint32, cmd);
|
2768 |
|
|
if (DEBUG_GDB) printf("Error %d Command readspr Read reg. %x = 0x%08x\n", err, regno, temp_uint32);
|
2769 |
|
|
}
|
2770 |
|
|
}
|
2771 |
|
|
|
2772 |
|
|
// pack the result into the buffer to send back
|
2773 |
|
|
sprintf (cmd, "%8x", (unsigned int)temp_uint32);
|
2774 |
|
|
ascii2hex (p_buf->data, cmd);
|
2775 |
|
|
p_buf->len = strlen (p_buf->data);
|
2776 |
|
|
put_packet (p_buf);
|
2777 |
|
|
}
|
2778 |
|
|
else if (0 == strncmp ("writespr ", cmd, strlen ("writespr")))
|
2779 |
|
|
{
|
2780 |
|
|
unsigned int regno;
|
2781 |
|
|
uint32_t val;
|
2782 |
|
|
|
2783 |
|
|
/* Parse and return error if we fail */
|
2784 |
|
|
if( 2 != sscanf (cmd, "writespr %4x %8x", ®no, &val))
|
2785 |
|
|
{
|
2786 |
|
|
fprintf (stderr, "Warning: qRcmd %s not recognized: ignored\n",
|
2787 |
|
|
cmd);
|
2788 |
|
|
put_str_packet ("E01");
|
2789 |
|
|
return;
|
2790 |
|
|
}
|
2791 |
|
|
|
2792 |
|
|
/* SPR out of range */
|
2793 |
|
|
if (regno > MAX_SPRS)
|
2794 |
|
|
{
|
2795 |
|
|
fprintf (stderr, "Warning: qRcmd writespr %x too large: ignored\n",
|
2796 |
|
|
regno);
|
2797 |
|
|
put_str_packet ("E01");
|
2798 |
|
|
return;
|
2799 |
|
|
}
|
2800 |
|
|
|
2801 |
|
|
// Make sure the processor is stalled
|
2802 |
|
|
gdb_ensure_or1k_stalled();
|
2803 |
|
|
|
2804 |
|
|
// First set the chain
|
2805 |
|
|
gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2806 |
|
|
|
2807 |
|
|
/* set the relevant register */
|
2808 |
|
|
// special case for NPC
|
2809 |
|
|
if(regno == NPC_CPU_REG_ADD)
|
2810 |
|
|
set_npc(val);
|
2811 |
|
|
else
|
2812 |
|
|
{
|
2813 |
|
|
|
2814 |
|
|
err = gdb_write_reg(regno, val);
|
2815 |
|
|
if(err > 0){
|
2816 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_command write Reg. %x = 0x%08x\n", err, regno, val);
|
2817 |
|
|
put_str_packet ("E01");
|
2818 |
|
|
return;
|
2819 |
|
|
}
|
2820 |
|
|
else{
|
2821 |
|
|
if (DEBUG_GDB) printf("Error %d Command writespr Write reg. %x = 0x%08x\n", err, regno, val);
|
2822 |
|
|
}
|
2823 |
|
|
}
|
2824 |
|
|
put_str_packet ("OK");
|
2825 |
|
|
}
|
2826 |
|
|
} /* rsp_command () */
|
2827 |
|
|
|
2828 |
|
|
|
2829 |
|
|
/*---------------------------------------------------------------------------*/
|
2830 |
|
|
/*!Handle a RSP set request
|
2831 |
|
|
|
2832 |
|
|
@param[in] p_buf The request */
|
2833 |
|
|
/*---------------------------------------------------------------------------*/
|
2834 |
|
|
static void
|
2835 |
|
|
rsp_set (struct rsp_buf *p_buf)
|
2836 |
|
|
{
|
2837 |
|
|
if (0 == strncmp ("QPassSignals:", p_buf->data, strlen ("QPassSignals:")))
|
2838 |
|
|
{
|
2839 |
|
|
/* Passing signals not supported */
|
2840 |
|
|
put_str_packet ("");
|
2841 |
|
|
}
|
2842 |
|
|
else if ((0 == strncmp ("QTDP", p_buf->data, strlen ("QTDP"))) ||
|
2843 |
|
|
(0 == strncmp ("QFrame", p_buf->data, strlen ("QFrame"))) ||
|
2844 |
|
|
(0 == strcmp ("QTStart", p_buf->data)) ||
|
2845 |
|
|
(0 == strcmp ("QTStop", p_buf->data)) ||
|
2846 |
|
|
(0 == strcmp ("QTinit", p_buf->data)) ||
|
2847 |
|
|
(0 == strncmp ("QTro", p_buf->data, strlen ("QTro"))))
|
2848 |
|
|
{
|
2849 |
|
|
/* All tracepoint features are not supported. This reply is really only
|
2850 |
|
|
needed to 'QTDP', since with that the others should not be
|
2851 |
|
|
generated. */
|
2852 |
|
|
put_str_packet ("");
|
2853 |
|
|
}
|
2854 |
|
|
else
|
2855 |
|
|
{
|
2856 |
|
|
fprintf (stderr, "Unrecognized RSP set request: ignored\n");
|
2857 |
|
|
}
|
2858 |
|
|
} /* rsp_set () */
|
2859 |
|
|
|
2860 |
|
|
|
2861 |
|
|
/*---------------------------------------------------------------------------*/
|
2862 |
|
|
/*!Handle a RSP restart request
|
2863 |
|
|
|
2864 |
|
|
For now we just put the program counter back to the one used with the last
|
2865 |
|
|
vRun request. There is no point in unstalling the processor, since we'll
|
2866 |
|
|
never get control back. */
|
2867 |
|
|
/*---------------------------------------------------------------------------*/
|
2868 |
|
|
static void
|
2869 |
|
|
rsp_restart (void)
|
2870 |
|
|
{
|
2871 |
|
|
// Make sure the processor is stalled
|
2872 |
|
|
gdb_ensure_or1k_stalled();
|
2873 |
|
|
|
2874 |
|
|
// First set the chain
|
2875 |
|
|
err = gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2876 |
|
|
if(err > 0){
|
2877 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_set_chain\n", err);
|
2878 |
|
|
put_str_packet ("E01");
|
2879 |
|
|
return;
|
2880 |
|
|
}
|
2881 |
|
|
// OR32 Arc sim equivalent --> set_npc (rsp.start_addr);
|
2882 |
|
|
/* Set NPC to reset vector 0x100 */
|
2883 |
|
|
set_npc(rsp.start_addr);
|
2884 |
|
|
/*
|
2885 |
|
|
err = gdb_write_reg(NPC_CPU_REG_ADD, rsp.start_addr);
|
2886 |
|
|
if(err > 0){
|
2887 |
|
|
if (DEBUG_GDB) printf("Error %d in rsp_restart write Reg. %x = 0x%08x\n", err, NPC_CPU_REG_ADD, rsp.start_addr);
|
2888 |
|
|
put_str_packet ("E01");
|
2889 |
|
|
return;
|
2890 |
|
|
}
|
2891 |
|
|
|
2892 |
|
|
else{
|
2893 |
|
|
if (DEBUG_GDB) printf("Error %d Command Reset. Set NPC to Start vector %x = 0x%08x\n", err, NPC_CPU_REG_ADD, rsp.start_addr);
|
2894 |
|
|
}
|
2895 |
|
|
*/
|
2896 |
|
|
} /* rsp_restart () */
|
2897 |
|
|
|
2898 |
|
|
|
2899 |
|
|
/*---------------------------------------------------------------------------*/
|
2900 |
|
|
/*!Handle a RSP step request
|
2901 |
|
|
|
2902 |
|
|
Parse the command to see if there is an address. Uses the underlying
|
2903 |
|
|
generic step function, with EXCEPT_NONE.
|
2904 |
|
|
|
2905 |
|
|
@param[in] p_buf The full step packet */
|
2906 |
|
|
/*---------------------------------------------------------------------------*/
|
2907 |
|
|
static void
|
2908 |
|
|
rsp_step (struct rsp_buf *p_buf)
|
2909 |
|
|
{
|
2910 |
|
|
uint32_t addr; /* The address to step from, if any */
|
2911 |
|
|
|
2912 |
|
|
// Make sure the processor is stalled
|
2913 |
|
|
gdb_ensure_or1k_stalled();
|
2914 |
|
|
|
2915 |
|
|
// First set the chain
|
2916 |
|
|
err = gdb_set_chain(SC_RISC_DEBUG); /* 1 RISC Debug Interface chain */
|
2917 |
|
|
if(err > 0){
|
2918 |
|
|
printf("Error %d to set RISC Debug Interface chain in the STEP command 's'\n", err);
|
2919 |
|
|
rsp_client_close ();
|
2920 |
|
|
return;
|
2921 |
|
|
}
|
2922 |
|
|
|
2923 |
|
|
if (0 == strcmp ("s", p_buf->data))
|
2924 |
|
|
{
|
2925 |
|
|
// Arc Sim Code --> addr = cpu_state.pc; /* Default uses current NPC */
|
2926 |
|
|
/* ---------- Npc ---------- */
|
2927 |
|
|
addr = get_npc();
|
2928 |
|
|
/*
|
2929 |
|
|
err = gdb_read_reg(NPC_CPU_REG_ADD, &addr);
|
2930 |
|
|
if(err > 0){
|
2931 |
|
|
printf("Error %d to read NPC in the STEP command 's'\n", err);
|
2932 |
|
|
rsp_client_close ();
|
2933 |
|
|
return;
|
2934 |
|
|
}
|
2935 |
|
|
*/
|
2936 |
|
|
}
|
2937 |
|
|
else if (1 != sscanf (p_buf->data, "s%x", &addr))
|
2938 |
|
|
{
|
2939 |
|
|
fprintf (stderr,
|
2940 |
|
|
"Warning: RSP step address %s not recognized: ignored\n",
|
2941 |
|
|
p_buf->data);
|
2942 |
|
|
|
2943 |
|
|
// Arc Sim Code --> addr = cpu_state.pc; /* Default uses current NPC */
|
2944 |
|
|
/* ---------- NPC ---------- */
|
2945 |
|
|
addr = get_npc();
|
2946 |
|
|
/*
|
2947 |
|
|
err = gdb_read_reg(NPC_CPU_REG_ADD, &addr);
|
2948 |
|
|
if(err > 0){
|
2949 |
|
|
printf("Error %d to read NPC in the STEP command 's'\n", err);
|
2950 |
|
|
rsp_client_close ();
|
2951 |
|
|
return;
|
2952 |
|
|
}
|
2953 |
|
|
*/
|
2954 |
|
|
}
|
2955 |
|
|
|
2956 |
|
|
//if (DEBUG_GDB) printf("rsp_step() --> Read NPC = 0x%08x\n", addr);
|
2957 |
|
|
rsp_step_generic (addr, EXCEPT_NONE);
|
2958 |
|
|
|
2959 |
|
|
} /* rsp_step () */
|
2960 |
|
|
|
2961 |
|
|
|
2962 |
|
|
/*---------------------------------------------------------------------------*/
|
2963 |
|
|
/*!Handle a RSP step with signal request
|
2964 |
|
|
|
2965 |
|
|
Currently null. Will use the underlying generic step function.
|
2966 |
|
|
|
2967 |
|
|
@param[in] p_buf The full step with signal packet */
|
2968 |
|
|
/*---------------------------------------------------------------------------*/
|
2969 |
|
|
static void
|
2970 |
|
|
rsp_step_with_signal (struct rsp_buf *p_buf)
|
2971 |
|
|
{
|
2972 |
|
|
printf ("RSP step with signal '%s' received\n", p_buf->data);
|
2973 |
|
|
|
2974 |
|
|
} /* rsp_step_with_signal () */
|
2975 |
|
|
|
2976 |
|
|
|
2977 |
|
|
/*---------------------------------------------------------------------------*/
|
2978 |
|
|
/*!Generic processing of a step request
|
2979 |
|
|
|
2980 |
|
|
The signal may be EXCEPT_NONE if there is no exception to be
|
2981 |
|
|
handled. Currently the exception is ignored.
|
2982 |
|
|
|
2983 |
|
|
The single step flag is set in the debug registers and then the processor
|
2984 |
|
|
is unstalled.
|
2985 |
|
|
|
2986 |
|
|
@param[in] addr Address from which to step
|
2987 |
|
|
@param[in] except The exception to use (if any) */
|
2988 |
|
|
/*---------------------------------------------------------------------------*/
|
2989 |
|
|
static void
|
2990 |
|
|
rsp_step_generic (uint32_t addr,
|
2991 |
|
|
uint32_t except)
|
2992 |
|
|
{
|
2993 |
|
|
uint32_t temp_uint32;
|
2994 |
|
|
|
2995 |
|
|
/* Set the address as the value of the next program counter */
|
2996 |
|
|
|
2997 |
|
|
set_npc (addr);
|
2998 |
|
|
|
2999 |
|
|
/* Clear Debug Reason Register (DRR) 0x3015 */
|
3000 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DRR] = 0;
|
3001 |
|
|
if(gdb_write_reg(DRR_CPU_REG_ADD, 0)) printf("Error write to DRR register\n");
|
3002 |
|
|
|
3003 |
|
|
/* Clear watchpoint break generation in Debug Mode Register 2 (DMR2) 0x3011 */
|
3004 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DMR2] &= ~SPR_DMR2_WGB;
|
3005 |
|
|
if(gdb_read_reg(DMR2_CPU_REG_ADD, &temp_uint32)) printf("Error read from DMR2 register\n");
|
3006 |
|
|
temp_uint32 &= ~SPR_DMR2_WGB;
|
3007 |
|
|
if(gdb_write_reg(DMR2_CPU_REG_ADD, temp_uint32)) printf("Error write to DMR2 register\n");
|
3008 |
|
|
|
3009 |
|
|
/* Set the single step trigger in Debug Mode Register 1 (DMR1) Register 0x3010 */
|
3010 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DMR1] |= SPR_DMR1_ST;
|
3011 |
|
|
if(gdb_read_reg(DMR1_CPU_REG_ADD, &temp_uint32)) printf("Error read from DMR1 register\n");
|
3012 |
|
|
temp_uint32 |= SPR_DMR1_ST;
|
3013 |
|
|
if(gdb_write_reg(DMR1_CPU_REG_ADD, temp_uint32)) printf("Error write to DMR1 register\n");
|
3014 |
|
|
|
3015 |
|
|
/* Set traps to be handled by the debug unit in the Debug Stop Register (DSR) Register 0x3014 */
|
3016 |
|
|
// Arc sim --> cpu_state.sprs[SPR_DSR] |= SPR_DSR_TE;
|
3017 |
|
|
if(gdb_read_reg(DSR_CPU_REG_ADD, &temp_uint32)) printf("Error read from DSR register\n");
|
3018 |
|
|
temp_uint32 |= SPR_DSR_TE;
|
3019 |
|
|
if(gdb_write_reg(DSR_CPU_REG_ADD, temp_uint32)) printf("Error write to DSR register\n");
|
3020 |
|
|
|
3021 |
|
|
/* Unstall the processor */
|
3022 |
|
|
set_stall_state (0);
|
3023 |
|
|
|
3024 |
|
|
/* Note the GDB client is now waiting for a reply. */
|
3025 |
|
|
rsp.client_waiting = 1;
|
3026 |
|
|
|
3027 |
|
|
} /* rsp_step_generic () */
|
3028 |
|
|
|
3029 |
|
|
|
3030 |
|
|
/*---------------------------------------------------------------------------*/
|
3031 |
|
|
/*!Handle a RSP 'v' packet
|
3032 |
|
|
|
3033 |
|
|
These are commands associated with executing the code on the target
|
3034 |
|
|
|
3035 |
|
|
@param[in] p_buf The request */
|
3036 |
|
|
/*---------------------------------------------------------------------------*/
|
3037 |
|
|
static void
|
3038 |
|
|
rsp_vpkt (struct rsp_buf *p_buf)
|
3039 |
|
|
{
|
3040 |
|
|
if (0 == strncmp ("vAttach;", p_buf->data, strlen ("vAttach;")))
|
3041 |
|
|
{
|
3042 |
|
|
/* Attaching is a null action, since we have no other process. We just
|
3043 |
|
|
return a stop packet (using TRAP) to indicate we are stopped. */
|
3044 |
|
|
put_str_packet ("S05");
|
3045 |
|
|
return;
|
3046 |
|
|
}
|
3047 |
|
|
else if (0 == strcmp ("vCont?", p_buf->data))
|
3048 |
|
|
{
|
3049 |
|
|
/* For now we don't support this. */
|
3050 |
|
|
put_str_packet ("");
|
3051 |
|
|
return;
|
3052 |
|
|
}
|
3053 |
|
|
else if (0 == strncmp ("vCont", p_buf->data, strlen ("vCont")))
|
3054 |
|
|
{
|
3055 |
|
|
/* This shouldn't happen, because we've reported non-support via vCont?
|
3056 |
|
|
above */
|
3057 |
|
|
fprintf (stderr, "Warning: RSP vCont not supported: ignored\n" );
|
3058 |
|
|
return;
|
3059 |
|
|
}
|
3060 |
|
|
else if (0 == strncmp ("vFile:", p_buf->data, strlen ("vFile:")))
|
3061 |
|
|
{
|
3062 |
|
|
/* For now we don't support this. */
|
3063 |
|
|
fprintf (stderr, "Warning: RSP vFile not supported: ignored\n" );
|
3064 |
|
|
put_str_packet ("");
|
3065 |
|
|
return;
|
3066 |
|
|
}
|
3067 |
|
|
else if (0 == strncmp ("vFlashErase:", p_buf->data, strlen ("vFlashErase:")))
|
3068 |
|
|
{
|
3069 |
|
|
/* For now we don't support this. */
|
3070 |
|
|
fprintf (stderr, "Warning: RSP vFlashErase not supported: ignored\n" );
|
3071 |
|
|
put_str_packet ("E01");
|
3072 |
|
|
return;
|
3073 |
|
|
}
|
3074 |
|
|
else if (0 == strncmp ("vFlashWrite:", p_buf->data, strlen ("vFlashWrite:")))
|
3075 |
|
|
{
|
3076 |
|
|
/* For now we don't support this. */
|
3077 |
|
|
fprintf (stderr, "Warning: RSP vFlashWrite not supported: ignored\n" );
|
3078 |
|
|
put_str_packet ("E01");
|
3079 |
|
|
return;
|
3080 |
|
|
}
|
3081 |
|
|
else if (0 == strcmp ("vFlashDone", p_buf->data))
|
3082 |
|
|
{
|
3083 |
|
|
/* For now we don't support this. */
|
3084 |
|
|
fprintf (stderr, "Warning: RSP vFlashDone not supported: ignored\n" );
|
3085 |
|
|
put_str_packet ("E01");
|
3086 |
|
|
return;
|
3087 |
|
|
}
|
3088 |
|
|
else if (0 == strncmp ("vRun;", p_buf->data, strlen ("vRun;")))
|
3089 |
|
|
{
|
3090 |
|
|
/* We shouldn't be given any args, but check for this */
|
3091 |
|
|
if (p_buf->len > (int) strlen ("vRun;"))
|
3092 |
|
|
{
|
3093 |
|
|
fprintf (stderr, "Warning: Unexpected arguments to RSP vRun "
|
3094 |
|
|
"command: ignored\n");
|
3095 |
|
|
}
|
3096 |
|
|
|
3097 |
|
|
/* Restart the current program. However unlike a "R" packet, "vRun"
|
3098 |
|
|
should behave as though it has just stopped. We use signal
|
3099 |
|
|
5 (TRAP). */
|
3100 |
|
|
rsp_restart ();
|
3101 |
|
|
put_str_packet ("S05");
|
3102 |
|
|
}
|
3103 |
|
|
else
|
3104 |
|
|
{
|
3105 |
|
|
fprintf (stderr, "Warning: Unknown RSP 'v' packet type %s: ignored\n",
|
3106 |
|
|
p_buf->data);
|
3107 |
|
|
put_str_packet ("E01");
|
3108 |
|
|
return;
|
3109 |
|
|
}
|
3110 |
|
|
} /* rsp_vpkt () */
|
3111 |
|
|
|
3112 |
|
|
|
3113 |
|
|
/*---------------------------------------------------------------------------*/
|
3114 |
|
|
/*!Handle a RSP write memory (binary) request
|
3115 |
|
|
|
3116 |
|
|
Syntax is:
|
3117 |
|
|
|
3118 |
|
|
X<addr>,<length>:
|
3119 |
|
|
|
3120 |
|
|
Followed by the specified number of bytes as raw binary. Response should be
|
3121 |
|
|
"OK" if all copied OK, E<nn> if error <nn> has occurred.
|
3122 |
|
|
|
3123 |
|
|
The length given is the number of bytes to be written. However the number
|
3124 |
|
|
of data bytes may be greater, since '#', '$' and '}' are escaped by
|
3125 |
|
|
preceding them by '}' and oring with 0x20.
|
3126 |
|
|
|
3127 |
|
|
@param[in] p_buf The command received */
|
3128 |
|
|
/*---------------------------------------------------------------------------*/
|
3129 |
|
|
static void
|
3130 |
|
|
rsp_write_mem_bin (struct rsp_buf *p_buf)
|
3131 |
|
|
{
|
3132 |
|
|
unsigned int addr; /* Where to write the memory */
|
3133 |
|
|
int len; /* Number of bytes to write */
|
3134 |
46 |
julius |
char *bindat, *bindat_ptr; /* Pointer to the binary data */
|
3135 |
39 |
julius |
int off = 0; /* Offset to start of binary data */
|
3136 |
|
|
int newlen; /* Number of bytes in bin data */
|
3137 |
46 |
julius |
int i;
|
3138 |
|
|
int bytes_per_word = 4; /* Current OR implementation is 4-byte words */
|
3139 |
39 |
julius |
|
3140 |
|
|
if (2 != sscanf (p_buf->data, "X%x,%x:", &addr, &len))
|
3141 |
|
|
{
|
3142 |
|
|
fprintf (stderr, "Warning: Failed to recognize RSP write memory "
|
3143 |
|
|
"command: %s\n", p_buf->data);
|
3144 |
|
|
put_str_packet ("E01");
|
3145 |
|
|
return;
|
3146 |
|
|
}
|
3147 |
|
|
|
3148 |
|
|
/* Find the start of the data and "unescape" it */
|
3149 |
|
|
bindat = p_buf->data;
|
3150 |
|
|
while(off < GDB_BUF_MAX){
|
3151 |
|
|
if(bindat[off] == ':'){
|
3152 |
|
|
bindat = bindat + off + 1;
|
3153 |
|
|
off++;
|
3154 |
|
|
break;
|
3155 |
|
|
}
|
3156 |
|
|
off++;
|
3157 |
|
|
}
|
3158 |
|
|
if(off >= GDB_BUF_MAX){
|
3159 |
|
|
put_str_packet ("E01");
|
3160 |
|
|
return;
|
3161 |
|
|
}
|
3162 |
|
|
|
3163 |
|
|
newlen = rsp_unescape (bindat, p_buf->len - off);
|
3164 |
|
|
|
3165 |
|
|
/* Sanity check */
|
3166 |
|
|
if (newlen != len)
|
3167 |
|
|
{
|
3168 |
|
|
int minlen = len < newlen ? len : newlen;
|
3169 |
|
|
|
3170 |
|
|
fprintf (stderr, "Warning: Write of %d bytes requested, but %d bytes "
|
3171 |
|
|
"supplied. %d will be written\n", len, newlen, minlen);
|
3172 |
|
|
len = minlen;
|
3173 |
|
|
}
|
3174 |
|
|
|
3175 |
|
|
// Make sure the processor is stalled
|
3176 |
|
|
gdb_ensure_or1k_stalled();
|
3177 |
|
|
|
3178 |
|
|
// Set chain 5 --> Wishbone Memory chain
|
3179 |
|
|
err = gdb_set_chain(SC_WISHBONE);
|
3180 |
|
|
if(err){
|
3181 |
|
|
put_str_packet ("E01");
|
3182 |
|
|
return;
|
3183 |
|
|
}
|
3184 |
|
|
|
3185 |
|
|
/* Write the bytes to memory */
|
3186 |
|
|
if (len)
|
3187 |
|
|
{
|
3188 |
46 |
julius |
//swap_buf(bindat, len);
|
3189 |
39 |
julius |
if (DEBUG_GDB_BLOCK_DATA){
|
3190 |
|
|
uint32_t temp_uint32;
|
3191 |
|
|
for (off = 0; off < len; off++){
|
3192 |
|
|
temp_uint32 = (temp_uint32 << 8) | (0x000000ff & bindat[off]);
|
3193 |
|
|
if((off %4 ) == 3){
|
3194 |
46 |
julius |
//temp_uint32 = htonl(temp_uint32);
|
3195 |
39 |
julius |
}
|
3196 |
|
|
switch(off % 16)
|
3197 |
|
|
{
|
3198 |
|
|
case 3:
|
3199 |
|
|
printf("Add 0x%08x Data 0x%08x ", addr + off - 3, temp_uint32);
|
3200 |
|
|
break;
|
3201 |
|
|
case 7:
|
3202 |
|
|
case 11:
|
3203 |
|
|
printf("0x%08x ", temp_uint32);
|
3204 |
|
|
break;
|
3205 |
|
|
case 15:
|
3206 |
|
|
printf("0x%08x\n", temp_uint32);
|
3207 |
|
|
break;
|
3208 |
|
|
default:
|
3209 |
|
|
break;
|
3210 |
|
|
}
|
3211 |
|
|
if ((len - off == 1) && (off % 16) < 15) printf("\n");
|
3212 |
|
|
}
|
3213 |
|
|
}
|
3214 |
|
|
|
3215 |
46 |
julius |
bindat_ptr = bindat; // Copy pointer so we don't trash the original.
|
3216 |
|
|
if (addr & 0x3) // not perfectly aligned at beginning - fix
|
3217 |
|
|
{
|
3218 |
|
|
if (DEBUG_GDB) {
|
3219 |
|
|
printf("rsp_write_mem_bin: address not word aligned: 0x%.8x\n",
|
3220 |
|
|
addr);fflush (stdout);
|
3221 |
|
|
}
|
3222 |
|
|
// Write enough to align us
|
3223 |
|
|
int bytes_to_write = bytes_per_word - (addr&0x3);
|
3224 |
|
|
if (bytes_to_write > len) bytes_to_write = len; // case of writing 1 byte to adr 0x1
|
3225 |
|
|
if (DEBUG_GDB) {
|
3226 |
|
|
printf("rsp_write_mem_bin: writing %d bytes of len (%d)\n",
|
3227 |
|
|
bytes_to_write, len);fflush (stdout);
|
3228 |
|
|
}
|
3229 |
|
|
|
3230 |
|
|
for (i=0;i<bytes_to_write;i++)
|
3231 |
|
|
err = gdb_write_byte(addr+i, (uint8_t) bindat_ptr[i]);
|
3232 |
|
|
|
3233 |
|
|
addr += bytes_to_write; bindat_ptr += bytes_to_write;
|
3234 |
|
|
len -= bytes_to_write;
|
3235 |
|
|
if (DEBUG_GDB){
|
3236 |
|
|
printf("rsp_write_mem_bin: address should now be word aligned: 0x%.8x\n", addr);
|
3237 |
|
|
fflush (stdout);
|
3238 |
|
|
}
|
3239 |
|
|
}
|
3240 |
|
|
if ((len > 3) && !err) // now write full words, if we can
|
3241 |
|
|
{
|
3242 |
|
|
int words_to_write = len/bytes_per_word;
|
3243 |
|
|
if (DEBUG_GDB)
|
3244 |
|
|
printf("rsp_write_mem_bin: writing %d words from 0x%x, len %d bytes\n",
|
3245 |
|
|
words_to_write, addr, len);fflush (stdout);
|
3246 |
|
|
|
3247 |
|
|
err = gdb_write_block(addr, (uint32_t*)bindat_ptr,
|
3248 |
|
|
(words_to_write*bytes_per_word));
|
3249 |
|
|
|
3250 |
|
|
addr+=(words_to_write*bytes_per_word);
|
3251 |
|
|
bindat_ptr+=(words_to_write*bytes_per_word);
|
3252 |
|
|
len-=(words_to_write*bytes_per_word);
|
3253 |
|
|
}
|
3254 |
|
|
if (len && !err) // leftover words. Write them out
|
3255 |
|
|
{
|
3256 |
|
|
if (DEBUG_GDB)
|
3257 |
|
|
printf("rsp_write_mem_bin: writing remainder %d bytes to 0x%.8x\n",
|
3258 |
|
|
len, addr);fflush (stdout);
|
3259 |
|
|
|
3260 |
|
|
for (i=0;i<len;i++)
|
3261 |
|
|
err = gdb_write_byte(addr+i, (uint8_t) bindat_ptr[i]);
|
3262 |
|
|
}
|
3263 |
|
|
|
3264 |
39 |
julius |
if(err){
|
3265 |
|
|
put_str_packet ("E01");
|
3266 |
|
|
return;
|
3267 |
|
|
}
|
3268 |
46 |
julius |
|
3269 |
39 |
julius |
if (DEBUG_GDB) printf("Error %x\n", err);fflush (stdout);
|
3270 |
|
|
}
|
3271 |
|
|
put_str_packet ("OK");
|
3272 |
46 |
julius |
|
3273 |
39 |
julius |
} /* rsp_write_mem_bin () */
|
3274 |
|
|
|
3275 |
|
|
|
3276 |
|
|
/*---------------------------------------------------------------------------*/
|
3277 |
|
|
/*!Handle a RSP remove breakpoint or matchpoint request
|
3278 |
|
|
|
3279 |
|
|
For now only memory breakpoints are implemented, which are implemented by
|
3280 |
|
|
substituting a breakpoint at the specified address. The implementation must
|
3281 |
|
|
cope with the possibility of duplicate packets.
|
3282 |
|
|
|
3283 |
|
|
@todo This doesn't work with icache/immu yet
|
3284 |
|
|
|
3285 |
|
|
@param[in] p_buf The command received */
|
3286 |
|
|
/*---------------------------------------------------------------------------*/
|
3287 |
|
|
static void
|
3288 |
|
|
rsp_remove_matchpoint (struct rsp_buf *p_buf)
|
3289 |
|
|
{
|
3290 |
|
|
enum mp_type type; /* What sort of matchpoint */
|
3291 |
|
|
uint32_t addr; /* Address specified */
|
3292 |
|
|
int len; /* Matchpoint length (not used) */
|
3293 |
|
|
struct mp_entry *mpe; /* Info about the replaced instr */
|
3294 |
|
|
|
3295 |
|
|
/* Break out the instruction */
|
3296 |
|
|
if (3 != sscanf (p_buf->data, "z%1d,%x,%1d", (int *)&type, &addr, &len))
|
3297 |
|
|
{
|
3298 |
|
|
fprintf (stderr, "Warning: RSP matchpoint deletion request not "
|
3299 |
|
|
"recognized: ignored\n");
|
3300 |
|
|
put_str_packet ("E01");
|
3301 |
|
|
return;
|
3302 |
|
|
}
|
3303 |
|
|
|
3304 |
|
|
/* Sanity check that the length is 4 */
|
3305 |
|
|
if (4 != len)
|
3306 |
|
|
{
|
3307 |
|
|
fprintf (stderr, "Warning: RSP matchpoint deletion length %d not "
|
3308 |
|
|
"valid: 4 assumed\n", len);
|
3309 |
|
|
len = 4;
|
3310 |
|
|
}
|
3311 |
|
|
|
3312 |
|
|
/* Sort out the type of matchpoint */
|
3313 |
|
|
switch (type)
|
3314 |
|
|
{
|
3315 |
|
|
case BP_MEMORY:
|
3316 |
|
|
/* Memory breakpoint - replace the original instruction. */
|
3317 |
|
|
mpe = mp_hash_delete (type, addr);
|
3318 |
|
|
|
3319 |
|
|
/* If the BP hasn't yet been deleted, put the original instruction
|
3320 |
|
|
back. Don't forget to free the hash table entry afterwards. */
|
3321 |
|
|
if (NULL != mpe)
|
3322 |
|
|
{
|
3323 |
|
|
// Arc Sim Code --> set_program32 (addr, mpe->instr);
|
3324 |
|
|
// Make sure the processor is stalled
|
3325 |
|
|
gdb_ensure_or1k_stalled();
|
3326 |
|
|
|
3327 |
|
|
// Set chain 5 --> Wishbone Memory chain
|
3328 |
|
|
err = gdb_set_chain(SC_WISHBONE);
|
3329 |
|
|
if(err){
|
3330 |
|
|
put_str_packet ("E01");
|
3331 |
|
|
return;
|
3332 |
|
|
}
|
3333 |
|
|
err = gdb_write_block(addr, &mpe->instr, 4);
|
3334 |
|
|
if(err){
|
3335 |
|
|
put_str_packet ("E01");
|
3336 |
|
|
return;
|
3337 |
|
|
}
|
3338 |
|
|
free (mpe);
|
3339 |
|
|
}
|
3340 |
|
|
|
3341 |
|
|
put_str_packet ("OK");
|
3342 |
|
|
return;
|
3343 |
|
|
|
3344 |
|
|
case BP_HARDWARE:
|
3345 |
|
|
put_str_packet (""); /* Not supported */
|
3346 |
|
|
return;
|
3347 |
|
|
|
3348 |
|
|
case WP_WRITE:
|
3349 |
|
|
put_str_packet (""); /* Not supported */
|
3350 |
|
|
return;
|
3351 |
|
|
|
3352 |
|
|
case WP_READ:
|
3353 |
|
|
put_str_packet (""); /* Not supported */
|
3354 |
|
|
return;
|
3355 |
|
|
|
3356 |
|
|
case WP_ACCESS:
|
3357 |
|
|
put_str_packet (""); /* Not supported */
|
3358 |
|
|
return;
|
3359 |
|
|
|
3360 |
|
|
default:
|
3361 |
|
|
fprintf (stderr, "Warning: RSP matchpoint type %d not "
|
3362 |
|
|
"recognized: ignored\n", type);
|
3363 |
|
|
put_str_packet ("E01");
|
3364 |
|
|
return;
|
3365 |
|
|
|
3366 |
|
|
}
|
3367 |
|
|
} /* rsp_remove_matchpoint () */
|
3368 |
|
|
|
3369 |
|
|
|
3370 |
|
|
/*---------------------------------------------------------------------------*/
|
3371 |
|
|
/*!Handle a RSP insert breakpoint or matchpoint request
|
3372 |
|
|
|
3373 |
|
|
For now only memory breakpoints are implemented, which are implemented by
|
3374 |
|
|
substituting a breakpoint at the specified address. The implementation must
|
3375 |
|
|
cope with the possibility of duplicate packets.
|
3376 |
|
|
|
3377 |
|
|
@todo This doesn't work with icache/immu yet
|
3378 |
|
|
|
3379 |
|
|
@param[in] p_buf The command received */
|
3380 |
|
|
/*---------------------------------------------------------------------------*/
|
3381 |
|
|
static void
|
3382 |
|
|
rsp_insert_matchpoint (struct rsp_buf *p_buf)
|
3383 |
|
|
{
|
3384 |
|
|
enum mp_type type; /* What sort of matchpoint */
|
3385 |
|
|
uint32_t addr; /* Address specified */
|
3386 |
|
|
int len; /* Matchpoint length (not used) */
|
3387 |
|
|
uint32_t instr;
|
3388 |
|
|
|
3389 |
|
|
/* Break out the instruction */
|
3390 |
|
|
if (3 != sscanf (p_buf->data, "Z%1d,%x,%1d", (int *)&type, &addr, &len))
|
3391 |
|
|
{
|
3392 |
|
|
fprintf (stderr, "Warning: RSP matchpoint insertion request not "
|
3393 |
|
|
"recognized: ignored\n");
|
3394 |
|
|
put_str_packet ("E01");
|
3395 |
|
|
return;
|
3396 |
|
|
}
|
3397 |
|
|
|
3398 |
|
|
/* Sanity check that the length is 4 */
|
3399 |
|
|
if (4 != len)
|
3400 |
|
|
{
|
3401 |
|
|
fprintf (stderr, "Warning: RSP matchpoint insertion length %d not "
|
3402 |
|
|
"valid: 4 assumed\n", len);
|
3403 |
|
|
len = 4;
|
3404 |
|
|
}
|
3405 |
|
|
|
3406 |
|
|
/* Sort out the type of matchpoint */
|
3407 |
|
|
switch (type)
|
3408 |
|
|
{
|
3409 |
|
|
case BP_MEMORY: // software-breakpoint Z0 break
|
3410 |
|
|
/* Memory breakpoint - substitute a TRAP instruction */
|
3411 |
|
|
// Make sure the processor is stalled
|
3412 |
|
|
gdb_ensure_or1k_stalled();
|
3413 |
|
|
|
3414 |
|
|
// Set chain 5 --> Wishbone Memory chain
|
3415 |
|
|
gdb_set_chain(SC_WISHBONE);
|
3416 |
|
|
|
3417 |
|
|
// Read the data from Wishbone Memory chain
|
3418 |
|
|
// Arc Sim Code --> mp_hash_add (type, addr, eval_direct32 (addr, 0, 0));
|
3419 |
|
|
gdb_read_block(addr, &instr, 4);
|
3420 |
|
|
|
3421 |
|
|
mp_hash_add (type, addr, instr);
|
3422 |
46 |
julius |
|
3423 |
|
|
//instr = OR1K_TRAP_INSTR;
|
3424 |
|
|
instr = ntohl(OR1K_TRAP_INSTR);// Endianess of this needs to be swapped -jb
|
3425 |
39 |
julius |
err = gdb_write_block(addr, &instr, 4);
|
3426 |
|
|
if(err){
|
3427 |
|
|
put_str_packet ("E01");
|
3428 |
|
|
return;
|
3429 |
|
|
}
|
3430 |
|
|
put_str_packet ("OK");
|
3431 |
|
|
return;
|
3432 |
|
|
|
3433 |
|
|
case BP_HARDWARE: // hardware-breakpoint Z1 hbreak
|
3434 |
|
|
put_str_packet (""); /* Not supported */
|
3435 |
|
|
return;
|
3436 |
|
|
|
3437 |
|
|
case WP_WRITE: // write-watchpoint Z2 watch
|
3438 |
|
|
put_str_packet (""); /* Not supported */
|
3439 |
|
|
return;
|
3440 |
|
|
|
3441 |
|
|
case WP_READ: // read-watchpoint Z3 rwatch
|
3442 |
|
|
put_str_packet (""); /* Not supported */
|
3443 |
|
|
return;
|
3444 |
|
|
|
3445 |
|
|
case WP_ACCESS: // access-watchpoint Z4 awatch
|
3446 |
|
|
put_str_packet (""); /* Not supported */
|
3447 |
|
|
return;
|
3448 |
|
|
|
3449 |
|
|
default:
|
3450 |
|
|
fprintf (stderr, "Warning: RSP matchpoint type %d not "
|
3451 |
|
|
"recognized: ignored\n", type);
|
3452 |
|
|
put_str_packet ("E01");
|
3453 |
|
|
return;
|
3454 |
|
|
}
|
3455 |
|
|
} /* rsp_insert_matchpoint () */
|
3456 |
|
|
|
3457 |
|
|
|
3458 |
|
|
/*---------------------------------------------------------------------------
|
3459 |
|
|
Setup the or32 to init state
|
3460 |
|
|
|
3461 |
|
|
---------------------------------------------------------------------------*/
|
3462 |
|
|
void setup_or32(void)
|
3463 |
|
|
{
|
3464 |
|
|
uint32_t temp_uint32;
|
3465 |
|
|
// First set the chain
|
3466 |
|
|
err = gdb_set_chain(SC_REGISTER); /* 4 Register Chain */
|
3467 |
|
|
if(err > 0){
|
3468 |
|
|
if (DEBUG_GDB) printf("Error %d in gdb_set_chain\n", err);
|
3469 |
|
|
}
|
3470 |
|
|
if(gdb_read_reg(0x04, &temp_uint32)) printf("Error read from register\n");
|
3471 |
|
|
if (DEBUG_GDB) printf("Read from chain 4 SC_REGISTER at add 0x00000004 = 0x%08x\n", temp_uint32 );
|
3472 |
|
|
|
3473 |
|
|
if(gdb_write_reg(0x04, 0x00000001)) printf("Error write to register\n");
|
3474 |
|
|
if (DEBUG_GDB) printf("Write to chain 4 SC_REGISTER at add 0x00000004 = 0x00000001\n");
|
3475 |
|
|
|
3476 |
|
|
// if(gdb_read_reg(0x04, &temp_uint32)) printf("Error read from register\n");
|
3477 |
|
|
// if (DEBUG_GDB) printf("Read from chain 4 SC_REGISTER at add 0x00000004 = 0x%08x\n", temp_uint32 );
|
3478 |
|
|
|
3479 |
|
|
// if(gdb_read_reg(0x04, &temp_uint32)) printf("Error read from register\n");
|
3480 |
|
|
// if (DEBUG_GDB) printf("Read from chain 4 SC_REGISTER at add 0x00000004 = 0x%08x\n", temp_uint32 );
|
3481 |
|
|
|
3482 |
|
|
if(gdb_write_reg(0x00, 0x01000001)) printf("Error write to register\n");
|
3483 |
|
|
if (DEBUG_GDB) printf("Write to chain 4 SC_REGISTER at add 0x00000000 = 0x01000001\n");
|
3484 |
|
|
}
|
3485 |
|
|
|
3486 |
|
|
// Function to check if the processor is stalled - if not then stall it.
|
3487 |
|
|
// this is useful in the event that GDB thinks the processor is stalled, but has, in fact
|
3488 |
|
|
// been hard reset on the board and is running.
|
3489 |
|
|
static void gdb_ensure_or1k_stalled()
|
3490 |
|
|
{
|
3491 |
|
|
unsigned char stalled;
|
3492 |
|
|
dbg_cpu0_read_ctrl(0, &stalled);
|
3493 |
|
|
if ((stalled & 0x1) != 0x1)
|
3494 |
|
|
{
|
3495 |
|
|
if (DEBUG_GDB)
|
3496 |
|
|
printf("Processor not stalled, like we thought\n");
|
3497 |
|
|
|
3498 |
|
|
// Set the TAP controller to its OR1k chain
|
3499 |
|
|
dbg_set_tap_ir(JI_DEBUG);
|
3500 |
|
|
gdb_chain = -1;
|
3501 |
|
|
|
3502 |
|
|
// Processor isn't stalled, contrary to what we though, so stall it
|
3503 |
|
|
printf("Stalling or1k\n");
|
3504 |
|
|
dbg_cpu0_write_ctrl(0, 0x01); // stall or1k
|
3505 |
|
|
}
|
3506 |
|
|
}
|
3507 |
|
|
|
3508 |
46 |
julius |
int gdb_write_byte(uint32_t adr, uint8_t data) {
|
3509 |
|
|
|
3510 |
|
|
#ifdef OR32_KERNEL_DBG_COMPAT
|
3511 |
|
|
if (IS_VM_ADDR(adr))
|
3512 |
|
|
adr = adr & ~OR32_LINUX_VM_MASK;
|
3513 |
|
|
#endif
|
3514 |
39 |
julius |
|
3515 |
46 |
julius |
if (DEBUG_CMDS) printf("wbyte %d\n", gdb_chain);
|
3516 |
39 |
julius |
switch (gdb_chain) {
|
3517 |
46 |
julius |
case SC_WISHBONE: return dbg_wb_write8(adr, data) ?
|
3518 |
39 |
julius |
ERR_CRC : ERR_NONE;
|
3519 |
|
|
default: return JTAG_PROXY_INVALID_CHAIN;
|
3520 |
|
|
}
|
3521 |
|
|
}
|
3522 |
|
|
|
3523 |
|
|
int gdb_write_reg(uint32_t adr, uint32_t data) {
|
3524 |
46 |
julius |
|
3525 |
|
|
#ifdef OR32_KERNEL_DBG_COMPAT
|
3526 |
|
|
if (IS_VM_ADDR(adr))
|
3527 |
|
|
adr = adr & ~OR32_LINUX_VM_MASK;
|
3528 |
|
|
#endif
|
3529 |
|
|
|
3530 |
39 |
julius |
switch (gdb_chain) { /* remap registers, to be compatible with jp1 */
|
3531 |
47 |
julius |
case SC_RISC_DEBUG: return dbg_cpu0_write(adr, &data, 4) ? ERR_CRC : ERR_NONE;
|
3532 |
39 |
julius |
case SC_REGISTER: return dbg_cpu0_write_ctrl(adr, data) ? ERR_CRC : ERR_NONE;
|
3533 |
|
|
case SC_WISHBONE: return dbg_wb_write32(adr, data) ? ERR_CRC : ERR_NONE;
|
3534 |
|
|
case SC_TRACE: return 0;
|
3535 |
|
|
default: return JTAG_PROXY_INVALID_CHAIN;
|
3536 |
|
|
}
|
3537 |
|
|
}
|
3538 |
46 |
julius |
int gdb_read_reg(uint32_t adr, uint32_t *data) {
|
3539 |
39 |
julius |
|
3540 |
46 |
julius |
#ifdef OR32_KERNEL_DBG_COMPAT
|
3541 |
|
|
if (IS_VM_ADDR(adr))
|
3542 |
|
|
adr = adr & ~OR32_LINUX_VM_MASK;
|
3543 |
|
|
#endif
|
3544 |
|
|
|
3545 |
|
|
switch (gdb_chain) {
|
3546 |
47 |
julius |
case SC_RISC_DEBUG: return dbg_cpu0_read(adr, data, 4) ? ERR_CRC : ERR_NONE;
|
3547 |
46 |
julius |
case SC_REGISTER: return dbg_cpu0_read_ctrl(adr, (unsigned char*)data) ?
|
3548 |
|
|
ERR_CRC : ERR_NONE;
|
3549 |
|
|
case SC_WISHBONE: return dbg_wb_read32(adr, data) ? ERR_CRC : ERR_NONE;
|
3550 |
|
|
case SC_TRACE: *data = 0; return 0;
|
3551 |
|
|
default: return JTAG_PROXY_INVALID_CHAIN;
|
3552 |
|
|
}
|
3553 |
|
|
}
|
3554 |
|
|
|
3555 |
|
|
|
3556 |
39 |
julius |
int gdb_read_block(uint32_t adr, uint32_t *data, int len) {
|
3557 |
46 |
julius |
|
3558 |
|
|
#ifdef OR32_KERNEL_DBG_COMPAT
|
3559 |
|
|
if (IS_VM_ADDR(adr))
|
3560 |
|
|
adr = adr & ~OR32_LINUX_VM_MASK;
|
3561 |
|
|
#endif
|
3562 |
|
|
|
3563 |
39 |
julius |
if (DEBUG_CMDS) printf("rb %d\n", gdb_chain);
|
3564 |
46 |
julius |
|
3565 |
39 |
julius |
switch (gdb_chain) {
|
3566 |
47 |
julius |
case SC_RISC_DEBUG: return dbg_cpu0_read(adr, data, len) ? ERR_CRC : ERR_NONE;
|
3567 |
|
|
case SC_WISHBONE: return dbg_wb_read_block32(adr, data, len) ? ERR_CRC : ERR_NONE;
|
3568 |
|
|
|
3569 |
39 |
julius |
default: return JTAG_PROXY_INVALID_CHAIN;
|
3570 |
|
|
}
|
3571 |
|
|
}
|
3572 |
|
|
|
3573 |
|
|
int gdb_write_block(uint32_t adr, uint32_t *data, int len) {
|
3574 |
46 |
julius |
|
3575 |
|
|
#ifdef OR32_KERNEL_DBG_COMPAT
|
3576 |
|
|
if (IS_VM_ADDR(adr))
|
3577 |
|
|
adr = adr & ~OR32_LINUX_VM_MASK;
|
3578 |
|
|
#endif
|
3579 |
|
|
|
3580 |
39 |
julius |
if (DEBUG_CMDS) printf("wb %d\n", gdb_chain);
|
3581 |
|
|
switch (gdb_chain) {
|
3582 |
47 |
julius |
case SC_RISC_DEBUG: return dbg_cpu0_write(adr, data, (uint32_t) len) ? ERR_CRC : ERR_NONE;
|
3583 |
|
|
case SC_WISHBONE: return dbg_wb_write_block32(adr, data, len) ? ERR_CRC : ERR_NONE;
|
3584 |
39 |
julius |
default: return JTAG_PROXY_INVALID_CHAIN;
|
3585 |
|
|
}
|
3586 |
|
|
}
|
3587 |
|
|
|
3588 |
|
|
int gdb_set_chain(int chain) {
|
3589 |
|
|
switch (chain) {
|
3590 |
|
|
case SC_RISC_DEBUG:
|
3591 |
|
|
case SC_REGISTER:
|
3592 |
|
|
case SC_TRACE:
|
3593 |
|
|
case SC_WISHBONE: gdb_chain = chain;
|
3594 |
|
|
return ERR_NONE;
|
3595 |
|
|
default: return JTAG_PROXY_INVALID_CHAIN;
|
3596 |
|
|
}
|
3597 |
|
|
}
|
3598 |
|
|
|
3599 |
|
|
/*****************************************************************************
|
3600 |
|
|
* Close the connection to the client if it is open
|
3601 |
|
|
******************************************************************************/
|
3602 |
|
|
static void client_close (char err)
|
3603 |
|
|
{
|
3604 |
|
|
if(gdb_fd) {
|
3605 |
|
|
perror("gdb socket - " + err);
|
3606 |
|
|
close(gdb_fd);
|
3607 |
|
|
gdb_fd = 0;
|
3608 |
|
|
}
|
3609 |
|
|
} /* client_close () */
|
3610 |
|
|
|
3611 |
|
|
|
3612 |
|
|
/*---------------------------------------------------------------------------*/
|
3613 |
|
|
/* Swap a buffer of 4-byte from 1234 to 4321
|
3614 |
|
|
|
3615 |
|
|
parameter[in] p_buf and len
|
3616 |
|
|
parameter[out] none */
|
3617 |
|
|
/*---------------------------------------------------------------------------*/
|
3618 |
|
|
static void swap_buf(char* p_buf, int len)
|
3619 |
|
|
{
|
3620 |
|
|
int temp;
|
3621 |
|
|
int n = 0;
|
3622 |
|
|
|
3623 |
|
|
if (len > 2)
|
3624 |
|
|
{
|
3625 |
|
|
while(n < len){
|
3626 |
|
|
// swap 0 and 3
|
3627 |
|
|
temp = p_buf[n];
|
3628 |
|
|
p_buf[n] = p_buf[n + 3];
|
3629 |
|
|
p_buf[n + 3] = temp;
|
3630 |
|
|
// swap 1 and 2
|
3631 |
|
|
temp = p_buf[n + 1];
|
3632 |
|
|
p_buf[n + 1] = p_buf[n + 2];
|
3633 |
|
|
p_buf[n + 2] = temp;
|
3634 |
|
|
|
3635 |
|
|
n += 4;
|
3636 |
|
|
}
|
3637 |
|
|
}
|
3638 |
|
|
}
|
3639 |
|
|
|
3640 |
|
|
|
3641 |
|
|
/*---------------------------------------------------------------------------*/
|
3642 |
|
|
/*!Set the stall state of the processor
|
3643 |
|
|
|
3644 |
|
|
@param[in] state If non-zero stall the processor. */
|
3645 |
|
|
/*---------------------------------------------------------------------------*/
|
3646 |
|
|
static void
|
3647 |
|
|
set_stall_state (int state)
|
3648 |
|
|
{
|
3649 |
|
|
|
3650 |
|
|
if(state == 0)
|
3651 |
|
|
{
|
3652 |
|
|
err = dbg_cpu0_write_ctrl(0, 0); /* unstall or1k */
|
3653 |
|
|
stallState = UNSTALLED;
|
3654 |
|
|
npcIsCached = 0;
|
3655 |
|
|
rsp.sigval = TARGET_SIGNAL_NONE;
|
3656 |
|
|
}
|
3657 |
|
|
else
|
3658 |
|
|
{
|
3659 |
|
|
err = dbg_cpu0_write_ctrl(0, 0x01); /* stall or1k */
|
3660 |
|
|
stallState = STALLED;
|
3661 |
|
|
}
|
3662 |
|
|
|
3663 |
|
|
if(err > 0 && DEBUG_GDB)printf("Error %d in set_stall_state Stall state = %d\n", err, state);
|
3664 |
|
|
|
3665 |
|
|
} /* set_stall_state () */
|
3666 |
|
|
|
3667 |
|
|
|
3668 |
|
|
/*---------------------------------------------------------------------------*/
|
3669 |
|
|
/*!Set the reset bit of the processor's control reg in debug interface
|
3670 |
|
|
*/
|
3671 |
|
|
/*---------------------------------------------------------------------------*/
|
3672 |
|
|
static void
|
3673 |
|
|
reset_or1k (void)
|
3674 |
|
|
{
|
3675 |
|
|
|
3676 |
79 |
julius |
//err = dbg_cpu0_write_ctrl(0, 0x02); /* reset or1k */
|
3677 |
39 |
julius |
|
3678 |
79 |
julius |
//if(err > 0 && DEBUG_GDB)printf("Error %d in reset_or1k()\n", err);
|
3679 |
39 |
julius |
|
3680 |
|
|
} /* reset_or1k () */
|
3681 |
|
|
|
3682 |
|
|
|
3683 |
|
|
/*---------------------------------------------------------------------------*/
|
3684 |
|
|
/*!Close down the connection with GDB in the event of a kill signal
|
3685 |
|
|
|
3686 |
|
|
*/
|
3687 |
|
|
/*---------------------------------------------------------------------------*/
|
3688 |
|
|
void gdb_close()
|
3689 |
|
|
{
|
3690 |
|
|
if (gdb_fd) close(gdb_fd);
|
3691 |
|
|
// Maybe do other things here!
|
3692 |
|
|
}
|