add GPRs to pypowersim demo
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 21 May 2021 14:08:39 +0000 (15:08 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 21 May 2021 14:08:39 +0000 (15:08 +0100)
src/openpower/decoder/isa/pypowersim.py
src/test/basic_pypowersim/Makefile
src/test/basic_pypowersim/gpr.list [new file with mode: 0644]

index d4e85585e091cc915e528c4f0273944b086f4b60..50d58c07dd8c268ce1905c7d31057d01b5aa6ecb 100644 (file)
@@ -13,11 +13,11 @@ from openpower.decoder.isa.all import ISA
 def convert_to_num(num):
     # detect number types
     if num.isdigit():
-        return int(reg)
+        return int(num)
     if num.startswith("0b"):
-        return int(value[2], 2)
-    if value.startswith("0x"):
-        return int(value[2], 16)
+        return int(num[2:], 2)
+    if num.startswith("0x"):
+        return int(num[2:], 16)
     return num
 
 
@@ -30,8 +30,9 @@ def read_entries(fname, listqty=None):
     with open(fname) as f:
         for line in f.readlines():
             # split line "x : y" into ["x", "y"], remove spaces
-            line = map(str.strip, line.strip().split(":"))
+            line = list(map(str.strip, line.strip().split(":")))
             assert len(line) == 2, "regfile line must be formatted 'x : y'"
+            # check and convert format
             reg, val = line
             reg = convert_to_num(reg)
             val = convert_to_num(val)
@@ -129,12 +130,14 @@ def run_simulation():
 
     binaryname = None
     initial_regs = None
+    initial_fprs = None
+    initial_sprs = None
     lst = None
 
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "i:l:g:f:", 
+        opts, args = getopt.getopt(sys.argv[1:], "i:l:g:f:s:", 
                                    ["binary", "listing",
-                                    "intregs"])
+                                    "intregs", "fpregs", "sprs"])
       
     except:
         sys.stderr.write("Command-line Error\n")
@@ -145,8 +148,12 @@ def run_simulation():
             binaryname = arg
         elif opt in ['-l', '--listing']:
             lst = arg
-        elif opt in ['g', '--intregs']:
+        elif opt in ['-g', '--intregs']:
             initial_regs = read_entries(arg, 32)
+        elif opt in ['-f', '--fpregs']:
+            initial_fprs = read_entries(arg, 32)
+        elif opt in ['-s', '--sprs']:
+            initial_sprs = read_entries(arg, 32)
 
     if binaryname is None and lst is None:
         sys.stderr.write("Must give binary or listing\n")
@@ -163,9 +170,10 @@ def run_simulation():
     with Program(lst, bigendian=False) as prog:
         simulator = run_tst(None, prog,
                             initial_regs,
-                            initial_sprs=None, svstate=0, mmu=False,
+                            initial_sprs=initial_sprs,
+                            svstate=0, mmu=False,
                             initial_cr=0, mem=None,
-                            initial_fprs=None)
+                            initial_fprs=initial_fprs)
         print ("GPRs")
         simulator.gpr.dump()
         print ("FPRs")
index cff373893d2ae9f8acd7a4e2d2b696c147dad802..80870f57cb19e36f0c7553171f2eb63d3b7098d2 100644 (file)
@@ -6,7 +6,7 @@ AFLAGS=-mpwr9
 all: sim
 
 sim: kernel.bin
-       pypowersim -i kernel.bin
+       pypowersim -g gpr.list -i kernel.bin
 
 clean:
        rm *.o *.elf *.bin
diff --git a/src/test/basic_pypowersim/gpr.list b/src/test/basic_pypowersim/gpr.list
new file mode 100644 (file)
index 0000000..8b29e3b
--- /dev/null
@@ -0,0 +1,3 @@
+8: 0x5005
+12: 0b1010
+15: 5