static char *sbp = simibuff; /* simulator buffer pointer */
extern char **environ;
char simactive = 0;
+
+
+#if 0
+#define MS_SLEEP(_ms) usleep(_ms * 1000)
+#endif
+
/*-----------------------------------------------------------------*/
-/* readSim - reads one character into simulator buffer */
+/* waitForSim - wait till simulator is done its job */
/*-----------------------------------------------------------------*/
-void readSim(int resetp)
+void waitForSim(int timeout_ms, char *expect)
{
- int ch ;
- /* if reset required then point to beginning of buffer */
- if (resetp)
- sbp = simibuff;
-
-#ifdef SDCDB_DEBUG
- fprintf(stderr,"stderr--> reading from sim\n");
-#endif
+ int i=0;
+ int ch;
+
+Dprintf(D_simi, ("waitForSim start(%d)\n", timeout_ms));
+ sbp = simibuff;
+
+ // MS_SLEEP(timeout_ms); dont need, in blocking mode.
while ((ch = fgetc(simin))) {
-#ifdef SDCDB_DEBUG
- fputc(ch,stdout);
-#endif
- *sbp++ = ch;
+ *sbp++ = ch;
+ }
+ *sbp = 0;
+ Dprintf(D_simi, ("waitForSim(%d) got[%s]\n", timeout_ms, simibuff));
+
+#if 0
+ hmmmm, I guess we are not running non-blocking, we may still
+ need this code...Im not sure how the above works, it must block
+ until something gets into the buffer, then fgetc() reads down the
+ buffer...
+ do {
+ while ((ch = fgetc(simin))) {
+ *sbp++ = ch;
+ }
+ *sbp = 0;
+printf("got1[%s]\n", simibuff);
+ MS_SLEEP(20);
+ timeout_ms -= 20;
+printf("..\n");
+
+ if (expect) {
+ if (strstr(expect, sbp)) {
+ timeout_ms = 0;
+ }
+ } else if (sbp != simibuff) {
+ timeout_ms = 0;
+ }
+
+ /* pull in data one more time after delay to try and
+ guarentee we pull in complete responce line */
+ if (timeout_ms <= 0) {
+printf(",,\n");
+ while ((ch = fgetc(simin))) {
+ *sbp++ = ch;
+ }
+ *sbp = 0;
+printf("got2[%s]\n", simibuff);
+ }
}
-#ifdef SDCDB_DEBUG
- fprintf(stderr,"stderr--> reading from sim done\n");
+ while (timeout_ms > 0);
+printf("...\n");
#endif
- *sbp = '\0';
-}
-
-/*-----------------------------------------------------------------*/
-/* waitForSim - wait till simulator is done its job */
-/*-----------------------------------------------------------------*/
-void waitForSim()
-{
- readSim(TRUE);
}
/*-----------------------------------------------------------------*/
struct sockaddr_in sin;
int retry = 0;
int i ;
- char *simargs[32] = { "s51","-P","-r 9756", NULL };
-
- /* create the arguments */
- for ( i = 0 ; i < nargs ;i++) {
- simargs[i+3] = args[i];
- }
- simargs[i+3]= NULL;
+ Dprintf(D_simi, ("openSimulator\n"));
/* fork and start the simulator as a subprocess */
if ((simPid = fork())) {
-#ifdef SDCDB_DEBUG
- printf("simulator pid %d\n",(int) simPid);
-#endif
+ Dprintf(D_simi, ("simulator pid %d\n",(int) simPid));
}
else {
-
- /* we are in the child process : start the simulator */
- if (execvp("s51",simargs) < 0) {
- perror("cannot exec simulator");
- exit(1);
- }
+ /* we are in the child process : start the simulator */
+ if (execvp(args[0],args) < 0) {
+ perror("cannot exec simulator");
+ exit(1);
+ }
}
try_connect:
exit(1);
}
- /* now that we have opend wait for the prompt */
- waitForSim();
+ /* now that we have opened, wait for the prompt */
+ waitForSim(200,NULL);
simactive = 1;
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
void sendSim(char *s)
{
+ Dprintf(D_simi, ("sendSim-->%s", s)); // s has LF at end already
fputs(s,simout);
fflush(simout);
}
break;
case 'H':
case 'J':
- prefix = "db" ;
+// prefix = "db" ;
+ prefix = "dump" ;
break;
case 'I':
prefix = "ds" ;
/* create the simulator command */
sprintf(buffer,"%s 0x%x \n",prefix,addr);
sendSim(buffer);
- waitForSim();
+ waitForSim(100,NULL);
resp = simResponse();
/* got the response we need to parse it the response
/* first skip thru white space */
while (isspace(*resp)) resp++ ;
+ if (strncmp(resp, "0x",2) == 0)
+ resp += 2;
+
/* then make the branch for bit variables */
/* skip thru the address part */
while (isxdigit(*resp)) resp++;
- if (!strcmp(prefix,"db")) {
+ if (!strcmp(prefix,"dump")) {
/* skip white space */
while (isspace(*resp)) resp++ ;
sprintf(buff,"break 0x%x\n",addr);
sendSim(buff);
- waitForSim();
+ waitForSim(100,NULL);
}
/*-----------------------------------------------------------------*/
sprintf(buff,"clear 0x%x\n",addr);
sendSim(buff);
- waitForSim();
+ waitForSim(100,NULL);
}
/*-----------------------------------------------------------------*/
{
char buff[128];
- sprintf(buff,"l %s\n",s);
+ sprintf(buff,"l \"%s\"\n",s);
printf(buff);
sendSim(buff);
- waitForSim();
+ waitForSim(500,NULL);
}
/*-----------------------------------------------------------------*/
char *sr, *svr;
unsigned addr ;
char *sfmt;
+ int wait_ms = 1000;
+
+ if (gaddr == 0) {
+ /* initial start, start & stop from address 0 */
+ char buf[20];
+
+ // this program is setting up a bunch of breakpoints automatically
+ // at key places. Like at startup & main() and other function
+ // entry points. So we don't need to setup one here..
+ //sendSim("break 0x0\n");
+ //sleep(1);
+ //waitForSim();
+
+ sendSim("run 0x0\n");
+ } else if (gaddr == -1) { /* resume */
+ sendSim ("run\n");
+ wait_ms = 100;
+ }
+ else {
+ printf("Error, simGoTillBp > 0!\n");
+ exit(1);
+ }
- if (gaddr != -1) {
- char buf[20];
- sprintf(buf,"g 0x%x\n",gaddr);
- sendSim(buf);
- } else
- sendSim ("g\n");
-
- waitForSim();
+ waitForSim(wait_ms, NULL);
/* get the simulator response */
svr = sr = strdup(simResponse());
[... F* <addr> <disassembled instruction> ]
we will ignore till we get F* then parse the address */
while (*sr) {
-
- if (strncmp(sr,"Stop at",7) == 0) {
- sr += 7;
- sfmt = "%x";
- break;
- }
-
- if (*sr == 'F' && ( *(sr+1) == '*' || *(sr+1) == ' ')) {
- sr += 2;
- sfmt = "%x";
- break;
- }
- sr++;
+ if (strncmp(sr,"Stop at",7) == 0) {
+ sr += 7;
+ sfmt = "%x";
+ break;
+ }
+
+ if (*sr == 'F' && ( *(sr+1) == '*' || *(sr+1) == ' ')) {
+ sr += 2;
+ sfmt = "%x";
+ break;
+ }
+ sr++;
}
- if (!*sr) return 0;
+ if (!*sr) {
+ fprintf(stderr, "Error?, simGoTillBp failed to Stop\n");
+ return 0;
+ }
while (isspace(*sr)) sr++ ;
- if (sscanf(sr,sfmt,&addr) != 1)
- return 0;
- else
+ if (sscanf(sr,sfmt,&addr) != 1) {
+ fprintf(stderr, "Error?, simGoTillBp failed to get Addr\n");
+ return 0;
+ }
return addr;
-
}
void simReset ()
{
sendSim("res\n");
- waitForSim();
+ waitForSim(100,NULL);
}
/*-----------------------------------------------------------------*/
char *rb = regBuff;
int i;
- sendSim("dr\n");
- waitForSim();
- /* make it some more readable */
+ sendSim("info registers\n");
+
+ waitForSim(100,NULL);
+
resp = simResponse();
+ return resp;
+
+#if 0
+ Take this out(2-09-02) cant see as its that useful to reformat, karl.
+
/* the response is of the form
XXXXXX R0 R1 R2 R3 R4 R5 R6 R7 ........
XXXXXX XX . ACC=0xxx dd cc B=0xxx dd cc DPTR= 0xxxxx @DPTR= 0xxx dd cc
- XXXXXX XX . PSW= 0xxx CY=[1|0] AC=[0|1] OV=[0|1] P=[1|0] */
+ XXXXXX XX . PSW= 0xxx CY=[1|0] AC=[0|1] OV=[0|1] P=[1|0]
+
+Format as of 8-4-01:
+ 0x00 00 00 00 00 00 00 00 00 ........
+ 000000 00 . ACC= 0x00 0 . B= 0x00 DPTR= 0x0000 @DPTR= 0x00 0 .
+ 000000 00 . PSW= 0x00 CY=0 AC=0 OV=0 P=0
+F 0x006d 75 87 80 MOV PCON,#80
+*/
+
memset(regBuff,0,sizeof(regBuff));
/* skip the first numerics */
while (*resp && !isxdigit(*resp)) resp++;
+
+ if (strncmp(resp, "0x", 2)) {
+ fprintf(stderr, "Error: Format1A\n");
+ return regBuff;
+ }
+ resp += 2;
while (*resp && isxdigit(*resp)) resp++;
/* now get the eight registers */
getValueStr(resp,"P="));
return regBuff;
-
-
+#endif
}