Explorar o código

Minor tool changes

Min %!s(int64=5) %!d(string=hai) anos
pai
achega
730940666e
Modificáronse 3 ficheiros con 35 adicións e 16 borrados
  1. 14 1
      tools/format_utils.py
  2. 21 15
      tools/debugging/debugging.py
  3. 0 0
      tools/quartus_tcl.py

+ 14 - 1
tools/format_utils.py

@@ -80,6 +80,12 @@ FORMAT_MAP = {
     'memb': ('mem',  convert_to_mem, {'binary': True}),
 }
 
+FORMAT_INPUT = [
+    "raw",
+    "bin",
+    "hex",
+]
+
 if __name__ == '__main__':
     import argparse
     import sys
@@ -93,6 +99,7 @@ if __name__ == '__main__':
     parser.add_argument('-S', '--slice', type=int, default=0, help='Slice output')
     parser.add_argument('-n', '--slice_no', type=int, default=-1, help='Output only nth slice')
     parser.add_argument('-w', '--width', type=int, default=8, help='Data width in bits')
+    parser.add_argument('-i', '--input_format', choices=FORMAT_INPUT, default='raw', help='Input format')
     parser.add_argument('-t', '--output_type', choices=list(FORMAT_MAP.keys()), default='mem', help='Output type')
 
     args = parser.parse_args(sys.argv[1:])
@@ -114,7 +121,13 @@ if __name__ == '__main__':
         mkdir(output_dir)
 
     ifile = open(args.file, 'rb')
-    binary = BitArray(ifile.read())
+    if args.input_format == 'bin':
+        binary = BitArray(bin=ifile.read().decode(encoding='ascii', errors='ignore'))
+    elif args.input_format == 'hex':
+        binary = BitArray(hex=ifile.read().decode(encoding='ascii', errors='ignore'))
+    else:
+        binary = BitArray(ifile.read())
+
     ifile.close()
 
     if args.slice > 1 and len(binary) % (args.slice*args.width) != 0:

+ 21 - 15
tools/debugging/debugging.py

@@ -1,7 +1,7 @@
 import curses
 import math
-from debugging.quartus_tcl import QuartusTCL, INSYS_SPI_ERROR, INSYS_MEM_ERROR, QUATUS_TCL_TIMEOUT
-
+from quartus_tcl import INSYS_SPI_ERROR, INSYS_MEM_ERROR, QuartusTCL, QUATUS_TCL_TIMEOUT
+from . import oisc8asm
 
 def render_list(w, items, offset=3):
     selected = 0
@@ -66,7 +66,6 @@ def read_probes(ps, q, pren):
 
 
 def memeditor(w, q, hw, dev, mem):
-    import traceback
     error = None
     try:
         memedit_window(w, q, hw, dev, mem)
@@ -305,6 +304,20 @@ def memedit_window(w, q, hw, dev, mem):
             return
 
 
+def oisc_comments(probe, value):
+    try:
+        data = int(value[0], 16)
+    except ValueError:
+        return None
+    except IndexError:
+        return None
+
+    if probe == "INST":
+        val = oisc8asm.asmc.decompile([data]).split('\n')[0]
+        return val
+    return None
+
+
 def debugging_window(w, q, hw, dev, ps, mem, pren):
     w.addstr(3, 0, "      Probes:", curses.color_pair(2) | curses.A_BOLD)
     w.clrtoeol()
@@ -315,6 +328,7 @@ def debugging_window(w, q, hw, dev, ps, mem, pren):
     profile = False
     ps_map = {name: (i, src_width, prb_width) for i, src_width, prb_width, name in ps}
     if pren and 'RST' in ps_map and 'CLKD' in ps_map and 'MCLK' in ps_map:
+        ## This is oisc
         profile = True
         q.write_source_data(ps_map['RST'][0], '1')
         q.write_source_data(ps_map['CLKD'][0], '1')
@@ -339,6 +353,10 @@ def debugging_window(w, q, hw, dev, ps, mem, pren):
                         w.addstr(d, mode)
                     if di < len(data) - 1:
                         w.addstr('|', mode)
+                if profile:
+                    comment = oisc_comments(name, data)
+                    if comment is not None:
+                        w.addstr(' ' + comment, curses.color_pair(1))
                 w.clrtoeol()
                 index += 1
             # <index> <depth> <width> <read/write mode> <instance type> <instance name>
@@ -492,17 +510,5 @@ def main(w):
         break
     q.disconnect()
 
-
-if __name__ == '__main__':
-    print_last = ""
-    try:
-        curses.wrapper(main)
-        # q = QuartusTCL()
-        # q.list_devices()
-        # q.disconnect()
-    except KeyboardInterrupt:
-        print('Interrupt!')
-    except curses.error as e:
-        print('Failed to start curses: ' + e.args[0])
     # except Exception as e:
     #     print("Unexpected error:" + e.args[0])

tools/debugging/quartus_tcl.py → tools/quartus_tcl.py