CVS: msp430simu core.py,1.17,1.18 gdbserver.py,1.1,1.2 simugui.py,1.12,1.13

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/msp430simu
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19502/msp430simu

Modified Files:
	core.py gdbserver.py simugui.py 
Log Message:
- several improvements
- gdb server update for remote commands

Index: core.py
===================================================================
RCS file: /cvsroot/mspgcc/msp430simu/core.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -w -d -r1.17 -r1.18
--- core.py	30 Dec 2005 00:19:10 -0000	1.17
+++ core.py	31 Dec 2005 00:25:06 -0000	1.18
@@ -49,17 +49,17 @@
         self.log = logging.getLogger('watch')
         self.description = description
 
-    def __call__(self, address, bytemode, oldvalue, newvalue):
-        if newvalue:    #for writes
+    def __call__(self, address, bytemode, oldvalue, newvalue=None):
+        if newvalue is not None:    #for writes
             self.log.info(
-                ('WATCHr: @0x%%04x: 0x%%0%dx -> 0x%%0%dx: %%s\n' % (
+                ('write: @0x%%04x: 0x%%0%dx -> 0x%%0%dx: %%s' % (
                     bytemode and 2 or 4, bytemode and 2 or 4)
                 ) % (
                     address, oldvalue, newvalue, self.description
                 ))
         else:           #for reads
             self.log.info(
-                ('WATCHr: @0x%%04x: 0x%%0%dx: %%s\n' % (
+                ('read: @0x%%04x: 0x%%0%dx: %%s' % (
                     bytemode and 2 or 4)
                 ) % (
                     address, oldvalue, self.description
@@ -73,7 +73,7 @@
 
     def __call__(self, memory, bytemode, writing, address):
         if self.condition_fu(memory, writing, address):
-            self.log.info('WATCHx: @0x%04x: %s %s\n' % (
+            self.log.info('access: @0x%04x: %s %s' % (
                 address, bytemode and 'b' or 'w', self.description
             ))
 
@@ -402,7 +402,7 @@
             if self.mode == self.MUL:
                 self.acc = r
                 self.sumext = 0
-            if self.mode == self.SIGNEDMUL:
+            elif self.mode == self.SIGNEDMUL:
                 if self.op1 < 0:    r = -r
                 if self.op2 < 0:    r = -r
                 self.acc = r
@@ -410,13 +410,13 @@
                     self.sumext = 0xffff
                 else:
                     self.sumext = 0
-            if self.mode == self.MULANDACCUM:
+            elif self.mode == self.MULANDACCUM:
                 self.acc += r
                 if self.acc > 0xffffffffL:
                     self.sumext = 0x0001
                 else:
                     self.sumext = 0
-            if self.mode == self.SIGNEDMULANDACCUM:
+            elif self.mode == self.SIGNEDMULANDACCUM:
                 if self.op1 < 0:    r = -r
                 if self.op2 < 0:    r = -r
                 self.acc += r
@@ -424,16 +424,20 @@
                     self.sumext = 0xffff
                 else:
                     self.sumext = 0
-            #TODO: broken!!
+            else:
+                raise ValueError('invalid internal state %s' % self.mode)
+            #XXX TODO: broken!!
         elif address == 0x13a:    #ResLo/acc
             self.acc = (self.acc & 0xffff0000L) | value
         elif address == 0x13c:    #ResHi/acc
             self.acc = (self.acc & 0x0000ffff) | (value<<16)
         elif address == 0x13e:    #SumExt
-            pass #readonly  #TODO: log
+            self.log.error('Access Error - SUMEXT is read only')
 
     def get(self, address, bytemode=0):
         """read from address"""
+        if bytemode:
+            self.log.error('Access Error - byte access not allowed')
         if address == 0x130:    value = self.mpy
         elif address == 0x132:  value = self.mpys
         elif address == 0x134:  value = self.mac
@@ -461,14 +465,14 @@
 
     def set(self, address, value, bytemode=0):
         """write value to address"""
-        if not bytemode and self.log:
-            self.log.error('PERIPH: Access Error - expected byte but got word access')
+        if not bytemode:
+            self.log.error('Access Error - expected byte but got word access')
         self.values[address] = value & 0xff
 
     def get(self, address, bytemode=0):
         """read from address"""
-        if not bytemode and self.log:
-            self.log.error('PERIPH: Access Error - expected byte but got word access')
+        if not bytemode:
+            self.log.error('Access Error - expected byte but got word access')
         return self.values[address]
 
 
@@ -501,7 +505,7 @@
 
     def load(self, filename):
         """fill memory with the contents of a file. file type is determined from extension"""
-        self.log.info('loading file %s' % filename)
+        self.log.info('loading file %r' % filename)
         if filename[-4:].lower() == '.txt':
             self.loadTIText(open(filename, "r"))
         else:
@@ -567,7 +571,7 @@
     def set(self, address, value, bytemode=0):
         """write value to address"""
         if address > 0xffff:
-            self.log.error('write outside valid address range (0x%04x)' % (address, ))
+            self.log.error('write outside valid of address range (0x%04x)' % (address, ))
             address &= 0xffff       #16 bit wrap around
         self.log.debug('write 0x%04x <- 0x%04x mode:%s' % (address, value, bytemode and 'b' or 'w'))
         if self.setwatches.has_key(address): self.setwatches[address](address, bytemode, self.memory[address], value)  #call watch
@@ -592,7 +596,7 @@
     def get(self, address, bytemode=0):
         """read value from address"""
         if address > 0xffff:
-            self.log.error('read outside valid address range (0x%04x)' % (address, ))
+            self.log.error('read outside of valid address range (0x%04x)' % (address, ))
             address &= 0xffff       #16 bit wrap around
         if self.getwatches.has_key(address): self.getwatches[address](address, bytemode, self.memory[address], None)  #call watch
         for a in self.accesswatches: a(self, bytemode, 0, address)
@@ -834,6 +838,9 @@
 ## CORE (CPU with Regs, Mem, insn)
 ##################################################################
 
+class MSP430CoreException(Exception):
+    """this exception is raised when code execution errors are detected"""
+    
 class Core(Subject):
     """CPU core with registers, memory and code execution logic"""
 
@@ -858,7 +865,7 @@
 
     def execSWPB(self, bytemode, arg):
         if bytemode:
-            raise "illegal insn"
+            raise MSP430CoreException("illegal use of SWPB")
         a = arg.get()
         r = ((a & 0xff00) >> 8) | ((a & 0x00ff) << 8)
         arg.set(r)
@@ -874,7 +881,7 @@
         arg.set(r)
 
     def execSXT(self, bytemode, arg):
-        if bytemode: raise "illegal use of SXT" #should actualy never happen
+        if bytemode: raise MSP430CoreException("illegal use of SXT") #should actualy never happen
         a = arg.get()
         r = a & 0xff
         if a & 0x80:  r |= 0xff00
@@ -943,7 +950,8 @@
         if store: dst.set(r)
 
     def execDADD(self, bytemode, src, dst):
-        raise "instruction not supported in this version of simu"
+        #XXX implement this one
+        raise NotImplementedError("instruction not supported in this version of simu")
 
     def execBIT(self, bytemode, src, dst):
         d = dst.get()
@@ -1089,7 +1097,7 @@
             Register(self, regnum=14),
             Register(self, regnum=15)
         )
-        #alisses
+        #aliases
         self.PC = self.R[0]
         self.SP = self.R[1]
         self.SR = self.R[2]
@@ -1168,7 +1176,7 @@
         if execfu:
             apply(execfu, [self]+args)
         else:
-            self.log.warning("%s @0x%02x" % (name, address))
+            self.log.warning("%s @0x%04x" % (name, address))
         self.notify()
         return note
 

Index: gdbserver.py
===================================================================
RCS file: /cvsroot/mspgcc/msp430simu/gdbserver.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- gdbserver.py	30 Dec 2005 00:19:10 -0000	1.1
+++ gdbserver.py	31 Dec 2005 00:25:06 -0000	1.2
@@ -114,10 +114,12 @@
         self.setDaemon(1)
         self.core = core
         self.log = logging.getLogger("gdbclient")
+        self.alive = True
         self.runner = BreakpointRunner(core)
         self.runner.start()
 
     def close(self):
+        self.alive = False
         self.log.info("closing...")
         self.netin.close()
         self.netout.close()
@@ -131,7 +133,7 @@
     def run(self):
         try:
             self.log.info("client loop ready...")
-            while 1:
+            while self.alive:
                 try:
                     pkt = self.readPacket()
                     self.log.debug('processing remote command %r' % pkt)
@@ -186,16 +188,23 @@
                         if pkt[1:5] == "Rcmd":
                             cmd = binascii.unhexlify(pkt.split(',')[1]).strip()
                             self.log.info("monitor command: %r" % cmd)
-                            if cmd[0:1] == '"': #its a string, execute python code !Security risk!
-                                ans = eval(cmd[1:-1])
-                                self.writePacket(binascii.hexlify(repr(ans)))
-                            #~ elif cmd == 'erase':
-                                #~ print "Erasing the device MAIN memory..."
-                                #~ self.writePacket("OK")
+                            if ' ' in cmd:
+                                command, args = cmd.split(None, 1)
                             else:
-                                self.writePacket("E01")
+                                command = cmd
+                                args = ''
+                            method_name = 'monitor_%s' % command
+                            if hasattr(self, method_name):
+                                try:
+                                    getattr(self, method_name)(args)
+                                except:
+                                    self.log.exception('error in monitor command')
+                                    self.writePacket("E03")
                         else:
-                            self.writePacket("E01") #write error
+                                self.log.warning('no such monitor command ("%s")' % command)
+                                self.writePacket("E02")
+                        else:
+                            self.writePacket("E01") #commond not known
                     elif pkt[0] == "s":     #single step
                         if len(pkt) > 1:
                             adr = int(pkt[1:],16)
@@ -256,6 +265,49 @@
         self.netout.write("$%s#%02x" % (msg, checksum(msg)))
         self.netout.flush()
 
+    def writeMessage(self, msg):
+        self.writePacket("O%s" % binascii.hexlify(msg))
+
+    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+    
+    def monitor_help(self, args):
+        """monitor commands help"""
+        self.writeMessage("Supported commands are:\n")
+        for name in dir(self):
+            if name.startswith('monitor_'):
+                self.writeMessage("%-10s: %s\n" % (name[8:], getattr(self, name).__doc__))
+        self.writePacket("OK")
+        
+    #~ def monitor_eval(self, args):
+        #~ """evaluate python expression !Security risk!"""
+        #~ ans = eval(args)
+        #~ self.writeMessage("%r\n" % (ans,))
+        #~ self.writePacket("OK")
+    
+    def monitor_erase(self, args):
+        """erase flash"""
+        self.log.info('monitor: Erasing Flash ("%s")...' % args)
+        #~ if args == 'main':
+        #~ elif args == 'info':
+        #~ elif args in ('', 'all'):
+        #~ else: #accept "address size"
+        self.writePacket("OK")
+
+    def monitor_puc(self, args):
+        """reset target"""
+        self.core.reset()
+        self.writePacket("OK")
+        
+    def monitor_reset(self, args):
+        """reset target"""
+        self.core.reset()
+        self.writePacket("OK")
+
+    def monitor_vcc(self, args):
+        """set adapter VCC, ignored. here to be compatible with the real gdbproxy"""
+        self.writePacket("OK")
+
+
 if __name__ == '__main__':
     logging.basicConfig(level=logging.INFO)
     #~ logging.basicConfig(level=logging.DEBUG)

Index: simugui.py
===================================================================
RCS file: /cvsroot/mspgcc/msp430simu/simugui.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -d -r1.12 -r1.13
--- simugui.py	29 Dec 2005 21:17:23 -0000	1.12
+++ simugui.py	31 Dec 2005 00:25:06 -0000	1.13
@@ -1,4 +1,11 @@
 #!/usr/bin/env python
+#
+# Simple GUI for the simulator with memory view and disassembler.
+#
+# (C) 2002-2004 Chris Liechti <[email protected]>
+# this is distributed under a free software license, see license.txt
+#
+# $Id$
 
 #import all of the wxPython GUI package
 from wxPython.wx import *
@@ -618,8 +625,9 @@
 
 #application....
 if __name__ == '__main__':
-    #~ import logging
+    import logging
     #~ logging.basicConfig(level=logging.DEBUG)
+    logging.basicConfig(level=logging.INFO)
     
     # Every wxWindows application must have a class derived from wxApp
     class MyApp(wxApp):



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.