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