1 |
786 |
skrzyp |
//========================================================================
|
2 |
|
|
//
|
3 |
|
|
// generic-stub.h
|
4 |
|
|
//
|
5 |
|
|
// Definitions for the generic GDB remote stub
|
6 |
|
|
//
|
7 |
|
|
//========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Red Hat, nickg
|
43 |
|
|
// Contributors: Red Hat, nickg, dmoseley
|
44 |
|
|
// Date: 1998-06-08
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description: Definitions for the generic GDB remote stub
|
47 |
|
|
// Usage: This header is not to be included by user code, and is
|
48 |
|
|
// only placed in a publically accessible directory so
|
49 |
|
|
// that platform stub packages are able to include it
|
50 |
|
|
// if required.
|
51 |
|
|
//
|
52 |
|
|
//####DESCRIPTIONEND####
|
53 |
|
|
//
|
54 |
|
|
//========================================================================
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
#ifndef GENERIC_STUB_H
|
58 |
|
|
#define GENERIC_STUB_H
|
59 |
|
|
|
60 |
|
|
#ifdef __cplusplus
|
61 |
|
|
extern "C" {
|
62 |
|
|
#endif
|
63 |
|
|
|
64 |
|
|
/* Three typedefs must be provided before including this file.
|
65 |
|
|
target_register_t should correspond to the largest register value on
|
66 |
|
|
this target processor.
|
67 |
|
|
regnames_t corresponds to a type representing a register number.
|
68 |
|
|
uint32 must correspond to at least a 32-bit unsigned integer type
|
69 |
|
|
(it may be larger). */
|
70 |
|
|
|
71 |
|
|
#ifndef ASM
|
72 |
|
|
|
73 |
|
|
#ifndef __ECOS__
|
74 |
|
|
#include "dbg-serial.h"
|
75 |
|
|
#endif // __ECOS__
|
76 |
|
|
|
77 |
|
|
struct gdb_packet
|
78 |
|
|
{
|
79 |
|
|
/* The checksum calculated so far. */
|
80 |
|
|
uint32 checksum;
|
81 |
|
|
/* The checksum we've received from the remote side. */
|
82 |
|
|
uint32 xmitcsum;
|
83 |
|
|
/* Contents of the accumulated packet. */
|
84 |
|
|
char *contents;
|
85 |
|
|
/* Number of characters received. */
|
86 |
|
|
uint32 length;
|
87 |
|
|
/*
|
88 |
|
|
* state is the current state:
|
89 |
|
|
* 0 = looking for start of packet
|
90 |
|
|
* 1 = got start of packet, looking for # terminator
|
91 |
|
|
* 2 = looking for first byte of checksum
|
92 |
|
|
* 3 = looking for second byte of checksum (indicating end of packet)
|
93 |
|
|
*/
|
94 |
|
|
char state;
|
95 |
|
|
char err; // This is set if the packet should be tossed because of overflow
|
96 |
|
|
};
|
97 |
|
|
|
98 |
|
|
/* Return the currently-saved value corresponding to register REG. */
|
99 |
|
|
extern target_register_t get_register (regnames_t reg);
|
100 |
|
|
|
101 |
|
|
/* Write the contents of register WHICH into VALUE as raw bytes */
|
102 |
|
|
extern int get_register_as_bytes (regnames_t which, char *value);
|
103 |
|
|
|
104 |
|
|
#ifdef CYGHWR_REGISTER_VALIDITY_CHECKING
|
105 |
|
|
// Return the validity of register REG.
|
106 |
|
|
extern int get_register_valid (regnames_t reg);
|
107 |
|
|
#endif
|
108 |
|
|
|
109 |
|
|
/* Store VALUE in the register corresponding to WHICH. */
|
110 |
|
|
extern void put_register (regnames_t which, target_register_t value);
|
111 |
|
|
|
112 |
|
|
extern int put_register_as_bytes (regnames_t which, char *value);
|
113 |
|
|
|
114 |
|
|
/* Set the next instruction to be executed when the user program resumes
|
115 |
|
|
execution to PC. */
|
116 |
|
|
#if !defined(SET_PC_PROTOTYPE_EXISTS) && !defined(set_pc)
|
117 |
|
|
#define SET_PC_PROTOTYPE_EXISTS
|
118 |
|
|
extern void set_pc (target_register_t pc);
|
119 |
|
|
#endif
|
120 |
|
|
|
121 |
|
|
/* Set the return value of the currently-pending syscall to VALUE. */
|
122 |
|
|
extern void set_syscall_value (target_register_t value);
|
123 |
|
|
|
124 |
|
|
/* Return the Nth argument to the currently-pending syscall (starting from
|
125 |
|
|
0). */
|
126 |
|
|
extern target_register_t get_syscall_arg (int n);
|
127 |
|
|
|
128 |
|
|
/* Initialize the stub. This will also install any trap handlers needed by
|
129 |
|
|
the stub. */
|
130 |
|
|
extern void initialize_stub (void);
|
131 |
|
|
|
132 |
|
|
/* Initialize the hardware. */
|
133 |
|
|
extern void initHardware (void);
|
134 |
|
|
|
135 |
|
|
/* Skip the current instruction. */
|
136 |
|
|
extern void __skipinst (void);
|
137 |
|
|
|
138 |
|
|
/* If the address in the PC register corresponds to the breakpoint()
|
139 |
|
|
instruction, return a non-zero value. */
|
140 |
|
|
#ifndef __is_breakpoint_function
|
141 |
|
|
extern int __is_breakpoint_function (void);
|
142 |
|
|
#endif
|
143 |
|
|
|
144 |
|
|
/* Execute a breakpoint instruction. Restarting will cause the instruction
|
145 |
|
|
to be skipped. */
|
146 |
|
|
#ifndef breakpoint
|
147 |
|
|
extern void breakpoint (void);
|
148 |
|
|
#endif
|
149 |
|
|
|
150 |
|
|
/* Return the syscall # corresponding to this system call. */
|
151 |
|
|
extern int __get_syscall_num (void);
|
152 |
|
|
|
153 |
|
|
/* Transfer exception event processing to the stub. */
|
154 |
|
|
extern void __switch_to_stub (void);
|
155 |
|
|
|
156 |
|
|
/* Send an exit packet containing the specified status. */
|
157 |
|
|
extern void __send_exit_status (int status);
|
158 |
|
|
|
159 |
|
|
/* Copy COUNT bytes of memory from ADDR to BUF.
|
160 |
|
|
ADDR is assumed to live in the user program's space.
|
161 |
|
|
Returns number of bytes successfully read
|
162 |
|
|
(caller must check to see if less than requested). */
|
163 |
|
|
extern int __read_mem_safe (void *buf,
|
164 |
|
|
void *addr,
|
165 |
|
|
int count);
|
166 |
|
|
|
167 |
|
|
extern int __read_progmem_safe (void *buf,
|
168 |
|
|
void *addr,
|
169 |
|
|
int count);
|
170 |
|
|
|
171 |
|
|
/* Copy COUNT bytes of memory from BUF to ADDR.
|
172 |
|
|
ADDR is assumed to live in the user program's space.
|
173 |
|
|
Returns number of bytes successfully read
|
174 |
|
|
(caller must check to see if less than requested). */
|
175 |
|
|
#ifndef __write_mem_safe
|
176 |
|
|
extern int __write_mem_safe (void *buf,
|
177 |
|
|
void *addr,
|
178 |
|
|
int count);
|
179 |
|
|
#endif
|
180 |
|
|
|
181 |
|
|
extern int __write_progmem_safe (void *buf,
|
182 |
|
|
void *addr,
|
183 |
|
|
int count);
|
184 |
|
|
|
185 |
|
|
/* Set to a non-zero value if a memory fault occurs while
|
186 |
|
|
__set_mem_fault_trap () is running. */
|
187 |
|
|
extern volatile int __mem_fault;
|
188 |
|
|
|
189 |
|
|
#ifndef __ECOS__
|
190 |
|
|
#if 1
|
191 |
|
|
#include "stub-tservice.h" /* target dependent stub services */
|
192 |
|
|
#else
|
193 |
|
|
/* Flush the instruction cache. */
|
194 |
|
|
extern void flush_i_cache (void);
|
195 |
|
|
|
196 |
|
|
/* Flush the data cache. */
|
197 |
|
|
extern void __flush_d_cache (void);
|
198 |
|
|
|
199 |
|
|
typedef enum {
|
200 |
|
|
CACHE_NOOP, CACHE_ENABLE, CACHE_DISABLE, CACHE_FLUSH
|
201 |
|
|
} cache_control_t;
|
202 |
|
|
|
203 |
|
|
/* Perform the specified operation on the instruction cache.
|
204 |
|
|
Returns 1 if the cache is enabled, 0 otherwise. */
|
205 |
|
|
extern int __instruction_cache (cache_control_t request);
|
206 |
|
|
/* Perform the specified operation on the data cache.
|
207 |
|
|
Returns 1 if the cache is enabled, 0 otherwise. */
|
208 |
|
|
extern int __data_cache (cache_control_t request);
|
209 |
|
|
#endif
|
210 |
|
|
#endif // __ECOS__
|
211 |
|
|
|
212 |
|
|
/* Write the 'T' packet in BUFFER. SIGVAL is the signal the program
|
213 |
|
|
received. */
|
214 |
|
|
extern void __build_t_packet (int sigval, char *buffer);
|
215 |
|
|
|
216 |
|
|
/* Return 1 when a complete packet has been received, 0 if the packet
|
217 |
|
|
is not yet complete, or -1 if an erroneous packet was NAKed. */
|
218 |
|
|
int __add_char_to_packet (unsigned character, struct gdb_packet *packet);
|
219 |
|
|
|
220 |
|
|
typedef int (*__PFI)(int);
|
221 |
|
|
typedef void (*__PFV)(void);
|
222 |
|
|
|
223 |
|
|
/* When an exception occurs, __process_exception_vec will be invoked with
|
224 |
|
|
the signal number corresponding to the trap/exception. The function
|
225 |
|
|
should return zero if it wishes execution to resume from the saved
|
226 |
|
|
register values; a non-zero value indicates that the exception handler
|
227 |
|
|
should be reinvoked. */
|
228 |
|
|
#if !defined(PROCESS_EXCEPTION_VEC_PROTOTYPE_EXISTS)
|
229 |
|
|
#define PROCESS_EXCEPTION_VEC_PROTOTYPE_EXISTS
|
230 |
|
|
extern volatile __PFI __process_exception_vec;
|
231 |
|
|
#endif
|
232 |
|
|
|
233 |
|
|
/* __process_exit_vec is invoked when a 'k' kill packet is received
|
234 |
|
|
from GDB. */
|
235 |
|
|
extern volatile __PFV __process_exit_vec;
|
236 |
|
|
|
237 |
|
|
/* If SIGSYSCALL is defined, and such a signal value is returned from
|
238 |
|
|
__computeSignal (), the function pointed to by this vector will
|
239 |
|
|
be invoked.
|
240 |
|
|
|
241 |
|
|
If the return value is negative, the user program is assumed to
|
242 |
|
|
have received the corresponding positive signal value, and an
|
243 |
|
|
exception will be processed. Otherwise, the user program is
|
244 |
|
|
restarted from the next instruction. */
|
245 |
|
|
extern volatile __PFI __process_syscall_vec;
|
246 |
|
|
|
247 |
|
|
/* A continue packet was received from GDB with a signal value. The function
|
248 |
|
|
pointed to by __process_signal_vec will be invoked with this signal
|
249 |
|
|
value.
|
250 |
|
|
|
251 |
|
|
If a zero value is returned, we will ignore the signal, and proceed
|
252 |
|
|
with the continue request. Otherwise, the program will be killed
|
253 |
|
|
with the signal. */
|
254 |
|
|
extern volatile __PFI __process_signal_vec;
|
255 |
|
|
|
256 |
|
|
/* If non-NULL, __init_vec is called right before the user program is
|
257 |
|
|
resumed. */
|
258 |
|
|
extern volatile __PFV __init_vec;
|
259 |
|
|
/* if non-NULL, __cleanup_vec is called after the user program takes
|
260 |
|
|
an exception. */
|
261 |
|
|
extern volatile __PFV __cleanup_vec;
|
262 |
|
|
|
263 |
|
|
/* Send an 'O' packet to GDB containing STR. */
|
264 |
|
|
extern int __output_gdb_string (target_register_t addr, int string_len);
|
265 |
|
|
|
266 |
|
|
/* Request MAXLEN bytes of input from GDB to be stored in DEST. If BLOCK
|
267 |
|
|
is set, GDB should block until MAXLEN bytes are available to be
|
268 |
|
|
read; otherwise, it will return immediately with whatever data is
|
269 |
|
|
available.
|
270 |
|
|
The return value is the number of bytes written into DEST. */
|
271 |
|
|
extern int __get_gdb_input (target_register_t dest, int maxlen, int block);
|
272 |
|
|
|
273 |
|
|
/* Return the ASCII equivalent of C (C>=0 && C<=15). The result will be
|
274 |
|
|
lower-case. */
|
275 |
|
|
extern char __tohex (int c);
|
276 |
|
|
|
277 |
|
|
/* Convert COUNT bytes of the memory region in MEM to a hexadecimal
|
278 |
|
|
string in DEST.
|
279 |
|
|
The resulting string will contain 2*COUNT characters.
|
280 |
|
|
If MAY_FAULT is non-zero, memory faults are trapped; if a fault occurs,
|
281 |
|
|
a NULL value will be returned.
|
282 |
|
|
The value returned is one byte past the end of the string written. */
|
283 |
|
|
extern char *__mem2hex (char *mem, char *dest, int count, int may_fault);
|
284 |
|
|
|
285 |
|
|
/* Given a hexadecimal string in MEM, write the equivalent bytes to DEST.
|
286 |
|
|
The string is assumed to contain 2*COUNT characters.
|
287 |
|
|
If MAY_FAULT is non-zero, memory faults are trapped; if a fault occurs,
|
288 |
|
|
a NULL value will be returned.
|
289 |
|
|
Otherwise, the value returned is one byte past the last byte written. */
|
290 |
|
|
extern char *__hex2mem (char *buf, char *mem, int count, int may_fault);
|
291 |
|
|
|
292 |
|
|
#ifdef CYGSEM_ECOS_SUPPORTS_PROGRAM_ARGS
|
293 |
|
|
/* Set the program arguments passed into the user program's main */
|
294 |
|
|
extern void __set_program_args (int argc, char **argv);
|
295 |
|
|
|
296 |
|
|
/* Return the user program arguments passed in from GDB (via an 'A'
|
297 |
|
|
packet). argcPtr is a pointer into the user program, which will hold
|
298 |
|
|
the number of arguments; the strings are returned. */
|
299 |
|
|
extern char **__get_program_args (target_register_t argcPtr);
|
300 |
|
|
#endif
|
301 |
|
|
|
302 |
|
|
/* Encode PACKET as a remote protocol packet and send it to GDB; this takes
|
303 |
|
|
care of sending the initial '$' character, as well as the trailing '#'
|
304 |
|
|
and checksum, and also waits for an ACK from the remote side, resending
|
305 |
|
|
as necessary. */
|
306 |
|
|
extern void __putpacket (char *packet);
|
307 |
|
|
|
308 |
|
|
/* Retrieve the next remote protocol packet from GDB, taking care of verifying
|
309 |
|
|
the checksum and sending an ACK when necessary. */
|
310 |
|
|
extern void __getpacket (char *buffer);
|
311 |
|
|
|
312 |
|
|
/* Convert the hexadecimal string pointed to by *PTR into an integer,
|
313 |
|
|
and store it in the value pointed to by INTVALUE. The number of
|
314 |
|
|
characters read from *PTR will be returned; *PTR will point to the first
|
315 |
|
|
non-hexadecmial character encountered. */
|
316 |
|
|
extern unsigned int __hexToInt (char **ptr, target_register_t *intValue);
|
317 |
|
|
|
318 |
|
|
/* Convert the value in INTVALUE into a string of hexadecimal
|
319 |
|
|
characters stored in PTR. NUMBITS are the number of bits to use
|
320 |
|
|
in INTVALUE. The number of characters written to PTR will be returned. */
|
321 |
|
|
extern unsigned int __intToHex (char *ptr,
|
322 |
|
|
target_register_t intValue,
|
323 |
|
|
int numBits);
|
324 |
|
|
|
325 |
|
|
/* Handle an exception, usually some sort of hardware or software trap.
|
326 |
|
|
This is responsible for communicating the exception to GDB. */
|
327 |
|
|
extern void __handle_exception (void);
|
328 |
|
|
|
329 |
|
|
/* Send a 'X' packet with signal SIGVAL to GDB. */
|
330 |
|
|
extern void __kill_program (int sigval);
|
331 |
|
|
|
332 |
|
|
/* Given a packet pointed to by PACKETCONTENTS, decode it and respond to
|
333 |
|
|
GDB appropriately. */
|
334 |
|
|
extern int __process_packet (char *packetContents);
|
335 |
|
|
|
336 |
|
|
/* Write the C-style string pointed to by STR to the GDB comm port.
|
337 |
|
|
Used for printing debug messages. */
|
338 |
|
|
extern void __putDebugStr (char *str);
|
339 |
|
|
|
340 |
|
|
#if defined(NO_MALLOC) && !defined(MAX_BP_NUM)
|
341 |
|
|
#define MAX_BP_NUM 64 /* Maximum allowed # of breakpoints */
|
342 |
|
|
#endif
|
343 |
|
|
|
344 |
|
|
extern int hal_syscall_handler(void);
|
345 |
|
|
extern int __is_bsp_syscall(void);
|
346 |
|
|
|
347 |
|
|
extern void __install_breakpoint_list (void);
|
348 |
|
|
extern void __clear_breakpoint_list (void);
|
349 |
|
|
extern int __display_breakpoint_list (void (*print_func)(target_register_t));
|
350 |
|
|
|
351 |
|
|
/* 'Z' packet types */
|
352 |
|
|
#define ZTYPE_SW_BREAKPOINT 0
|
353 |
|
|
#define ZTYPE_HW_BREAKPOINT 1
|
354 |
|
|
#define ZTYPE_HW_WATCHPOINT_WRITE 2
|
355 |
|
|
#define ZTYPE_HW_WATCHPOINT_READ 3
|
356 |
|
|
#define ZTYPE_HW_WATCHPOINT_ACCESS 4
|
357 |
|
|
|
358 |
|
|
#endif /* ASM */
|
359 |
|
|
|
360 |
|
|
#ifdef __cplusplus
|
361 |
|
|
} /* extern "C" */
|
362 |
|
|
#endif
|
363 |
|
|
|
364 |
|
|
#endif /* GENERIC_STUB_H */
|