1 /****************************************************************************
3 THIS SOFTWARE IS NOT COPYRIGHTED
5 HP offers the following for use in the public domain. HP makes no
6 warranty with regard to the software or it's performance and the
7 user accepts the software "AS IS" with all faults.
9 HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
10 TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
11 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ****************************************************************************/
15 /****************************************************************************
18 * $Module name: remcom.c $
21 * $Contributor: Lake Stevens Instrument Division$
23 * $Description: low level support for gdb debugger. $
25 * $Considerations: only works on target hardware $
27 * $Written by: Glenn Engel $
28 * $ModuleState: Experimental $
32 * To enable debugger support, two things need to happen. One, a
33 * call to set_debug_traps() is necessary in order to allow any breakpoints
34 * or error conditions to be properly intercepted and reported to gdb.
35 * Two, a breakpoint needs to be generated to begin communication. This
36 * is most easily accomplished by a call to breakpoint(). Breakpoint()
37 * simulates a breakpoint by executing a trap #1.
39 * Some explanation is probably necessary to explain how exceptions are
40 * handled. When an exception is encountered the 68000 pushes the current
41 * program counter and status register onto the supervisor stack and then
42 * transfers execution to a location specified in it's vector table.
43 * The handlers for the exception vectors are hardwired to jmp to an address
44 * given by the relation: (exception - 256) * 6. These are decending
45 * addresses starting from -6, -12, -18, ... By allowing 6 bytes for
46 * each entry, a jsr, jmp, bsr, ... can be used to enter the exception
47 * handler. Using a jsr to handle an exception has an added benefit of
48 * allowing a single handler to service several exceptions and use the
49 * return address as the key differentiation. The vector number can be
50 * computed from the return address by [ exception = (addr + 1530) / 6 ].
51 * The sole purpose of the routine _catchException is to compute the
52 * exception number and push it on the stack in place of the return address.
53 * The external function exceptionHandler() is
54 * used to attach a specific handler to a specific 68k exception.
55 * For 68020 machines, the ability to have a return address around just
56 * so the vector can be determined is not necessary because the '020 pushes an
57 * extra word onto the stack containing the vector offset
59 * Because gdb will sometimes write to the stack area to execute function
60 * calls, this program cannot rely on using the supervisor stack so it
61 * uses it's own stack area reserved in the int array remcomStack.
65 * The following gdb commands are supported:
67 * command function Return value
69 * g return the value of the CPU registers hex data or ENN
70 * G set the value of the CPU registers OK or ENN
72 * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
73 * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
75 * c Resume at current address SNN ( signal NN)
76 * cAA..AA Continue at address AA..AA SNN
78 * s Step one instruction SNN
79 * sAA..AA Step one instruction from AA..AA SNN
83 * ? What was the last sigval ? SNN (signal NN)
85 * All commands and responses are sent with a packet which includes a
86 * checksum. A packet consists of
88 * $<packet info>#<checksum>.
91 * <packet info> :: <characters representing the command or response>
92 * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>
94 * When a packet is received, it is first acknowledged with either '+' or '-'.
95 * '+' indicates a successful transfer. '-' indicates a failed transfer.
100 * $m0,10#2a +$00010203040506070809101112131415#42
102 ****************************************************************************/
108 /************************************************************************
110 * external low-level support routines
112 typedef void (*ExceptionHook
)(int); /* pointer to function with int parm */
113 typedef void (*Function
)(); /* pointer to a function */
115 extern putDebugChar(); /* write a single character */
116 extern getDebugChar(); /* read and return a single char */
118 extern Function
exceptionHandler(); /* assign an exception handler */
119 extern ExceptionHook exceptionHook
; /* hook variable for errors/exceptions */
121 /************************/
122 /* FORWARD DECLARATIONS */
123 /************************/
124 void initializeRemcomErrorFrame(void);
126 /************************************************************************/
127 /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
128 /* at least NUMREGBYTES*2 are needed for register packets */
131 static char initialized
; /* boolean flag. != 0 means we've been initialized */
134 /* debug > 0 prints ill-formed commands in valid packets & checksum errors */
136 static const char hexchars
[]="0123456789abcdef";
138 /* there are 180 bytes of registers on a 68020 w/68881 */
139 /* many of the fpa registers are 12 byte (96 bit) registers */
140 #define NUMREGBYTES 180
141 enum regnames
{D0
,D1
,D2
,D3
,D4
,D5
,D6
,D7
,
142 A0
,A1
,A2
,A3
,A4
,A5
,A6
,A7
,
144 FP0
,FP1
,FP2
,FP3
,FP4
,FP5
,FP6
,FP7
,
145 FPCONTROL
,FPSTATUS
,FPIADDR
148 typedef struct FrameStruct
150 struct FrameStruct
*previous
;
151 int exceptionPC
; /* pc value when this frame created */
152 int exceptionVector
; /* cpu vector causing exception */
153 short frameSize
; /* size of cpu frame in words */
154 short sr
; /* for 68000, this not always sr */
158 int morejunk
[0]; /* exception frame, fp save... */
161 #define FRAMESIZE 500
162 int gdbFrameStack
[FRAMESIZE
];
163 static Frame
*lastFrame
;
166 * these should not be static cuz they can be used outside this module
168 int registers
[NUMREGBYTES
/4];
171 #define STACKSIZE 10000
172 int remcomStack
[STACKSIZE
/sizeof(int)];
173 static int* stackPtr
= &remcomStack
[STACKSIZE
/sizeof(int) - 1];
176 * In many cases, the system will want to continue exception processing
177 * when a continue command is given.
178 * oldExceptionHook is a function to invoke in this case.
181 static ExceptionHook oldExceptionHook
;
183 /* the size of the exception stack on the 68020 varies with the type of
184 * exception. The following table is the number of WORDS used
185 * for each exception format.
187 const short exceptionSize
[] = { 4,4,6,4,4,4,4,4,29,10,16,46,12,4,4,4 };
189 /************* jump buffer used for setjmp/longjmp **************************/
192 /*************************** ASSEMBLY CODE MACROS *************************/
195 #ifdef __HAVE_68881__
196 /* do an fsave, then remember the address to begin a restore from */
197 #define SAVE_FP_REGS() asm(" fsave a0@-"); \
198 asm(" fmovemx fp0-fp7,_registers+72"); \
199 asm(" fmoveml fpcr/fpsr/fpi,_registers+168");
200 #define RESTORE_FP_REGS() \
202 fmoveml _registers+168,fpcr/fpsr/fpi \n\
203 fmovemx _registers+72,fp0-fp7 \n\
204 cmpl #-1,a0@ | skip frestore flag set ? \n\
205 beq skip_frestore \n\
211 #define SAVE_FP_REGS()
212 #define RESTORE_FP_REGS()
213 #endif /* __HAVE_68881__ */
215 void return_to_super(void);
216 void return_to_user(void);
220 .globl _return_to_super
222 movel _registers+60,sp /* get new stack pointer */
223 movel _lastFrame,a0 /* get last frame info */
226 .globl _return_to_user
228 movel _registers+60,a0 /* get usp */
229 movel a0,usp /* set usp */
230 movel _superStack,sp /* get original stack pointer */
233 movel _lastFrame,a0 /* get last frame info */
234 movel a0@+,_lastFrame /* link in previous frame */
235 addql #8,a0 /* skip over pc, vector#*/
236 movew a0@+,d0 /* get # of words in cpu frame */
237 addw d0,a0 /* point to end of data */
238 addw d0,a0 /* point to end of data */
241 # copy the stack frame
248 asm(" moveml _registers,d0-d7/a0-a6");
249 asm(" rte"); /* pop and go! */
251 #define DISABLE_INTERRUPTS() asm(" oriw #0x0700,sr");
252 #define BREAKPOINT() asm(" trap #1");
254 /* this function is called immediately when a level 7 interrupt occurs */
255 /* if the previous interrupt level was 7 then we're already servicing */
256 /* this interrupt and an rte is in order to return to the debugger. */
257 /* For the 68000, the offset for sr is 6 due to the jsr return address */
260 .globl __debug_level7
264 asm(" movew sp@(2),d0");
266 asm(" movew sp@(6),d0");
268 asm(" andiw #0x700,d0
276 asm(" lea sp@(4),sp"); /* pull off 68000 return address */
280 extern void _catchException();
283 /* This function is called when a 68020 exception occurs. It saves
284 * all the cpu and fpcp regs in the _registers array, creates a frame on a
285 * linked list of frames which has the cpu and fpcp stack frames needed
286 * to properly restore the context of these processors, and invokes
287 * an exception handler (remcom_handler).
289 * stack on entry: stack on exit:
290 * N bytes of junk exception # MSWord
291 * Exception Format Word exception # MSWord
292 * Program counter LSWord
293 * Program counter MSWord
300 .globl __catchException
302 DISABLE_INTERRUPTS();
304 moveml d0-d7/a0-a6,_registers /* save registers */
305 movel _lastFrame,a0 /* last frame pointer */
309 lea _registers,a5 /* get address of registers */
310 movew sp@,d1 /* get status register */
311 movew d1,a5@(66) /* save sr */
312 movel sp@(2),a4 /* save pc in a4 for later use */
313 movel a4,a5@(68) /* save pc in _regisers[] */
316 # figure out how many bytes in the stack frame
317 movew sp@(6),d0 /* get '020 exception format */
318 movew d0,d2 /* make a copy of format word */
319 andiw #0xf000,d0 /* mask off format type */
320 rolw #5,d0 /* rotate into the low byte *2 */
321 lea _exceptionSize,a1
322 addw d0,a1 /* index into the table */
323 movew a1@,d0 /* get number of words in frame */
324 movew d0,d3 /* save it */
325 subw d0,a0 /* adjust save pointer */
326 subw d0,a0 /* adjust save pointer(bytes) */
327 movel a0,a1 /* copy save pointer */
328 subql #1,d0 /* predecrement loop counter */
335 # now that the stack has been clenaed,
336 # save the a7 in use at time of exception
337 movel sp,_superStack /* save supervisor sp */
338 andiw #0x2000,d1 /* were we in supervisor mode ? */
340 movel a7,a5@(60) /* save a7 */
344 movel a1,a5@(60) /* save user stack pointer */
352 # compute exception number
353 andl #0xfff,d2 /* mask off vector offset */
354 lsrw #2,d2 /* divide by 4 to get vect num */
355 movel d2,a0@- /* save it */
357 # save pc causing exception
360 # save old frame link and set the new value
361 movel _lastFrame,a1 /* last frame pointer */
362 movel a1,a0@- /* save pointer to prev frame */
365 movel d2,sp@- /* push exception num */
366 movel _exceptionHook,a0 /* get address of handler */
367 jbsr a0@ /* and call it */
368 clrl sp@ /* replace exception num parm with frame ptr */
369 jbsr __returnFromException /* jbsr, but never returns */
372 /* This function is called when an exception occurs. It translates the
373 * return address found on the stack into an exception vector # which
374 * is then handled by either handle_exception or a system handler.
375 * _catchException provides a front end for both.
377 * stack on entry: stack on exit:
378 * Program counter MSWord exception # MSWord
379 * Program counter LSWord exception # MSWord
381 * Return Address MSWord
382 * Return Address LSWord
386 .globl __catchException
388 DISABLE_INTERRUPTS();
390 moveml d0-d7/a0-a6,_registers /* save registers */
391 movel _lastFrame,a0 /* last frame pointer */
395 lea _registers,a5 /* get address of registers */
396 movel sp@+,d2 /* pop return address */
397 addl #1530,d2 /* convert return addr to */
398 divs #6,d2 /* exception number */
401 moveql #3,d3 /* assume a three word frame */
403 cmpiw #3,d2 /* bus error or address error ? */
404 bgt normal /* if >3 then normal error */
405 movel sp@+,a0@- /* copy error info to frame buff*/
406 movel sp@+,a0@- /* these are never used */
407 moveql #7,d3 /* this is a 7 word frame */
410 movew sp@+,d1 /* pop status register */
411 movel sp@+,a4 /* pop program counter */
412 movew d1,a5@(66) /* save sr */
413 movel a4,a5@(68) /* save pc in _regisers[] */
414 movel a4,a0@- /* copy pc to frame buffer */
415 movew d1,a0@- /* copy sr to frame buffer */
417 movel sp,_superStack /* save supervisor sp */
419 andiw #0x2000,d1 /* were we in supervisor mode ? */
421 movel a7,a5@(60) /* save a7 */
424 movel usp,a1 /* save user stack pointer */
425 movel a1,a5@(60) /* save user stack pointer */
428 movew d3,a0@- /* push frame size in words */
429 movel d2,a0@- /* push vector number */
430 movel a4,a0@- /* push exception pc */
433 # save old frame link and set the new value
434 movel _lastFrame,a1 /* last frame pointer */
435 movel a1,a0@- /* save pointer to prev frame */
438 movel d2,sp@- /* push exception num */
439 movel _exceptionHook,a0 /* get address of handler */
440 jbsr a0@ /* and call it */
441 clrl sp@ /* replace exception num parm with frame ptr */
442 jbsr __returnFromException /* jbsr, but never returns */
448 * remcomHandler is a front end for handle_exception. It moves the
449 * stack pointer into an area reserved for debugger use in case the
450 * breakpoint happened in supervisor mode.
452 asm("_remcomHandler:");
453 asm(" addl #4,sp"); /* pop off return address */
454 asm(" movel sp@+,d0"); /* get the exception number */
455 asm(" movel _stackPtr,sp"); /* move to remcom stack area */
456 asm(" movel d0,sp@-"); /* push exception onto stack */
457 asm(" jbsr _handle_exception"); /* this never returns */
458 asm(" rts"); /* return */
460 void _returnFromException( Frame
*frame
)
462 /* if no passed in frame, use the last one */
466 frame
->frameSize
= 4;
468 frame
->fsaveHeader
= -1; /* restore regs, but we dont have fsave info*/
472 /* a 68000 cannot use the internal info pushed onto a bus error
473 * or address error frame when doing an RTE so don't put this info
474 * onto the stack or the stack will creep every time this happens.
479 /* throw away any frames in the list after this frame */
482 frame
->sr
= registers
[(int) PS
];
483 frame
->pc
= registers
[(int) PC
];
485 if (registers
[(int) PS
] & 0x2000)
487 /* return to supervisor mode... */
491 { /* return to user mode */
499 if ((ch
>= 'a') && (ch
<= 'f')) return (ch
-'a'+10);
500 if ((ch
>= '0') && (ch
<= '9')) return (ch
-'0');
501 if ((ch
>= 'A') && (ch
<= 'F')) return (ch
-'A'+10);
506 /* scan for the sequence $<data>#<checksum> */
507 void getpacket(buffer
)
510 unsigned char checksum
;
511 unsigned char xmitcsum
;
517 /* wait around for the start character, ignore all other characters */
518 while ((ch
= getDebugChar()) != '$');
524 /* now, read until a # or end of buffer is found */
525 while (count
< BUFMAX
) {
527 if (ch
== '#') break;
528 checksum
= checksum
+ ch
;
535 xmitcsum
= hex(getDebugChar()) << 4;
536 xmitcsum
+= hex(getDebugChar());
537 if ((remote_debug
) && (checksum
!= xmitcsum
)) {
538 fprintf(stderr
,"bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n",
539 checksum
,xmitcsum
,buffer
);
542 if (checksum
!= xmitcsum
) putDebugChar('-'); /* failed checksum */
544 putDebugChar('+'); /* successful transfer */
545 /* if a sequence char is present, reply the sequence ID */
546 if (buffer
[2] == ':') {
547 putDebugChar( buffer
[0] );
548 putDebugChar( buffer
[1] );
549 /* remove sequence chars from buffer */
550 count
= strlen(buffer
);
551 for (i
=3; i
<= count
; i
++) buffer
[i
-3] = buffer
[i
];
555 } while (checksum
!= xmitcsum
);
559 /* send the packet in buffer. The host get's one chance to read it.
560 This routine does not wait for a positive acknowledge. */
563 void putpacket(buffer
)
566 unsigned char checksum
;
570 /* $<packet info>#<checksum>. */
576 while (ch
=buffer
[count
]) {
577 if (! putDebugChar(ch
)) return;
583 putDebugChar(hexchars
[checksum
>> 4]);
584 putDebugChar(hexchars
[checksum
% 16]);
586 } while (1 == 0); /* (getDebugChar() != '+'); */
590 char remcomInBuffer
[BUFMAX
];
591 char remcomOutBuffer
[BUFMAX
];
595 void debug_error(format
, parm
)
599 if (remote_debug
) fprintf(stderr
,format
,parm
);
602 /* convert the memory pointed to by mem into hex, placing result in buf */
603 /* return a pointer to the last char put in buf (null) */
604 char* mem2hex(mem
, buf
, count
)
611 for (i
=0;i
<count
;i
++) {
613 *buf
++ = hexchars
[ch
>> 4];
614 *buf
++ = hexchars
[ch
% 16];
620 /* convert the hex array pointed to by buf into binary to be placed in mem */
621 /* return a pointer to the character AFTER the last byte written */
622 char* hex2mem(buf
, mem
, count
)
629 for (i
=0;i
<count
;i
++) {
630 ch
= hex(*buf
++) << 4;
631 ch
= ch
+ hex(*buf
++);
637 /* a bus error has occurred, perform a longjmp
638 to return execution and allow handling of the error */
640 void handle_buserror()
642 longjmp(remcomEnv
,1);
645 /* this function takes the 68000 exception number and attempts to
646 translate this number into a unix compatible signal value */
647 int computeSignal( exceptionVector
)
651 switch (exceptionVector
) {
652 case 2 : sigval
= 10; break; /* bus error */
653 case 3 : sigval
= 10; break; /* address error */
654 case 4 : sigval
= 4; break; /* illegal instruction */
655 case 5 : sigval
= 8; break; /* zero divide */
656 case 6 : sigval
= 16; break; /* chk instruction */
657 case 7 : sigval
= 16; break; /* trapv instruction */
658 case 8 : sigval
= 11; break; /* privilege violation */
659 case 9 : sigval
= 5; break; /* trace trap */
660 case 10: sigval
= 4; break; /* line 1010 emulator */
661 case 11: sigval
= 4; break; /* line 1111 emulator */
662 case 13: sigval
= 8; break; /* floating point err */
663 case 31: sigval
= 2; break; /* interrupt */
664 case 33: sigval
= 5; break; /* breakpoint */
665 case 40: sigval
= 8; break; /* floating point err */
666 case 48: sigval
= 8; break; /* floating point err */
667 case 49: sigval
= 8; break; /* floating point err */
668 case 50: sigval
= 8; break; /* zero divide */
669 case 51: sigval
= 8; break; /* underflow */
670 case 52: sigval
= 8; break; /* operand error */
671 case 53: sigval
= 8; break; /* overflow */
672 case 54: sigval
= 8; break; /* NAN */
674 sigval
= 7; /* "software generated"*/
679 /**********************************************/
680 /* WHILE WE FIND NICE HEX CHARS, BUILD AN INT */
681 /* RETURN NUMBER OF CHARS PROCESSED */
682 /**********************************************/
683 int hexToInt(char **ptr
, int *intValue
)
692 hexValue
= hex(**ptr
);
695 *intValue
= (*intValue
<<4) | hexValue
;
708 * This function does all command procesing for interfacing to gdb.
710 void handle_exception(int exceptionVector
)
718 if (remote_debug
) printf("vector=%d, sr=0x%x, pc=0x%x\n",
723 /* reply to host that an exception has occurred */
724 sigval
= computeSignal( exceptionVector
);
725 remcomOutBuffer
[0] = 'S';
726 remcomOutBuffer
[1] = hexchars
[sigval
>> 4];
727 remcomOutBuffer
[2] = hexchars
[sigval
% 16];
728 remcomOutBuffer
[3] = 0;
730 putpacket(remcomOutBuffer
);
734 remcomOutBuffer
[0] = 0;
735 getpacket(remcomInBuffer
);
736 switch (remcomInBuffer
[0]) {
737 case '?' : remcomOutBuffer
[0] = 'S';
738 remcomOutBuffer
[1] = hexchars
[sigval
>> 4];
739 remcomOutBuffer
[2] = hexchars
[sigval
% 16];
740 remcomOutBuffer
[3] = 0;
742 case 'd' : remote_debug
= !(remote_debug
); /* toggle debug flag */
744 case 'g' : /* return the value of the CPU registers */
745 mem2hex((char*) registers
, remcomOutBuffer
, NUMREGBYTES
);
747 case 'G' : /* set the value of the CPU registers - return OK */
748 hex2mem(&remcomInBuffer
[1], (char*) registers
, NUMREGBYTES
);
749 strcpy(remcomOutBuffer
,"OK");
752 /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
754 if (setjmp(remcomEnv
) == 0)
756 exceptionHandler(2,handle_buserror
);
758 /* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
759 ptr
= &remcomInBuffer
[1];
760 if (hexToInt(&ptr
,&addr
))
762 if (hexToInt(&ptr
,&length
))
765 mem2hex((char*) addr
, remcomOutBuffer
, length
);
770 strcpy(remcomOutBuffer
,"E01");
771 debug_error("malformed read memory command: %s",remcomInBuffer
);
775 exceptionHandler(2,_catchException
);
776 strcpy(remcomOutBuffer
,"E03");
777 debug_error("bus error");
780 /* restore handler for bus error */
781 exceptionHandler(2,_catchException
);
784 /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
786 if (setjmp(remcomEnv
) == 0) {
787 exceptionHandler(2,handle_buserror
);
789 /* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
790 ptr
= &remcomInBuffer
[1];
791 if (hexToInt(&ptr
,&addr
))
793 if (hexToInt(&ptr
,&length
))
796 hex2mem(ptr
, (char*) addr
, length
);
798 strcpy(remcomOutBuffer
,"OK");
802 strcpy(remcomOutBuffer
,"E02");
803 debug_error("malformed write memory command: %s",remcomInBuffer
);
807 exceptionHandler(2,_catchException
);
808 strcpy(remcomOutBuffer
,"E03");
809 debug_error("bus error");
812 /* restore handler for bus error */
813 exceptionHandler(2,_catchException
);
816 /* cAA..AA Continue at address AA..AA(optional) */
817 /* sAA..AA Step one instruction from AA..AA(optional) */
820 /* try to read optional parameter, pc unchanged if no parm */
821 ptr
= &remcomInBuffer
[1];
822 if (hexToInt(&ptr
,&addr
))
823 registers
[ PC
] = addr
;
825 newPC
= registers
[ PC
];
827 /* clear the trace bit */
828 registers
[ PS
] &= 0x7fff;
830 /* set the trace bit if we're stepping */
831 if (remcomInBuffer
[0] == 's') registers
[ PS
] |= 0x8000;
834 * look for newPC in the linked list of exception frames.
835 * if it is found, use the old frame it. otherwise,
836 * fake up a dummy frame in returnFromException().
838 if (remote_debug
) printf("new pc = 0x%x\n",newPC
);
843 printf("frame at 0x%x has pc=0x%x, except#=%d\n",
844 frame
,frame
->exceptionPC
,
845 frame
->exceptionVector
);
846 if (frame
->exceptionPC
== newPC
) break; /* bingo! a match */
848 * for a breakpoint instruction, the saved pc may
849 * be off by two due to re-executing the instruction
850 * replaced by the trap instruction. Check for this.
852 if ((frame
->exceptionVector
== 33) &&
853 (frame
->exceptionPC
== (newPC
+2))) break;
854 if (frame
== frame
->previous
)
856 frame
= 0; /* no match found */
859 frame
= frame
->previous
;
863 * If we found a match for the PC AND we are not returning
864 * as a result of a breakpoint (33),
865 * trace exception (9), nmi (31), jmp to
866 * the old exception handler as if this code never ran.
870 if ((frame
->exceptionVector
!= 9) &&
871 (frame
->exceptionVector
!= 31) &&
872 (frame
->exceptionVector
!= 33))
875 * invoke the previous handler.
877 if (oldExceptionHook
)
878 (*oldExceptionHook
) (frame
->exceptionVector
);
879 newPC
= registers
[ PC
]; /* pc may have changed */
880 if (newPC
!= frame
->exceptionPC
)
883 printf("frame at 0x%x has pc=0x%x, except#=%d\n",
884 frame
,frame
->exceptionPC
,
885 frame
->exceptionVector
);
886 /* re-use the last frame, we're skipping it (longjump?)*/
888 _returnFromException( frame
); /* this is a jump */
893 /* if we couldn't find a frame, create one */
896 frame
= lastFrame
-1 ;
898 /* by using a bunch of print commands with breakpoints,
899 it's possible for the frame stack to creep down. If it creeps
900 too far, give up and reset it to the top. Normal use should
903 if ((unsigned int) (frame
-2) < (unsigned int) &gdbFrameStack
)
905 initializeRemcomErrorFrame();
908 frame
->previous
= lastFrame
;
910 frame
= 0; /* null so _return... will properly initialize it */
913 _returnFromException( frame
); /* this is a jump */
917 /* kill the program */
918 case 'k' : /* do nothing */
922 /* reply to the request */
923 putpacket(remcomOutBuffer
);
928 void initializeRemcomErrorFrame(void)
930 lastFrame
= ((Frame
*) &gdbFrameStack
[FRAMESIZE
-1]) - 1;
931 lastFrame
->previous
= lastFrame
;
934 /* this function is used to set up exception handlers for tracing and
936 void set_debug_traps()
938 extern void _debug_level7();
939 extern void remcomHandler();
942 initializeRemcomErrorFrame();
943 stackPtr
= &remcomStack
[STACKSIZE
/sizeof(int) - 1];
945 for (exception
= 2; exception
<= 23; exception
++)
946 exceptionHandler(exception
,_catchException
);
948 /* level 7 interrupt */
949 exceptionHandler(31,_debug_level7
);
951 /* breakpoint exception (trap #1) */
952 exceptionHandler(33,_catchException
);
954 /* floating point error (trap #8) */
955 exceptionHandler(40,_catchException
);
957 /* 48 to 54 are floating point coprocessor errors */
958 for (exception
= 48; exception
<= 54; exception
++)
959 exceptionHandler(exception
,_catchException
);
961 if (oldExceptionHook
!= remcomHandler
)
963 oldExceptionHook
= exceptionHook
;
964 exceptionHook
= remcomHandler
;
971 /* This function will generate a breakpoint exception. It is used at the
972 beginning of a program to sync up with a debugger and can be used
973 otherwise as a quick means to stop program execution and "break" into
978 if (initialized
) BREAKPOINT();