fix some things
[fw/sdcc] / debugger / mcs51 / simi.c
index 16e25b7ed50e7ed4daa57dd0478c344fe56f74d1..aac8f253fd5b5b92f02212708777d05b92e384ab 100644 (file)
@@ -54,19 +54,20 @@ void readSim(int resetp)
     if (resetp)
        sbp = simibuff;
     
-#ifdef SDCDB_DEBUG
-    fprintf(stderr,"stderr--> reading from sim\n");
-#endif
+    Dprintf(D_simi, ("readSim: reading from sim["));
 
     while ((ch = fgetc(simin))) {
+
 #ifdef SDCDB_DEBUG     
-       fputc(ch,stdout);
+ if (D_simi) {
+       fputc(ch,stdout);
+ }
 #endif
+
        *sbp++ = ch;    
     }
-#ifdef SDCDB_DEBUG
-    fprintf(stderr,"stderr--> reading from sim done\n");
-#endif
+
+    Dprintf(D_simi, ("] end readSim\n"));
 
     *sbp = '\0';
 }
@@ -87,6 +88,8 @@ void openSimulator (char **args, int nargs)
     struct sockaddr_in sin;     
     int retry = 0;
     int i ;
+
+#if 0
     char *simargs[32] = { "s51","-P","-r 9756", NULL };
     
     /* create the arguments */
@@ -94,17 +97,17 @@ void openSimulator (char **args, int nargs)
        simargs[i+3] = args[i];       
     }
     simargs[i+3]= NULL;
+#endif
 
     /* 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) {
+//     if (execvp("s51",simargs) < 0) {
+       if (execvp(args[0],args) < 0) {
            perror("cannot exec simulator");
            exit(1);
        }       
@@ -159,6 +162,7 @@ char *simResponse()
 /*-----------------------------------------------------------------*/
 void sendSim(char *s)
 {
+    Dprintf(D_simi, ("sendSim-->%s", s));  // s has LF at end already
     fputs(s,simout);
     fflush(simout);
 }
@@ -194,7 +198,8 @@ unsigned long simGetValue (unsigned int addr,char mem, int size)
        break;
     case 'H':
     case 'J':
-       prefix = "db" ;
+//     prefix = "db" ;
+       prefix = "dump" ;
        break;
     case 'I':
        prefix = "ds" ;
@@ -215,11 +220,14 @@ unsigned long simGetValue (unsigned int addr,char mem, int size)
     /* 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++ ;
@@ -280,7 +288,7 @@ void simLoadFile (char *s)
 {
     char buff[128];
 
-    sprintf(buff,"l %s\n",s);
+    sprintf(buff,"l \"%s\"\n",s);
     printf(buff);
     sendSim(buff);
     waitForSim();    
@@ -295,12 +303,41 @@ unsigned int simGoTillBp ( unsigned int gaddr)
     unsigned addr ; 
     char *sfmt;
 
+    /* kpb: new code 8-03-01 */
+    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");
+      sleep(1);  /* do I need this? */
+    } else     if (gaddr == -1) { /* resume */
+
+      // try adding this(kpb)
+      sendSim("step\n");
+      usleep(100000);
+      waitForSim();
+
+       sendSim ("run\n");
+    }
+    else {
+      printf("Error, simGoTillBp > 0!\n");
+      exit(1);
+    }
+
+#if 0
     if (gaddr != -1) {
        char buf[20];
        sprintf(buf,"g 0x%x\n",gaddr);
        sendSim(buf);
     } else     
        sendSim ("g\n");
+#endif
     
     waitForSim();
     
@@ -327,15 +364,18 @@ unsigned int simGoTillBp ( unsigned int gaddr)
        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;
-     
 
 }
 
@@ -378,18 +418,39 @@ char  *simRegs()
     char *rb = regBuff;
     int i;
 
-    sendSim("dr\n");
+    sendSim("info registers\n");
+    //kpb(8-5-01) sendSim("dr\n");
+
     waitForSim();
     /* make it some more readable */
     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 */
@@ -435,8 +496,7 @@ char  *simRegs()
            getValueStr(resp,"P="));
 
     return regBuff;
-    
-    
+#endif
 
 }