Use 'ao-dbg' instead of 's51' to communicate with TeleMetrum
[fw/sdcc] / debugger / mcs51 / simi.c
index 1e9089e5705cf38c25d29598d9b6417e5d2a7a58..4a771a339fcc4782fa304011bb4b6aa4afb2733b 100644 (file)
@@ -82,7 +82,14 @@ static char *getMemCache(unsigned int addr,int cachenum, int size)
         {
             sendSim("ds 0x80 0xff\n");
         }
-        else
+        else if ( cachenum == CMEM_CACHE )
+       {
+#define CMEM_CACHE_MASK ((MAX_CACHE_SIZE >> 2) - 1)
+            laddr = addr & ~CMEM_CACHE_MASK;
+            sprintf(cache->buffer,"dump rom 0x%x 0x%x\n",laddr,laddr+CMEM_CACHE_MASK );
+            sendSim(cache->buffer);
+       }
+       else
         {
             laddr = addr & 0xffffffc0;
             sprintf(cache->buffer,"dx 0x%x 0x%x\n",laddr,laddr+0xff );
@@ -283,6 +290,7 @@ void openSimulator (char **args, int nargs)
     invalidateCache(XMEM_CACHE);
     invalidateCache(IMEM_CACHE);
     invalidateCache(SREG_CACHE);
+    invalidateCache(CMEM_CACHE);
 
     if (INVALID_SOCKET == (sock = WSASocket(PF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0))) {
         fprintf(stderr, "cannot create socket: %d\n", WSAGetLastError());
@@ -363,6 +371,7 @@ static int execSimulator(char **args, int nargs)
             exit(1);
         }
     }
+    return simPid;
 }
 
 void openSimulator (char **args, int nargs)
@@ -385,6 +394,7 @@ void openSimulator (char **args, int nargs)
     invalidateCache(XMEM_CACHE);
     invalidateCache(IMEM_CACHE);
     invalidateCache(SREG_CACHE);
+    invalidateCache(CMEM_CACHE);
 
     if ((sock = socket(AF_INET,SOCK_STREAM,0)) < 0)
     {
@@ -473,12 +483,14 @@ static int getMemString(char *buffer, char wrflag,
     {
         case 'A': /* External stack */
         case 'F': /* External ram */
+       case 'P': /* Pdata space */
             prefix = "xram";
             cachenr = XMEM_CACHE;
             break;
         case 'C': /* Code */
         case 'D': /* Code / static segment */
             prefix = "rom";
+           cachenr = CMEM_CACHE;
             break;
         case 'B': /* Internal stack */
         case 'E': /* Internal ram (lower 128) bytes */
@@ -527,6 +539,16 @@ void simSetPC( unsigned int addr )
     simResponse();
 }
 
+unsigned int simGetPC(void)
+{
+    char *sr;
+    sendSim("pc\n");
+    waitForSim(100,NULL);
+    simResponse();
+    sr = simResponse();
+    return strtol(sr+3,0,0);
+}
+    
 int simSetValue (unsigned int addr,char mem, int size, unsigned long val)
 {
     char cachenr, i;
@@ -544,7 +566,7 @@ int simSetValue (unsigned int addr,char mem, int size, unsigned long val)
     s = buffer + strlen(buffer) -1;
     for ( i = 0 ; i < size ; i++ )
     {
-        sprintf(s," 0x%x", val & 0xff);
+        sprintf(s," 0x%lx", val & 0xff);
         s += strlen(s);
         val >>= 8;
     }
@@ -589,7 +611,7 @@ unsigned long simGetValue (unsigned int addr,char mem, int size)
            case of bit variables which case it becomes
            [address] [assembler bit address] [v] */
         /* first skip thru white space */
-        while (isspace(*resp)) resp++ ;
+        resp = trim_left(resp);
 
         if (strncmp(resp, "0x",2) == 0)
             resp += 2;
@@ -611,7 +633,7 @@ unsigned long simGetValue (unsigned int addr,char mem, int size)
         for (i = 0 ; i < size ; i++ )
         {
             /* skip white space */
-            while (isspace(*resp)) resp++ ;
+            resp = trim_left(resp);
 
             b[i] = strtol(resp,&resp,16);
         }
@@ -653,7 +675,7 @@ void simLoadFile (char *s)
     char buff[128];
 
     sprintf(buff,"file \"%s\"\n",s);
-    printf(buff);
+    printf("%s",buff);
     sendSim(buff);
     waitForSim(500,NULL);
 }
@@ -743,6 +765,7 @@ void simReset (void)
     invalidateCache(XMEM_CACHE);
     invalidateCache(IMEM_CACHE);
     invalidateCache(SREG_CACHE);
+    invalidateCache(CMEM_CACHE);
     sendSim("res\n");
     waitForSim(100,NULL);
 }