add test case for kaivb to jump to 0x2700
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 26 Jun 2022 11:56:59 +0000 (12:56 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 26 Jun 2022 11:56:59 +0000 (12:56 +0100)
src/openpower/decoder/isa/caller.py
src/openpower/test/trap/trap_cases.py

index 941a89f0bb2eedfc323b3a51c52464bd8cbd03ef..16fbaa1b17500b0a55012a52a3d75c3a680faeee 100644 (file)
@@ -741,15 +741,18 @@ class ISACaller(ISACallerHelper, ISAFPHelpers):
         hence the default arguments.  when calling from inside ISACaller
         it is best to use call_trap()
         """
-        log("TRAP:", hex(trap_addr), hex(self.namespace['MSR'].value))
+        # https://bugs.libre-soc.org/show_bug.cgi?id=859
+        kaivb = self.spr['KAIVB'].value
+        msr = self.namespace['MSR'].value
+        log("TRAP:", hex(trap_addr), hex(msr), "kaivb", hex(kaivb))
         # store CIA(+4?) in SRR0, set NIA to 0x700
         # store MSR in SRR1, set MSR to um errr something, have to check spec
         # store SVSTATE (if enabled) in SVSRR0
         self.spr['SRR0'].value = self.pc.CIA.value
-        self.spr['SRR1'].value = self.namespace['MSR'].value
+        self.spr['SRR1'].value = msr
         if self.is_svp64_mode:
             self.spr['SVSRR0'] = self.namespace['SVSTATE'].value
-        self.trap_nia = SelectableInt(trap_addr, 64)
+        self.trap_nia = SelectableInt(trap_addr | (kaivb&~0x1fff), 64)
         self.spr['SRR1'][trap_bit] = 1  # change *copy* of MSR in SRR1
 
         # set exception bits.  TODO: this should, based on the address
index 41d343489540af84a2e433a205ac245059ee9df1..1501b8ab32af26f888834f998f1695d4ecb69763 100644 (file)
@@ -10,6 +10,7 @@ import random
 class TrapTestCase(TestAccumulatorBase):
 
     def case_1_kaivb(self):
+        # https://bugs.libre-soc.org/show_bug.cgi?id=859
         lst = ["mtspr 850, 1",  # KAIVB
                "mfspr 2, 850",
                ]
@@ -22,6 +23,26 @@ class TrapTestCase(TestAccumulatorBase):
                       initial_regs, initial_sprs,
                                     initial_msr=msr)
 
+    def case_2_kaivb_test(self):
+        # https://bugs.libre-soc.org/show_bug.cgi?id=859
+        # sets KAIVB to 1<<13 then deliberately causes exception.
+        # PC expected to jump to (1<<13)|0x700 *NOT* 0x700 as usual
+        lst = ["mtspr 850, 1",  # KAIVB
+               "tbegin.",       # deliberately use illegal instruction
+               ]
+        initial_regs = [0] * 32
+        initial_regs[1] = 1<<13
+        initial_sprs = {'KAIVB': 0x12345678,
+                        }
+        msr = 0xa000000000000003
+        e = ExpectedState(pc=0x2700)
+        e.intregs[1] = 1<<13
+        e.msr = 0xa000000000000003 # TODO, not actually checked
+        self.add_case(Program(lst, bigendian),
+                      initial_regs, initial_sprs,
+                                    initial_msr=msr,
+                                    expected=e)
+
     def case_0_hrfid(self):
         lst = ["hrfid"]
         initial_regs = [0] * 32