* fork-child.c (escape_bang_in_quoted_argument): New function.
[deliverable/binutils-gdb.git] / gdb / m32r-stub.c
CommitLineData
05d57f6f
AC
1// OBSOLETE /****************************************************************************
2// OBSOLETE
3// OBSOLETE THIS SOFTWARE IS NOT COPYRIGHTED
4// OBSOLETE
5// OBSOLETE HP offers the following for use in the public domain. HP makes no
6// OBSOLETE warranty with regard to the software or it's performance and the
7// OBSOLETE user accepts the software "AS IS" with all faults.
8// OBSOLETE
9// OBSOLETE HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
10// OBSOLETE TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
11// OBSOLETE OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12// OBSOLETE
13// OBSOLETE ****************************************************************************/
14// OBSOLETE
15// OBSOLETE /****************************************************************************
16// OBSOLETE * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
17// OBSOLETE *
18// OBSOLETE * Module name: remcom.c $
19// OBSOLETE * Revision: 1.34 $
20// OBSOLETE * Date: 91/03/09 12:29:49 $
21// OBSOLETE * Contributor: Lake Stevens Instrument Division$
22// OBSOLETE *
23// OBSOLETE * Description: low level support for gdb debugger. $
24// OBSOLETE *
25// OBSOLETE * Considerations: only works on target hardware $
26// OBSOLETE *
27// OBSOLETE * Written by: Glenn Engel $
28// OBSOLETE * ModuleState: Experimental $
29// OBSOLETE *
30// OBSOLETE * NOTES: See Below $
31// OBSOLETE *
32// OBSOLETE * Modified for M32R by Michael Snyder, Cygnus Support.
33// OBSOLETE *
34// OBSOLETE * To enable debugger support, two things need to happen. One, a
35// OBSOLETE * call to set_debug_traps() is necessary in order to allow any breakpoints
36// OBSOLETE * or error conditions to be properly intercepted and reported to gdb.
37// OBSOLETE * Two, a breakpoint needs to be generated to begin communication. This
38// OBSOLETE * is most easily accomplished by a call to breakpoint(). Breakpoint()
39// OBSOLETE * simulates a breakpoint by executing a trap #1.
40// OBSOLETE *
41// OBSOLETE * The external function exceptionHandler() is
42// OBSOLETE * used to attach a specific handler to a specific M32R vector number.
43// OBSOLETE * It should use the same privilege level it runs at. It should
44// OBSOLETE * install it as an interrupt gate so that interrupts are masked
45// OBSOLETE * while the handler runs.
46// OBSOLETE *
47// OBSOLETE * Because gdb will sometimes write to the stack area to execute function
48// OBSOLETE * calls, this program cannot rely on using the supervisor stack so it
49// OBSOLETE * uses it's own stack area reserved in the int array remcomStack.
50// OBSOLETE *
51// OBSOLETE *************
52// OBSOLETE *
53// OBSOLETE * The following gdb commands are supported:
54// OBSOLETE *
55// OBSOLETE * command function Return value
56// OBSOLETE *
57// OBSOLETE * g return the value of the CPU registers hex data or ENN
58// OBSOLETE * G set the value of the CPU registers OK or ENN
59// OBSOLETE *
60// OBSOLETE * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
61// OBSOLETE * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
62// OBSOLETE * XAA..AA,LLLL: Write LLLL binary bytes at address OK or ENN
63// OBSOLETE * AA..AA
64// OBSOLETE *
65// OBSOLETE * c Resume at current address SNN ( signal NN)
66// OBSOLETE * cAA..AA Continue at address AA..AA SNN
67// OBSOLETE *
68// OBSOLETE * s Step one instruction SNN
69// OBSOLETE * sAA..AA Step one instruction from AA..AA SNN
70// OBSOLETE *
71// OBSOLETE * k kill
72// OBSOLETE *
73// OBSOLETE * ? What was the last sigval ? SNN (signal NN)
74// OBSOLETE *
75// OBSOLETE * All commands and responses are sent with a packet which includes a
76// OBSOLETE * checksum. A packet consists of
77// OBSOLETE *
78// OBSOLETE * $<packet info>#<checksum>.
79// OBSOLETE *
80// OBSOLETE * where
81// OBSOLETE * <packet info> :: <characters representing the command or response>
82// OBSOLETE * <checksum> :: <two hex digits computed as modulo 256 sum of <packetinfo>>
83// OBSOLETE *
84// OBSOLETE * When a packet is received, it is first acknowledged with either '+' or '-'.
85// OBSOLETE * '+' indicates a successful transfer. '-' indicates a failed transfer.
86// OBSOLETE *
87// OBSOLETE * Example:
88// OBSOLETE *
89// OBSOLETE * Host: Reply:
90// OBSOLETE * $m0,10#2a +$00010203040506070809101112131415#42
91// OBSOLETE *
92// OBSOLETE ****************************************************************************/
93// OBSOLETE
94// OBSOLETE
95// OBSOLETE /************************************************************************
96// OBSOLETE *
97// OBSOLETE * external low-level support routines
98// OBSOLETE */
99// OBSOLETE extern void putDebugChar(); /* write a single character */
100// OBSOLETE extern int getDebugChar(); /* read and return a single char */
101// OBSOLETE extern void exceptionHandler(); /* assign an exception handler */
102// OBSOLETE
103// OBSOLETE /*****************************************************************************
104// OBSOLETE * BUFMAX defines the maximum number of characters in inbound/outbound buffers
105// OBSOLETE * at least NUMREGBYTES*2 are needed for register packets
106// OBSOLETE */
107// OBSOLETE #define BUFMAX 400
108// OBSOLETE
109// OBSOLETE static char initialized; /* boolean flag. != 0 means we've been initialized */
110// OBSOLETE
111// OBSOLETE int remote_debug;
112// OBSOLETE /* debug > 0 prints ill-formed commands in valid packets & checksum errors */
113// OBSOLETE
114// OBSOLETE static const unsigned char hexchars[]="0123456789abcdef";
115// OBSOLETE
116// OBSOLETE #define NUMREGS 24
117// OBSOLETE
118// OBSOLETE /* Number of bytes of registers. */
119// OBSOLETE #define NUMREGBYTES (NUMREGS * 4)
120// OBSOLETE enum regnames { R0, R1, R2, R3, R4, R5, R6, R7,
121// OBSOLETE R8, R9, R10, R11, R12, R13, R14, R15,
122// OBSOLETE PSW, CBR, SPI, SPU, BPC, PC, ACCL, ACCH };
123// OBSOLETE
124// OBSOLETE enum SYS_calls {
125// OBSOLETE SYS_null,
126// OBSOLETE SYS_exit,
127// OBSOLETE SYS_open,
128// OBSOLETE SYS_close,
129// OBSOLETE SYS_read,
130// OBSOLETE SYS_write,
131// OBSOLETE SYS_lseek,
132// OBSOLETE SYS_unlink,
133// OBSOLETE SYS_getpid,
134// OBSOLETE SYS_kill,
135// OBSOLETE SYS_fstat,
136// OBSOLETE SYS_sbrk,
137// OBSOLETE SYS_fork,
138// OBSOLETE SYS_execve,
139// OBSOLETE SYS_wait4,
140// OBSOLETE SYS_link,
141// OBSOLETE SYS_chdir,
142// OBSOLETE SYS_stat,
143// OBSOLETE SYS_utime,
144// OBSOLETE SYS_chown,
145// OBSOLETE SYS_chmod,
146// OBSOLETE SYS_time,
147// OBSOLETE SYS_pipe };
148// OBSOLETE
149// OBSOLETE static int registers[NUMREGS];
150// OBSOLETE
151// OBSOLETE #define STACKSIZE 8096
152// OBSOLETE static unsigned char remcomInBuffer[BUFMAX];
153// OBSOLETE static unsigned char remcomOutBuffer[BUFMAX];
154// OBSOLETE static int remcomStack[STACKSIZE/sizeof(int)];
155// OBSOLETE static int* stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1];
156// OBSOLETE
157// OBSOLETE static unsigned int save_vectors[18]; /* previous exception vectors */
158// OBSOLETE
159// OBSOLETE /* Indicate to caller of mem2hex or hex2mem that there has been an error. */
160// OBSOLETE static volatile int mem_err = 0;
161// OBSOLETE
162// OBSOLETE /* Store the vector number here (since GDB only gets the signal
163// OBSOLETE number through the usual means, and that's not very specific). */
164// OBSOLETE int gdb_m32r_vector = -1;
165// OBSOLETE
166// OBSOLETE #if 0
167// OBSOLETE #include "syscall.h" /* for SYS_exit, SYS_write etc. */
168// OBSOLETE #endif
169// OBSOLETE
170// OBSOLETE /* Global entry points:
171// OBSOLETE */
172// OBSOLETE
173// OBSOLETE extern void handle_exception(int);
174// OBSOLETE extern void set_debug_traps(void);
175// OBSOLETE extern void breakpoint(void);
176// OBSOLETE
177// OBSOLETE /* Local functions:
178// OBSOLETE */
179// OBSOLETE
180// OBSOLETE static int computeSignal(int);
181// OBSOLETE static void putpacket(unsigned char *);
182// OBSOLETE static unsigned char *getpacket(void);
183// OBSOLETE
184// OBSOLETE static unsigned char *mem2hex(unsigned char *, unsigned char *, int, int);
185// OBSOLETE static unsigned char *hex2mem(unsigned char *, unsigned char *, int, int);
186// OBSOLETE static int hexToInt(unsigned char **, int *);
187// OBSOLETE static unsigned char *bin2mem(unsigned char *, unsigned char *, int, int);
188// OBSOLETE static void stash_registers(void);
189// OBSOLETE static void restore_registers(void);
190// OBSOLETE static int prepare_to_step(int);
191// OBSOLETE static int finish_from_step(void);
192// OBSOLETE static unsigned long crc32 (unsigned char *, int, unsigned long);
193// OBSOLETE
194// OBSOLETE static void gdb_error(char *, char *);
195// OBSOLETE static int gdb_putchar(int), gdb_puts(char *), gdb_write(char *, int);
196// OBSOLETE
197// OBSOLETE static unsigned char *strcpy (unsigned char *, const unsigned char *);
198// OBSOLETE static int strlen (const unsigned char *);
199// OBSOLETE
200// OBSOLETE /*
201// OBSOLETE * This function does all command procesing for interfacing to gdb.
202// OBSOLETE */
203// OBSOLETE
204// OBSOLETE void
205// OBSOLETE handle_exception(int exceptionVector)
206// OBSOLETE {
207// OBSOLETE int sigval, stepping;
208// OBSOLETE int addr, length, i;
209// OBSOLETE unsigned char * ptr;
210// OBSOLETE unsigned char buf[16];
211// OBSOLETE int binary;
212// OBSOLETE
213// OBSOLETE /* Do not call finish_from_step() if this is not a trap #1
214// OBSOLETE * (breakpoint trap). Without this check, the finish_from_step()
215// OBSOLETE * might interpret a system call trap as a single step trap. This
216// OBSOLETE * can happen if: the stub receives 's' and exits, but an interrupt
217// OBSOLETE * was pending; the interrupt is now handled and causes the stub to
218// OBSOLETE * be reentered because some function makes a system call.
219// OBSOLETE */
220// OBSOLETE if (exceptionVector == 1) /* Trap exception? */
221// OBSOLETE if (!finish_from_step()) /* Go see if stepping state needs update. */
222// OBSOLETE return; /* "false step": let the target continue */
223// OBSOLETE
224// OBSOLETE gdb_m32r_vector = exceptionVector;
225// OBSOLETE
226// OBSOLETE if (remote_debug)
227// OBSOLETE {
228// OBSOLETE mem2hex((unsigned char *) &exceptionVector, buf, 4, 0);
229// OBSOLETE gdb_error("Handle exception %s, ", buf);
230// OBSOLETE mem2hex((unsigned char *) &registers[PC], buf, 4, 0);
231// OBSOLETE gdb_error("PC == 0x%s\n", buf);
232// OBSOLETE }
233// OBSOLETE
234// OBSOLETE /* reply to host that an exception has occurred */
235// OBSOLETE sigval = computeSignal( exceptionVector );
236// OBSOLETE
237// OBSOLETE ptr = remcomOutBuffer;
238// OBSOLETE
239// OBSOLETE *ptr++ = 'T'; /* notify gdb with signo, PC, FP and SP */
240// OBSOLETE *ptr++ = hexchars[sigval >> 4];
241// OBSOLETE *ptr++ = hexchars[sigval & 0xf];
242// OBSOLETE
243// OBSOLETE *ptr++ = hexchars[PC >> 4];
244// OBSOLETE *ptr++ = hexchars[PC & 0xf];
245// OBSOLETE *ptr++ = ':';
246// OBSOLETE ptr = mem2hex((unsigned char *)&registers[PC], ptr, 4, 0); /* PC */
247// OBSOLETE *ptr++ = ';';
248// OBSOLETE
249// OBSOLETE *ptr++ = hexchars[R13 >> 4];
250// OBSOLETE *ptr++ = hexchars[R13 & 0xf];
251// OBSOLETE *ptr++ = ':';
252// OBSOLETE ptr = mem2hex((unsigned char *)&registers[R13], ptr, 4, 0); /* FP */
253// OBSOLETE *ptr++ = ';';
254// OBSOLETE
255// OBSOLETE *ptr++ = hexchars[R15 >> 4];
256// OBSOLETE *ptr++ = hexchars[R15 & 0xf];
257// OBSOLETE *ptr++ = ':';
258// OBSOLETE ptr = mem2hex((unsigned char *)&registers[R15], ptr, 4, 0); /* SP */
259// OBSOLETE *ptr++ = ';';
260// OBSOLETE *ptr++ = 0;
261// OBSOLETE
262// OBSOLETE if (exceptionVector == 0) /* simulated SYS call stuff */
263// OBSOLETE {
264// OBSOLETE mem2hex((unsigned char *) &registers[PC], buf, 4, 0);
265// OBSOLETE switch (registers[R0]) {
266// OBSOLETE case SYS_exit:
267// OBSOLETE gdb_error("Target program has exited at %s\n", buf);
268// OBSOLETE ptr = remcomOutBuffer;
269// OBSOLETE *ptr++ = 'W';
270// OBSOLETE sigval = registers[R1] & 0xff;
271// OBSOLETE *ptr++ = hexchars[sigval >> 4];
272// OBSOLETE *ptr++ = hexchars[sigval & 0xf];
273// OBSOLETE *ptr++ = 0;
274// OBSOLETE break;
275// OBSOLETE case SYS_open:
276// OBSOLETE gdb_error("Target attempts SYS_open call at %s\n", buf);
277// OBSOLETE break;
278// OBSOLETE case SYS_close:
279// OBSOLETE gdb_error("Target attempts SYS_close call at %s\n", buf);
280// OBSOLETE break;
281// OBSOLETE case SYS_read:
282// OBSOLETE gdb_error("Target attempts SYS_read call at %s\n", buf);
283// OBSOLETE break;
284// OBSOLETE case SYS_write:
285// OBSOLETE if (registers[R1] == 1 || /* write to stdout */
286// OBSOLETE registers[R1] == 2) /* write to stderr */
287// OBSOLETE { /* (we can do that) */
288// OBSOLETE registers[R0] = gdb_write((void *) registers[R2], registers[R3]);
289// OBSOLETE return;
290// OBSOLETE }
291// OBSOLETE else
292// OBSOLETE gdb_error("Target attempts SYS_write call at %s\n", buf);
293// OBSOLETE break;
294// OBSOLETE case SYS_lseek:
295// OBSOLETE gdb_error("Target attempts SYS_lseek call at %s\n", buf);
296// OBSOLETE break;
297// OBSOLETE case SYS_unlink:
298// OBSOLETE gdb_error("Target attempts SYS_unlink call at %s\n", buf);
299// OBSOLETE break;
300// OBSOLETE case SYS_getpid:
301// OBSOLETE gdb_error("Target attempts SYS_getpid call at %s\n", buf);
302// OBSOLETE break;
303// OBSOLETE case SYS_kill:
304// OBSOLETE gdb_error("Target attempts SYS_kill call at %s\n", buf);
305// OBSOLETE break;
306// OBSOLETE case SYS_fstat:
307// OBSOLETE gdb_error("Target attempts SYS_fstat call at %s\n", buf);
308// OBSOLETE break;
309// OBSOLETE default:
310// OBSOLETE gdb_error("Target attempts unknown SYS call at %s\n", buf);
311// OBSOLETE break;
312// OBSOLETE }
313// OBSOLETE }
314// OBSOLETE
315// OBSOLETE putpacket(remcomOutBuffer);
316// OBSOLETE
317// OBSOLETE stepping = 0;
318// OBSOLETE
319// OBSOLETE while (1==1) {
320// OBSOLETE remcomOutBuffer[0] = 0;
321// OBSOLETE ptr = getpacket();
322// OBSOLETE binary = 0;
323// OBSOLETE switch (*ptr++) {
324// OBSOLETE default: /* Unknown code. Return an empty reply message. */
325// OBSOLETE break;
326// OBSOLETE case 'R':
327// OBSOLETE if (hexToInt (&ptr, &addr))
328// OBSOLETE registers[PC] = addr;
329// OBSOLETE strcpy(remcomOutBuffer, "OK");
330// OBSOLETE break;
331// OBSOLETE case '!':
332// OBSOLETE strcpy(remcomOutBuffer, "OK");
333// OBSOLETE break;
334// OBSOLETE case 'X': /* XAA..AA,LLLL:<binary data>#cs */
335// OBSOLETE binary = 1;
336// OBSOLETE case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
337// OBSOLETE /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
338// OBSOLETE {
339// OBSOLETE if (hexToInt(&ptr,&addr))
340// OBSOLETE if (*(ptr++) == ',')
341// OBSOLETE if (hexToInt(&ptr,&length))
342// OBSOLETE if (*(ptr++) == ':')
343// OBSOLETE {
344// OBSOLETE mem_err = 0;
345// OBSOLETE if (binary)
346// OBSOLETE bin2mem (ptr, (unsigned char *) addr, length, 1);
347// OBSOLETE else
348// OBSOLETE hex2mem(ptr, (unsigned char*) addr, length, 1);
349// OBSOLETE if (mem_err) {
350// OBSOLETE strcpy (remcomOutBuffer, "E03");
351// OBSOLETE gdb_error ("memory fault", "");
352// OBSOLETE } else {
353// OBSOLETE strcpy(remcomOutBuffer,"OK");
354// OBSOLETE }
355// OBSOLETE ptr = 0;
356// OBSOLETE }
357// OBSOLETE if (ptr)
358// OBSOLETE {
359// OBSOLETE strcpy(remcomOutBuffer,"E02");
360// OBSOLETE }
361// OBSOLETE }
362// OBSOLETE break;
363// OBSOLETE case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
364// OBSOLETE /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
365// OBSOLETE if (hexToInt(&ptr,&addr))
366// OBSOLETE if (*(ptr++) == ',')
367// OBSOLETE if (hexToInt(&ptr,&length))
368// OBSOLETE {
369// OBSOLETE ptr = 0;
370// OBSOLETE mem_err = 0;
371// OBSOLETE mem2hex((unsigned char*) addr, remcomOutBuffer, length, 1);
372// OBSOLETE if (mem_err) {
373// OBSOLETE strcpy (remcomOutBuffer, "E03");
374// OBSOLETE gdb_error ("memory fault", "");
375// OBSOLETE }
376// OBSOLETE }
377// OBSOLETE if (ptr)
378// OBSOLETE {
379// OBSOLETE strcpy(remcomOutBuffer,"E01");
380// OBSOLETE }
381// OBSOLETE break;
382// OBSOLETE case '?':
383// OBSOLETE remcomOutBuffer[0] = 'S';
384// OBSOLETE remcomOutBuffer[1] = hexchars[sigval >> 4];
385// OBSOLETE remcomOutBuffer[2] = hexchars[sigval % 16];
386// OBSOLETE remcomOutBuffer[3] = 0;
387// OBSOLETE break;
388// OBSOLETE case 'd':
389// OBSOLETE remote_debug = !(remote_debug); /* toggle debug flag */
390// OBSOLETE break;
391// OBSOLETE case 'g': /* return the value of the CPU registers */
392// OBSOLETE mem2hex((unsigned char*) registers, remcomOutBuffer, NUMREGBYTES, 0);
393// OBSOLETE break;
394// OBSOLETE case 'P': /* set the value of a single CPU register - return OK */
395// OBSOLETE {
396// OBSOLETE int regno;
397// OBSOLETE
398// OBSOLETE if (hexToInt (&ptr, &regno) && *ptr++ == '=')
399// OBSOLETE if (regno >= 0 && regno < NUMREGS)
400// OBSOLETE {
401// OBSOLETE int stackmode;
402// OBSOLETE
403// OBSOLETE hex2mem (ptr, (unsigned char *) &registers[regno], 4, 0);
404// OBSOLETE /*
405// OBSOLETE * Since we just changed a single CPU register, let's
406// OBSOLETE * make sure to keep the several stack pointers consistant.
407// OBSOLETE */
408// OBSOLETE stackmode = registers[PSW] & 0x80;
409// OBSOLETE if (regno == R15) /* stack pointer changed */
410// OBSOLETE { /* need to change SPI or SPU */
411// OBSOLETE if (stackmode == 0)
412// OBSOLETE registers[SPI] = registers[R15];
413// OBSOLETE else
414// OBSOLETE registers[SPU] = registers[R15];
415// OBSOLETE }
416// OBSOLETE else if (regno == SPU) /* "user" stack pointer changed */
417// OBSOLETE {
418// OBSOLETE if (stackmode != 0) /* stack in user mode: copy SP */
419// OBSOLETE registers[R15] = registers[SPU];
420// OBSOLETE }
421// OBSOLETE else if (regno == SPI) /* "interrupt" stack pointer changed */
422// OBSOLETE {
423// OBSOLETE if (stackmode == 0) /* stack in interrupt mode: copy SP */
424// OBSOLETE registers[R15] = registers[SPI];
425// OBSOLETE }
426// OBSOLETE else if (regno == PSW) /* stack mode may have changed! */
427// OBSOLETE { /* force SP to either SPU or SPI */
428// OBSOLETE if (stackmode == 0) /* stack in user mode */
429// OBSOLETE registers[R15] = registers[SPI];
430// OBSOLETE else /* stack in interrupt mode */
431// OBSOLETE registers[R15] = registers[SPU];
432// OBSOLETE }
433// OBSOLETE strcpy (remcomOutBuffer, "OK");
434// OBSOLETE break;
435// OBSOLETE }
436// OBSOLETE strcpy (remcomOutBuffer, "E01");
437// OBSOLETE break;
438// OBSOLETE }
439// OBSOLETE case 'G': /* set the value of the CPU registers - return OK */
440// OBSOLETE hex2mem(ptr, (unsigned char*) registers, NUMREGBYTES, 0);
441// OBSOLETE strcpy(remcomOutBuffer,"OK");
442// OBSOLETE break;
443// OBSOLETE case 's': /* sAA..AA Step one instruction from AA..AA(optional) */
444// OBSOLETE stepping = 1;
445// OBSOLETE case 'c': /* cAA..AA Continue from address AA..AA(optional) */
446// OBSOLETE /* try to read optional parameter, pc unchanged if no parm */
447// OBSOLETE if (hexToInt(&ptr,&addr))
448// OBSOLETE registers[ PC ] = addr;
449// OBSOLETE
450// OBSOLETE if (stepping) /* single-stepping */
451// OBSOLETE {
452// OBSOLETE if (!prepare_to_step(0)) /* set up for single-step */
453// OBSOLETE {
454// OBSOLETE /* prepare_to_step has already emulated the target insn:
455// OBSOLETE Send SIGTRAP to gdb, don't resume the target at all. */
456// OBSOLETE ptr = remcomOutBuffer;
457// OBSOLETE *ptr++ = 'T'; /* Simulate stopping with SIGTRAP */
458// OBSOLETE *ptr++ = '0';
459// OBSOLETE *ptr++ = '5';
460// OBSOLETE
461// OBSOLETE *ptr++ = hexchars[PC >> 4]; /* send PC */
462// OBSOLETE *ptr++ = hexchars[PC & 0xf];
463// OBSOLETE *ptr++ = ':';
464// OBSOLETE ptr = mem2hex((unsigned char *)&registers[PC], ptr, 4, 0);
465// OBSOLETE *ptr++ = ';';
466// OBSOLETE
467// OBSOLETE *ptr++ = hexchars[R13 >> 4]; /* send FP */
468// OBSOLETE *ptr++ = hexchars[R13 & 0xf];
469// OBSOLETE *ptr++ = ':';
470// OBSOLETE ptr = mem2hex((unsigned char *)&registers[R13], ptr, 4, 0);
471// OBSOLETE *ptr++ = ';';
472// OBSOLETE
473// OBSOLETE *ptr++ = hexchars[R15 >> 4]; /* send SP */
474// OBSOLETE *ptr++ = hexchars[R15 & 0xf];
475// OBSOLETE *ptr++ = ':';
476// OBSOLETE ptr = mem2hex((unsigned char *)&registers[R15], ptr, 4, 0);
477// OBSOLETE *ptr++ = ';';
478// OBSOLETE *ptr++ = 0;
479// OBSOLETE
480// OBSOLETE break;
481// OBSOLETE }
482// OBSOLETE }
483// OBSOLETE else /* continuing, not single-stepping */
484// OBSOLETE {
485// OBSOLETE /* OK, about to do a "continue". First check to see if the
486// OBSOLETE target pc is on an odd boundary (second instruction in the
487// OBSOLETE word). If so, we must do a single-step first, because
488// OBSOLETE ya can't jump or return back to an odd boundary! */
489// OBSOLETE if ((registers[PC] & 2) != 0)
490// OBSOLETE prepare_to_step(1);
491// OBSOLETE }
492// OBSOLETE
493// OBSOLETE return;
494// OBSOLETE
495// OBSOLETE case 'D': /* Detach */
496// OBSOLETE #if 0
497// OBSOLETE /* I am interpreting this to mean, release the board from control
498// OBSOLETE by the remote stub. To do this, I am restoring the original
499// OBSOLETE (or at least previous) exception vectors.
500// OBSOLETE */
501// OBSOLETE for (i = 0; i < 18; i++)
502// OBSOLETE exceptionHandler (i, save_vectors[i]);
503// OBSOLETE putpacket ("OK");
504// OBSOLETE return; /* continue the inferior */
505// OBSOLETE #else
506// OBSOLETE strcpy(remcomOutBuffer,"OK");
507// OBSOLETE break;
508// OBSOLETE #endif
509// OBSOLETE case 'q':
510// OBSOLETE if (*ptr++ == 'C' &&
511// OBSOLETE *ptr++ == 'R' &&
512// OBSOLETE *ptr++ == 'C' &&
513// OBSOLETE *ptr++ == ':')
514// OBSOLETE {
515// OBSOLETE unsigned long start, len, our_crc;
516// OBSOLETE
517// OBSOLETE if (hexToInt (&ptr, (int *) &start) &&
518// OBSOLETE *ptr++ == ',' &&
519// OBSOLETE hexToInt (&ptr, (int *) &len))
520// OBSOLETE {
521// OBSOLETE remcomOutBuffer[0] = 'C';
522// OBSOLETE our_crc = crc32 ((unsigned char *) start, len, 0xffffffff);
523// OBSOLETE mem2hex ((char *) &our_crc,
524// OBSOLETE &remcomOutBuffer[1],
525// OBSOLETE sizeof (long),
526// OBSOLETE 0);
527// OBSOLETE } /* else do nothing */
528// OBSOLETE } /* else do nothing */
529// OBSOLETE break;
530// OBSOLETE
531// OBSOLETE case 'k': /* kill the program */
532// OBSOLETE continue;
533// OBSOLETE } /* switch */
534// OBSOLETE
535// OBSOLETE /* reply to the request */
536// OBSOLETE putpacket(remcomOutBuffer);
537// OBSOLETE }
538// OBSOLETE }
539// OBSOLETE
540// OBSOLETE /* qCRC support */
541// OBSOLETE
542// OBSOLETE /* Table used by the crc32 function to calcuate the checksum. */
543// OBSOLETE static unsigned long crc32_table[256] = {0, 0};
544// OBSOLETE
545// OBSOLETE static unsigned long
546// OBSOLETE crc32 (unsigned char *buf, int len, unsigned long crc)
547// OBSOLETE {
548// OBSOLETE if (! crc32_table[1])
549// OBSOLETE {
550// OBSOLETE /* Initialize the CRC table and the decoding table. */
551// OBSOLETE int i, j;
552// OBSOLETE unsigned long c;
553// OBSOLETE
554// OBSOLETE for (i = 0; i < 256; i++)
555// OBSOLETE {
556// OBSOLETE for (c = i << 24, j = 8; j > 0; --j)
557// OBSOLETE c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
558// OBSOLETE crc32_table[i] = c;
559// OBSOLETE }
560// OBSOLETE }
561// OBSOLETE
562// OBSOLETE while (len--)
563// OBSOLETE {
564// OBSOLETE crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
565// OBSOLETE buf++;
566// OBSOLETE }
567// OBSOLETE return crc;
568// OBSOLETE }
569// OBSOLETE
570// OBSOLETE static int
571// OBSOLETE hex (unsigned char ch)
572// OBSOLETE {
573// OBSOLETE if ((ch >= 'a') && (ch <= 'f')) return (ch-'a'+10);
574// OBSOLETE if ((ch >= '0') && (ch <= '9')) return (ch-'0');
575// OBSOLETE if ((ch >= 'A') && (ch <= 'F')) return (ch-'A'+10);
576// OBSOLETE return (-1);
577// OBSOLETE }
578// OBSOLETE
579// OBSOLETE /* scan for the sequence $<data>#<checksum> */
580// OBSOLETE
581// OBSOLETE unsigned char *
582// OBSOLETE getpacket (void)
583// OBSOLETE {
584// OBSOLETE unsigned char *buffer = &remcomInBuffer[0];
585// OBSOLETE unsigned char checksum;
586// OBSOLETE unsigned char xmitcsum;
587// OBSOLETE int count;
588// OBSOLETE char ch;
589// OBSOLETE
590// OBSOLETE while (1)
591// OBSOLETE {
592// OBSOLETE /* wait around for the start character, ignore all other characters */
593// OBSOLETE while ((ch = getDebugChar ()) != '$')
594// OBSOLETE ;
595// OBSOLETE
596// OBSOLETE retry:
597// OBSOLETE checksum = 0;
598// OBSOLETE xmitcsum = -1;
599// OBSOLETE count = 0;
600// OBSOLETE
601// OBSOLETE /* now, read until a # or end of buffer is found */
602// OBSOLETE while (count < BUFMAX)
603// OBSOLETE {
604// OBSOLETE ch = getDebugChar ();
605// OBSOLETE if (ch == '$')
606// OBSOLETE goto retry;
607// OBSOLETE if (ch == '#')
608// OBSOLETE break;
609// OBSOLETE checksum = checksum + ch;
610// OBSOLETE buffer[count] = ch;
611// OBSOLETE count = count + 1;
612// OBSOLETE }
613// OBSOLETE buffer[count] = 0;
614// OBSOLETE
615// OBSOLETE if (ch == '#')
616// OBSOLETE {
617// OBSOLETE ch = getDebugChar ();
618// OBSOLETE xmitcsum = hex (ch) << 4;
619// OBSOLETE ch = getDebugChar ();
620// OBSOLETE xmitcsum += hex (ch);
621// OBSOLETE
622// OBSOLETE if (checksum != xmitcsum)
623// OBSOLETE {
624// OBSOLETE if (remote_debug)
625// OBSOLETE {
626// OBSOLETE unsigned char buf[16];
627// OBSOLETE
628// OBSOLETE mem2hex((unsigned char *) &checksum, buf, 4, 0);
629// OBSOLETE gdb_error("Bad checksum: my count = %s, ", buf);
630// OBSOLETE mem2hex((unsigned char *) &xmitcsum, buf, 4, 0);
631// OBSOLETE gdb_error("sent count = %s\n", buf);
632// OBSOLETE gdb_error(" -- Bad buffer: \"%s\"\n", buffer);
633// OBSOLETE }
634// OBSOLETE putDebugChar ('-'); /* failed checksum */
635// OBSOLETE }
636// OBSOLETE else
637// OBSOLETE {
638// OBSOLETE putDebugChar ('+'); /* successful transfer */
639// OBSOLETE
640// OBSOLETE /* if a sequence char is present, reply the sequence ID */
641// OBSOLETE if (buffer[2] == ':')
642// OBSOLETE {
643// OBSOLETE putDebugChar (buffer[0]);
644// OBSOLETE putDebugChar (buffer[1]);
645// OBSOLETE
646// OBSOLETE return &buffer[3];
647// OBSOLETE }
648// OBSOLETE
649// OBSOLETE return &buffer[0];
650// OBSOLETE }
651// OBSOLETE }
652// OBSOLETE }
653// OBSOLETE }
654// OBSOLETE
655// OBSOLETE /* send the packet in buffer. */
656// OBSOLETE
657// OBSOLETE static void
658// OBSOLETE putpacket (unsigned char *buffer)
659// OBSOLETE {
660// OBSOLETE unsigned char checksum;
661// OBSOLETE int count;
662// OBSOLETE char ch;
663// OBSOLETE
664// OBSOLETE /* $<packet info>#<checksum>. */
665// OBSOLETE do {
666// OBSOLETE putDebugChar('$');
667// OBSOLETE checksum = 0;
668// OBSOLETE count = 0;
669// OBSOLETE
670// OBSOLETE while (ch=buffer[count]) {
671// OBSOLETE putDebugChar(ch);
672// OBSOLETE checksum += ch;
673// OBSOLETE count += 1;
674// OBSOLETE }
675// OBSOLETE putDebugChar('#');
676// OBSOLETE putDebugChar(hexchars[checksum >> 4]);
677// OBSOLETE putDebugChar(hexchars[checksum % 16]);
678// OBSOLETE } while (getDebugChar() != '+');
679// OBSOLETE }
680// OBSOLETE
681// OBSOLETE /* Address of a routine to RTE to if we get a memory fault. */
682// OBSOLETE
683// OBSOLETE static void (*volatile mem_fault_routine)() = 0;
684// OBSOLETE
685// OBSOLETE static void
686// OBSOLETE set_mem_err (void)
687// OBSOLETE {
688// OBSOLETE mem_err = 1;
689// OBSOLETE }
690// OBSOLETE
691// OBSOLETE /* Check the address for safe access ranges. As currently defined,
692// OBSOLETE this routine will reject the "expansion bus" address range(s).
693// OBSOLETE To make those ranges useable, someone must implement code to detect
694// OBSOLETE whether there's anything connected to the expansion bus. */
695// OBSOLETE
696// OBSOLETE static int
697// OBSOLETE mem_safe (unsigned char *addr)
698// OBSOLETE {
699// OBSOLETE #define BAD_RANGE_ONE_START ((unsigned char *) 0x600000)
700// OBSOLETE #define BAD_RANGE_ONE_END ((unsigned char *) 0xa00000)
701// OBSOLETE #define BAD_RANGE_TWO_START ((unsigned char *) 0xff680000)
702// OBSOLETE #define BAD_RANGE_TWO_END ((unsigned char *) 0xff800000)
703// OBSOLETE
704// OBSOLETE if (addr < BAD_RANGE_ONE_START) return 1; /* safe */
705// OBSOLETE if (addr < BAD_RANGE_ONE_END) return 0; /* unsafe */
706// OBSOLETE if (addr < BAD_RANGE_TWO_START) return 1; /* safe */
707// OBSOLETE if (addr < BAD_RANGE_TWO_END) return 0; /* unsafe */
708// OBSOLETE }
709// OBSOLETE
710// OBSOLETE /* These are separate functions so that they are so short and sweet
711// OBSOLETE that the compiler won't save any registers (if there is a fault
712// OBSOLETE to mem_fault, they won't get restored, so there better not be any
713// OBSOLETE saved). */
714// OBSOLETE static int
715// OBSOLETE get_char (unsigned char *addr)
716// OBSOLETE {
717// OBSOLETE #if 1
718// OBSOLETE if (mem_fault_routine && !mem_safe(addr))
719// OBSOLETE {
720// OBSOLETE mem_fault_routine ();
721// OBSOLETE return 0;
722// OBSOLETE }
723// OBSOLETE #endif
724// OBSOLETE return *addr;
725// OBSOLETE }
726// OBSOLETE
727// OBSOLETE static void
728// OBSOLETE set_char (unsigned char *addr, unsigned char val)
729// OBSOLETE {
730// OBSOLETE #if 1
731// OBSOLETE if (mem_fault_routine && !mem_safe (addr))
732// OBSOLETE {
733// OBSOLETE mem_fault_routine ();
734// OBSOLETE return;
735// OBSOLETE }
736// OBSOLETE #endif
737// OBSOLETE *addr = val;
738// OBSOLETE }
739// OBSOLETE
740// OBSOLETE /* Convert the memory pointed to by mem into hex, placing result in buf.
741// OBSOLETE Return a pointer to the last char put in buf (null).
742// OBSOLETE If MAY_FAULT is non-zero, then we should set mem_err in response to
743// OBSOLETE a fault; if zero treat a fault like any other fault in the stub. */
744// OBSOLETE
745// OBSOLETE static unsigned char *
746// OBSOLETE mem2hex (unsigned char *mem, unsigned char *buf, int count, int may_fault)
747// OBSOLETE {
748// OBSOLETE int i;
749// OBSOLETE unsigned char ch;
750// OBSOLETE
751// OBSOLETE if (may_fault)
752// OBSOLETE mem_fault_routine = set_mem_err;
753// OBSOLETE for (i=0;i<count;i++) {
754// OBSOLETE ch = get_char (mem++);
755// OBSOLETE if (may_fault && mem_err)
756// OBSOLETE return (buf);
757// OBSOLETE *buf++ = hexchars[ch >> 4];
758// OBSOLETE *buf++ = hexchars[ch % 16];
759// OBSOLETE }
760// OBSOLETE *buf = 0;
761// OBSOLETE if (may_fault)
762// OBSOLETE mem_fault_routine = 0;
763// OBSOLETE return(buf);
764// OBSOLETE }
765// OBSOLETE
766// OBSOLETE /* Convert the hex array pointed to by buf into binary to be placed in mem.
767// OBSOLETE Return a pointer to the character AFTER the last byte written. */
768// OBSOLETE
769// OBSOLETE static unsigned char*
770// OBSOLETE hex2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault)
771// OBSOLETE {
772// OBSOLETE int i;
773// OBSOLETE unsigned char ch;
774// OBSOLETE
775// OBSOLETE if (may_fault)
776// OBSOLETE mem_fault_routine = set_mem_err;
777// OBSOLETE for (i=0;i<count;i++) {
778// OBSOLETE ch = hex(*buf++) << 4;
779// OBSOLETE ch = ch + hex(*buf++);
780// OBSOLETE set_char (mem++, ch);
781// OBSOLETE if (may_fault && mem_err)
782// OBSOLETE return (mem);
783// OBSOLETE }
784// OBSOLETE if (may_fault)
785// OBSOLETE mem_fault_routine = 0;
786// OBSOLETE return(mem);
787// OBSOLETE }
788// OBSOLETE
789// OBSOLETE /* Convert the binary stream in BUF to memory.
790// OBSOLETE
791// OBSOLETE Gdb will escape $, #, and the escape char (0x7d).
792// OBSOLETE COUNT is the total number of bytes to write into
793// OBSOLETE memory. */
794// OBSOLETE static unsigned char *
795// OBSOLETE bin2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault)
796// OBSOLETE {
797// OBSOLETE int i;
798// OBSOLETE unsigned char ch;
799// OBSOLETE
800// OBSOLETE if (may_fault)
801// OBSOLETE mem_fault_routine = set_mem_err;
802// OBSOLETE for (i = 0; i < count; i++)
803// OBSOLETE {
804// OBSOLETE /* Check for any escaped characters. Be paranoid and
805// OBSOLETE only unescape chars that should be escaped. */
806// OBSOLETE if (*buf == 0x7d)
807// OBSOLETE {
808// OBSOLETE switch (*(buf+1))
809// OBSOLETE {
810// OBSOLETE case 0x3: /* # */
811// OBSOLETE case 0x4: /* $ */
812// OBSOLETE case 0x5d: /* escape char */
813// OBSOLETE buf++;
814// OBSOLETE *buf |= 0x20;
815// OBSOLETE break;
816// OBSOLETE default:
817// OBSOLETE /* nothing */
818// OBSOLETE break;
819// OBSOLETE }
820// OBSOLETE }
821// OBSOLETE
822// OBSOLETE set_char (mem++, *buf++);
823// OBSOLETE
824// OBSOLETE if (may_fault && mem_err)
825// OBSOLETE return mem;
826// OBSOLETE }
827// OBSOLETE
828// OBSOLETE if (may_fault)
829// OBSOLETE mem_fault_routine = 0;
830// OBSOLETE return mem;
831// OBSOLETE }
832// OBSOLETE
833// OBSOLETE /* this function takes the m32r exception vector and attempts to
834// OBSOLETE translate this number into a unix compatible signal value */
835// OBSOLETE
836// OBSOLETE static int
837// OBSOLETE computeSignal (int exceptionVector)
838// OBSOLETE {
839// OBSOLETE int sigval;
840// OBSOLETE switch (exceptionVector) {
841// OBSOLETE case 0 : sigval = 23; break; /* I/O trap */
842// OBSOLETE case 1 : sigval = 5; break; /* breakpoint */
843// OBSOLETE case 2 : sigval = 5; break; /* breakpoint */
844// OBSOLETE case 3 : sigval = 5; break; /* breakpoint */
845// OBSOLETE case 4 : sigval = 5; break; /* breakpoint */
846// OBSOLETE case 5 : sigval = 5; break; /* breakpoint */
847// OBSOLETE case 6 : sigval = 5; break; /* breakpoint */
848// OBSOLETE case 7 : sigval = 5; break; /* breakpoint */
849// OBSOLETE case 8 : sigval = 5; break; /* breakpoint */
850// OBSOLETE case 9 : sigval = 5; break; /* breakpoint */
851// OBSOLETE case 10 : sigval = 5; break; /* breakpoint */
852// OBSOLETE case 11 : sigval = 5; break; /* breakpoint */
853// OBSOLETE case 12 : sigval = 5; break; /* breakpoint */
854// OBSOLETE case 13 : sigval = 5; break; /* breakpoint */
855// OBSOLETE case 14 : sigval = 5; break; /* breakpoint */
856// OBSOLETE case 15 : sigval = 5; break; /* breakpoint */
857// OBSOLETE case 16 : sigval = 10; break; /* BUS ERROR (alignment) */
858// OBSOLETE case 17 : sigval = 2; break; /* INTerrupt */
859// OBSOLETE default : sigval = 7; break; /* "software generated" */
860// OBSOLETE }
861// OBSOLETE return (sigval);
862// OBSOLETE }
863// OBSOLETE
864// OBSOLETE /**********************************************/
865// OBSOLETE /* WHILE WE FIND NICE HEX CHARS, BUILD AN INT */
866// OBSOLETE /* RETURN NUMBER OF CHARS PROCESSED */
867// OBSOLETE /**********************************************/
868// OBSOLETE static int
869// OBSOLETE hexToInt (unsigned char **ptr, int *intValue)
870// OBSOLETE {
871// OBSOLETE int numChars = 0;
872// OBSOLETE int hexValue;
873// OBSOLETE
874// OBSOLETE *intValue = 0;
875// OBSOLETE while (**ptr)
876// OBSOLETE {
877// OBSOLETE hexValue = hex(**ptr);
878// OBSOLETE if (hexValue >=0)
879// OBSOLETE {
880// OBSOLETE *intValue = (*intValue <<4) | hexValue;
881// OBSOLETE numChars ++;
882// OBSOLETE }
883// OBSOLETE else
884// OBSOLETE break;
885// OBSOLETE (*ptr)++;
886// OBSOLETE }
887// OBSOLETE return (numChars);
888// OBSOLETE }
889// OBSOLETE
890// OBSOLETE /*
891// OBSOLETE Table of branch instructions:
892// OBSOLETE
893// OBSOLETE 10B6 RTE return from trap or exception
894// OBSOLETE 1FCr JMP jump
895// OBSOLETE 1ECr JL jump and link
896// OBSOLETE 7Fxx BRA branch
897// OBSOLETE FFxxxxxx BRA branch (long)
898// OBSOLETE B09rxxxx BNEZ branch not-equal-zero
899// OBSOLETE Br1rxxxx BNE branch not-equal
900// OBSOLETE 7Dxx BNC branch not-condition
901// OBSOLETE FDxxxxxx BNC branch not-condition (long)
902// OBSOLETE B0Arxxxx BLTZ branch less-than-zero
903// OBSOLETE B0Crxxxx BLEZ branch less-equal-zero
904// OBSOLETE 7Exx BL branch and link
905// OBSOLETE FExxxxxx BL branch and link (long)
906// OBSOLETE B0Drxxxx BGTZ branch greater-than-zero
907// OBSOLETE B0Brxxxx BGEZ branch greater-equal-zero
908// OBSOLETE B08rxxxx BEQZ branch equal-zero
909// OBSOLETE Br0rxxxx BEQ branch equal
910// OBSOLETE 7Cxx BC branch condition
911// OBSOLETE FCxxxxxx BC branch condition (long)
912// OBSOLETE */
913// OBSOLETE
914// OBSOLETE static int
915// OBSOLETE isShortBranch (unsigned char *instr)
916// OBSOLETE {
917// OBSOLETE unsigned char instr0 = instr[0] & 0x7F; /* mask off high bit */
918// OBSOLETE
919// OBSOLETE if (instr0 == 0x10 && instr[1] == 0xB6) /* RTE */
920// OBSOLETE return 1; /* return from trap or exception */
921// OBSOLETE
922// OBSOLETE if (instr0 == 0x1E || instr0 == 0x1F) /* JL or JMP */
923// OBSOLETE if ((instr[1] & 0xF0) == 0xC0)
924// OBSOLETE return 2; /* jump thru a register */
925// OBSOLETE
926// OBSOLETE if (instr0 == 0x7C || instr0 == 0x7D || /* BC, BNC, BL, BRA */
927// OBSOLETE instr0 == 0x7E || instr0 == 0x7F)
928// OBSOLETE return 3; /* eight bit PC offset */
929// OBSOLETE
930// OBSOLETE return 0;
931// OBSOLETE }
932// OBSOLETE
933// OBSOLETE static int
934// OBSOLETE isLongBranch (unsigned char *instr)
935// OBSOLETE {
936// OBSOLETE if (instr[0] == 0xFC || instr[0] == 0xFD || /* BRA, BNC, BL, BC */
937// OBSOLETE instr[0] == 0xFE || instr[0] == 0xFF) /* 24 bit relative */
938// OBSOLETE return 4;
939// OBSOLETE if ((instr[0] & 0xF0) == 0xB0) /* 16 bit relative */
940// OBSOLETE {
941// OBSOLETE if ((instr[1] & 0xF0) == 0x00 || /* BNE, BEQ */
942// OBSOLETE (instr[1] & 0xF0) == 0x10)
943// OBSOLETE return 5;
944// OBSOLETE if (instr[0] == 0xB0) /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ, BEQZ */
945// OBSOLETE if ((instr[1] & 0xF0) == 0x80 || (instr[1] & 0xF0) == 0x90 ||
946// OBSOLETE (instr[1] & 0xF0) == 0xA0 || (instr[1] & 0xF0) == 0xB0 ||
947// OBSOLETE (instr[1] & 0xF0) == 0xC0 || (instr[1] & 0xF0) == 0xD0)
948// OBSOLETE return 6;
949// OBSOLETE }
950// OBSOLETE return 0;
951// OBSOLETE }
952// OBSOLETE
953// OBSOLETE /* if address is NOT on a 4-byte boundary, or high-bit of instr is zero,
954// OBSOLETE then it's a 2-byte instruction, else it's a 4-byte instruction. */
955// OBSOLETE
956// OBSOLETE #define INSTRUCTION_SIZE(addr) \
957// OBSOLETE ((((int) addr & 2) || (((unsigned char *) addr)[0] & 0x80) == 0) ? 2 : 4)
958// OBSOLETE
959// OBSOLETE static int
960// OBSOLETE isBranch (unsigned char *instr)
961// OBSOLETE {
962// OBSOLETE if (INSTRUCTION_SIZE(instr) == 2)
963// OBSOLETE return isShortBranch(instr);
964// OBSOLETE else
965// OBSOLETE return isLongBranch(instr);
966// OBSOLETE }
967// OBSOLETE
968// OBSOLETE static int
969// OBSOLETE willBranch (unsigned char *instr, int branchCode)
970// OBSOLETE {
971// OBSOLETE switch (branchCode)
972// OBSOLETE {
973// OBSOLETE case 0: return 0; /* not a branch */
974// OBSOLETE case 1: return 1; /* RTE */
975// OBSOLETE case 2: return 1; /* JL or JMP */
976// OBSOLETE case 3: /* BC, BNC, BL, BRA (short) */
977// OBSOLETE case 4: /* BC, BNC, BL, BRA (long) */
978// OBSOLETE switch (instr[0] & 0x0F)
979// OBSOLETE {
980// OBSOLETE case 0xC: /* Branch if Condition Register */
981// OBSOLETE return (registers[CBR] != 0);
982// OBSOLETE case 0xD: /* Branch if NOT Condition Register */
983// OBSOLETE return (registers[CBR] == 0);
984// OBSOLETE case 0xE: /* Branch and Link */
985// OBSOLETE case 0xF: /* Branch (unconditional) */
986// OBSOLETE return 1;
987// OBSOLETE default: /* oops? */
988// OBSOLETE return 0;
989// OBSOLETE }
990// OBSOLETE case 5: /* BNE, BEQ */
991// OBSOLETE switch (instr[1] & 0xF0)
992// OBSOLETE {
993// OBSOLETE case 0x00: /* Branch if r1 equal to r2 */
994// OBSOLETE return (registers[instr[0] & 0x0F] == registers[instr[1] & 0x0F]);
995// OBSOLETE case 0x10: /* Branch if r1 NOT equal to r2 */
996// OBSOLETE return (registers[instr[0] & 0x0F] != registers[instr[1] & 0x0F]);
997// OBSOLETE default: /* oops? */
998// OBSOLETE return 0;
999// OBSOLETE }
1000// OBSOLETE case 6: /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ ,BEQZ */
1001// OBSOLETE switch (instr[1] & 0xF0)
1002// OBSOLETE {
1003// OBSOLETE case 0x80: /* Branch if reg equal to zero */
1004// OBSOLETE return (registers[instr[1] & 0x0F] == 0);
1005// OBSOLETE case 0x90: /* Branch if reg NOT equal to zero */
1006// OBSOLETE return (registers[instr[1] & 0x0F] != 0);
1007// OBSOLETE case 0xA0: /* Branch if reg less than zero */
1008// OBSOLETE return (registers[instr[1] & 0x0F] < 0);
1009// OBSOLETE case 0xB0: /* Branch if reg greater or equal to zero */
1010// OBSOLETE return (registers[instr[1] & 0x0F] >= 0);
1011// OBSOLETE case 0xC0: /* Branch if reg less than or equal to zero */
1012// OBSOLETE return (registers[instr[1] & 0x0F] <= 0);
1013// OBSOLETE case 0xD0: /* Branch if reg greater than zero */
1014// OBSOLETE return (registers[instr[1] & 0x0F] > 0);
1015// OBSOLETE default: /* oops? */
1016// OBSOLETE return 0;
1017// OBSOLETE }
1018// OBSOLETE default: /* oops? */
1019// OBSOLETE return 0;
1020// OBSOLETE }
1021// OBSOLETE }
1022// OBSOLETE
1023// OBSOLETE static int
1024// OBSOLETE branchDestination (unsigned char *instr, int branchCode)
1025// OBSOLETE {
1026// OBSOLETE switch (branchCode) {
1027// OBSOLETE default:
1028// OBSOLETE case 0: /* not a branch */
1029// OBSOLETE return 0;
1030// OBSOLETE case 1: /* RTE */
1031// OBSOLETE return registers[BPC] & ~3; /* pop BPC into PC */
1032// OBSOLETE case 2: /* JL or JMP */
1033// OBSOLETE return registers[instr[1] & 0x0F] & ~3; /* jump thru a register */
1034// OBSOLETE case 3: /* BC, BNC, BL, BRA (short, 8-bit relative offset) */
1035// OBSOLETE return (((int) instr) & ~3) + ((char) instr[1] << 2);
1036// OBSOLETE case 4: /* BC, BNC, BL, BRA (long, 24-bit relative offset) */
1037// OBSOLETE return ((int) instr +
1038// OBSOLETE ((((char) instr[1] << 16) | (instr[2] << 8) | (instr[3])) << 2));
1039// OBSOLETE case 5: /* BNE, BEQ (16-bit relative offset) */
1040// OBSOLETE case 6: /* BNEZ, BLTZ, BLEZ, BGTZ, BGEZ ,BEQZ (ditto) */
1041// OBSOLETE return ((int) instr + ((((char) instr[2] << 8) | (instr[3])) << 2));
1042// OBSOLETE }
1043// OBSOLETE
1044// OBSOLETE /* An explanatory note: in the last three return expressions, I have
1045// OBSOLETE cast the most-significant byte of the return offset to char.
1046// OBSOLETE What this accomplishes is sign extension. If the other
1047// OBSOLETE less-significant bytes were signed as well, they would get sign
1048// OBSOLETE extended too and, if negative, their leading bits would clobber
1049// OBSOLETE the bits of the more-significant bytes ahead of them. There are
1050// OBSOLETE other ways I could have done this, but sign extension from
1051// OBSOLETE odd-sized integers is always a pain. */
1052// OBSOLETE }
1053// OBSOLETE
1054// OBSOLETE static void
1055// OBSOLETE branchSideEffects (unsigned char *instr, int branchCode)
1056// OBSOLETE {
1057// OBSOLETE switch (branchCode)
1058// OBSOLETE {
1059// OBSOLETE case 1: /* RTE */
1060// OBSOLETE return; /* I <THINK> this is already handled... */
1061// OBSOLETE case 2: /* JL (or JMP) */
1062// OBSOLETE case 3: /* BL (or BC, BNC, BRA) */
1063// OBSOLETE case 4:
1064// OBSOLETE if ((instr[0] & 0x0F) == 0x0E) /* branch/jump and link */
1065// OBSOLETE registers[R14] = (registers[PC] & ~3) + 4;
1066// OBSOLETE return;
1067// OBSOLETE default: /* any other branch has no side effects */
1068// OBSOLETE return;
1069// OBSOLETE }
1070// OBSOLETE }
1071// OBSOLETE
1072// OBSOLETE static struct STEPPING_CONTEXT {
1073// OBSOLETE int stepping; /* true when we've started a single-step */
1074// OBSOLETE unsigned long target_addr; /* the instr we're trying to execute */
1075// OBSOLETE unsigned long target_size; /* the size of the target instr */
1076// OBSOLETE unsigned long noop_addr; /* where we've inserted a no-op, if any */
1077// OBSOLETE unsigned long trap1_addr; /* the trap following the target instr */
1078// OBSOLETE unsigned long trap2_addr; /* the trap at a branch destination, if any */
1079// OBSOLETE unsigned short noop_save; /* instruction overwritten by our no-op */
1080// OBSOLETE unsigned short trap1_save; /* instruction overwritten by trap1 */
1081// OBSOLETE unsigned short trap2_save; /* instruction overwritten by trap2 */
1082// OBSOLETE unsigned short continue_p; /* true if NOT returning to gdb after step */
1083// OBSOLETE } stepping;
1084// OBSOLETE
1085// OBSOLETE /* Function: prepare_to_step
1086// OBSOLETE Called from handle_exception to prepare the user program to single-step.
1087// OBSOLETE Places a trap instruction after the target instruction, with special
1088// OBSOLETE extra handling for branch instructions and for instructions in the
1089// OBSOLETE second half-word of a word.
1090// OBSOLETE
1091// OBSOLETE Returns: True if we should actually execute the instruction;
1092// OBSOLETE False if we are going to emulate executing the instruction,
1093// OBSOLETE in which case we simply report to GDB that the instruction
1094// OBSOLETE has already been executed. */
1095// OBSOLETE
1096// OBSOLETE #define TRAP1 0x10f1; /* trap #1 instruction */
1097// OBSOLETE #define NOOP 0x7000; /* noop instruction */
1098// OBSOLETE
1099// OBSOLETE static unsigned short trap1 = TRAP1;
1100// OBSOLETE static unsigned short noop = NOOP;
1101// OBSOLETE
1102// OBSOLETE static int
1103// OBSOLETE prepare_to_step(continue_p)
1104// OBSOLETE int continue_p; /* if this isn't REALLY a single-step (see below) */
1105// OBSOLETE {
1106// OBSOLETE unsigned long pc = registers[PC];
1107// OBSOLETE int branchCode = isBranch((unsigned char *) pc);
1108// OBSOLETE unsigned char *p;
1109// OBSOLETE
1110// OBSOLETE /* zero out the stepping context
1111// OBSOLETE (paranoia -- it should already be zeroed) */
1112// OBSOLETE for (p = (unsigned char *) &stepping;
1113// OBSOLETE p < ((unsigned char *) &stepping) + sizeof(stepping);
1114// OBSOLETE p++)
1115// OBSOLETE *p = 0;
1116// OBSOLETE
1117// OBSOLETE if (branchCode != 0) /* next instruction is a branch */
1118// OBSOLETE {
1119// OBSOLETE branchSideEffects((unsigned char *) pc, branchCode);
1120// OBSOLETE if (willBranch((unsigned char *)pc, branchCode))
1121// OBSOLETE registers[PC] = branchDestination((unsigned char *) pc, branchCode);
1122// OBSOLETE else
1123// OBSOLETE registers[PC] = pc + INSTRUCTION_SIZE(pc);
1124// OBSOLETE return 0; /* branch "executed" -- just notify GDB */
1125// OBSOLETE }
1126// OBSOLETE else if (((int) pc & 2) != 0) /* "second-slot" instruction */
1127// OBSOLETE {
1128// OBSOLETE /* insert no-op before pc */
1129// OBSOLETE stepping.noop_addr = pc - 2;
1130// OBSOLETE stepping.noop_save = *(unsigned short *) stepping.noop_addr;
1131// OBSOLETE *(unsigned short *) stepping.noop_addr = noop;
1132// OBSOLETE /* insert trap after pc */
1133// OBSOLETE stepping.trap1_addr = pc + 2;
1134// OBSOLETE stepping.trap1_save = *(unsigned short *) stepping.trap1_addr;
1135// OBSOLETE *(unsigned short *) stepping.trap1_addr = trap1;
1136// OBSOLETE }
1137// OBSOLETE else /* "first-slot" instruction */
1138// OBSOLETE {
1139// OBSOLETE /* insert trap after pc */
1140// OBSOLETE stepping.trap1_addr = pc + INSTRUCTION_SIZE(pc);
1141// OBSOLETE stepping.trap1_save = *(unsigned short *) stepping.trap1_addr;
1142// OBSOLETE *(unsigned short *) stepping.trap1_addr = trap1;
1143// OBSOLETE }
1144// OBSOLETE /* "continue_p" means that we are actually doing a continue, and not
1145// OBSOLETE being requested to single-step by GDB. Sometimes we have to do
1146// OBSOLETE one single-step before continuing, because the PC is on a half-word
1147// OBSOLETE boundary. There's no way to simply resume at such an address. */
1148// OBSOLETE stepping.continue_p = continue_p;
1149// OBSOLETE stepping.stepping = 1; /* starting a single-step */
1150// OBSOLETE return 1;
1151// OBSOLETE }
1152// OBSOLETE
1153// OBSOLETE /* Function: finish_from_step
1154// OBSOLETE Called from handle_exception to finish up when the user program
1155// OBSOLETE returns from a single-step. Replaces the instructions that had
1156// OBSOLETE been overwritten by traps or no-ops,
1157// OBSOLETE
1158// OBSOLETE Returns: True if we should notify GDB that the target stopped.
1159// OBSOLETE False if we only single-stepped because we had to before we
1160// OBSOLETE could continue (ie. we were trying to continue at a
1161// OBSOLETE half-word boundary). In that case don't notify GDB:
1162// OBSOLETE just "continue continuing". */
1163// OBSOLETE
1164// OBSOLETE static int
1165// OBSOLETE finish_from_step (void)
1166// OBSOLETE {
1167// OBSOLETE if (stepping.stepping) /* anything to do? */
1168// OBSOLETE {
1169// OBSOLETE int continue_p = stepping.continue_p;
1170// OBSOLETE unsigned char *p;
1171// OBSOLETE
1172// OBSOLETE if (stepping.noop_addr) /* replace instr "under" our no-op */
1173// OBSOLETE *(unsigned short *) stepping.noop_addr = stepping.noop_save;
1174// OBSOLETE if (stepping.trap1_addr) /* replace instr "under" our trap */
1175// OBSOLETE *(unsigned short *) stepping.trap1_addr = stepping.trap1_save;
1176// OBSOLETE if (stepping.trap2_addr) /* ditto our other trap, if any */
1177// OBSOLETE *(unsigned short *) stepping.trap2_addr = stepping.trap2_save;
1178// OBSOLETE
1179// OBSOLETE for (p = (unsigned char *) &stepping; /* zero out the stepping context */
1180// OBSOLETE p < ((unsigned char *) &stepping) + sizeof(stepping);
1181// OBSOLETE p++)
1182// OBSOLETE *p = 0;
1183// OBSOLETE
1184// OBSOLETE return !(continue_p);
1185// OBSOLETE }
1186// OBSOLETE else /* we didn't single-step, therefore this must be a legitimate stop */
1187// OBSOLETE return 1;
1188// OBSOLETE }
1189// OBSOLETE
1190// OBSOLETE struct PSWreg { /* separate out the bit flags in the PSW register */
1191// OBSOLETE int pad1 : 16;
1192// OBSOLETE int bsm : 1;
1193// OBSOLETE int bie : 1;
1194// OBSOLETE int pad2 : 5;
1195// OBSOLETE int bc : 1;
1196// OBSOLETE int sm : 1;
1197// OBSOLETE int ie : 1;
1198// OBSOLETE int pad3 : 5;
1199// OBSOLETE int c : 1;
1200// OBSOLETE } *psw;
1201// OBSOLETE
1202// OBSOLETE /* Upon entry the value for LR to save has been pushed.
1203// OBSOLETE We unpush that so that the value for the stack pointer saved is correct.
1204// OBSOLETE Upon entry, all other registers are assumed to have not been modified
1205// OBSOLETE since the interrupt/trap occured. */
1206// OBSOLETE
1207// OBSOLETE asm ("
1208// OBSOLETE stash_registers:
1209// OBSOLETE push r0
1210// OBSOLETE push r1
1211// OBSOLETE seth r1, #shigh(registers)
1212// OBSOLETE add3 r1, r1, #low(registers)
1213// OBSOLETE pop r0 ; r1
1214// OBSOLETE st r0, @(4,r1)
1215// OBSOLETE pop r0 ; r0
1216// OBSOLETE st r0, @r1
1217// OBSOLETE addi r1, #4 ; only add 4 as subsequent saves are `pre inc'
1218// OBSOLETE st r2, @+r1
1219// OBSOLETE st r3, @+r1
1220// OBSOLETE st r4, @+r1
1221// OBSOLETE st r5, @+r1
1222// OBSOLETE st r6, @+r1
1223// OBSOLETE st r7, @+r1
1224// OBSOLETE st r8, @+r1
1225// OBSOLETE st r9, @+r1
1226// OBSOLETE st r10, @+r1
1227// OBSOLETE st r11, @+r1
1228// OBSOLETE st r12, @+r1
1229// OBSOLETE st r13, @+r1 ; fp
1230// OBSOLETE pop r0 ; lr (r14)
1231// OBSOLETE st r0, @+r1
1232// OBSOLETE st sp, @+r1 ; sp contains right value at this point
1233// OBSOLETE mvfc r0, cr0
1234// OBSOLETE st r0, @+r1 ; cr0 == PSW
1235// OBSOLETE mvfc r0, cr1
1236// OBSOLETE st r0, @+r1 ; cr1 == CBR
1237// OBSOLETE mvfc r0, cr2
1238// OBSOLETE st r0, @+r1 ; cr2 == SPI
1239// OBSOLETE mvfc r0, cr3
1240// OBSOLETE st r0, @+r1 ; cr3 == SPU
1241// OBSOLETE mvfc r0, cr6
1242// OBSOLETE st r0, @+r1 ; cr6 == BPC
1243// OBSOLETE st r0, @+r1 ; PC == BPC
1244// OBSOLETE mvfaclo r0
1245// OBSOLETE st r0, @+r1 ; ACCL
1246// OBSOLETE mvfachi r0
1247// OBSOLETE st r0, @+r1 ; ACCH
1248// OBSOLETE jmp lr");
1249// OBSOLETE
1250// OBSOLETE /* C routine to clean up what stash_registers did.
1251// OBSOLETE It is called after calling stash_registers.
1252// OBSOLETE This is separate from stash_registers as we want to do this in C
1253// OBSOLETE but doing stash_registers in C isn't straightforward. */
1254// OBSOLETE
1255// OBSOLETE static void
1256// OBSOLETE cleanup_stash (void)
1257// OBSOLETE {
1258// OBSOLETE psw = (struct PSWreg *) &registers[PSW]; /* fields of PSW register */
1259// OBSOLETE psw->sm = psw->bsm; /* fix up pre-trap values of psw fields */
1260// OBSOLETE psw->ie = psw->bie;
1261// OBSOLETE psw->c = psw->bc;
1262// OBSOLETE registers[CBR] = psw->bc; /* fix up pre-trap "C" register */
1263// OBSOLETE
1264// OBSOLETE #if 0 /* FIXME: Was in previous version. Necessary?
1265// OBSOLETE (Remember that we use the "rte" insn to return from the
1266// OBSOLETE trap/interrupt so the values of bsm, bie, bc are important. */
1267// OBSOLETE psw->bsm = psw->bie = psw->bc = 0; /* zero post-trap values */
1268// OBSOLETE #endif
1269// OBSOLETE
1270// OBSOLETE /* FIXME: Copied from previous version. This can probably be deleted
1271// OBSOLETE since methinks stash_registers has already done this. */
1272// OBSOLETE registers[PC] = registers[BPC]; /* pre-trap PC */
1273// OBSOLETE
1274// OBSOLETE /* FIXME: Copied from previous version. Necessary? */
1275// OBSOLETE if (psw->sm) /* copy R15 into (psw->sm ? SPU : SPI) */
1276// OBSOLETE registers[SPU] = registers[R15];
1277// OBSOLETE else
1278// OBSOLETE registers[SPI] = registers[R15];
1279// OBSOLETE }
1280// OBSOLETE
1281// OBSOLETE asm ("
1282// OBSOLETE restore_and_return:
1283// OBSOLETE seth r0, #shigh(registers+8)
1284// OBSOLETE add3 r0, r0, #low(registers+8)
1285// OBSOLETE ld r2, @r0+ ; restore r2
1286// OBSOLETE ld r3, @r0+ ; restore r3
1287// OBSOLETE ld r4, @r0+ ; restore r4
1288// OBSOLETE ld r5, @r0+ ; restore r5
1289// OBSOLETE ld r6, @r0+ ; restore r6
1290// OBSOLETE ld r7, @r0+ ; restore r7
1291// OBSOLETE ld r8, @r0+ ; restore r8
1292// OBSOLETE ld r9, @r0+ ; restore r9
1293// OBSOLETE ld r10, @r0+ ; restore r10
1294// OBSOLETE ld r11, @r0+ ; restore r11
1295// OBSOLETE ld r12, @r0+ ; restore r12
1296// OBSOLETE ld r13, @r0+ ; restore r13
1297// OBSOLETE ld r14, @r0+ ; restore r14
1298// OBSOLETE ld r15, @r0+ ; restore r15
1299// OBSOLETE addi r0, #4 ; don't restore PSW (rte will do it)
1300// OBSOLETE ld r1, @r0+ ; restore cr1 == CBR (no-op, because it's read only)
1301// OBSOLETE mvtc r1, cr1
1302// OBSOLETE ld r1, @r0+ ; restore cr2 == SPI
1303// OBSOLETE mvtc r1, cr2
1304// OBSOLETE ld r1, @r0+ ; restore cr3 == SPU
1305// OBSOLETE mvtc r1, cr3
1306// OBSOLETE addi r0, #4 ; skip BPC
1307// OBSOLETE ld r1, @r0+ ; restore cr6 (BPC) == PC
1308// OBSOLETE mvtc r1, cr6
1309// OBSOLETE ld r1, @r0+ ; restore ACCL
1310// OBSOLETE mvtaclo r1
1311// OBSOLETE ld r1, @r0+ ; restore ACCH
1312// OBSOLETE mvtachi r1
1313// OBSOLETE seth r0, #shigh(registers)
1314// OBSOLETE add3 r0, r0, #low(registers)
1315// OBSOLETE ld r1, @(4,r0) ; restore r1
1316// OBSOLETE ld r0, @r0 ; restore r0
1317// OBSOLETE rte");
1318// OBSOLETE
1319// OBSOLETE /* General trap handler, called after the registers have been stashed.
1320// OBSOLETE NUM is the trap/exception number. */
1321// OBSOLETE
1322// OBSOLETE static void
1323// OBSOLETE process_exception (int num)
1324// OBSOLETE {
1325// OBSOLETE cleanup_stash ();
1326// OBSOLETE asm volatile ("
1327// OBSOLETE seth r1, #shigh(stackPtr)
1328// OBSOLETE add3 r1, r1, #low(stackPtr)
1329// OBSOLETE ld r15, @r1 ; setup local stack (protect user stack)
1330// OBSOLETE mv r0, %0
1331// OBSOLETE bl handle_exception
1332// OBSOLETE bl restore_and_return"
1333// OBSOLETE : : "r" (num) : "r0", "r1");
1334// OBSOLETE }
1335// OBSOLETE
1336// OBSOLETE void _catchException0 ();
1337// OBSOLETE
1338// OBSOLETE asm ("
1339// OBSOLETE _catchException0:
1340// OBSOLETE push lr
1341// OBSOLETE bl stash_registers
1342// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1343// OBSOLETE ldi r0, #0
1344// OBSOLETE bl process_exception");
1345// OBSOLETE
1346// OBSOLETE void _catchException1 ();
1347// OBSOLETE
1348// OBSOLETE asm ("
1349// OBSOLETE _catchException1:
1350// OBSOLETE push lr
1351// OBSOLETE bl stash_registers
1352// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1353// OBSOLETE bl cleanup_stash
1354// OBSOLETE seth r1, #shigh(stackPtr)
1355// OBSOLETE add3 r1, r1, #low(stackPtr)
1356// OBSOLETE ld r15, @r1 ; setup local stack (protect user stack)
1357// OBSOLETE seth r1, #shigh(registers + 21*4) ; PC
1358// OBSOLETE add3 r1, r1, #low(registers + 21*4)
1359// OBSOLETE ld r0, @r1
1360// OBSOLETE addi r0, #-4 ; back up PC for breakpoint trap.
1361// OBSOLETE st r0, @r1 ; FIXME: what about bp in right slot?
1362// OBSOLETE ldi r0, #1
1363// OBSOLETE bl handle_exception
1364// OBSOLETE bl restore_and_return");
1365// OBSOLETE
1366// OBSOLETE void _catchException2 ();
1367// OBSOLETE
1368// OBSOLETE asm ("
1369// OBSOLETE _catchException2:
1370// OBSOLETE push lr
1371// OBSOLETE bl stash_registers
1372// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1373// OBSOLETE ldi r0, #2
1374// OBSOLETE bl process_exception");
1375// OBSOLETE
1376// OBSOLETE void _catchException3 ();
1377// OBSOLETE
1378// OBSOLETE asm ("
1379// OBSOLETE _catchException3:
1380// OBSOLETE push lr
1381// OBSOLETE bl stash_registers
1382// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1383// OBSOLETE ldi r0, #3
1384// OBSOLETE bl process_exception");
1385// OBSOLETE
1386// OBSOLETE void _catchException4 ();
1387// OBSOLETE
1388// OBSOLETE asm ("
1389// OBSOLETE _catchException4:
1390// OBSOLETE push lr
1391// OBSOLETE bl stash_registers
1392// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1393// OBSOLETE ldi r0, #4
1394// OBSOLETE bl process_exception");
1395// OBSOLETE
1396// OBSOLETE void _catchException5 ();
1397// OBSOLETE
1398// OBSOLETE asm ("
1399// OBSOLETE _catchException5:
1400// OBSOLETE push lr
1401// OBSOLETE bl stash_registers
1402// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1403// OBSOLETE ldi r0, #5
1404// OBSOLETE bl process_exception");
1405// OBSOLETE
1406// OBSOLETE void _catchException6 ();
1407// OBSOLETE
1408// OBSOLETE asm ("
1409// OBSOLETE _catchException6:
1410// OBSOLETE push lr
1411// OBSOLETE bl stash_registers
1412// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1413// OBSOLETE ldi r0, #6
1414// OBSOLETE bl process_exception");
1415// OBSOLETE
1416// OBSOLETE void _catchException7 ();
1417// OBSOLETE
1418// OBSOLETE asm ("
1419// OBSOLETE _catchException7:
1420// OBSOLETE push lr
1421// OBSOLETE bl stash_registers
1422// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1423// OBSOLETE ldi r0, #7
1424// OBSOLETE bl process_exception");
1425// OBSOLETE
1426// OBSOLETE void _catchException8 ();
1427// OBSOLETE
1428// OBSOLETE asm ("
1429// OBSOLETE _catchException8:
1430// OBSOLETE push lr
1431// OBSOLETE bl stash_registers
1432// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1433// OBSOLETE ldi r0, #8
1434// OBSOLETE bl process_exception");
1435// OBSOLETE
1436// OBSOLETE void _catchException9 ();
1437// OBSOLETE
1438// OBSOLETE asm ("
1439// OBSOLETE _catchException9:
1440// OBSOLETE push lr
1441// OBSOLETE bl stash_registers
1442// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1443// OBSOLETE ldi r0, #9
1444// OBSOLETE bl process_exception");
1445// OBSOLETE
1446// OBSOLETE void _catchException10 ();
1447// OBSOLETE
1448// OBSOLETE asm ("
1449// OBSOLETE _catchException10:
1450// OBSOLETE push lr
1451// OBSOLETE bl stash_registers
1452// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1453// OBSOLETE ldi r0, #10
1454// OBSOLETE bl process_exception");
1455// OBSOLETE
1456// OBSOLETE void _catchException11 ();
1457// OBSOLETE
1458// OBSOLETE asm ("
1459// OBSOLETE _catchException11:
1460// OBSOLETE push lr
1461// OBSOLETE bl stash_registers
1462// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1463// OBSOLETE ldi r0, #11
1464// OBSOLETE bl process_exception");
1465// OBSOLETE
1466// OBSOLETE void _catchException12 ();
1467// OBSOLETE
1468// OBSOLETE asm ("
1469// OBSOLETE _catchException12:
1470// OBSOLETE push lr
1471// OBSOLETE bl stash_registers
1472// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1473// OBSOLETE ldi r0, #12
1474// OBSOLETE bl process_exception");
1475// OBSOLETE
1476// OBSOLETE void _catchException13 ();
1477// OBSOLETE
1478// OBSOLETE asm ("
1479// OBSOLETE _catchException13:
1480// OBSOLETE push lr
1481// OBSOLETE bl stash_registers
1482// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1483// OBSOLETE ldi r0, #13
1484// OBSOLETE bl process_exception");
1485// OBSOLETE
1486// OBSOLETE void _catchException14 ();
1487// OBSOLETE
1488// OBSOLETE asm ("
1489// OBSOLETE _catchException14:
1490// OBSOLETE push lr
1491// OBSOLETE bl stash_registers
1492// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1493// OBSOLETE ldi r0, #14
1494// OBSOLETE bl process_exception");
1495// OBSOLETE
1496// OBSOLETE void _catchException15 ();
1497// OBSOLETE
1498// OBSOLETE asm ("
1499// OBSOLETE _catchException15:
1500// OBSOLETE push lr
1501// OBSOLETE bl stash_registers
1502// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1503// OBSOLETE ldi r0, #15
1504// OBSOLETE bl process_exception");
1505// OBSOLETE
1506// OBSOLETE void _catchException16 ();
1507// OBSOLETE
1508// OBSOLETE asm ("
1509// OBSOLETE _catchException16:
1510// OBSOLETE push lr
1511// OBSOLETE bl stash_registers
1512// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1513// OBSOLETE ldi r0, #16
1514// OBSOLETE bl process_exception");
1515// OBSOLETE
1516// OBSOLETE void _catchException17 ();
1517// OBSOLETE
1518// OBSOLETE asm ("
1519// OBSOLETE _catchException17:
1520// OBSOLETE push lr
1521// OBSOLETE bl stash_registers
1522// OBSOLETE ; Note that at this point the pushed value of `lr' has been popped
1523// OBSOLETE ldi r0, #17
1524// OBSOLETE bl process_exception");
1525// OBSOLETE
1526// OBSOLETE
1527// OBSOLETE /* this function is used to set up exception handlers for tracing and
1528// OBSOLETE breakpoints */
1529// OBSOLETE void
1530// OBSOLETE set_debug_traps (void)
1531// OBSOLETE {
1532// OBSOLETE /* extern void remcomHandler(); */
1533// OBSOLETE int i;
1534// OBSOLETE
1535// OBSOLETE for (i = 0; i < 18; i++) /* keep a copy of old vectors */
1536// OBSOLETE if (save_vectors[i] == 0) /* only copy them the first time */
1537// OBSOLETE save_vectors[i] = getExceptionHandler (i);
1538// OBSOLETE
1539// OBSOLETE stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1];
1540// OBSOLETE
1541// OBSOLETE exceptionHandler (0, _catchException0);
1542// OBSOLETE exceptionHandler (1, _catchException1);
1543// OBSOLETE exceptionHandler (2, _catchException2);
1544// OBSOLETE exceptionHandler (3, _catchException3);
1545// OBSOLETE exceptionHandler (4, _catchException4);
1546// OBSOLETE exceptionHandler (5, _catchException5);
1547// OBSOLETE exceptionHandler (6, _catchException6);
1548// OBSOLETE exceptionHandler (7, _catchException7);
1549// OBSOLETE exceptionHandler (8, _catchException8);
1550// OBSOLETE exceptionHandler (9, _catchException9);
1551// OBSOLETE exceptionHandler (10, _catchException10);
1552// OBSOLETE exceptionHandler (11, _catchException11);
1553// OBSOLETE exceptionHandler (12, _catchException12);
1554// OBSOLETE exceptionHandler (13, _catchException13);
1555// OBSOLETE exceptionHandler (14, _catchException14);
1556// OBSOLETE exceptionHandler (15, _catchException15);
1557// OBSOLETE exceptionHandler (16, _catchException16);
1558// OBSOLETE /* exceptionHandler (17, _catchException17); */
1559// OBSOLETE
1560// OBSOLETE initialized = 1;
1561// OBSOLETE }
1562// OBSOLETE
1563// OBSOLETE /* This function will generate a breakpoint exception. It is used at the
1564// OBSOLETE beginning of a program to sync up with a debugger and can be used
1565// OBSOLETE otherwise as a quick means to stop program execution and "break" into
1566// OBSOLETE the debugger. */
1567// OBSOLETE
1568// OBSOLETE #define BREAKPOINT() asm volatile (" trap #2");
1569// OBSOLETE
1570// OBSOLETE void
1571// OBSOLETE breakpoint (void)
1572// OBSOLETE {
1573// OBSOLETE if (initialized)
1574// OBSOLETE BREAKPOINT();
1575// OBSOLETE }
1576// OBSOLETE
1577// OBSOLETE /* STDOUT section:
1578// OBSOLETE Stuff pertaining to simulating stdout by sending chars to gdb to be echoed.
1579// OBSOLETE Functions: gdb_putchar(char ch)
1580// OBSOLETE gdb_puts(char *str)
1581// OBSOLETE gdb_write(char *str, int len)
1582// OBSOLETE gdb_error(char *format, char *parm)
1583// OBSOLETE */
1584// OBSOLETE
1585// OBSOLETE /* Function: gdb_putchar(int)
1586// OBSOLETE Make gdb write a char to stdout.
1587// OBSOLETE Returns: the char */
1588// OBSOLETE
1589// OBSOLETE static int
1590// OBSOLETE gdb_putchar (int ch)
1591// OBSOLETE {
1592// OBSOLETE char buf[4];
1593// OBSOLETE
1594// OBSOLETE buf[0] = 'O';
1595// OBSOLETE buf[1] = hexchars[ch >> 4];
1596// OBSOLETE buf[2] = hexchars[ch & 0x0F];
1597// OBSOLETE buf[3] = 0;
1598// OBSOLETE putpacket(buf);
1599// OBSOLETE return ch;
1600// OBSOLETE }
1601// OBSOLETE
1602// OBSOLETE /* Function: gdb_write(char *, int)
1603// OBSOLETE Make gdb write n bytes to stdout (not assumed to be null-terminated).
1604// OBSOLETE Returns: number of bytes written */
1605// OBSOLETE
1606// OBSOLETE static int
1607// OBSOLETE gdb_write (char *data, int len)
1608// OBSOLETE {
1609// OBSOLETE char *buf, *cpy;
1610// OBSOLETE int i;
1611// OBSOLETE
1612// OBSOLETE buf = remcomOutBuffer;
1613// OBSOLETE buf[0] = 'O';
1614// OBSOLETE i = 0;
1615// OBSOLETE while (i < len)
1616// OBSOLETE {
1617// OBSOLETE for (cpy = buf+1;
1618// OBSOLETE i < len && cpy < buf + sizeof(remcomOutBuffer) - 3;
1619// OBSOLETE i++)
1620// OBSOLETE {
1621// OBSOLETE *cpy++ = hexchars[data[i] >> 4];
1622// OBSOLETE *cpy++ = hexchars[data[i] & 0x0F];
1623// OBSOLETE }
1624// OBSOLETE *cpy = 0;
1625// OBSOLETE putpacket(buf);
1626// OBSOLETE }
1627// OBSOLETE return len;
1628// OBSOLETE }
1629// OBSOLETE
1630// OBSOLETE /* Function: gdb_puts(char *)
1631// OBSOLETE Make gdb write a null-terminated string to stdout.
1632// OBSOLETE Returns: the length of the string */
1633// OBSOLETE
1634// OBSOLETE static int
1635// OBSOLETE gdb_puts (char *str)
1636// OBSOLETE {
1637// OBSOLETE return gdb_write(str, strlen(str));
1638// OBSOLETE }
1639// OBSOLETE
1640// OBSOLETE /* Function: gdb_error(char *, char *)
1641// OBSOLETE Send an error message to gdb's stdout.
1642// OBSOLETE First string may have 1 (one) optional "%s" in it, which
1643// OBSOLETE will cause the optional second string to be inserted. */
1644// OBSOLETE
1645// OBSOLETE static void
1646// OBSOLETE gdb_error (char *format, char *parm)
1647// OBSOLETE {
1648// OBSOLETE char buf[400], *cpy;
1649// OBSOLETE int len;
1650// OBSOLETE
1651// OBSOLETE if (remote_debug)
1652// OBSOLETE {
1653// OBSOLETE if (format && *format)
1654// OBSOLETE len = strlen(format);
1655// OBSOLETE else
1656// OBSOLETE return; /* empty input */
1657// OBSOLETE
1658// OBSOLETE if (parm && *parm)
1659// OBSOLETE len += strlen(parm);
1660// OBSOLETE
1661// OBSOLETE for (cpy = buf; *format; )
1662// OBSOLETE {
1663// OBSOLETE if (format[0] == '%' && format[1] == 's') /* include second string */
1664// OBSOLETE {
1665// OBSOLETE format += 2; /* advance two chars instead of just one */
1666// OBSOLETE while (parm && *parm)
1667// OBSOLETE *cpy++ = *parm++;
1668// OBSOLETE }
1669// OBSOLETE else
1670// OBSOLETE *cpy++ = *format++;
1671// OBSOLETE }
1672// OBSOLETE *cpy = '\0';
1673// OBSOLETE gdb_puts(buf);
1674// OBSOLETE }
1675// OBSOLETE }
1676// OBSOLETE
1677// OBSOLETE static unsigned char *
1678// OBSOLETE strcpy (unsigned char *dest, const unsigned char *src)
1679// OBSOLETE {
1680// OBSOLETE unsigned char *ret = dest;
1681// OBSOLETE
1682// OBSOLETE if (dest && src)
1683// OBSOLETE {
1684// OBSOLETE while (*src)
1685// OBSOLETE *dest++ = *src++;
1686// OBSOLETE *dest = 0;
1687// OBSOLETE }
1688// OBSOLETE return ret;
1689// OBSOLETE }
1690// OBSOLETE
1691// OBSOLETE static int
1692// OBSOLETE strlen (const unsigned char *src)
1693// OBSOLETE {
1694// OBSOLETE int ret;
1695// OBSOLETE
1696// OBSOLETE for (ret = 0; *src; src++)
1697// OBSOLETE ret++;
1698// OBSOLETE
1699// OBSOLETE return ret;
1700// OBSOLETE }
1701// OBSOLETE
1702// OBSOLETE #if 0
1703// OBSOLETE void exit (code)
1704// OBSOLETE int code;
1705// OBSOLETE {
1706// OBSOLETE _exit (code);
1707// OBSOLETE }
1708// OBSOLETE
1709// OBSOLETE int atexit (void *p)
1710// OBSOLETE {
1711// OBSOLETE return 0;
1712// OBSOLETE }
1713// OBSOLETE
1714// OBSOLETE void abort (void)
1715// OBSOLETE {
1716// OBSOLETE _exit (1);
1717// OBSOLETE }
1718// OBSOLETE #endif
This page took 0.123188 seconds and 4 git commands to generate.