#include <stdio.h>
#include <string.h>
-#include "ansidecl.h"
/************************************************************************
*
typedef void (*ExceptionHook)(int); /* pointer to function with int parm */
typedef void (*Function)(); /* pointer to a function */
-extern putDebugChar(); /* write a single character */
-extern getDebugChar(); /* read and return a single char */
+extern void putDebugChar(); /* write a single character */
+extern int getDebugChar(); /* read and return a single char */
extern Function exceptionHandler(); /* assign an exception handler */
extern ExceptionHook exceptionHook; /* hook variable for errors/exceptions */
int remote_debug;
/* debug > 0 prints ill-formed commands in valid packets & checksum errors */
-void waitabit();
-
static const char hexchars[]="0123456789abcdef";
+/* Number of registers. */
+#define NUMREGS 16
+
/* Number of bytes of registers. */
-#define NUMREGBYTES 64
+#define NUMREGBYTES (NUMREGS * 4)
+
enum regnames {EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
PC /* also known as eip */,
PS /* also known as eflags */,
/*
* these should not be static cuz they can be used outside this module
*/
-int registers[NUMREGBYTES/4];
+int registers[NUMREGS];
#define STACKSIZE 10000
int remcomStack[STACKSIZE/sizeof(int)];
/* */
extern void
-return_to_prog PARAMS ((void));
+return_to_prog ();
/* Restore the program's registers (including the stack pointer, which
means we get the right stack and don't have to worry about popping our
asm ("cmpl $0, _mem_fault_routine"); \
asm ("jne mem_fault");
+asm (".text");
asm ("mem_fault:");
/* OK to clobber temp registers; we're just going to end up in set_mem_err. */
/* Pop error code from the stack and save it. */
do {
/* wait around for the start character, ignore all other characters */
- while ((ch = getDebugChar()) != '$');
+ while ((ch = (getDebugChar() & 0x7f)) != '$');
checksum = 0;
xmitcsum = -1;
/* now, read until a # or end of buffer is found */
while (count < BUFMAX) {
- ch = getDebugChar();
+ ch = getDebugChar() & 0x7f;
if (ch == '#') break;
checksum = checksum + ch;
buffer[count] = ch;
buffer[count] = 0;
if (ch == '#') {
- xmitcsum = hex(getDebugChar()) << 4;
- xmitcsum += hex(getDebugChar());
+ xmitcsum = hex(getDebugChar() & 0x7f) << 4;
+ xmitcsum += hex(getDebugChar() & 0x7f);
if ((remote_debug ) && (checksum != xmitcsum)) {
- fprintf(stderr,"bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n",
- checksum,xmitcsum,buffer);
+ fprintf (stderr ,"bad checksum. My count = 0x%x, sent=0x%x. buf=%s\n",
+ checksum,xmitcsum,buffer);
}
if (checksum != xmitcsum) putDebugChar('-'); /* failed checksum */
count = 0;
while (ch=buffer[count]) {
- if (! putDebugChar(ch)) return;
+ putDebugChar(ch);
checksum += ch;
count += 1;
}
putDebugChar(hexchars[checksum >> 4]);
putDebugChar(hexchars[checksum % 16]);
- } while (getDebugChar() != '+');
+ } while ((getDebugChar() & 0x7f) != '+');
}
char * format;
char * parm;
{
- if (remote_debug) fprintf(stderr,format,parm);
+ if (remote_debug) fprintf (stderr,format,parm);
}
/* Address of a routine to RTE to if we get a memory fault. */
-static NORETURN void (*mem_fault_routine)() = NULL;
+static void (*volatile mem_fault_routine)() = NULL;
/* Indicate to caller of mem2hex or hex2mem that there has been an
error. */
hex2mem(&remcomInBuffer[1], (char*) registers, NUMREGBYTES, 0);
strcpy(remcomOutBuffer,"OK");
break;
+ case 'P' : /* set the value of a single CPU register - return OK */
+ {
+ int regno;
+
+ ptr = &remcomInBuffer[1];
+ if (hexToInt (&ptr, ®no) && *ptr++ == '=')
+ if (regno >= 0 && regno < NUMREGS)
+ {
+ hex2mem (ptr, (char *)®isters[regno], 4, 0);
+ strcpy(remcomOutBuffer,"OK");
+ break;
+ }
+
+ strcpy (remcomOutBuffer, "E01");
+ break;
+ }
/* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
case 'm' :
/* kill the program */
case 'k' : /* do nothing */
+#if 0
+ /* Huh? This doesn't look like "nothing".
+ m68k-stub.c and sparc-stub.c don't have it. */
BREAKPOINT();
+#endif
break;
} /* switch */
exceptionHook = remcomHandler;
}
- /* In case GDB is started before us, ack any packets (presumably
- "$?#xx") sitting there. */
- putDebugChar ('+');
-
initialized = 1;
-
}
/* This function will generate a breakpoint exception. It is used at the
void breakpoint()
{
if (initialized)
-#if 0
- handle_exception(3);
-#else
BREAKPOINT();
-#endif
- waitabit();
-}
-
-int waitlimit = 1000000;
-
-#if 0
-void
-bogon()
-{
- waitabit();
-}
-#endif
-
-void
-waitabit()
-{
- int i;
- for (i = 0; i < waitlimit; i++) ;
}