add in privileged instruction decision-making in PowerDecode2
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 14 Jul 2020 12:00:19 +0000 (13:00 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 14 Jul 2020 12:00:19 +0000 (13:00 +0100)
src/soc/decoder/power_decoder2.py

index 89c87383ce5717d333e4982faadcb57e5f277254..e503d2dd2cb213f4bd5804e9f5630cbf36125b74 100644 (file)
@@ -20,6 +20,7 @@ from soc.decoder.power_enums import (MicrOp, CryIn, Function,
                                      LdstLen, In1Sel, In2Sel, In3Sel,
                                      OutSel, SPR, RC)
 from soc.decoder.decode2execute1 import Decode2ToExecute1Type, Data
                                      LdstLen, In1Sel, In2Sel, In3Sel,
                                      OutSel, SPR, RC)
 from soc.decoder.decode2execute1 import Decode2ToExecute1Type, Data
+from soc.consts import MSR
 
 from soc.regfile.regfiles import FastRegs
 
 
 from soc.regfile.regfiles import FastRegs
 
@@ -39,17 +40,18 @@ def instr_is_priv(m, op, insn):
     """determines if the instruction is privileged or not
     """
     comb = m.d.comb
     """determines if the instruction is privileged or not
     """
     comb = m.d.comb
-    Signal = is_priv_insn(reset_less=True)
+    is_priv_insn = Signal(reset_less=True)
     with m.Switch(op):
         with m.Case(MicrOp.OP_ATTN)  : comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_MFMSR) : comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_MTMSRD): comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_MTMSR): comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_RFID)  : comb += is_priv_insn.eq(1)
     with m.Switch(op):
         with m.Case(MicrOp.OP_ATTN)  : comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_MFMSR) : comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_MTMSRD): comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_MTMSR): comb += is_priv_insn.eq(1)
         with m.Case(MicrOp.OP_RFID)  : comb += is_priv_insn.eq(1)
-        with m.Case(MicrOp.OP_TLBIE) : comb += is_priv_insn.eq(1)
-    with m.If(op == OP_MFSPR | op == OP_MTSPR):
-        with m.If(insn[20]): # field XFX.spr[-1] i think
-            comb += is_priv_insn.eq(1)
+        # XXX TODO
+        #with m.Case(MicrOp.OP_TLBIE) : comb += is_priv_insn.eq(1)
+        with m.Case(MicrOp.OP_MFSPR, MicrOp.OP_MTSPR):
+            with m.If(insn[20]): # field XFX.spr[-1] i think
+                comb += is_priv_insn.eq(1)
     return is_priv_insn
 
 
     return is_priv_insn
 
 
@@ -710,12 +712,11 @@ class PowerDecode2(Elaboratable):
             comb += e.read_fast2.data.eq(FastRegs.SRR1) # constant: SRR1
             comb += e.read_fast2.ok.eq(1)
 
             comb += e.read_fast2.data.eq(FastRegs.SRR1) # constant: SRR1
             comb += e.read_fast2.ok.eq(1)
 
-        return m
-
         # TODO: get msr, then can do privileged instruction
         # TODO: get msr, then can do privileged instruction
-        with m.If(instr_is_priv(m, op.internal_op, e.insn) & msr[MSR_PR]):
+        with m.If(instr_is_priv(m, op.internal_op, e.do.insn) & msr[MSR.PR]):
             # privileged instruction trap
             self.trap(m, TT_PRIV, 0x700)
             # privileged instruction trap
             self.trap(m, TT_PRIV, 0x700)
+
         return m
 
     def trap(self, m, traptype, trapaddr):
         return m
 
     def trap(self, m, traptype, trapaddr):