Mercurial > nand-ecoscentric
annotate packages/hal/common/current/src/generic-stub.c @ 34:29bc183297e1 ecos-sw-1999-09-02
Merge from eCos master repository on 1999-09-02-16:26:10-BST
| author | jlarmour |
|---|---|
| date | Thu, 02 Sep 1999 16:11:22 +0000 |
| parents | 18ee5a9c102e |
| children | e7ba79f6d3a8 |
| 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 */ | |
| 841 break; | |
| 842 | |
| 843 case 'q': | |
| 844 /* general query packet */ | |
| 845 process_query (&packet[1]); | |
| 846 break; | |
| 847 | |
| 848 case 'Q': | |
| 849 /* general set packet */ | |
| 850 process_set (&packet[1]); | |
| 851 break; | |
| 852 | |
| 2 | 853 case 'g': /* return the value of the CPU registers */ |
| 0 | 854 { |
| 2 | 855 char *ptr = remcomOutBuffer; |
| 856 int regnum; | |
| 857 | |
| 858 for (regnum = 0; regnum < NUMREGS_GDB; regnum++) | |
| 859 { | |
| 860 /* We need to compensate for the value offset within the | |
| 861 register. */ | |
| 862 char dummyDat[32]; | |
| 863 target_register_t addr; | |
| 864 char *vptr; | |
| 865 int reg_valid = 1; | |
| 866 | |
| 867 #ifdef TARGET_HAS_LARGE_REGISTERS | |
| 868 if (sizeof (target_register_t) < REGSIZE (regnum)) | |
| 869 { | |
| 870 get_register_as_bytes (regnum, dummyDat); | |
| 871 vptr = dummyDat; | |
| 872 } | |
| 873 else | |
| 874 #endif | |
| 875 { | |
| 876 if (_get_trace_register_hook) | |
| 877 reg_valid = _get_trace_register_hook (regnum, &addr); | |
| 878 else | |
| 879 addr = get_register (regnum); | |
| 880 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
881 vptr = ((char *) &addr); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
882 if (sizeof (addr) > REGSIZE(regnum)) |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
883 { |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
884 /* 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
|
885 |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
886 #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
|
887 vptr += sizeof (addr) - REGSIZE (regnum); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
888 #endif |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
889 } |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
890 else if (sizeof (addr) < REGSIZE (regnum)) |
| 2 | 891 { |
| 892 int off = REGSIZE (regnum) - sizeof (addr); | |
| 893 int x; | |
| 0 | 894 |
| 2 | 895 for (x = 0; x < off; x++) |
| 896 dummyDat[x] = 0; | |
| 897 memcpy (dummyDat + off, &addr, sizeof (addr)); | |
| 898 vptr = dummyDat; | |
| 899 } | |
| 900 } | |
| 901 if (reg_valid) /* we have a valid reg value */ | |
| 902 { | |
| 903 ptr = __mem2hex (vptr, ptr, REGSIZE (regnum), 0); | |
| 904 } | |
| 905 else | |
| 906 { | |
| 907 /* Trace component returned a failure code. | |
| 908 This means that the register value is not available. | |
| 909 We'll fill it with 'x's, and GDB will understand. */ | |
| 910 memset (ptr, 'x', 2 * REGSIZE (regnum)); | |
| 911 ptr += 2 * REGSIZE (regnum); | |
| 912 } | |
| 913 } | |
| 914 break; | |
| 915 } | |
| 0 | 916 |
| 2 | 917 case 'A': /* set program arguments */ |
| 918 { | |
| 919 if (packet[1] == '\0') | |
| 920 { | |
| 921 __free_program_args (); | |
| 922 strcpy (remcomOutBuffer, "OK"); | |
| 923 } | |
| 924 else | |
| 925 { | |
| 926 target_register_t arglen, argnum; | |
| 927 char *ptr = &packet[1]; | |
| 928 | |
| 929 while (1) | |
| 930 { | |
| 931 if (__hexToInt (&ptr, &arglen) | |
| 932 && (*ptr++ == ',') | |
| 933 && __hexToInt (&ptr, &argnum) | |
| 934 && (*ptr++ == ',')) | |
| 935 { | |
| 936 if (arglen > 0) | |
| 937 { | |
| 938 char *s = __add_program_arg (argnum, arglen); | |
| 939 if (s != NULL) | |
| 940 { | |
| 941 __hex2mem (ptr, s, arglen, 0); | |
| 942 } | |
| 943 ptr += arglen * 2; | |
| 944 } | |
| 945 | |
| 946 if (*ptr == ',') | |
| 947 ptr++; | |
| 948 else | |
| 949 break; | |
| 950 } | |
| 951 else | |
| 952 break; | |
| 953 } | |
| 954 if (*ptr == '\0') | |
| 955 strcpy (remcomOutBuffer, "OK"); | |
| 956 else | |
| 957 strcpy (remcomOutBuffer, "E01"); | |
| 958 } | |
| 0 | 959 } |
| 2 | 960 break; |
| 0 | 961 |
| 962 case 'P': | |
| 2 | 963 case 'G': /* set the value of the CPU registers - return OK */ |
| 0 | 964 { |
| 2 | 965 int x; |
| 966 int sr = 0, er = NUMREGS_GDB; | |
| 967 char *ptr = &packet[1]; | |
| 968 | |
| 969 if (packet[0] == 'P') | |
| 970 { | |
| 971 target_register_t regno; | |
| 0 | 972 |
| 2 | 973 if (__hexToInt (&ptr, ®no) |
| 974 && (*ptr++ == '=')) | |
| 975 { | |
| 976 sr = regno; | |
| 977 er = regno + 1; | |
| 978 } | |
| 979 else | |
| 980 { | |
| 981 strcpy (remcomOutBuffer, "P01"); | |
| 982 break; | |
| 983 } | |
| 984 } | |
| 0 | 985 |
| 2 | 986 for (x = sr; x < er; x++) |
| 987 { | |
| 988 target_register_t value = 0; | |
| 989 char *vptr; | |
| 990 | |
| 991 #ifdef TARGET_HAS_LARGE_REGISTERS | |
| 992 if (sizeof (target_register_t) < REGSIZE (x)) | |
| 993 { | |
| 994 char dummyDat [32]; | |
| 0 | 995 |
| 2 | 996 __hex2mem (ptr, dummyDat, REGSIZE (x), 0); |
| 997 put_register_as_bytes (x, dummyDat); | |
| 998 } | |
| 999 else | |
| 1000 #endif | |
| 1001 { | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1002 vptr = ((char *) &value); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1003 #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
|
1004 vptr += sizeof (value) - REGSIZE (x); |
|
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1005 #endif |
| 2 | 1006 __hex2mem (ptr, vptr, REGSIZE (x), 0); |
| 1007 put_register (x, value); | |
| 1008 } | |
| 1009 ptr += REGSIZE (x) * 2; | |
| 1010 } | |
| 0 | 1011 |
| 2 | 1012 strcpy (remcomOutBuffer, "OK"); |
| 1013 break; | |
| 0 | 1014 } |
| 1015 | |
| 2 | 1016 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ |
| 0 | 1017 /* Try to read %x,%x. */ |
| 1018 { | |
| 2 | 1019 target_register_t addr, length; |
| 1020 char *ptr = &packet[1]; | |
| 0 | 1021 |
| 2 | 1022 if (__hexToInt (&ptr, &addr) |
| 1023 && *ptr++ == ',' | |
| 1024 && __hexToInt (&ptr, &length)) | |
| 1025 { | |
| 1026 if (__mem2hex ((char *) addr, remcomOutBuffer, length, 1)) | |
| 1027 break; | |
| 0 | 1028 |
| 2 | 1029 strcpy (remcomOutBuffer, "E03"); |
| 1030 } | |
| 1031 else | |
| 1032 strcpy (remcomOutBuffer, "E01"); | |
| 1033 break; | |
| 0 | 1034 } |
| 1035 | |
| 2 | 1036 case 'X': |
| 1037 /* XAA..AA,LLLL: Write LLLL escaped binary bytes at address AA.AA */ | |
| 1038 is_binary = 1; | |
| 1039 /* fall through */ | |
| 0 | 1040 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */ |
| 1041 /* Try to read '%x,%x:'. */ | |
| 1042 { | |
| 2 | 1043 target_register_t addr, length; |
| 1044 char *ptr = &packet[1], buf[128]; | |
| 1045 int i; | |
| 1046 | |
| 1047 if (__hexToInt (&ptr, &addr) | |
| 1048 && *ptr++ == ',' | |
| 1049 && __hexToInt (&ptr, &length) | |
| 1050 && *ptr++ == ':') | |
| 1051 { | |
| 1052 if (is_binary) | |
| 1053 { | |
| 1054 while (length > 0) | |
| 1055 { | |
| 1056 for (i = 0; i < sizeof(buf) && i < length; i++) | |
| 1057 if ((buf[i] = *ptr++) == 0x7d) | |
| 1058 buf[i] = 0x20 | (*ptr++ & 0xff); | |
| 1059 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1060 if (__write_mem_safe (buf, (void *)addr, i) != i) |
| 2 | 1061 break; |
| 0 | 1062 |
| 2 | 1063 length -= i; |
| 1064 addr += i; | |
| 1065 } | |
| 1066 if (length <= 0) | |
| 1067 strcpy (remcomOutBuffer, "OK"); | |
| 1068 else | |
| 1069 strcpy (remcomOutBuffer, "E03"); | |
| 1070 } | |
| 1071 else | |
| 1072 { | |
| 1073 if (__hex2mem (ptr, (char *) addr, length, 1) != NULL) | |
| 1074 strcpy (remcomOutBuffer, "OK"); | |
| 1075 else | |
| 1076 strcpy (remcomOutBuffer, "E03"); | |
| 1077 } | |
| 1078 } | |
| 1079 else | |
| 1080 strcpy (remcomOutBuffer, "E02"); | |
| 1081 break; | |
| 0 | 1082 } |
| 1083 | |
| 1084 case 'S': | |
| 2 | 1085 case 's': /* sAA..AA Step from address AA..AA (optional) */ |
| 0 | 1086 case 'C': |
| 2 | 1087 case 'c': /* cAA..AA Continue at address AA..AA (optional) */ |
| 0 | 1088 /* try to read optional parameter, pc unchanged if no parm */ |
| 1089 | |
| 1090 { | |
| 2 | 1091 char *ptr = &packet[1]; |
| 1092 target_register_t addr; | |
| 1093 target_register_t sigval = 0; | |
| 1094 | |
| 1095 if (packet[0] == 'C' || packet[0] == 'S') | |
| 1096 { | |
| 1097 __hexToInt (&ptr, &sigval); | |
| 1098 if (*ptr == ';') | |
| 1099 ptr++; | |
| 1100 } | |
| 0 | 1101 |
| 2 | 1102 if (__hexToInt (&ptr, &addr)) |
| 1103 set_pc (addr); | |
| 1104 | |
| 1105 /* Need to flush the instruction cache here, as we may have | |
| 1106 deposited a breakpoint, and the icache probably has no way of | |
| 1107 knowing that a data ref to some location may have changed | |
| 1108 something that is in the instruction cache. */ | |
| 1109 | |
| 1110 #ifdef __ECOS__ | |
| 1111 __data_cache (CACHE_FLUSH) ; | |
| 1112 #endif | |
| 1113 __instruction_cache (CACHE_FLUSH) ; | |
| 0 | 1114 |
| 2 | 1115 /* If we have a function to handle signals, call it. */ |
| 1116 if (sigval != 0 && __process_signal_vec != NULL) | |
| 1117 { | |
| 1118 /* If 0 is returned, we either ignored the signal or invoked a user | |
| 1119 handler. Otherwise, the user program should die. */ | |
| 1120 if (! __process_signal_vec (sigval)) | |
| 1121 sigval = 0; | |
| 1122 } | |
| 0 | 1123 |
| 2 | 1124 if (sigval != 0) |
| 1125 { | |
| 1126 sigval = SIGKILL; /* Always nuke the program */ | |
| 1127 __kill_program (sigval); | |
| 1128 return 0; | |
| 1129 } | |
| 0 | 1130 |
| 2 | 1131 /* Set machine state to force a single step. */ |
| 1132 if (packet[0] == 's' || packet[0] == 'S') | |
| 1133 { | |
| 1134 lock_thread_scheduler (0); /* 0 == single-step */ | |
| 1135 #ifdef __ECOS__ | |
| 1136 // PR 19845 workaround: | |
| 1137 // Make sure the single-step magic affects the correct registers. | |
| 1138 _registers = ®isters[0]; | |
| 1139 #endif | |
| 1140 __single_step (); | |
| 1141 } | |
| 1142 else | |
| 1143 { | |
| 1144 lock_thread_scheduler (1); /* 1 == continue */ | |
| 1145 } | |
| 0 | 1146 |
|
28
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1147 #ifdef __ECOS__ |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1148 /* 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
|
1149 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
|
1150 |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1151 __data_cache (CACHE_FLUSH) ; |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1152 __instruction_cache (CACHE_FLUSH) ; |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1153 #endif |
|
18ee5a9c102e
Merge from eCos master repository on 1999-08-09-17:04:48-BST
jlarmour
parents:
2
diff
changeset
|
1154 |
| 2 | 1155 return -1; |
| 0 | 1156 } |
| 1157 | |
| 1158 /* kill the program */ | |
| 1159 case 'k' : | |
| 1160 __process_exit_vec (); | |
| 1161 return 1; | |
| 2 | 1162 |
| 1163 case 'r': /* Reset */ | |
| 0 | 1164 __reset (); |
| 1165 break; | |
| 2 | 1166 |
| 0 | 1167 case 'H': |
| 1168 STUB_PKT_CHANGETHREAD (packet+1, remcomOutBuffer, 300) ; | |
| 1169 break ; | |
| 1170 case 'T' : | |
| 1171 STUB_PKT_THREAD_ALIVE (packet+1, remcomOutBuffer, 300) ; | |
| 1172 break ; | |
| 2 | 1173 case 'B': |
| 1174 /* breakpoint */ | |
| 0 | 1175 { |
| 2 | 1176 target_register_t addr; |
| 1177 char mode; | |
| 1178 char *ptr = &packet[1]; | |
| 1179 if (__hexToInt (&ptr, &addr) && *(ptr++) == ',') | |
| 1180 { | |
| 1181 mode = *(ptr++); | |
| 1182 if (mode == 'C') | |
| 1183 __remove_breakpoint (addr); | |
| 1184 else | |
| 1185 __set_breakpoint (addr); | |
| 1186 strcpy (remcomOutBuffer, "OK"); | |
| 1187 } | |
| 1188 else | |
| 1189 { | |
| 1190 strcpy (remcomOutBuffer, "E01"); | |
| 1191 } | |
| 1192 break; | |
| 1193 } | |
| 0 | 1194 |
| 2 | 1195 case 'b': /* bBB... Set baud rate to BB... */ |
| 1196 { | |
| 1197 target_register_t baudrate; | |
| 0 | 1198 |
| 2 | 1199 char *ptr = &packet[1]; |
| 1200 if (!__hexToInt (&ptr, &baudrate)) | |
| 1201 { | |
| 1202 strcpy (remcomOutBuffer, "B01"); | |
| 1203 break; | |
| 1204 } | |
| 1205 | |
| 1206 __putpacket ("OK"); /* Ack before changing speed */ | |
| 1207 __set_baud_rate (baudrate); | |
| 1208 break; | |
| 0 | 1209 } |
| 2 | 1210 default: |
| 1211 __process_target_packet (packet, remcomOutBuffer, 300); | |
| 1212 break; | |
| 0 | 1213 } |
| 1214 | |
| 1215 /* reply to the request */ | |
| 2 | 1216 __putpacket (remcomOutBuffer); |
| 0 | 1217 return 0; |
| 1218 } | |
| 1219 | |
| 1220 static void | |
| 1221 send_t_packet (int sigval) | |
| 1222 { | |
| 1223 __build_t_packet (sigval, remcomOutBuffer); | |
| 2 | 1224 __putpacket (remcomOutBuffer); |
| 0 | 1225 } |
| 1226 | |
| 1227 /* | |
| 1228 * This function does all command procesing for interfacing to gdb. | |
| 1229 */ | |
| 1230 | |
| 1231 static int | |
| 1232 process_exception (int sigval) | |
| 1233 { | |
| 1234 int status; | |
| 1235 | |
| 1236 /* Nasty. */ | |
| 1237 if (ungot_char < 0) | |
| 1238 send_t_packet (sigval); | |
| 1239 | |
| 1240 do { | |
| 1241 getpacket (remcomInBuffer); | |
| 2 | 1242 status = __process_packet (remcomInBuffer); |
| 0 | 1243 } while (status == 0); |
| 1244 | |
| 1245 if (status < 0) | |
| 1246 return 0; | |
| 1247 else | |
| 1248 return 1; | |
| 1249 } | |
| 1250 | |
| 1251 void | |
| 1252 __send_exit_status (int status) | |
| 1253 { | |
| 1254 remcomOutBuffer[0] = 'W'; | |
| 1255 remcomOutBuffer[1] = hexchars[(status >> 4) & 0xf]; | |
| 1256 remcomOutBuffer[2] = hexchars[status & 0xf]; | |
| 1257 remcomOutBuffer[3] = 0; | |
| 2 | 1258 __putpacket (remcomOutBuffer); |
| 0 | 1259 } |
| 1260 | |
| 2 | 1261 /* Read up to MAXLEN bytes from the remote GDB client, and store in DEST |
| 1262 (which is a pointer in the user program). BLOCK indicates what mode | |
| 1263 is being used; if it is set, we will wait for MAXLEN bytes to be | |
| 1264 entered. Otherwise, the function will return immediately with whatever | |
| 1265 bytes are waiting to be read. | |
| 1266 | |
| 1267 The value returned is the number of bytes read. A -1 indicates that an | |
| 1268 error of some sort occurred. */ | |
| 1269 | |
| 0 | 1270 int |
| 2 | 1271 __get_gdb_input (target_register_t dest, int maxlen, int block) |
| 0 | 1272 { |
| 1273 char buf[4]; | |
| 1274 int len, i; | |
| 2 | 1275 char d; |
| 0 | 1276 |
| 1277 buf[0] = 'I'; | |
| 1278 buf[1] = '0'; | |
| 1279 buf[2] = block ? '0' : '1'; | |
| 1280 buf[3] = 0; | |
| 2 | 1281 __putpacket (buf); |
| 0 | 1282 getpacket (remcomInBuffer); |
| 1283 if (remcomInBuffer[0] != 'I') | |
| 1284 return -1; | |
| 1285 len = stubhex (remcomInBuffer[1]) * 16 + stubhex (remcomInBuffer[2]); | |
| 1286 for (i = 0; i < len; i++) | |
| 1287 { | |
| 2 | 1288 d = stubhex (remcomInBuffer[3 + i * 2]) * 16; |
| 1289 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
|
1290 __write_mem_safe (&d, (void *)(dest + i), 1); |
| 0 | 1291 } |
| 2 | 1292 /* Write the trailing \0. */ |
| 1293 d = '\0'; | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1294 __write_mem_safe (&d, (void *)(dest + i), 1); |
| 0 | 1295 return len; |
| 1296 } | |
| 1297 | |
| 1298 void | |
| 1299 __output_hex_value (target_register_t i) | |
| 1300 { | |
| 1301 char buf[32], *ptr=buf+31; | |
| 1302 unsigned int x; | |
| 1303 | |
| 1304 *ptr = 0; | |
| 2 | 1305 for (x = 0; x < (sizeof (i) * 2); x++) |
| 0 | 1306 { |
| 1307 *(--ptr) = hexchars[i & 15]; | |
| 1308 i = i >> 4; | |
| 1309 } | |
| 1310 while (*ptr) | |
| 1311 { | |
| 1312 putDebugChar (*(ptr++)); | |
| 1313 } | |
| 1314 } | |
| 1315 | |
| 2 | 1316 /* Write the C-style string pointed to by STR to the GDB comm port. */ |
| 1317 void | |
| 1318 __putDebugStr (char *str) | |
| 1319 { | |
| 1320 while (*str) | |
| 1321 { | |
| 1322 putDebugChar (*str); | |
| 1323 str++; | |
| 1324 } | |
| 1325 } | |
| 1326 | |
| 1327 /* Send STRING_LEN bytes of STR to GDB, using 'O' packets. | |
| 1328 STR is assumed to be in the program being debugged. */ | |
| 1329 | |
| 0 | 1330 int |
| 2 | 1331 __output_gdb_string (target_register_t str, int string_len) |
| 0 | 1332 { |
| 2 | 1333 /* We will arbitrarily limit output packets to less than 400 bytes. */ |
| 1334 static char buf[400]; | |
| 0 | 1335 int x; |
| 1336 int len; | |
| 1337 | |
| 1338 if (string_len == 0) | |
| 2 | 1339 { |
| 1340 /* We can't do strlen on a user pointer. */ | |
| 1341 return -1; | |
| 1342 } | |
| 0 | 1343 |
| 2 | 1344 len = string_len; |
| 1345 while (len > 0) | |
| 0 | 1346 { |
| 2 | 1347 int packetlen = ((len < 175) ? len : 175); |
| 1348 buf[0] = 'O'; | |
| 1349 for (x = 0; x < packetlen; x++) | |
| 1350 { | |
| 1351 char c; | |
| 1352 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1353 __read_mem_safe (&c, (void *)(str + x), 1); |
| 2 | 1354 buf[x*2+1] = hexchars[(c >> 4) & 0xf]; |
| 1355 buf[x*2+2] = hexchars[c % 16]; | |
| 1356 } | |
| 1357 str += x; | |
| 1358 len -= x; | |
| 1359 buf[x*2+1] = 0; | |
| 1360 __putpacket (buf); | |
| 0 | 1361 } |
| 1362 return string_len; | |
| 1363 } | |
| 1364 | |
| 1365 static void | |
| 1366 do_nothing (void) | |
| 1367 { | |
| 1368 /* mmmm */ | |
| 1369 } | |
| 1370 | |
| 1371 static int | |
| 1372 syscall_do_nothing (int junk) | |
| 1373 { | |
| 1374 return 0; | |
| 1375 } | |
| 1376 | |
| 1377 /* Start the stub running. */ | |
| 1378 void | |
| 2 | 1379 __switch_to_stub (void) |
| 0 | 1380 { |
| 1381 __process_exception_vec = process_exception; | |
| 1382 } | |
| 1383 | |
| 2 | 1384 #if ! defined(BOARD_SPECIFIC_STUB_INIT) |
| 1385 void | |
| 1386 initialize_stub (void) | |
| 1387 { | |
| 1388 set_debug_traps (); | |
| 1389 /* FIXME: This function should be renamed to specifically init the | |
| 1390 hardware required by debug operations. If initHardware is implemented at | |
| 1391 all, it should be called before main (). | |
| 1392 */ | |
| 1393 initHardware () ; | |
| 1394 /* This acks any stale packets , NOT an effective solution */ | |
| 1395 putDebugChar ('+'); | |
| 1396 } | |
| 1397 #endif | |
| 1398 | |
| 0 | 1399 void |
| 1400 ungetDebugChar (int c) | |
| 1401 { | |
| 1402 ungot_char = c; | |
| 1403 } | |
| 1404 | |
| 2 | 1405 void |
| 1406 __kill_program (int sigval) | |
| 0 | 1407 { |
| 1408 remcomOutBuffer[0] = 'X'; | |
| 1409 remcomOutBuffer[1] = hexchars[(sigval >> 4) & 15]; | |
| 1410 remcomOutBuffer[2] = hexchars[sigval & 15]; | |
| 1411 remcomOutBuffer[3] = 0; | |
| 2 | 1412 __putpacket (remcomOutBuffer); |
| 1413 } | |
| 1414 | |
| 1415 #define MAX_ARG_COUNT 20 | |
| 1416 #define MAX_ARGDATA 128 | |
| 1417 | |
| 1418 static char *program_argv [MAX_ARG_COUNT]; | |
| 1419 static int program_argc; | |
| 1420 static int last_program_arg; | |
| 1421 static char program_argstr [MAX_ARGDATA], *argptr; | |
| 1422 static int args_initted = 0; | |
| 1423 | |
| 1424 void | |
| 1425 __free_program_args (void) | |
| 1426 { | |
| 1427 last_program_arg = -1; | |
| 1428 program_argc = 0; | |
| 1429 program_argv [0] = NULL; | |
| 1430 argptr = program_argstr; | |
| 1431 args_initted = 1; | |
| 1432 } | |
| 1433 | |
| 1434 static char * | |
| 1435 __add_program_arg (int argc, uint32 len) | |
| 1436 { | |
| 1437 char *res; | |
| 1438 | |
| 1439 if (! args_initted) | |
| 1440 { | |
| 1441 __free_program_args (); | |
| 1442 } | |
| 1443 | |
| 1444 if ((argc >= (MAX_ARG_COUNT - 1)) | |
| 1445 || ((argptr - program_argstr + len) > MAX_ARGDATA)) | |
| 1446 { | |
| 1447 return NULL; | |
| 1448 } | |
| 1449 | |
| 1450 if (argc != last_program_arg) | |
| 1451 { | |
| 1452 if (argc >= program_argc) | |
| 1453 { | |
| 1454 program_argc = argc + 1; | |
| 1455 program_argv [program_argc] = NULL; | |
| 1456 } | |
| 1457 program_argv [argc] = argptr; | |
| 1458 last_program_arg = argc; | |
| 1459 } | |
| 1460 | |
| 1461 res = argptr; | |
| 1462 argptr += len; | |
| 1463 | |
| 1464 return res; | |
| 1465 } | |
| 1466 | |
| 1467 void | |
| 1468 __set_program_args (int argc, char **argv) | |
| 1469 { | |
| 1470 int x; | |
| 1471 | |
| 1472 __free_program_args (); | |
| 1473 if (argc) | |
| 1474 { | |
| 1475 for (x = 0; x < argc; x++) | |
| 1476 { | |
| 1477 uint32 len = strlen (argv[x])+1; | |
| 1478 char *s = __add_program_arg (x, len); | |
| 1479 | |
| 1480 if (s == NULL) | |
| 1481 return; | |
| 1482 | |
| 1483 memcpy (s, argv[x], len); | |
| 1484 } | |
| 1485 } | |
| 1486 } | |
| 1487 | |
| 1488 char ** | |
| 1489 __get_program_args (target_register_t argcPtr) | |
| 1490 { | |
| 1491 if (!args_initted) | |
| 1492 { | |
| 1493 __free_program_args (); | |
| 1494 } | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1495 __write_mem_safe ((char *) &program_argc, (void *)argcPtr, sizeof (program_argc)); |
| 2 | 1496 return program_argv; |
| 0 | 1497 } |
| 1498 | |
| 1499 /* Table used by the crc32 function to calcuate the checksum. */ | |
| 1500 static uint32 crc32_table[256]; | |
| 1501 static int tableInit = 0; | |
| 1502 | |
| 1503 /* | |
| 1504 Calculate a CRC-32 using LEN bytes of PTR. CRC is the initial CRC | |
| 1505 value. | |
| 1506 PTR is assumed to be a pointer in the user program. */ | |
| 1507 | |
| 1508 static uint32 | |
| 2 | 1509 crc32 (ptr, len, crc) |
| 1510 unsigned char *ptr; | |
| 1511 int len; | |
| 1512 uint32 crc; | |
| 0 | 1513 { |
| 1514 if (! tableInit) | |
| 1515 { | |
| 1516 /* Initialize the CRC table and the decoding table. */ | |
| 1517 uint32 i, j; | |
| 1518 uint32 c; | |
| 1519 | |
| 1520 tableInit = 1; | |
| 1521 for (i = 0; i < 256; i++) | |
| 2 | 1522 { |
| 1523 for (c = i << 24, j = 8; j > 0; --j) | |
| 1524 c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); | |
| 1525 crc32_table[i] = c; | |
| 1526 } | |
| 0 | 1527 } |
| 1528 | |
| 1529 __mem_fault = 0; | |
| 1530 while (len--) | |
| 1531 { | |
| 1532 unsigned char ch; | |
| 1533 | |
|
34
29bc183297e1
Merge from eCos master repository on 1999-09-02-16:26:10-BST
jlarmour
parents:
28
diff
changeset
|
1534 __read_mem_safe (&ch, (void *)ptr, 1); |
| 0 | 1535 if (__mem_fault) |
| 2 | 1536 { |
| 1537 break; | |
| 1538 } | |
| 0 | 1539 crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ ch) & 255]; |
| 1540 ptr++; | |
| 1541 } | |
| 1542 return crc; | |
| 1543 } | |
| 1544 | |
| 1545 /* Handle the 'q' request */ | |
| 1546 | |
| 1547 static void | |
| 1548 process_query (char *pkt) | |
| 1549 { | |
| 1550 remcomOutBuffer[0] = '\0'; | |
| 2 | 1551 #ifdef __ECOS__ |
| 0 | 1552 if ('C' == pkt[0] && |
| 1553 'R' == pkt[1] && | |
| 1554 'C' == pkt[2] && | |
| 1555 ':' == pkt[3]) | |
| 2 | 1556 #else // __ECOS__ |
| 1557 if (strncmp (pkt, "CRC:", 4) == 0) | |
| 1558 #endif // __ECOS__ | |
| 0 | 1559 { |
| 1560 target_register_t startmem; | |
| 1561 target_register_t length; | |
| 1562 uint32 our_crc; | |
| 1563 | |
| 1564 pkt += 4; | |
| 1565 if (__hexToInt (&pkt, &startmem) | |
| 2 | 1566 && *(pkt++) == ',' |
| 1567 && __hexToInt (&pkt, &length)) | |
| 1568 { | |
| 1569 our_crc = crc32 ((unsigned char *) startmem, length, 0xffffffff); | |
| 1570 if (__mem_fault) | |
| 1571 { | |
| 1572 strcpy (remcomOutBuffer, "E01"); | |
| 1573 } | |
| 1574 else | |
| 1575 { | |
| 1576 int numb = __intToHex (remcomOutBuffer + 1, our_crc, 32); | |
| 1577 remcomOutBuffer[0] = 'C'; | |
| 1578 remcomOutBuffer[numb + 1] = 0; | |
| 1579 } | |
| 1580 } | |
| 0 | 1581 return; |
| 1582 } | |
| 1583 else | |
| 1584 { | |
| 1585 char ch ; | |
| 1586 char * subpkt ; | |
| 1587 ch = *pkt ; | |
| 1588 subpkt = pkt + 1 ; | |
| 1589 switch (ch) | |
| 2 | 1590 { |
| 1591 case 'L' : /* threadlistquery */ | |
| 1592 STUB_PKT_GETTHREADLIST (subpkt, remcomOutBuffer, 300); | |
| 1593 break ; | |
| 1594 case 'P' : /* Thread or process information request */ | |
| 1595 STUB_PKT_GETTHREADINFO (subpkt, remcomOutBuffer, 300); | |
| 1596 break ; | |
| 1597 case 'C' : /* current thread query */ | |
| 1598 STUB_PKT_CURRTHREAD(subpkt, remcomOutBuffer, sizeof(remcomOutBuffer)); | |
| 1599 break; | |
| 1600 default: | |
| 1601 __process_target_query (pkt, remcomOutBuffer, 300); | |
| 1602 break ; | |
| 1603 } | |
| 0 | 1604 } |
| 1605 } | |
| 1606 | |
| 1607 /* Handle the 'Q' request */ | |
| 1608 | |
| 1609 static void | |
| 1610 process_set (char *pkt) | |
| 1611 { | |
| 1612 char ch ; | |
| 1613 ch = *pkt ; | |
| 1614 | |
| 1615 switch (ch) | |
| 1616 { | |
| 1617 case 'p' : /* Set current process or thread */ | |
| 1618 /* reserve the packet id even if support is not present */ | |
| 1619 /* Dont strip the 'p' off the header, there are several variations of | |
| 2 | 1620 this packet */ |
| 0 | 1621 STUB_PKT_CHANGETHREAD (pkt, remcomOutBuffer, 300) ; |
| 1622 break ; | |
| 1623 default: | |
| 1624 __process_target_set (pkt, remcomOutBuffer, 300); | |
| 1625 break ; | |
| 1626 } | |
| 1627 } | |
| 1628 #endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS |
