summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/m68k/ods68302/startup/m68k-stub.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/m68k/ods68302/startup/m68k-stub.c')
-rw-r--r--c/src/lib/libbsp/m68k/ods68302/startup/m68k-stub.c282
1 files changed, 141 insertions, 141 deletions
diff --git a/c/src/lib/libbsp/m68k/ods68302/startup/m68k-stub.c b/c/src/lib/libbsp/m68k/ods68302/startup/m68k-stub.c
index cf9b4c2e39..95e404677f 100644
--- a/c/src/lib/libbsp/m68k/ods68302/startup/m68k-stub.c
+++ b/c/src/lib/libbsp/m68k/ods68302/startup/m68k-stub.c
@@ -1,9 +1,9 @@
/****************************************************************************
- THIS SOFTWARE IS NOT COPYRIGHTED
-
+ THIS SOFTWARE IS NOT COPYRIGHTED
+
HP offers the following for use in the public domain. HP makes no
- warranty with regard to the software or it's performance and the
+ warranty with regard to the software or it's performance and the
user accepts the software "AS IS" with all faults.
HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
@@ -13,22 +13,22 @@
****************************************************************************/
/****************************************************************************
- * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
+ * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
*
- * Module name: remcom.c $
+ * Module name: remcom.c $
* Revision: 1.34 $
* Date: 91/03/09 12:29:49 $
* Contributor: Lake Stevens Instrument Division$
- *
+ *
* Description: low level support for gdb debugger. $
*
* Considerations: only works on target hardware $
*
* Written by: Glenn Engel $
- * ModuleState: Experimental $
+ * ModuleState: Experimental $
*
* NOTES: See Below $
- *
+ *
* To enable debugger support, two things need to happen. One, a
* call to set_debug_traps() is necessary in order to allow any breakpoints
* or error conditions to be properly intercepted and reported to gdb.
@@ -39,15 +39,15 @@
* there either should be a standard breakpoint instruction, or the protocol
* should be extended to provide some means to communicate which breakpoint
* instruction is in use (or have the stub insert the breakpoint).
- *
+ *
* Some explanation is probably necessary to explain how exceptions are
* handled. When an exception is encountered the 68000 pushes the current
* program counter and status register onto the supervisor stack and then
* transfers execution to a location specified in it's vector table.
* The handlers for the exception vectors are hardwired to jmp to an address
- * given by the relation: (exception - 256) * 6. These are decending
+ * given by the relation: (exception - 256) * 6. These are decending
* addresses starting from -6, -12, -18, ... By allowing 6 bytes for
- * each entry, a jsr, jmp, bsr, ... can be used to enter the exception
+ * each entry, a jsr, jmp, bsr, ... can be used to enter the exception
* handler. Using a jsr to handle an exception has an added benefit of
* allowing a single handler to service several exceptions and use the
* return address as the key differentiation. The vector number can be
@@ -59,50 +59,50 @@
* For 68020 machines, the ability to have a return address around just
* so the vector can be determined is not necessary because the '020 pushes an
* extra word onto the stack containing the vector offset
- *
+ *
* Because gdb will sometimes write to the stack area to execute function
* calls, this program cannot rely on using the supervisor stack so it
- * uses it's own stack area reserved in the int array remcomStack.
- *
+ * uses it's own stack area reserved in the int array remcomStack.
+ *
*************
*
* The following gdb commands are supported:
- *
+ *
* command function Return value
- *
+ *
* g return the value of the CPU registers hex data or ENN
* G set the value of the CPU registers OK or ENN
- *
+ *
* mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
* MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
- *
+ *
* c Resume at current address SNN ( signal NN)
* cAA..AA Continue at address AA..AA SNN
- *
+ *
* s Step one instruction SNN
* sAA..AA Step one instruction from AA..AA SNN
- *
+ *
* k kill
*
* ? What was the last sigval ? SNN (signal NN)
- *
- * All commands and responses are sent with a packet which includes a
- * checksum. A packet consists of
- *
+ *
+ * All commands and responses are sent with a packet which includes a
+ * checksum. A packet consists of
+ *
* $<packet info>#<checksum>.
- *
+ *
* where
* <packet info> :: <characters representing the command or response>
* <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>
- *
+ *
* When a packet is received, it is first acknowledged with either '+' or '-'.
* '+' indicates a successful transfer. '-' indicates a failed transfer.
- *
+ *
* Example:
- *
+ *
* Host: Reply:
* $m0,10#2a +$00010203040506070809101112131415#42
- *
+ *
* $Id$
*
****************************************************************************/
@@ -116,7 +116,7 @@
/************************************************************************
*
- * external low-level support routines
+ * external low-level support routines
*/
typedef void (*ExceptionHook)(int); /* pointer to function with int parm */
typedef void (*Function)(void); /* pointer to a function */
@@ -153,15 +153,15 @@ void breakpoint(void);
static char initialized; /* boolean flag. != 0 means we've been initialized */
int remote_debug;
-/* debug > 0 prints ill-formed commands in valid packets & checksum errors */
+/* debug > 0 prints ill-formed commands in valid packets & checksum errors */
static const char hexchars[]="0123456789abcdef";
/* there are 180 bytes of registers on a 68020 w/68881 */
/* many of the fpa registers are 12 byte (96 bit) registers */
#define NUMREGBYTES 180
-enum regnames {D0,D1,D2,D3,D4,D5,D6,D7,
- A0,A1,A2,A3,A4,A5,A6,A7,
+enum regnames {D0,D1,D2,D3,D4,D5,D6,D7,
+ A0,A1,A2,A3,A4,A5,A6,A7,
PS,PC,
FP0,FP1,FP2,FP3,FP4,FP5,FP6,FP7,
FPCONTROL,FPSTATUS,FPIADDR
@@ -205,7 +205,7 @@ static int* stackPtr = &remcomStack[STACKSIZE/sizeof(int) - 1];
/*
* In many cases, the system will want to continue exception processing
- * when a continue command is given.
+ * when a continue command is given.
* oldExceptionHook is a function to invoke in this case.
*/
@@ -351,11 +351,11 @@ extern void _catchException(void);
* stack on entry: stack on exit:
* N bytes of junk exception # MSWord
* Exception Format Word exception # MSWord
- * Program counter LSWord
- * Program counter MSWord
- * Status Register
- *
- *
+ * Program counter LSWord
+ * Program counter MSWord
+ * Status Register
+ *
+ *
*/
asm(" \n\
.text\n\
@@ -371,7 +371,7 @@ asm("\n\
moveml %d0-%d7/%a0-%a6,registers /* save registers */\n\
movel lastFrame,%a0 /* last frame pointer */\n\
");
-SAVE_FP_REGS();
+SAVE_FP_REGS();
asm("\n\
lea registers,%a5 /* get address of registers */\n\
movew %sp@,%d1 /* get status register */\n\
@@ -445,14 +445,14 @@ a7saveDone:\n\
/* This function is called when an exception occurs. It translates the
* return address found on the stack into an exception vector # which
* is then handled by either handle_exception or a system handler.
- * _catchException provides a front end for both.
+ * _catchException provides a front end for both.
*
* stack on entry: stack on exit:
- * Program counter MSWord exception # MSWord
+ * Program counter MSWord exception # MSWord
* Program counter LSWord exception # MSWord
- * Status Register
- * Return Address MSWord
- * Return Address LSWord
+ * Status Register
+ * Return Address MSWord
+ * Return Address LSWord
*/
asm("\n\
.text\n\
@@ -466,7 +466,7 @@ asm("\n\
movel lastFrame,%a0 /* last frame pointer */\n\
");
-SAVE_FP_REGS();
+SAVE_FP_REGS();
asm("\n\
moveq.l #0,%d2\n\
movew %sp@+,%d2\n\
@@ -566,7 +566,7 @@ void _returnFromException(Frame *frame)
frame->pc = registers[(int) PC];
if (registers[(int) PS] & 0x2000)
- {
+ {
/* return to supervisor mode... */
return_to_super();
}
@@ -592,15 +592,15 @@ void getpacket(char *buffer)
int i;
int count;
char ch;
-
+
do {
/* wait around for the start character, ignore all other characters */
- while ((ch = (getDebugChar() & 0x7f)) != '$');
+ while ((ch = (getDebugChar() & 0x7f)) != '$');
checksum = 0;
xmitcsum = -1;
-
+
count = 0;
-
+
/* now, read until a # or end of buffer is found */
while (count < BUFMAX) {
ch = getDebugChar() & 0x7f;
@@ -618,8 +618,8 @@ void getpacket(char *buffer)
debug_port_printf ("bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n",
checksum,xmitcsum,buffer);
}
-
- if (checksum != xmitcsum) putDebugChar('-'); /* failed checksum */
+
+ if (checksum != xmitcsum) putDebugChar('-'); /* failed checksum */
else {
putDebugChar('+'); /* successful transfer */
/* if a sequence char is present, reply the sequence ID */
@@ -629,13 +629,13 @@ void getpacket(char *buffer)
/* remove sequence chars from buffer */
count = strlen(buffer);
for (i=3; i <= count; i++) buffer[i-3] = buffer[i];
- }
- }
- }
- } while (checksum != xmitcsum);
+ }
+ }
+ }
+ } while (checksum != xmitcsum);
}
-/* send the packet in buffer. The host get's one chance to read it.
+/* send the packet in buffer. The host get's one chance to read it.
This routine does not wait for a positive acknowledge. */
@@ -645,25 +645,25 @@ putpacket(char *buffer)
unsigned char checksum;
int count;
char ch;
-
+
/* $<packet info>#<checksum>. */
do {
putDebugChar('$');
checksum = 0;
count = 0;
-
+
while ((ch=buffer[count])) {
if (! putDebugChar(ch)) return;
checksum += ch;
count += 1;
}
-
+
putDebugChar('#');
putDebugChar(hexchars[checksum >> 4]);
putDebugChar(hexchars[checksum % 16]);
} while (1 == 0); /* (getDebugChar() != '+'); */
-
+
}
char remcomInBuffer[BUFMAX];
@@ -676,16 +676,16 @@ char *mem2hex(char *mem, char *buf, int count)
{
int i;
unsigned char ch;
-
+
if (remote_debug)
- debug_port_printf("mem=0x%x, count=0x%x\n", mem, count);
-
+ debug_port_printf("mem=0x%x, count=0x%x\n", mem, count);
+
for (i=0;i<count;i++) {
ch = *mem++;
*buf++ = hexchars[ch >> 4];
*buf++ = hexchars[ch % 16];
}
- *buf = 0;
+ *buf = 0;
return(buf);
}
@@ -695,10 +695,10 @@ char *hex2mem(char *buf, char *mem, int count)
{
int i;
unsigned char ch;
-
+
if (remote_debug)
- debug_port_printf("mem=0x%x, count=0x%x\n", mem, count);
-
+ debug_port_printf("mem=0x%x, count=0x%x\n", mem, count);
+
for (i=0;i<count;i++) {
ch = hex(*buf++) << 4;
ch = ch + hex(*buf++);
@@ -715,7 +715,7 @@ void handle_buserror()
longjmp(remcomEnv,1);
}
-/* this function takes the 68000 exception number and attempts to
+/* this function takes the 68000 exception number and attempts to
translate this number into a unix compatible signal value */
int computeSignal(int exceptionVector)
{
@@ -752,7 +752,7 @@ int computeSignal(int exceptionVector)
case 52: sigval = 8; break; /* operand error */
case 53: sigval = 8; break; /* overflow */
case 54: sigval = 8; break; /* NAN */
- default:
+ default:
sigval = 7; /* "software generated"*/
}
return (sigval);
@@ -766,7 +766,7 @@ int hexToInt(char **ptr, int *intValue)
{
int numChars = 0;
int hexValue;
-
+
*intValue = 0;
while (**ptr)
@@ -779,7 +779,7 @@ int hexToInt(char **ptr, int *intValue)
}
else
break;
-
+
(*ptr)++;
}
@@ -796,11 +796,11 @@ void handle_exception(int exceptionVector)
char * ptr;
int newPC;
Frame *frame;
-
+
if (remote_debug)
- printf("vector=%d, sr=0x%x, pc=0x%x\n",
+ printf("vector=%d, sr=0x%x, pc=0x%x\n",
exceptionVector,
- registers[ PS ],
+ registers[ PS ],
registers[ PC ]);
/* reply to host that an exception has occurred */
@@ -810,9 +810,9 @@ void handle_exception(int exceptionVector)
remcomOutBuffer[2] = hexchars[sigval % 16];
remcomOutBuffer[3] = 0;
- putpacket(remcomOutBuffer);
+ putpacket(remcomOutBuffer);
- while (1==1) {
+ while (1==1) {
error = 0;
remcomOutBuffer[0] = 0;
getpacket(remcomInBuffer);
@@ -821,19 +821,19 @@ void handle_exception(int exceptionVector)
remcomOutBuffer[1] = hexchars[sigval >> 4];
remcomOutBuffer[2] = hexchars[sigval % 16];
remcomOutBuffer[3] = 0;
- break;
+ break;
case 'd' :
remote_debug = !(remote_debug); /* toggle debug flag */
debug_port_printf("debug mode ");
if (remote_debug)
- {
+ {
debug_port_printf("on\n");
}
else
- {
+ {
debug_port_printf("off\n");
- }
- break;
+ }
+ break;
case 'g' : /* return the value of the CPU registers */
mem2hex((char*) registers, remcomOutBuffer, NUMREGBYTES);
break;
@@ -841,18 +841,18 @@ void handle_exception(int exceptionVector)
hex2mem(&remcomInBuffer[1], (char*) registers, NUMREGBYTES);
strcpy(remcomOutBuffer,"OK");
break;
-
+
/* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
- case 'm' :
+ case 'm' :
if (setjmp(remcomEnv) == 0)
{
- exceptionHandler(2,handle_buserror);
+ exceptionHandler(2,handle_buserror);
/* TRY TO READ %x,%x. IF SUCCEED, SET PTR = 0 */
ptr = &remcomInBuffer[1];
if (hexToInt(&ptr,&addr))
if (*(ptr++) == ',')
- if (hexToInt(&ptr,&length))
+ if (hexToInt(&ptr,&length))
{
ptr = 0;
mem2hex((char*) addr, remcomOutBuffer, length);
@@ -863,24 +863,24 @@ void handle_exception(int exceptionVector)
strcpy(remcomOutBuffer,"E01");
if (remote_debug)
printf("malformed read memory command: %s",remcomInBuffer);
- }
- }
+ }
+ }
else {
- exceptionHandler(2,_catchException);
+ exceptionHandler(2,_catchException);
strcpy(remcomOutBuffer,"E03");
if (remote_debug)
printf("bus error");
- }
-
+ }
+
/* restore handler for bus error */
- exceptionHandler(2,_catchException);
+ exceptionHandler(2,_catchException);
break;
-
+
/* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
- case 'M' :
+ case 'M' :
if (setjmp(remcomEnv) == 0) {
- exceptionHandler(2,handle_buserror);
-
+ exceptionHandler(2,handle_buserror);
+
/* TRY TO READ '%x,%x:'. IF SUCCEED, SET PTR = 0 */
ptr = &remcomInBuffer[1];
if (hexToInt(&ptr,&addr))
@@ -897,43 +897,43 @@ void handle_exception(int exceptionVector)
strcpy(remcomOutBuffer,"E02");
if (remote_debug)
printf("malformed write memory command: %s",remcomInBuffer);
- }
- }
+ }
+ }
else {
- exceptionHandler(2,_catchException);
+ exceptionHandler(2,_catchException);
strcpy(remcomOutBuffer,"E03");
if (remote_debug)
printf("bus error");
- }
+ }
/* restore handler for bus error */
- exceptionHandler(2,_catchException);
+ exceptionHandler(2,_catchException);
break;
-
+
/* cAA..AA Continue at address AA..AA(optional) */
/* sAA..AA Step one instruction from AA..AA(optional) */
- case 'c' :
- case 's' :
+ case 'c' :
+ case 's' :
/* try to read optional parameter, pc unchanged if no parm */
ptr = &remcomInBuffer[1];
if (hexToInt(&ptr,&addr))
registers[ PC ] = addr;
-
+
newPC = registers[ PC];
-
+
/* clear the trace bit */
registers[ PS ] &= 0x7fff;
-
+
/* set the trace bit if we're stepping */
if (remcomInBuffer[0] == 's') registers[ PS ] |= 0x8000;
-
+
/*
* look for newPC in the linked list of exception frames.
* if it is found, use the old frame it. otherwise,
* fake up a dummy frame in returnFromException().
*/
if (remote_debug) debug_port_printf("new pc = 0x%x\n",newPC);
-
+
frame = lastFrame;
while (frame)
{
@@ -951,24 +951,24 @@ void handle_exception(int exceptionVector)
(frame->exceptionPC == newPC)) break;
if (frame == frame->previous)
{
- frame = 0; /* no match found */
- break;
+ frame = 0; /* no match found */
+ break;
}
frame = frame->previous;
}
-
+
/*
* If we found a match for the PC AND we are not returning
* as a result of a breakpoint (33),
* trace exception (9), nmi (31), jmp to
* the old exception handler as if this code never ran.
*/
- if (frame)
+ if (frame)
{
- if ((frame->exceptionVector != 9) &&
- (frame->exceptionVector != 31) &&
+ if ((frame->exceptionVector != 9) &&
+ (frame->exceptionVector != 31) &&
(frame->exceptionVector != 33))
- {
+ {
/*
* invoke the previous handler.
*/
@@ -986,13 +986,13 @@ void handle_exception(int exceptionVector)
_returnFromException( frame ); /* this is a jump */
}
}
- }
+ }
/* if we couldn't find a frame, create one */
if (frame == 0)
{
frame = lastFrame -1 ;
-
+
/* by using a bunch of print commands with breakpoints,
it's possible for the frame stack to creep down. If it creeps
too far, give up and reset it to the top. Normal use should
@@ -1001,28 +1001,28 @@ void handle_exception(int exceptionVector)
if ((unsigned int) (frame-2) < (unsigned int) &gdbFrameStack)
{
initializeRemcomErrorFrame();
- frame = lastFrame;
+ frame = lastFrame;
}
frame->previous = lastFrame;
lastFrame = frame;
- frame = 0; /* null so _return... will properly initialize it */
- }
-
+ frame = 0; /* null so _return... will properly initialize it */
+ }
+
_returnFromException( frame ); /* this is a jump */
break;
-
+
/* kill the program */
case 'k' :
/* reset the board */
WATCHDOG_TRIGGER();
while (1 == 1);
break;
-
- } /* switch */
-
+
+ } /* switch */
+
/* reply to the request */
- putpacket(remcomOutBuffer);
+ putpacket(remcomOutBuffer);
}
}
@@ -1033,13 +1033,13 @@ void initializeRemcomErrorFrame()
lastFrame->previous = lastFrame;
}
-/* this function is used to set up exception handlers for tracing and
+/* this function is used to set up exception handlers for tracing and
breakpoints */
void set_debug_traps()
{
extern void _debug_level7(void);
extern void remcomHandler(void);
-
+
int exception;
initializeRemcomErrorFrame();
@@ -1047,39 +1047,39 @@ void set_debug_traps()
registers[ PC ] = 0x400;
registers[ PS ] = 0x2700;
-
+
for (exception = 2; exception <= 30; exception++)
- exceptionHandler(exception,_catchException);
+ exceptionHandler(exception,_catchException);
/* level 7 interrupt */
- exceptionHandler(31,_debug_level7);
-
+ exceptionHandler(31,_debug_level7);
+
for (exception = 32; exception <= 47; exception++)
- exceptionHandler(exception,_catchException);
+ exceptionHandler(exception,_catchException);
/* exclude the unassigned, reserved vector locations */
-
+
for (exception = 64; exception <= 255; exception++)
- exceptionHandler(exception,_catchException);
+ exceptionHandler(exception,_catchException);
if (oldExceptionHook != (ExceptionHook) remcomHandler)
{
oldExceptionHook = exceptionHook;
exceptionHook = (ExceptionHook) remcomHandler;
}
-
+
initialized = 1;
-#if defined(UPDATE_DISPLAY)
+#if defined(UPDATE_DISPLAY)
UPDATE_DISPLAY("gdb ");
-#endif
+#endif
}
/* This function will generate a breakpoint exception. It is used at the
beginning of a program to sync up with a debugger and can be used
otherwise as a quick means to stop program execution and "break" into
the debugger. */
-
+
void breakpoint()
{
if (initialized) BREAKPOINT();