Mercurial > flash_v2
annotate packages/hal/common/current/src/generic-stub.c @ 38:e7ba79f6d3a8 ecos-sw-1999-09-23
Merge from eCos master repository on 1999-09-23-20:10:25-BST
| author | jlarmour |
|---|---|
| date | Thu, 23 Sep 1999 19:52:27 +0000 |
| parents | 29bc183297e1 |
| children | 797268ecc331 |
| rev | line source |
|---|---|
| 2 | 1 #include "board.h" |
| 2 | |
| 3 #ifdef CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS | |
| 4 | |
| 5 /* Eventually, this should default to ON */ | |
| 6 #if USE_GDBSTUB_PROTOTYPES | |
| 7 #include "stub-tservice.h" | |
| 8 #include "generic-stub.h" | |
| 9 #else | |
| 10 // Function declarations (prevents compiler warnings) | |
| 11 int stubhex (unsigned char ch); | |
| 12 static void getpacket (char *buffer); | |
| 13 static void unlock_thread_scheduler (void); | |
| 14 static uint32 crc32 (unsigned char *ptr, int len, uint32 crc); | |
| 15 #endif | |
| 16 | |
| 17 #include "thread-pkts.h" | |
| 18 /* Defines function macros if thread support is not selected in board.h */ | |
| 19 | |
| 20 | |
| 0 | 21 /**************************************************************************** |
| 22 | |
| 2 | 23 THIS SOFTWARE IS NOT COPYRIGHTED |
| 0 | 24 |
| 25 HP offers the following for use in the public domain. HP makes no | |
| 26 warranty with regard to the software or it's performance and the | |
| 27 user accepts the software "AS IS" with all faults. | |
| 28 | |
| 29 HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD | |
| 30 TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
| 31 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
| 32 | |
| 33 ****************************************************************************/ | |
| 34 | |
| 35 /**************************************************************************** | |
| 36 * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $ | |
| 37 * | |
| 38 * Module name: remcom.c $ | |
| 39 * Revision: 1.34 $ | |
| 40 * Date: 91/03/09 12:29:49 $ | |
| 41 * Contributor: Lake Stevens Instrument Division$ | |
| 42 * | |
| 43 * Description: low level support for gdb debugger. $ | |
| 44 * | |
| 45 * Considerations: only works on target hardware $ | |
| 46 * | |
| 47 * Written by: Glenn Engel $ | |
| 48 * ModuleState: Experimental $ | |
| 49 * | |
| 50 * NOTES: See Below $ | |
| 51 * | |
| 2 | 52 * Modified for SPARC by Stu Grossman, Cygnus Solutions. |
| 0 | 53 * Modified for generic CygMON stub support by Bob Manson, Cygnus Solutions. |
| 54 * | |
| 55 * To enable debugger support, two things need to happen. One, a | |
| 2 | 56 * call to set_debug_traps () is necessary in order to allow any breakpoints |
| 0 | 57 * or error conditions to be properly intercepted and reported to gdb. |
| 58 * Two, a breakpoint needs to be generated to begin communication. This | |
| 2 | 59 * is most easily accomplished by a call to breakpoint (). Breakpoint () |
| 0 | 60 * simulates a breakpoint by executing a trap #1. |
| 61 * | |
| 62 ************* | |
| 63 * | |
| 64 * The following gdb commands are supported: | |
| 65 * | |
| 66 * command function Return value | |
| 67 * | |
| 68 * g return the value of the CPU registers hex data or ENN | |
| 69 * G set the value of the CPU registers OK or ENN | |
| 70 * | |
| 71 * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN | |
| 72 * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN | |
| 73 * | |
| 74 * c Resume at current address SNN ( signal NN) | |
| 75 * cAA..AA Continue at address AA..AA SNN | |
| 76 * | |
| 77 * s Step one instruction SNN | |
| 78 * sAA..AA Step one instruction from AA..AA SNN | |
| 79 * | |
| 80 * k kill | |
| 81 * | |
| 82 * ? What was the last sigval ? SNN (signal NN) | |
| 83 * | |
| 2 | 84 * bBB..BB Set baud rate to BB..BB OK or BNN, then sets |
| 85 * baud rate | |
| 0 | 86 * |
| 87 * All commands and responses are sent with a packet which includes a | |
| 88 * checksum. A packet consists of | |
| 89 * | |
| 90 * $<packet info>#<checksum>. | |
| 91 * | |
| 92 * where | |
| 93 * <packet info> :: <characters representing the command or response> | |
| 94 * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>> | |
| 95 * | |
| 96 * When a packet is received, it is first acknowledged with either '+' or '-'. | |
| 97 * '+' indicates a successful transfer. '-' indicates a failed transfer. | |
| 98 * | |
| 99 * Example: | |
| 100 * | |
| 101 * Host: Reply: | |
| 102 * $m0,10#2a +$00010203040506070809101112131415#42 | |
| 103 * | |
| 104 ****************************************************************************/ | |
| 105 | |
| 2 | 106 #ifndef __ECOS__ |
| 107 #include <string.h> | |
| 108 #include <signal.h> | |
| 109 #endif // __ECOS__ | |
| 0 | 110 |
| 111 /************************************************************************/ | |
| 112 /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/ | |
| 113 /* at least NUMREGBYTES*2 are needed for register packets */ | |
| 114 #define BUFMAX 2048 | |
| 115 | |
| 2 | 116 static int initialized = 0; /* !0 means we've been initialized */ |
| 117 | |
| 0 | 118 static int process_exception (int sigval); |
| 119 static void do_nothing (void); /* and do it gracefully */ | |
| 120 static int syscall_do_nothing (int); | |
| 2 | 121 |
| 122 void __free_program_args (void); | |
| 0 | 123 |
| 124 volatile __PFI __process_exception_vec = process_exception; | |
| 125 volatile __PFV __process_exit_vec = do_nothing; | |
| 126 volatile __PFI __process_syscall_vec = syscall_do_nothing; | |
| 127 volatile __PFI __process_signal_vec = NULL; | |
| 2 | 128 volatile __PFV __init_vec = NULL; |
| 129 volatile __PFV __cleanup_vec = NULL; | |
| 130 | |
| 131 static char *__add_program_arg (int argnum, uint32 arglen); | |
| 0 | 132 |
| 133 static const char hexchars[] = "0123456789abcdef"; | |
| 134 | |
| 2 | 135 static void process_query (char *pkt); |
| 136 static void process_set (char *pkt); | |
| 0 | 137 |
| 138 char | |
| 139 __tohex (int c) | |
| 140 { | |
| 141 return hexchars [c & 15]; | |
| 142 } | |
| 143 | |
| 2 | 144 #define __tohex(c) hexchars[(c) & 15] |
| 0 | 145 |
| 146 #ifndef NUMREGS_GDB | |
| 147 #define NUMREGS_GDB NUMREGS | |
| 148 #endif | |
| 149 | |
| 150 /* One pushback character. */ | |
| 151 int ungot_char = -1; | |
| 152 | |
| 153 static int | |
| 154 readDebugChar (void) | |
| 155 { | |
| 156 if (ungot_char > 0) | |
| 157 { | |
| 158 int result = ungot_char; | |
| 159 ungot_char = -1; | |
| 160 return result; | |
| 161 } | |
| 162 else | |
| 163 return getDebugChar (); | |
| 164 } | |
| 165 | |
| 166 /* Convert ch from a hex digit to an int. */ | |
| 167 | |
| 168 int | |
| 2 | 169 stubhex (ch) |
| 170 unsigned char ch; | |
| 0 | 171 { |
| 172 if (ch >= 'a' && ch <= 'f') | |
| 173 return ch-'a'+10; | |
| 174 if (ch >= '0' && ch <= '9') | |
| 175 return ch-'0'; | |
| 176 if (ch >= 'A' && ch <= 'F') | |
| 177 return ch-'A'+10; | |
| 178 return -1; | |
| 179 } | |
| 180 | |
| 181 static void | |
| 2 | 182 getpacket (buffer) |
| 183 char *buffer; | |
| 0 | 184 { |
| 185 struct gdb_packet packet; | |
| 186 | |
| 187 packet.state = 0; | |
| 188 packet.contents = buffer; | |
| 2 | 189 while (__add_char_to_packet (readDebugChar () & 0xff, &packet) != 1) |
| 0 | 190 { |
| 191 /* Empty */ | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 int | |
| 2 | 196 __add_char_to_packet (ch, packet) |
| 197 unsigned int ch; | |
| 198 struct gdb_packet *packet; | |
| 0 | 199 { |
| 200 if (packet->state == 0) | |
| 201 { | |
| 202 if (ch == '$') | |
| 2 | 203 { |
| 204 packet->state = 1; | |
| 205 packet->length = 0; | |
| 206 packet->checksum = 0; | |
| 207 packet->xmitcsum = -1; | |
| 208 } | |
| 0 | 209 return 0; |
| 210 } | |
| 211 | |
| 212 if (packet->state == 1) | |
| 213 { | |
| 214 if (ch == '#') | |
| 2 | 215 { |
| 216 packet->contents[packet->length] = 0; | |
| 217 packet->state = 2; | |
| 218 } | |
| 0 | 219 else |
| 2 | 220 { |
| 221 if (packet->length == BUFMAX) { | |
| 222 packet->state = 0; | |
| 223 return -1; | |
| 224 } | |
| 225 packet->checksum += ch; | |
| 226 packet->contents[packet->length++] = ch; | |
| 227 } | |
| 0 | 228 return 0; |
| 229 } | |
| 230 | |
| 231 if (packet->state == 2) | |
| 232 { | |
| 233 packet->xmitcsum = stubhex (ch) << 4; | |
| 234 packet->state = 3; | |
| 235 return 0; | |
| 236 } | |
| 237 | |
| 238 if (packet->state == 3) | |
| 239 { | |
| 2 | 240 packet->xmitcsum |= stubhex (ch); |
| 0 | 241 if ((packet->checksum & 255) != packet->xmitcsum) |
| 2 | 242 { |
| 243 putDebugChar ('-'); /* failed checksum */ | |
| 244 packet->state = 0; | |
| 245 return -1; | |
| 246 } | |
| 0 | 247 else |
| 2 | 248 { |
| 249 putDebugChar ('+'); /* successful transfer */ | |
| 250 /* if a sequence char is present, reply the sequence ID */ | |
| 251 if (packet->contents[2] == ':') | |
| 252 { | |
| 253 uint32 count = packet->length; | |
| 254 uint32 i; | |
| 255 putDebugChar (packet->contents[0]); | |
| 256 putDebugChar (packet->contents[1]); | |
| 257 /* remove sequence chars from buffer */ | |
| 258 for (i=3; i <= count; i++) | |
| 259 packet->contents[i-3] = packet->contents[i]; | |
| 260 } | |
| 261 return 1; | |
| 262 } | |
| 0 | 263 } |
| 264 /* We should never get here. */ | |
| 265 packet->state = 0; | |
| 266 return -1; | |
| 267 } | |
| 268 | |
| 269 /* send the packet in buffer. */ | |
| 270 | |
| 2 | 271 void |
| 272 __putpacket (buffer) | |
| 273 char *buffer; | |
| 0 | 274 { |
| 275 unsigned char checksum; | |
| 2 | 276 uint32 count; |
| 0 | 277 unsigned char ch; |
| 278 | |
| 279 /* $<packet info>#<checksum>. */ | |
| 280 do | |
| 281 { | |
| 282 putDebugChar ('$'); | |
| 283 checksum = 0; | |
| 284 count = 0; | |
| 285 | |
| 286 while ((ch = buffer[count])) | |
| 2 | 287 { |
| 288 putDebugChar (ch); | |
| 289 checksum += ch; | |
| 290 count += 1; | |
| 291 } | |
| 0 | 292 |
| 293 putDebugChar ('#'); | |
| 294 putDebugChar (hexchars[(checksum >> 4) & 0xf]); | |
| 295 putDebugChar (hexchars[checksum & 0xf]); | |
| 296 | |
| 297 } | |
| 298 while ((readDebugChar () & 0x7f) != '+'); | |
| 299 } | |
| 300 | |
| 301 static char remcomInBuffer[BUFMAX]; | |
| 302 static char remcomOutBuffer[BUFMAX]; | |
| 303 | |
| 304 /* Indicate to caller of mem2hex or hex2mem that there has been an | |
| 305 error. */ | |
| 306 volatile int __mem_fault = 0; | |
| 307 | |
| 2 | 308 |
| 309 #ifndef TARGET_HAS_OWN_MEM_FUNCS | |
| 310 /* | |
| 311 * _target_readmem_hook / _target_writemem_hook: | |
| 312 * Allow target to get involved in reading/writing memory. | |
| 313 * | |
| 314 * If these hooks are defined by the target, they will be | |
| 315 * called for each user program memory access. Otherwise, the stub | |
| 316 * will simply dereference a pointer to access user program memory. | |
| 317 */ | |
| 318 | |
| 319 unsigned char (*_target_readmem_hook) (unsigned char* addr); | |
| 320 void (*_target_writemem_hook) (unsigned char* addr, | |
| 321 unsigned char value); | |
| 322 | |
| 323 static unsigned char | |
| 324 get_target_byte (volatile unsigned char *address) | |
| 0 | 325 { |
| 2 | 326 if (_target_readmem_hook) /* target needs to control memory access */ |
| 327 return _target_readmem_hook ((unsigned char *) address); | |
| 328 else | |
| 329 return *address; | |
| 330 } | |
| 331 | |
| 332 static void | |
| 333 put_target_byte (volatile unsigned char *address, unsigned char value) | |
| 334 { | |
| 335 if (_target_writemem_hook) /* target needs to control memory access */ | |
| 336 _target_writemem_hook ((unsigned char *) address, value); | |
| 337 else | |
| 338 *address = value; | |
| 339 } | |
| 340 | |
| 341 /* These are the "arguments" to __do_read_mem and __do_write_mem, | |
| 342 which are passed as globals to avoid squeezing them thru | |
| 343 __set_mem_fault_trap. */ | |
| 344 | |
| 345 static volatile target_register_t memCount; | |
| 346 static volatile unsigned char *memSrc, *memDst; | |
| 0 | 347 |
| 2 | 348 /* |
| 349 * __do_read_mem: | |
| 350 * Copy from target memory to trusted memory. | |
| 351 */ | |
| 352 | |
| 353 static void | |
| 354 __do_read_mem (void) | |
| 355 { | |
| 356 __mem_fault = 0; | |
| 357 while (memCount) | |
| 358 { | |
| 359 unsigned char ch = get_target_byte (memSrc++); | |
| 360 | |
| 361 if (__mem_fault) | |
| 362 return; | |
| 363 *memDst++ = ch; | |
| 364 memCount--; | |
| 365 } | |
| 0 | 366 } |
| 367 | |
| 2 | 368 /* |
| 369 * __do_write_mem: | |
| 370 * Copy from trusted memory to target memory. | |
| 371 */ | |
| 372 | |
| 373 static void | |
| 374 __do_write_mem (void) | |
| 375 { | |
| 376 __mem_fault = 0; | |
| 377 while (memCount) | |
| 378 { | |
| 379 unsigned char ch = *memSrc++; | |
| 380 | |
| 381 put_target_byte (memDst++, ch); | |
| 382 if (__mem_fault) | |
| 383 return; | |
| 384 memCount--; | |
| 385 } | |
| 386 } | |
| 387 | |
| 388 /* | |
| 389 * __read_mem_safe: | |
| 390 * Get contents of target memory, abort on error. | |
| 391 */ | |
| 392 | |
| 0 | 393 int |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
394 __read_mem_safe (void *dst, target_register_t src, int count) |
| 0 | 395 { |
| 2 | 396 memCount = count; |
| 397 memSrc = (unsigned char *) src; | |
| 398 memDst = (unsigned char *) dst; | |
| 399 __set_mem_fault_trap (__do_read_mem); | |
| 400 return count - memCount; /* return number of bytes successfully read */ | |
| 0 | 401 } |
| 402 | |
| 2 | 403 /* |
| 404 * __write_mem_safe: | |
| 405 * Set contents of target memory, abort on error. | |
| 406 */ | |
| 407 | |
| 0 | 408 int |
| 409 __write_mem_safe (unsigned char *src, target_register_t dst, int count) | |
| 410 { | |
| 2 | 411 memCount = count; |
| 412 memSrc = (unsigned char *) src; | |
| 413 memDst = (unsigned char *) dst; | |
| 414 __set_mem_fault_trap (__do_write_mem); | |
| 415 return count - memCount; /* return number of bytes successfully read */ | |
| 0 | 416 } |
| 417 | |
| 2 | 418 #endif /* TARGET_HAS_OWN_MEM_FUNCS */ |
| 419 | |
| 420 /* These are the "arguments" to __mem2hex_helper and __hex2mem_helper, | |
| 421 which are passed as globals to avoid squeezing them thru | |
| 422 __set_mem_fault_trap. */ | |
| 423 | |
| 424 static int hexMemCount; | |
| 425 static char *hexMemSrc, *hexMemDst; | |
| 426 static int may_fault_mode; | |
| 427 | |
| 428 /* Hamburger helper? */ | |
| 429 static void | |
| 430 __mem2hex_helper (void) | |
| 431 { | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
432 union { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
433 unsigned long long_val; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
434 unsigned char bytes[sizeof(long)]; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
435 } val; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
436 int len, i; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
437 unsigned char ch; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
438 __mem_fault = 0; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
439 while (hexMemCount > 0) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
440 if (may_fault_mode) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
441 if ((hexMemCount >= sizeof(long)) && |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
442 (((target_register_t)hexMemSrc & (sizeof(long)-1)) == 0)) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
443 // Should be safe to access via a long |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
444 len = sizeof(long); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
445 } else if ((hexMemCount >= sizeof(short)) && |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
446 (((target_register_t)hexMemSrc & (sizeof(short)-1)) == 0)) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
447 // Should be safe to access via a short |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
448 len = sizeof(short); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
449 } else { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
450 len = 1; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
451 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
452 __read_mem_safe(&val.bytes[0], hexMemSrc, len); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
453 } else { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
454 len = 1; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
455 val.bytes[0] = *hexMemSrc; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
456 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
457 if (__mem_fault) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
458 return; |
| 2 | 459 |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
460 for (i = 0; i < len; i++) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
461 ch = val.bytes[i]; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
462 *(hexMemDst++) = hexchars[(ch >> 4) & 0xf]; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
463 if (__mem_fault) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
464 return; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
465 *(hexMemDst++) = hexchars[ch & 0xf]; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
466 if (__mem_fault) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
467 return; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
468 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
469 hexMemCount -= len; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
470 hexMemSrc += len; |
| 2 | 471 } |
| 472 } | |
| 473 | |
| 474 /* Convert the memory pointed to by MEM into HEX, placing result in BUF. | |
| 475 * Return a pointer to the last char put in buf (NUL). In case of a memory | |
| 476 * fault, return 0. | |
| 0 | 477 * If MAY_FAULT is non-zero, then we will handle memory faults by returning |
| 2 | 478 * a 0 (and assume that MEM is a pointer into the user program), else we |
| 479 * treat a fault like any other fault in the stub (and assume that MEM is | |
| 480 * a pointer into the stub's memory). | |
| 0 | 481 */ |
| 482 | |
| 2 | 483 char * |
| 484 __mem2hex (mem, buf, count, may_fault) | |
| 485 char *mem; | |
| 486 char *buf; | |
| 0 | 487 int count; |
| 488 int may_fault; | |
| 489 { | |
| 2 | 490 hexMemDst = (unsigned char *) buf; |
| 491 hexMemSrc = (unsigned char *) mem; | |
| 492 hexMemCount = count; | |
| 493 may_fault_mode = may_fault; | |
| 494 | |
| 495 if (may_fault) | |
| 0 | 496 { |
| 2 | 497 if (__set_mem_fault_trap (__mem2hex_helper)) |
| 498 return 0; | |
| 0 | 499 } |
| 2 | 500 else |
| 501 __mem2hex_helper (); | |
| 0 | 502 |
| 2 | 503 *hexMemDst = 0; |
| 0 | 504 |
| 2 | 505 return (char *) hexMemDst; |
| 0 | 506 } |
| 507 | |
| 2 | 508 static void |
| 509 __hex2mem_helper (void) | |
| 0 | 510 { |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
511 union { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
512 unsigned long long_val; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
513 unsigned char bytes[sizeof(long)]; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
514 } val; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
515 int len, i; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
516 unsigned char ch = '\0'; |
| 0 | 517 |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
518 __mem_fault = 0; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
519 while (hexMemCount > 0 && *hexMemSrc) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
520 if (may_fault_mode) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
521 if ((hexMemCount >= sizeof(long)) && |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
522 (((target_register_t)hexMemDst & (sizeof(long)-1)) == 0)) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
523 len = sizeof(long); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
524 } else if ((hexMemCount >= sizeof(short)) && |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
525 (((target_register_t)hexMemDst & (sizeof(short)-1)) == 0)) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
526 len = sizeof(short); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
527 } else { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
528 len = 1; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
529 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
530 } else { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
531 len = 1; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
532 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
533 |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
534 for (i = 0; i < len; i++) { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
535 // Check for short data? |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
536 ch = stubhex (*(hexMemSrc++)) << 4; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
537 if (__mem_fault) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
538 return; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
539 ch |= stubhex (*(hexMemSrc++)); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
540 if (__mem_fault) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
541 return; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
542 val.bytes[i] = ch; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
543 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
544 |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
545 if (may_fault_mode) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
546 __write_mem_safe (&val.bytes[0], hexMemDst, len); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
547 else |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
548 *hexMemDst = ch; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
549 |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
550 if (__mem_fault) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
551 return; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
552 hexMemCount -= len; |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
553 hexMemDst += len; |
| 0 | 554 } |
| 2 | 555 } |
| 556 | |
| 557 /* Convert COUNT bytes of the hex array pointed to by BUF into binary | |
| 558 to be placed in MEM. Return a pointer to the character AFTER the | |
| 559 last byte written. | |
| 560 | |
| 561 If MAY_FAULT is set, we will return a non-zero value if a memory | |
| 562 fault occurs (and we assume that MEM is a pointer into the user | |
| 563 program). Otherwise, we will take a trap just like any other memory | |
| 564 fault (and assume that MEM points into the stub's memory). */ | |
| 0 | 565 |
| 2 | 566 char * |
| 567 __hex2mem (buf, mem, count, may_fault) | |
| 568 char *buf; | |
| 569 char *mem; | |
| 570 int count; | |
| 571 int may_fault; | |
| 572 { | |
| 573 hexMemSrc = (unsigned char *) buf; | |
| 574 hexMemDst = (unsigned char *) mem; | |
| 575 hexMemCount = count; | |
| 576 may_fault_mode = may_fault; | |
| 0 | 577 |
| 2 | 578 if (may_fault) |
| 579 { | |
| 580 if (__set_mem_fault_trap (__hex2mem_helper)) | |
| 581 return 0; | |
| 582 } | |
| 583 else | |
| 584 __hex2mem_helper (); | |
| 585 | |
| 586 return (char *) hexMemDst; | |
| 587 } | |
| 588 | |
| 589 void | |
| 590 set_debug_traps (void) | |
| 591 { | |
| 592 __install_traps (); | |
| 593 initialized = 1; /* FIXME: Change this to dbg_stub_initialized */ | |
| 0 | 594 } |
| 595 | |
| 596 /* | |
| 597 * While we find nice hex chars, build an int. | |
| 598 * Return number of chars processed. | |
| 599 */ | |
| 600 | |
| 2 | 601 unsigned int |
| 602 __hexToInt (char **ptr, target_register_t *intValue) | |
| 0 | 603 { |
| 604 int numChars = 0; | |
| 605 int hexValue; | |
| 606 | |
| 607 *intValue = 0; | |
| 608 | |
| 609 while (**ptr) | |
| 610 { | |
| 2 | 611 hexValue = stubhex (**ptr); |
| 0 | 612 if (hexValue < 0) |
| 2 | 613 break; |
| 0 | 614 |
| 615 *intValue = (*intValue << 4) | hexValue; | |
| 616 numChars ++; | |
| 617 | |
| 618 (*ptr)++; | |
| 619 } | |
| 620 | |
| 621 return (numChars); | |
| 622 } | |
| 623 | |
| 624 /* | |
| 625 * Complement of __hexToInt: take an int of size "numBits", | |
| 626 * convert it to a hex string. Return length of (unterminated) output. | |
| 627 */ | |
| 628 | |
| 629 unsigned int | |
| 630 __intToHex (char *ptr, target_register_t intValue, int numBits) | |
| 631 { | |
| 632 int numChars = 0; | |
| 633 | |
| 634 if (intValue == 0) | |
| 635 { | |
| 636 *(ptr++) = '0'; | |
| 637 *(ptr++) = '0'; | |
| 638 return 2; | |
| 639 } | |
| 640 | |
| 641 numBits = (numBits + 7) / 8; | |
| 642 while (numBits) | |
| 643 { | |
| 644 int v = (intValue >> ((numBits - 1) * 8)); | |
| 645 if (v || (numBits == 1)) | |
| 2 | 646 { |
| 647 v = v & 255; | |
| 648 *(ptr++) = __tohex ((v / 16) & 15); | |
| 649 *(ptr++) = __tohex (v & 15); | |
| 650 numChars += 2; | |
| 651 } | |
| 0 | 652 numBits--; |
| 653 } | |
| 654 | |
| 655 return (numChars); | |
| 656 } | |
| 657 | |
| 2 | 658 #if DEBUG_THREADS |
| 659 /* | |
| 660 * Kernel Thread Control | |
| 661 * | |
| 662 * If the current thread is set to other than zero (or minus one), | |
| 663 * then ask the kernel to lock it's scheduler so that only that thread | |
| 664 * can run. | |
| 665 */ | |
| 666 | |
| 667 static unsigned char did_lock_scheduler = 0; | |
| 668 static unsigned char did_disable_interrupts = 0; | |
| 669 | |
| 670 /* Pointer to "kernel call" for scheduler control */ | |
| 671 static int (*schedlock_fn) (int, int, long) = stub_lock_scheduler; | |
| 672 | |
| 673 /* Pointer to target stub call for disabling interrupts. | |
| 674 Target stub will initialize this if it can. */ | |
| 675 int (*__disable_interrupts_hook) (int); /* don't initialize here! */ | |
| 676 #endif | |
| 677 | |
| 678 static void | |
| 679 lock_thread_scheduler (int kind) /* "step" or "continue" */ | |
| 680 { | |
| 681 #if DEBUG_THREADS | |
| 682 int ret = 0; | |
| 683 | |
| 684 /* GDB will signal its desire to run a single thread | |
| 685 by setting _gdb_cont_thread to non-zero / non-negative. */ | |
| 686 if (_gdb_cont_thread <= 0) | |
| 687 return; | |
| 688 | |
| 689 if (schedlock_fn) /* kernel call */ | |
| 690 ret = (*schedlock_fn) (1, kind, _gdb_cont_thread); | |
| 691 | |
| 692 if (ret == 1) | |
| 693 { | |
| 694 did_lock_scheduler = 1; | |
| 695 return; | |
| 696 } | |
| 697 | |
| 698 if (schedlock_fn == 0 || /* no kernel scheduler call */ | |
| 699 ret == -1) /* kernel asks stub to handle it */ | |
| 700 if (__disable_interrupts_hook) /* target stub has capability */ | |
| 701 if ((*__disable_interrupts_hook) (1)) | |
| 702 { | |
| 703 did_disable_interrupts = 1; | |
| 704 return; | |
| 705 } | |
| 706 #endif /* DEBUG_THREADS */ | |
| 707 } | |
| 708 | |
| 709 static void | |
| 710 unlock_thread_scheduler () | |
| 711 { | |
| 712 #if DEBUG_THREADS | |
| 713 if (did_lock_scheduler) | |
| 714 if (schedlock_fn) /* kernel call */ | |
| 715 { | |
| 716 (*schedlock_fn) (0, 0, _gdb_cont_thread); | |
| 717 /* I could check the return value, but | |
| 718 what would I do if it failed??? */ | |
| 719 did_lock_scheduler = 0; | |
| 720 } | |
| 721 if (did_disable_interrupts) | |
| 722 if (__disable_interrupts_hook) /* target stub call */ | |
| 723 { | |
| 724 (*__disable_interrupts_hook) (0); | |
| 725 /* Again, I could check the return value, but | |
| 726 what would I do if it failed??? */ | |
| 727 did_disable_interrupts = 0; | |
| 728 } | |
| 729 #endif /* DEBUG_THREADS */ | |
| 730 } | |
| 731 | |
| 0 | 732 void |
| 733 __handle_exception (void) | |
| 734 { | |
| 735 int sigval; | |
| 736 | |
| 2 | 737 #ifdef TARGET_HAS_NEXT_STEP |
| 738 if (! __next_step_done ()) | |
| 739 { | |
| 740 __clear_breakpoints (); | |
| 741 __install_breakpoints (); | |
| 742 __single_step (); | |
| 743 return; | |
| 744 } | |
| 745 #endif | |
| 0 | 746 |
| 2 | 747 #ifdef __ECOS__ |
| 748 // We need to unpack the registers before they are accessed. | |
| 749 if (__cleanup_vec != NULL) | |
| 750 __cleanup_vec (); | |
| 0 | 751 |
| 2 | 752 #ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT |
| 753 // Special case for GDB BREAKs. This flag is set by cyg_stub_cleanup. | |
| 754 if (cyg_hal_gdb_break) { | |
| 755 cyg_hal_gdb_break = 0; | |
| 756 sigval = SIGINT; | |
| 757 } else | |
| 758 #endif | |
| 759 sigval = __computeSignal (__get_trap_number ()); | |
| 760 #else // __ECOS__ | |
| 0 | 761 /* reply to host that an exception has occurred */ |
| 762 sigval = __computeSignal (__get_trap_number ()); | |
| 2 | 763 #endif // __ECOS__ |
| 0 | 764 |
| 765 if (__is_breakpoint_function ()) | |
| 766 __skipinst (); | |
| 767 | |
| 2 | 768 #ifndef __ECOS__ |
| 769 if (__cleanup_vec != NULL) | |
| 770 __cleanup_vec (); | |
| 771 #endif // !__ECOS__ | |
| 772 | |
| 773 __clear_breakpoints (); | |
| 774 | |
| 775 /* Undo effect of previous single step. */ | |
| 776 unlock_thread_scheduler (); | |
| 777 __clear_single_step (); | |
| 778 | |
| 779 #ifdef SIGSYSCALL | |
| 780 if (sigval == SIGSYSCALL) | |
| 0 | 781 { |
| 782 int val; | |
| 783 /* Do the skipinst FIRST. */ | |
| 2 | 784 #ifndef SYSCALL_PC_AFTER_INST |
| 0 | 785 __skipinst (); |
| 2 | 786 #endif |
| 0 | 787 val = __process_syscall_vec (__get_syscall_num ()); |
| 2 | 788 if (val < 0) |
| 789 sigval = -val; | |
| 790 else | |
| 791 sigval = 0; | |
| 0 | 792 } |
| 793 | |
| 794 #endif | |
| 795 | |
| 2 | 796 /* Indirect function call to stub, cygmon monitor or other */ |
| 797 if (sigval != 0) | |
| 798 { | |
| 799 while (__process_exception_vec (sigval)) | |
| 800 { | |
| 801 /* Empty! */ | |
| 802 } | |
| 803 } | |
| 0 | 804 |
| 2 | 805 __install_breakpoints (); |
| 0 | 806 |
| 2 | 807 if (__init_vec != NULL) |
| 808 __init_vec (); | |
| 0 | 809 } |
| 810 | |
| 2 | 811 /* |
| 812 * _get_trace_register_hook: | |
| 813 * This function pointer will be non-zero if the trace component | |
| 814 * wants to intercept requests for register values. | |
| 815 * | |
| 816 * FIXME: evidently I need a new hook for large registers... | |
| 817 */ | |
| 818 | |
| 819 int (*_get_trace_register_hook) (regnames_t, target_register_t *); | |
| 820 | |
| 821 int | |
| 822 __process_packet (char *packet) | |
| 0 | 823 { |
| 2 | 824 int is_binary = 0; |
| 0 | 825 remcomOutBuffer[0] = 0; |
| 826 | |
| 827 switch (packet[0]) | |
| 828 { | |
| 829 case '?': | |
| 830 { | |
| 2 | 831 int sigval = __computeSignal (__get_trap_number ()); |
| 832 remcomOutBuffer[0] = 'S'; | |
| 833 remcomOutBuffer[1] = hexchars[(sigval >> 4) & 0xf]; | |
| 834 remcomOutBuffer[2] = hexchars[sigval & 0xf]; | |
| 835 remcomOutBuffer[3] = 0; | |
| 836 break; | |
| 0 | 837 } |
| 838 | |
| 839 case 'd': | |
| 840 /* toggle debug flag */ | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
34
diff
changeset
|
841 #ifdef __ECOS__ |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
34
diff
changeset
|
842 #if !defined(CYG_HAL_STARTUP_RAM) // Only for ROM based stubs |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
34
diff
changeset
|
843 strcpy(remcomOutBuffer, "eCos GDB stubs - built " __DATE__ " / " __TIME__); |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
34
diff
changeset
|
844 #endif |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
34
diff
changeset
|
845 #endif // __ECOS__ |
| 0 | 846 break; |
| 847 | |
| 848 case 'q': | |
| 849 /* general query packet */ | |
| 850 process_query (&packet[1]); | |
| 851 break; | |
| 852 | |
| 853 case 'Q': | |
| 854 /* general set packet */ | |
| 855 process_set (&packet[1]); | |
| 856 break; | |
| 857 | |
| 2 | 858 case 'g': /* return the value of the CPU registers */ |
| 0 | 859 { |
| 2 | 860 char *ptr = remcomOutBuffer; |
| 861 int regnum; | |
| 862 | |
| 863 for (regnum = 0; regnum < NUMREGS_GDB; regnum++) | |
| 864 { | |
| 865 /* We need to compensate for the value offset within the | |
| 866 register. */ | |
| 867 char dummyDat[32]; | |
| 868 target_register_t addr; | |
| 869 char *vptr; | |
| 870 int reg_valid = 1; | |
| 871 | |
| 872 #ifdef TARGET_HAS_LARGE_REGISTERS | |
| 873 if (sizeof (target_register_t) < REGSIZE (regnum)) | |
| 874 { | |
| 875 get_register_as_bytes (regnum, dummyDat); | |
| 876 vptr = dummyDat; | |
| 877 } | |
| 878 else | |
| 879 #endif | |
| 880 { | |
| 881 if (_get_trace_register_hook) | |
| 882 reg_valid = _get_trace_register_hook (regnum, &addr); | |
| 883 else | |
| 884 addr = get_register (regnum); | |
| 885 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
886 vptr = ((char *) &addr); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
887 if (sizeof (addr) > REGSIZE(regnum)) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
888 { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
889 /* May need to cope with endian-ness */ |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
890 |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
891 #if !defined(__LITTLE_ENDIAN__) && !defined(_LITTLE_ENDIAN) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
892 vptr += sizeof (addr) - REGSIZE (regnum); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
893 #endif |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
894 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
895 else if (sizeof (addr) < REGSIZE (regnum)) |
| 2 | 896 { |
| 897 int off = REGSIZE (regnum) - sizeof (addr); | |
| 898 int x; | |
| 0 | 899 |
| 2 | 900 for (x = 0; x < off; x++) |
| 901 dummyDat[x] = 0; | |
| 902 memcpy (dummyDat + off, &addr, sizeof (addr)); | |
| 903 vptr = dummyDat; | |
| 904 } | |
| 905 } | |
| 906 if (reg_valid) /* we have a valid reg value */ | |
| 907 { | |
| 908 ptr = __mem2hex (vptr, ptr, REGSIZE (regnum), 0); | |
| 909 } | |
| 910 else | |
| 911 { | |
| 912 /* Trace component returned a failure code. | |
| 913 This means that the register value is not available. | |
| 914 We'll fill it with 'x's, and GDB will understand. */ | |
| 915 memset (ptr, 'x', 2 * REGSIZE (regnum)); | |
| 916 ptr += 2 * REGSIZE (regnum); | |
| 917 } | |
| 918 } | |
| 919 break; | |
| 920 } | |
| 0 | 921 |
| 2 | 922 case 'A': /* set program arguments */ |
| 923 { | |
| 924 if (packet[1] == '\0') | |
| 925 { | |
| 926 __free_program_args (); | |
| 927 strcpy (remcomOutBuffer, "OK"); | |
| 928 } | |
| 929 else | |
| 930 { | |
| 931 target_register_t arglen, argnum; | |
| 932 char *ptr = &packet[1]; | |
| 933 | |
| 934 while (1) | |
| 935 { | |
| 936 if (__hexToInt (&ptr, &arglen) | |
| 937 && (*ptr++ == ',') | |
| 938 && __hexToInt (&ptr, &argnum) | |
| 939 && (*ptr++ == ',')) | |
| 940 { | |
| 941 if (arglen > 0) | |
| 942 { | |
| 943 char *s = __add_program_arg (argnum, arglen); | |
| 944 if (s != NULL) | |
| 945 { | |
| 946 __hex2mem (ptr, s, arglen, 0); | |
| 947 } | |
| 948 ptr += arglen * 2; | |
| 949 } | |
| 950 | |
| 951 if (*ptr == ',') | |
| 952 ptr++; | |
| 953 else | |
| 954 break; | |
| 955 } | |
| 956 else | |
| 957 break; | |
| 958 } | |
| 959 if (*ptr == '\0') | |
| 960 strcpy (remcomOutBuffer, "OK"); | |
| 961 else | |
| 962 strcpy (remcomOutBuffer, "E01"); | |
| 963 } | |
| 0 | 964 } |
| 2 | 965 break; |
| 0 | 966 |
| 967 case 'P': | |
| 2 | 968 case 'G': /* set the value of the CPU registers - return OK */ |
| 0 | 969 { |
| 2 | 970 int x; |
| 971 int sr = 0, er = NUMREGS_GDB; | |
| 972 char *ptr = &packet[1]; | |
| 973 | |
| 974 if (packet[0] == 'P') | |
| 975 { | |
| 976 target_register_t regno; | |
| 0 | 977 |
| 2 | 978 if (__hexToInt (&ptr, ®no) |
| 979 && (*ptr++ == '=')) | |
| 980 { | |
| 981 sr = regno; | |
| 982 er = regno + 1; | |
| 983 } | |
| 984 else | |
| 985 { | |
| 986 strcpy (remcomOutBuffer, "P01"); | |
| 987 break; | |
| 988 } | |
| 989 } | |
| 0 | 990 |
| 2 | 991 for (x = sr; x < er; x++) |
| 992 { | |
| 993 target_register_t value = 0; | |
| 994 char *vptr; | |
| 995 | |
| 996 #ifdef TARGET_HAS_LARGE_REGISTERS | |
| 997 if (sizeof (target_register_t) < REGSIZE (x)) | |
| 998 { | |
| 999 char dummyDat [32]; | |
| 0 | 1000 |
| 2 | 1001 __hex2mem (ptr, dummyDat, REGSIZE (x), 0); |
| 1002 put_register_as_bytes (x, dummyDat); | |
| 1003 } | |
| 1004 else | |
| 1005 #endif | |
| 1006 { | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1007 vptr = ((char *) &value); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1008 #if !defined(__LITTLE_ENDIAN__) && !defined(_LITTLE_ENDIAN) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1009 vptr += sizeof (value) - REGSIZE (x); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1010 #endif |
| 2 | 1011 __hex2mem (ptr, vptr, REGSIZE (x), 0); |
| 1012 put_register (x, value); | |
| 1013 } | |
| 1014 ptr += REGSIZE (x) * 2; | |
| 1015 } | |
| 0 | 1016 |
| 2 | 1017 strcpy (remcomOutBuffer, "OK"); |
| 1018 break; | |
| 0 | 1019 } |
| 1020 | |
| 2 | 1021 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ |
| 0 | 1022 /* Try to read %x,%x. */ |
| 1023 { | |
| 2 | 1024 target_register_t addr, length; |
| 1025 char *ptr = &packet[1]; | |
| 0 | 1026 |
| 2 | 1027 if (__hexToInt (&ptr, &addr) |
| 1028 && *ptr++ == ',' | |
| 1029 && __hexToInt (&ptr, &length)) | |
| 1030 { | |
| 1031 if (__mem2hex ((char *) addr, remcomOutBuffer, length, 1)) | |
| 1032 break; | |
| 0 | 1033 |
| 2 | 1034 strcpy (remcomOutBuffer, "E03"); |
| 1035 } | |
| 1036 else | |
| 1037 strcpy (remcomOutBuffer, "E01"); | |
| 1038 break; | |
| 0 | 1039 } |
| 1040 | |
| 2 | 1041 case 'X': |
| 1042 /* XAA..AA,LLLL: Write LLLL escaped binary bytes at address AA.AA */ | |
| 1043 is_binary = 1; | |
| 1044 /* fall through */ | |
| 0 | 1045 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ |
| 1046 /* Try to read '%x,%x:'. */ | |
| 1047 { | |
| 2 | 1048 target_register_t addr, length; |
| 1049 char *ptr = &packet[1], buf[128]; | |
| 1050 int i; | |
| 1051 | |
| 1052 if (__hexToInt (&ptr, &addr) | |
| 1053 && *ptr++ == ',' | |
| 1054 && __hexToInt (&ptr, &length) | |
| 1055 && *ptr++ == ':') | |
| 1056 { | |
| 1057 if (is_binary) | |
| 1058 { | |
| 1059 while (length > 0) | |
| 1060 { | |
| 1061 for (i = 0; i < sizeof(buf) && i < length; i++) | |
| 1062 if ((buf[i] = *ptr++) == 0x7d) | |
| 1063 buf[i] = 0x20 | (*ptr++ & 0xff); | |
| 1064 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1065 if (__write_mem_safe (buf, (void *)addr, i) != i) |
| 2 | 1066 break; |
| 0 | 1067 |
| 2 | 1068 length -= i; |
| 1069 addr += i; | |
| 1070 } | |
| 1071 if (length <= 0) | |
| 1072 strcpy (remcomOutBuffer, "OK"); | |
| 1073 else | |
| 1074 strcpy (remcomOutBuffer, "E03"); | |
| 1075 } | |
| 1076 else | |
| 1077 { | |
| 1078 if (__hex2mem (ptr, (char *) addr, length, 1) != NULL) | |
| 1079 strcpy (remcomOutBuffer, "OK"); | |
| 1080 else | |
| 1081 strcpy (remcomOutBuffer, "E03"); | |
| 1082 } | |
| 1083 } | |
| 1084 else | |
| 1085 strcpy (remcomOutBuffer, "E02"); | |
| 1086 break; | |
| 0 | 1087 } |
| 1088 | |
| 1089 case 'S': | |
| 2 | 1090 case 's': /* sAA..AA Step from address AA..AA (optional) */ |
| 0 | 1091 case 'C': |
| 2 | 1092 case 'c': /* cAA..AA Continue at address AA..AA (optional) */ |
| 0 | 1093 /* try to read optional parameter, pc unchanged if no parm */ |
| 1094 | |
| 1095 { | |
| 2 | 1096 char *ptr = &packet[1]; |
| 1097 target_register_t addr; | |
| 1098 target_register_t sigval = 0; | |
| 1099 | |
| 1100 if (packet[0] == 'C' || packet[0] == 'S') | |
| 1101 { | |
| 1102 __hexToInt (&ptr, &sigval); | |
| 1103 if (*ptr == ';') | |
| 1104 ptr++; | |
| 1105 } | |
| 0 | 1106 |
| 2 | 1107 if (__hexToInt (&ptr, &addr)) |
| 1108 set_pc (addr); | |
| 1109 | |
| 1110 /* Need to flush the instruction cache here, as we may have | |
| 1111 deposited a breakpoint, and the icache probably has no way of | |
| 1112 knowing that a data ref to some location may have changed | |
| 1113 something that is in the instruction cache. */ | |
| 1114 | |
| 1115 #ifdef __ECOS__ | |
| 1116 __data_cache (CACHE_FLUSH) ; | |
| 1117 #endif | |
| 1118 __instruction_cache (CACHE_FLUSH) ; | |
| 0 | 1119 |
| 2 | 1120 /* If we have a function to handle signals, call it. */ |
| 1121 if (sigval != 0 && __process_signal_vec != NULL) | |
| 1122 { | |
| 1123 /* If 0 is returned, we either ignored the signal or invoked a user | |
| 1124 handler. Otherwise, the user program should die. */ | |
| 1125 if (! __process_signal_vec (sigval)) | |
| 1126 sigval = 0; | |
| 1127 } | |
| 0 | 1128 |
| 2 | 1129 if (sigval != 0) |
| 1130 { | |
| 1131 sigval = SIGKILL; /* Always nuke the program */ | |
| 1132 __kill_program (sigval); | |
| 1133 return 0; | |
| 1134 } | |
| 0 | 1135 |
| 2 | 1136 /* Set machine state to force a single step. */ |
| 1137 if (packet[0] == 's' || packet[0] == 'S') | |
| 1138 { | |
| 1139 lock_thread_scheduler (0); /* 0 == single-step */ | |
| 1140 #ifdef __ECOS__ | |
| 1141 // PR 19845 workaround: | |
| 1142 // Make sure the single-step magic affects the correct registers. | |
| 1143 _registers = ®isters[0]; | |
| 1144 #endif | |
| 1145 __single_step (); | |
| 1146 } | |
| 1147 else | |
| 1148 { | |
| 1149 lock_thread_scheduler (1); /* 1 == continue */ | |
| 1150 } | |
| 0 | 1151 |
|
28
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1152 #ifdef __ECOS__ |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1153 /* Need to flush the data and instruction cache here, as we may have |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1154 deposited a breakpoint in __single_step. */ |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1155 |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1156 __data_cache (CACHE_FLUSH) ; |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1157 __instruction_cache (CACHE_FLUSH) ; |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1158 #endif |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1159 |
| 2 | 1160 return -1; |
| 0 | 1161 } |
| 1162 | |
| 1163 /* kill the program */ | |
| 1164 case 'k' : | |
| 1165 __process_exit_vec (); | |
| 1166 return 1; | |
| 2 | 1167 |
| 1168 case 'r': /* Reset */ | |
| 0 | 1169 __reset (); |
| 1170 break; | |
| 2 | 1171 |
| 0 | 1172 case 'H': |
| 1173 STUB_PKT_CHANGETHREAD (packet+1, remcomOutBuffer, 300) ; | |
| 1174 break ; | |
| 1175 case 'T' : | |
| 1176 STUB_PKT_THREAD_ALIVE (packet+1, remcomOutBuffer, 300) ; | |
| 1177 break ; | |
| 2 | 1178 case 'B': |
| 1179 /* breakpoint */ | |
| 0 | 1180 { |
| 2 | 1181 target_register_t addr; |
| 1182 char mode; | |
| 1183 char *ptr = &packet[1]; | |
| 1184 if (__hexToInt (&ptr, &addr) && *(ptr++) == ',') | |
| 1185 { | |
| 1186 mode = *(ptr++); | |
| 1187 if (mode == 'C') | |
| 1188 __remove_breakpoint (addr); | |
| 1189 else | |
| 1190 __set_breakpoint (addr); | |
| 1191 strcpy (remcomOutBuffer, "OK"); | |
| 1192 } | |
| 1193 else | |
| 1194 { | |
| 1195 strcpy (remcomOutBuffer, "E01"); | |
| 1196 } | |
| 1197 break; | |
| 1198 } | |
| 0 | 1199 |
| 2 | 1200 case 'b': /* bBB... Set baud rate to BB... */ |
| 1201 { | |
| 1202 target_register_t baudrate; | |
| 0 | 1203 |
| 2 | 1204 char *ptr = &packet[1]; |
| 1205 if (!__hexToInt (&ptr, &baudrate)) | |
| 1206 { | |
| 1207 strcpy (remcomOutBuffer, "B01"); | |
| 1208 break; | |
| 1209 } | |
| 1210 | |
| 1211 __putpacket ("OK"); /* Ack before changing speed */ | |
| 1212 __set_baud_rate (baudrate); | |
| 1213 break; | |
| 0 | 1214 } |
| 2 | 1215 default: |
| 1216 __process_target_packet (packet, remcomOutBuffer, 300); | |
| 1217 break; | |
| 0 | 1218 } |
| 1219 | |
| 1220 /* reply to the request */ | |
| 2 | 1221 __putpacket (remcomOutBuffer); |
| 0 | 1222 return 0; |
| 1223 } | |
| 1224 | |
| 1225 static void | |
| 1226 send_t_packet (int sigval) | |
| 1227 { | |
| 1228 __build_t_packet (sigval, remcomOutBuffer); | |
| 2 | 1229 __putpacket (remcomOutBuffer); |
| 0 | 1230 } |
| 1231 | |
| 1232 /* | |
| 1233 * This function does all command procesing for interfacing to gdb. | |
| 1234 */ | |
| 1235 | |
| 1236 static int | |
| 1237 process_exception (int sigval) | |
| 1238 { | |
| 1239 int status; | |
| 1240 | |
| 1241 /* Nasty. */ | |
| 1242 if (ungot_char < 0) | |
| 1243 send_t_packet (sigval); | |
| 1244 | |
| 1245 do { | |
| 1246 getpacket (remcomInBuffer); | |
| 2 | 1247 status = __process_packet (remcomInBuffer); |
| 0 | 1248 } while (status == 0); |
| 1249 | |
| 1250 if (status < 0) | |
| 1251 return 0; | |
| 1252 else | |
| 1253 return 1; | |
| 1254 } | |
| 1255 | |
| 1256 void | |
| 1257 __send_exit_status (int status) | |
| 1258 { | |
| 1259 remcomOutBuffer[0] = 'W'; | |
| 1260 remcomOutBuffer[1] = hexchars[(status >> 4) & 0xf]; | |
| 1261 remcomOutBuffer[2] = hexchars[status & 0xf]; | |
| 1262 remcomOutBuffer[3] = 0; | |
| 2 | 1263 __putpacket (remcomOutBuffer); |
| 0 | 1264 } |
| 1265 | |
| 2 | 1266 /* Read up to MAXLEN bytes from the remote GDB client, and store in DEST |
| 1267 (which is a pointer in the user program). BLOCK indicates what mode | |
| 1268 is being used; if it is set, we will wait for MAXLEN bytes to be | |
| 1269 entered. Otherwise, the function will return immediately with whatever | |
| 1270 bytes are waiting to be read. | |
| 1271 | |
| 1272 The value returned is the number of bytes read. A -1 indicates that an | |
| 1273 error of some sort occurred. */ | |
| 1274 | |
| 0 | 1275 int |
| 2 | 1276 __get_gdb_input (target_register_t dest, int maxlen, int block) |
| 0 | 1277 { |
| 1278 char buf[4]; | |
| 1279 int len, i; | |
| 2 | 1280 char d; |
| 0 | 1281 |
| 1282 buf[0] = 'I'; | |
| 1283 buf[1] = '0'; | |
| 1284 buf[2] = block ? '0' : '1'; | |
| 1285 buf[3] = 0; | |
| 2 | 1286 __putpacket (buf); |
| 0 | 1287 getpacket (remcomInBuffer); |
| 1288 if (remcomInBuffer[0] != 'I') | |
| 1289 return -1; | |
| 1290 len = stubhex (remcomInBuffer[1]) * 16 + stubhex (remcomInBuffer[2]); | |
| 1291 for (i = 0; i < len; i++) | |
| 1292 { | |
| 2 | 1293 d = stubhex (remcomInBuffer[3 + i * 2]) * 16; |
| 1294 d |= stubhex (remcomInBuffer[3 + i * 2 + 1]); | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1295 __write_mem_safe (&d, (void *)(dest + i), 1); |
| 0 | 1296 } |
| 2 | 1297 /* Write the trailing \0. */ |
| 1298 d = '\0'; | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1299 __write_mem_safe (&d, (void *)(dest + i), 1); |
| 0 | 1300 return len; |
| 1301 } | |
| 1302 | |
| 1303 void | |
| 1304 __output_hex_value (target_register_t i) | |
| 1305 { | |
| 1306 char buf[32], *ptr=buf+31; | |
| 1307 unsigned int x; | |
| 1308 | |
| 1309 *ptr = 0; | |
| 2 | 1310 for (x = 0; x < (sizeof (i) * 2); x++) |
| 0 | 1311 { |
| 1312 *(--ptr) = hexchars[i & 15]; | |
| 1313 i = i >> 4; | |
| 1314 } | |
| 1315 while (*ptr) | |
| 1316 { | |
| 1317 putDebugChar (*(ptr++)); | |
| 1318 } | |
| 1319 } | |
| 1320 | |
| 2 | 1321 /* Write the C-style string pointed to by STR to the GDB comm port. */ |
| 1322 void | |
| 1323 __putDebugStr (char *str) | |
| 1324 { | |
| 1325 while (*str) | |
| 1326 { | |
| 1327 putDebugChar (*str); | |
| 1328 str++; | |
| 1329 } | |
| 1330 } | |
| 1331 | |
| 1332 /* Send STRING_LEN bytes of STR to GDB, using 'O' packets. | |
| 1333 STR is assumed to be in the program being debugged. */ | |
| 1334 | |
| 0 | 1335 int |
| 2 | 1336 __output_gdb_string (target_register_t str, int string_len) |
| 0 | 1337 { |
| 2 | 1338 /* We will arbitrarily limit output packets to less than 400 bytes. */ |
| 1339 static char buf[400]; | |
| 0 | 1340 int x; |
| 1341 int len; | |
| 1342 | |
| 1343 if (string_len == 0) | |
| 2 | 1344 { |
| 1345 /* We can't do strlen on a user pointer. */ | |
| 1346 return -1; | |
| 1347 } | |
| 0 | 1348 |
| 2 | 1349 len = string_len; |
| 1350 while (len > 0) | |
| 0 | 1351 { |
| 2 | 1352 int packetlen = ((len < 175) ? len : 175); |
| 1353 buf[0] = 'O'; | |
| 1354 for (x = 0; x < packetlen; x++) | |
| 1355 { | |
| 1356 char c; | |
| 1357 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1358 __read_mem_safe (&c, (void *)(str + x), 1); |
| 2 | 1359 buf[x*2+1] = hexchars[(c >> 4) & 0xf]; |
| 1360 buf[x*2+2] = hexchars[c % 16]; | |
| 1361 } | |
| 1362 str += x; | |
| 1363 len -= x; | |
| 1364 buf[x*2+1] = 0; | |
| 1365 __putpacket (buf); | |
| 0 | 1366 } |
| 1367 return string_len; | |
| 1368 } | |
| 1369 | |
| 1370 static void | |
| 1371 do_nothing (void) | |
| 1372 { | |
| 1373 /* mmmm */ | |
| 1374 } | |
| 1375 | |
| 1376 static int | |
| 1377 syscall_do_nothing (int junk) | |
| 1378 { | |
| 1379 return 0; | |
| 1380 } | |
| 1381 | |
| 1382 /* Start the stub running. */ | |
| 1383 void | |
| 2 | 1384 __switch_to_stub (void) |
| 0 | 1385 { |
| 1386 __process_exception_vec = process_exception; | |
| 1387 } | |
| 1388 | |
| 2 | 1389 #if ! defined(BOARD_SPECIFIC_STUB_INIT) |
| 1390 void | |
| 1391 initialize_stub (void) | |
| 1392 { | |
| 1393 set_debug_traps (); | |
| 1394 /* FIXME: This function should be renamed to specifically init the | |
| 1395 hardware required by debug operations. If initHardware is implemented at | |
| 1396 all, it should be called before main (). | |
| 1397 */ | |
| 1398 initHardware () ; | |
| 1399 /* This acks any stale packets , NOT an effective solution */ | |
| 1400 putDebugChar ('+'); | |
| 1401 } | |
| 1402 #endif | |
| 1403 | |
| 0 | 1404 void |
| 1405 ungetDebugChar (int c) | |
| 1406 { | |
| 1407 ungot_char = c; | |
| 1408 } | |
| 1409 | |
| 2 | 1410 void |
| 1411 __kill_program (int sigval) | |
| 0 | 1412 { |
| 1413 remcomOutBuffer[0] = 'X'; | |
| 1414 remcomOutBuffer[1] = hexchars[(sigval >> 4) & 15]; | |
| 1415 remcomOutBuffer[2] = hexchars[sigval & 15]; | |
| 1416 remcomOutBuffer[3] = 0; | |
| 2 | 1417 __putpacket (remcomOutBuffer); |
| 1418 } | |
| 1419 | |
| 1420 #define MAX_ARG_COUNT 20 | |
| 1421 #define MAX_ARGDATA 128 | |
| 1422 | |
| 1423 static char *program_argv [MAX_ARG_COUNT]; | |
| 1424 static int program_argc; | |
| 1425 static int last_program_arg; | |
| 1426 static char program_argstr [MAX_ARGDATA], *argptr; | |
| 1427 static int args_initted = 0; | |
| 1428 | |
| 1429 void | |
| 1430 __free_program_args (void) | |
| 1431 { | |
| 1432 last_program_arg = -1; | |
| 1433 program_argc = 0; | |
| 1434 program_argv [0] = NULL; | |
| 1435 argptr = program_argstr; | |
| 1436 args_initted = 1; | |
| 1437 } | |
| 1438 | |
| 1439 static char * | |
| 1440 __add_program_arg (int argc, uint32 len) | |
| 1441 { | |
| 1442 char *res; | |
| 1443 | |
| 1444 if (! args_initted) | |
| 1445 { | |
| 1446 __free_program_args (); | |
| 1447 } | |
| 1448 | |
| 1449 if ((argc >= (MAX_ARG_COUNT - 1)) | |
| 1450 || ((argptr - program_argstr + len) > MAX_ARGDATA)) | |
| 1451 { | |
| 1452 return NULL; | |
| 1453 } | |
| 1454 | |
| 1455 if (argc != last_program_arg) | |
| 1456 { | |
| 1457 if (argc >= program_argc) | |
| 1458 { | |
| 1459 program_argc = argc + 1; | |
| 1460 program_argv [program_argc] = NULL; | |
| 1461 } | |
| 1462 program_argv [argc] = argptr; | |
| 1463 last_program_arg = argc; | |
| 1464 } | |
| 1465 | |
| 1466 res = argptr; | |
| 1467 argptr += len; | |
| 1468 | |
| 1469 return res; | |
| 1470 } | |
| 1471 | |
| 1472 void | |
| 1473 __set_program_args (int argc, char **argv) | |
| 1474 { | |
| 1475 int x; | |
| 1476 | |
| 1477 __free_program_args (); | |
| 1478 if (argc) | |
| 1479 { | |
| 1480 for (x = 0; x < argc; x++) | |
| 1481 { | |
| 1482 uint32 len = strlen (argv[x])+1; | |
| 1483 char *s = __add_program_arg (x, len); | |
| 1484 | |
| 1485 if (s == NULL) | |
| 1486 return; | |
| 1487 | |
| 1488 memcpy (s, argv[x], len); | |
| 1489 } | |
| 1490 } | |
| 1491 } | |
| 1492 | |
| 1493 char ** | |
| 1494 __get_program_args (target_register_t argcPtr) | |
| 1495 { | |
| 1496 if (!args_initted) | |
| 1497 { | |
| 1498 __free_program_args (); | |
| 1499 } | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1500 __write_mem_safe ((char *) &program_argc, (void *)argcPtr, sizeof (program_argc)); |
| 2 | 1501 return program_argv; |
| 0 | 1502 } |
| 1503 | |
| 1504 /* Table used by the crc32 function to calcuate the checksum. */ | |
| 1505 static uint32 crc32_table[256]; | |
| 1506 static int tableInit = 0; | |
| 1507 | |
| 1508 /* | |
| 1509 Calculate a CRC-32 using LEN bytes of PTR. CRC is the initial CRC | |
| 1510 value. | |
| 1511 PTR is assumed to be a pointer in the user program. */ | |
| 1512 | |
| 1513 static uint32 | |
| 2 | 1514 crc32 (ptr, len, crc) |
| 1515 unsigned char *ptr; | |
| 1516 int len; | |
| 1517 uint32 crc; | |
| 0 | 1518 { |
| 1519 if (! tableInit) | |
| 1520 { | |
| 1521 /* Initialize the CRC table and the decoding table. */ | |
| 1522 uint32 i, j; | |
| 1523 uint32 c; | |
| 1524 | |
| 1525 tableInit = 1; | |
| 1526 for (i = 0; i < 256; i++) | |
| 2 | 1527 { |
| 1528 for (c = i << 24, j = 8; j > 0; --j) | |
| 1529 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); | |
| 1530 crc32_table[i] = c; | |
| 1531 } | |
| 0 | 1532 } |
| 1533 | |
| 1534 __mem_fault = 0; | |
| 1535 while (len--) | |
| 1536 { | |
| 1537 unsigned char ch; | |
| 1538 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1539 __read_mem_safe (&ch, (void *)ptr, 1); |
| 0 | 1540 if (__mem_fault) |
| 2 | 1541 { |
| 1542 break; | |
| 1543 } | |
| 0 | 1544 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ ch) & 255]; |
| 1545 ptr++; | |
| 1546 } | |
| 1547 return crc; | |
| 1548 } | |
| 1549 | |
| 1550 /* Handle the 'q' request */ | |
| 1551 | |
| 1552 static void | |
| 1553 process_query (char *pkt) | |
| 1554 { | |
| 1555 remcomOutBuffer[0] = '\0'; | |
| 2 | 1556 #ifdef __ECOS__ |
| 0 | 1557 if ('C' == pkt[0] && |
| 1558 'R' == pkt[1] && | |
| 1559 'C' == pkt[2] && | |
| 1560 ':' == pkt[3]) | |
| 2 | 1561 #else // __ECOS__ |
| 1562 if (strncmp (pkt, "CRC:", 4) == 0) | |
| 1563 #endif // __ECOS__ | |
| 0 | 1564 { |
| 1565 target_register_t startmem; | |
| 1566 target_register_t length; | |
| 1567 uint32 our_crc; | |
| 1568 | |
| 1569 pkt += 4; | |
| 1570 if (__hexToInt (&pkt, &startmem) | |
| 2 | 1571 && *(pkt++) == ',' |
| 1572 && __hexToInt (&pkt, &length)) | |
| 1573 { | |
| 1574 our_crc = crc32 ((unsigned char *) startmem, length, 0xffffffff); | |
| 1575 if (__mem_fault) | |
| 1576 { | |
| 1577 strcpy (remcomOutBuffer, "E01"); | |
| 1578 } | |
| 1579 else | |
| 1580 { | |
| 1581 int numb = __intToHex (remcomOutBuffer + 1, our_crc, 32); | |
| 1582 remcomOutBuffer[0] = 'C'; | |
| 1583 remcomOutBuffer[numb + 1] = 0; | |
| 1584 } | |
| 1585 } | |
| 0 | 1586 return; |
| 1587 } | |
| 1588 else | |
| 1589 { | |
| 1590 char ch ; | |
| 1591 char * subpkt ; | |
| 1592 ch = *pkt ; | |
| 1593 subpkt = pkt + 1 ; | |
| 1594 switch (ch) | |
| 2 | 1595 { |
| 1596 case 'L' : /* threadlistquery */ | |
| 1597 STUB_PKT_GETTHREADLIST (subpkt, remcomOutBuffer, 300); | |
| 1598 break ; | |
| 1599 case 'P' : /* Thread or process information request */ | |
| 1600 STUB_PKT_GETTHREADINFO (subpkt, remcomOutBuffer, 300); | |
| 1601 break ; | |
| 1602 case 'C' : /* current thread query */ | |
| 1603 STUB_PKT_CURRTHREAD(subpkt, remcomOutBuffer, sizeof(remcomOutBuffer)); | |
| 1604 break; | |
| 1605 default: | |
| 1606 __process_target_query (pkt, remcomOutBuffer, 300); | |
| 1607 break ; | |
| 1608 } | |
| 0 | 1609 } |
| 1610 } | |
| 1611 | |
| 1612 /* Handle the 'Q' request */ | |
| 1613 | |
| 1614 static void | |
| 1615 process_set (char *pkt) | |
| 1616 { | |
| 1617 char ch ; | |
| 1618 ch = *pkt ; | |
| 1619 | |
| 1620 switch (ch) | |
| 1621 { | |
| 1622 case 'p' : /* Set current process or thread */ | |
| 1623 /* reserve the packet id even if support is not present */ | |
| 1624 /* Dont strip the 'p' off the header, there are several variations of | |
| 2 | 1625 this packet */ |
| 0 | 1626 STUB_PKT_CHANGETHREAD (pkt, remcomOutBuffer, 300) ; |
| 1627 break ; | |
| 1628 default: | |
| 1629 __process_target_set (pkt, remcomOutBuffer, 300); | |
| 1630 break ; | |
| 1631 } | |
| 1632 } | |
| 1633 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS |
