Chipcon: peek and poke of xdata work.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 23 Jun 2009 03:03:23 +0000 (03:03 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 23 Jun 2009 03:03:23 +0000 (03:03 +0000)
Docco seems to be wrong about DEBUG length.
Use length of 1 per *cycle*, not 1 per *byte*.
Dummy bytes don't hurt.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@54 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFET.py
client/goodfet.cc
firmware/apps/chipcon/chipcon.c
firmware/include/chipcon.h

index 36f680e..14728c7 100755 (executable)
@@ -149,11 +149,54 @@ class GoodFET:
         hi=ord(self.data[0]);
         lo=ord(self.data[1]);
         return (hi<<8)+lo;
+    def CCdebuginstr(self,instr):
+        self.writecmd(0x30,0x88,len(instr),instr);
+        return ord(self.data[0]);
     def MSP430peek(self,adr):
         """Read the contents of memory at an address."""
         self.data=[adr&0xff, (adr&0xff00)>>8];
         self.writecmd(0x11,0x02,2,self.data);
         return ord(self.data[0])+(ord(self.data[1])<<8);
+    def CCpeekcodebyte(self,adr):
+        """Read the contents of code memory at an address."""
+        self.data=[adr&0xff, (adr&0xff00)>>8];
+        self.writecmd(0x30,0x90,2,self.data);
+        return ord(self.data[0]);
+    def CCpeekdatabyte(self,adr):
+        """Read the contents of data memory at an address."""
+        self.data=[adr&0xff, (adr&0xff00)>>8];
+        self.writecmd(0x30,0x91, 2, self.data);
+        return ord(self.data[0]);
+    def CCpokedatabyte(self,adr,val):
+        """Write a byte to data memory."""
+        self.data=[adr&0xff, (adr&0xff00)>>8, val];
+        self.writecmd(0x30, 0x92, 3, self.data);
+        return ord(self.data[0]);
+    def CCchiperase(self):
+        """Erase all of the target's memory."""
+        self.writecmd(0x30,0x80,0,None);
+    def CCstatus(self):
+        """Check the status."""
+        self.writecmd(0x30,0x84,0,None);
+        return ord(self.data[0])
+    CCstatusbits={0x80 : "erased",
+                  0x40 : "pcon_idle",
+                  0x20 : "halted",
+                  0x10 : "pm0",
+                  0x08 : "halted",
+                  0x04 : "locked",
+                  0x02 : "oscstable",
+                  0x01 : "overflow"};
+    def CCstatusstr(self):
+        """Check the status as a string."""
+        status=self.CCstatus();
+        str="";
+        i=1;
+        while i<0x100:
+            if(status&i):
+                str="%s %s" %(self.CCstatusbits[i],str);
+            i*=2;
+        return str;
     def MSP430poke(self,adr,val):
         """Read the contents of memory at an address."""
         self.data=[adr&0xff, (adr&0xff00)>>8, val&0xff, (val&0xff00)>>8];
@@ -170,6 +213,10 @@ class GoodFET:
         self.writecmd(0x30,0x20,0,self.data);
         ident=self.CCidentstr();
         print "Target identifies as %s." % ident;
+        print "Status: %s." % self.CCstatusstr();
+        self.CCreleasecpu();
+        self.CChaltcpu();
+        print "Status: %s." % self.CCstatusstr();
     def CCstop(self):
         """Stop debugging."""
         self.writecmd(0x30,0x21,0,self.data);
@@ -185,7 +232,12 @@ class GoodFET:
     def MSP430releasecpu(self):
         """Resume the CPU."""
         self.writecmd(0x11,0xA1,0,self.data);
-
+    def CChaltcpu(self):
+        """Halt the CPU."""
+        self.writecmd(0x30,0x86,0,self.data);
+    def CCreleasecpu(self):
+        """Resume the CPU."""
+        self.writecmd(0x30,0x87,0,self.data);
     def MSP430shiftir8(self,ins):
         """Shift the 8-bit Instruction Register."""
         data=[ins];
@@ -246,6 +298,10 @@ class GoodFET:
             print "%04x %04x" % (i, self.MSP430peek(i));
             i+=2;
     def CCtest(self):
+        self.CCreleasecpu();
+        self.CChaltcpu();
+        print "Status: %s" % self.CCstatusstr();
+        
         #Grab ident three times, should be equal.
         ident1=self.CCident();
         ident2=self.CCident();
@@ -255,10 +311,26 @@ class GoodFET:
             print "%04x, %04x, %04x" % (ident1, ident2, ident3);
         
         #Single step, printing PC.
-        print "Tracing execution at startup."
+        #print "Tracing execution at startup."
         for i in range(1,15):
-            print "PC=%04x" % self.CCgetPC();
+            pc=self.CCgetPC();
+            byte=self.CCpeekcodebyte(i);
+            print "PC=%04x, %02x" % (pc, byte);
             self.CCstep_instr();
+        
+        #print "Verifying that debugging a NOP doesn't affect the PC."
+        for i in range(1,15):
+            pc=self.CCgetPC();
+            self.CCdebuginstr([0x00]);
+            if(pc!=self.CCgetPC()):
+                print "ERROR: PC changed during CCdebuginstr([NOP])!";
+        for i in range(0xE500,0xE600):
+            byte=self.CCpeekdatabyte(i);
+            print "data %04x: %02x" % (i,byte);
+            self.CCpokedatabyte(i,i&0xFF);
+            byte=self.CCpeekdatabyte(i);
+            print "data %04x: %02x" % (i,byte);
+        print "Status: %s." % self.CCstatusstr();
         #Exit debugger
         self.CCstop();
         print "Done.";
index 27941a7..e573679 100755 (executable)
@@ -27,10 +27,6 @@ client.serInit("/dev/ttyUSB0")
 client.CCsetup();
 client.CCstart();
 
-#client.setBaud(2);
-
-if(sys.argv[1]=="monitortest"):
-    client.monitortest();
 if(sys.argv[1]=="test"):
     client.CCtest();
 if(sys.argv[1]=="dump"):
@@ -52,9 +48,10 @@ if(sys.argv[1]=="dump"):
         i+=2;
     h.write_hex_file(f);
 if(sys.argv[1]=="erase"):
-    client.MSP430masserase();
-if(sys.argv[1]=="ivt"):
-    client.MSP430dumpmem(0xFFE0,0xFFFF);
+  print "Status: %s" % client.CCstatusstr();
+  client.CCchiperase();
+  print "Status: %s" %client.CCstatusstr();
+
 if(sys.argv[1]=="flash"):
     f=sys.argv[2];
     start=0;
@@ -93,6 +90,4 @@ if(sys.argv[1]=="verify"):
             if(i%0x100==0):
                 print "%04x" % i;
 
-
-#client.MSP430releasecpu();
-#client.MSP430stop();
+client.CCstop();
index b90c33d..1499629 100644 (file)
@@ -187,7 +187,8 @@ void cchandle(unsigned char app,
     txdata(app,verb,1);
     break;
   case CC_DEBUG_INSTR:
-    txdata(app,NOK,0);//TODO add me
+    cc_debug_instr(len);
+    txdata(app,verb,1);
     break;
   case CC_STEP_INSTR:
     cc_step_instr();
@@ -204,8 +205,17 @@ void cchandle(unsigned char app,
 
   //Macro commands
   case CC_READ_CODE_MEMORY:
+    cmddata[0]=peekcodebyte(cmddataword[0]);
+    txdata(app,verb,1);
+    break;
   case CC_READ_XDATA_MEMORY:
+    cmddata[0]=peekdatabyte(cmddataword[0]);
+    txdata(app,verb,1);
+    break;
   case CC_WRITE_XDATA_MEMORY:
+    cmddata[0]=pokedatabyte(cmddataword[0], cmddata[2]);
+    txdata(app,verb,1);
+    break;
   case CC_SET_PC:
   case CC_CLOCK_INIT:
   case CC_WRITE_FLASH_PAGE:
@@ -304,3 +314,103 @@ void cc_step_instr(){
   ccread(1);
   return;
 }
+
+//! Debug an instruction.
+void cc_debug_instr(unsigned char len){
+  //Bottom two bits of command indicate length.
+  unsigned char cmd=0x54+(len&0x3);
+  CCWRITE;
+  cctrans8(cmd);  //Second command code
+  cccmd(len&0x3); //Command itself.
+  ccread(1);
+  return;
+}
+
+//! Debug an instruction, for local use.
+unsigned char cc_debug(unsigned char len,
+             unsigned char a,
+             unsigned char b,
+             unsigned char c){
+  unsigned char cmd=0x54+0x3;//(len&0x3);
+  CCWRITE;
+  cctrans8(cmd);
+  /*if(len--)*/ cctrans8(a);
+  if(len--) cctrans8(b);
+  if(len--) cctrans8(c);
+  CCREAD;
+  return cctrans8(0x00);
+}
+
+//! Fetch a byte of code memory.
+unsigned char peekcodebyte(unsigned long adr){
+  /** See page 9 of SWRA124 */
+  unsigned char bank=adr>>15,
+    lb=adr&0xFF,
+    hb=(adr>>8)&0x7F,
+    toret=0;
+  adr&=0x7FFF;
+  
+  //MOV MEMCTR, (bank*16)+1
+  cc_debug(3, 0x75, 0xC7, 0);//(bank<<4) + 1);
+  //MOV DPTR, address
+  cc_debug(3, 0x90, hb, lb);
+  
+  //for each byte
+  //CLR A
+  cc_debug(1, 0xE4, 0, 0);
+  //MOVC A, @A+DPTR;
+  toret=cc_debug(1, 0x93, 0, 0);
+  //INC DPTR
+  //cc_debug(1, 0xA3, 0, 0);
+  
+  return toret;
+}
+
+
+//! Set a byte of data memory.
+unsigned char pokedatabyte(unsigned int adr,
+                          unsigned char val){
+  unsigned char
+    hb=(adr&0xFF00)>>8,
+    lb=adr&0xFF;
+  
+  //MOV DPTR, adr
+  cc_debug(3, 0x90, hb, lb);
+  //MOV A, val
+  cc_debug(2, 0x74, val, 0);
+  //MOVX @DPTR, A
+  cc_debug(1, 0xF0, 0, 0);
+  
+  return;
+  /*
+DEBUG_INSTR(IN: 0x90, HIBYTE(address), LOBYTE(address), OUT: Discard);
+for (n = 0; n < count; n++) {
+    DEBUG_INSTR(IN: 0x74, inputArray[n], OUT: Discard);
+    DEBUG_INSTR(IN: 0xF0, OUT: Discard);
+    DEBUG_INSTR(IN: 0xA3, OUT: Discard);
+}
+   */
+}
+
+//! Fetch a byte of data memory.
+unsigned char peekdatabyte(unsigned int adr){
+  unsigned char
+    hb=(adr&0xFF00)>>8,
+    lb=adr&0xFF,
+    toret;
+
+  //MOV DPTR, adr
+  cc_debug(3, 0x90, hb, lb);
+  //MOVX A, @DPTR
+  //Must be 2, perhaps for clocking?
+  toret=cc_debug(3, 0xE0, 0, 0);
+  return toret;
+  
+    /*
+DEBUG_INSTR(IN: 0x90, HIBYTE(address), LOBYTE(address), OUT: Discard);
+for (n = 0; n < count; n++) {
+    DEBUG_INSTR(IN: 0xE0, OUT: outputArray[n]);
+    DEBUG_INSTR(IN: 0xA3, OUT: Discard);
+}
+  */
+}
index cf339f1..3289c7e 100644 (file)
@@ -15,6 +15,20 @@ unsigned short cc_get_chip_id();
 unsigned short cc_get_pc();
 //! Set a hardware breakpoint.
 void cc_set_hw_brkpnt(unsigned short);
+//! Debug an instruction, for remote use.
+void cc_debug_instr(unsigned char);
+//!Read a byte of code memory.
+unsigned char peekcodebyte(unsigned long adr);
+//!Read a byte of data memory.
+unsigned char peekdatabyte(unsigned int adr);
+//! Set a byte of data memory.
+unsigned char pokedatabyte(unsigned int adr,
+                          unsigned char val);
+//! Debug an instruction, for local use.
+unsigned char cc_debug(unsigned char len,
+                      unsigned char a,
+                      unsigned char b,
+                      unsigned char c);
 
 //! Halt the CPU.
 void cc_halt();