arch-power: Added support for Trap instructons
authorKajol Jain <kajoljain797@gmail.com>
Wed, 12 Jun 2019 08:41:04 +0000 (14:11 +0530)
committerKajol Jain <kajoljain797@gmail.com>
Wed, 12 Jun 2019 08:41:04 +0000 (14:11 +0530)
* Added trap instructons.
* Added trap interrupt handler.
* Raise trap interrupt whenever condition satisfied for corresponding trap instruction.
* Added bit need to set for that type of interrupt.

Change-Id: I46de00558139e0726c056fd71f819d63cb8045df
Signed-off-by: Kajol Jain <kajoljain797@gmail.com>
src/arch/power/faults.hh
src/arch/power/isa/bitfields.isa
src/arch/power/isa/decoder.isa

index cdaf1c8b448dfb6937f9a0216b9b46fdae1ae950..28eac707bbbd740ce4def870e9962f8a4953c4c3 100644 (file)
@@ -36,6 +36,7 @@
 #include "cpu/thread_context.hh"
 #include "sim/faults.hh"
 
+#define SRR1_TRAP_BIT     16
 #define SRR1_PRI_BIT      17
 #define SRR1_ILLEGAL_INSTR_BIT 18
 
@@ -206,6 +207,19 @@ class ProgramIllegalInterrupt : public ProgramInterrupt
     }
 };
 
+class ProgramTrapInterrupt : public ProgramInterrupt
+{
+  public:
+    ProgramTrapInterrupt()
+    {
+    }
+    virtual void invoke(ThreadContext * tc, const StaticInstPtr &inst =
+                       StaticInst::nullStaticInstPtr)
+    {
+      ProgramInterrupt::invoke(tc, inst ,setBitMask(SRR1_TRAP_BIT));
+    }
+};
+
 class ProgramPriInterrupt : public ProgramInterrupt
 {
   public:
index 2f828a674dd259e9c9fefb490c228c78f72713ef..2a1974bfc14ebb9ec1b17c5f6e08b13aac95c1b9 100644 (file)
@@ -100,3 +100,6 @@ def bitfield BHRB          <20:11>;
 
 //L field for mtmsr and SLB move from entry VSID,ESID instructions.
 def bitfield L             <16>;
+
+//TO field for trap instructions
+def bitfield TO           <25:21>;
index 285487d5acd73ab06e45e04bb0459ed6143c111a..59af89cff4096dd328c2f388dd2b2109fc8694c1 100644 (file)
@@ -175,7 +175,6 @@ decode PO default Unknown::unknown() {
             }
             }},
               [ IsSyscall, IsNonSpeculative, IsSerializeAfter ]);
-        2: tdi({{ }});
     }
 
     format LoadDispOp {
@@ -282,6 +281,38 @@ decode PO default Unknown::unknown() {
         }
     }
 
+
+    format IntImmArithOp {
+
+        3: twi({{
+             if(FullSystem) {
+               int32_t val = Ra_sw;
+               if(((TO & 0x10) && (val < simm))                    ||
+                 ((TO & 0x08) && (val > simm))                     ||
+                 ((TO & 0x04) && (val == simm))                    ||
+                 ((TO & 0x02) && ((uint32_t)val < (uint32_t)simm)) ||
+                 ((TO & 0x01) && ((uint32_t)val > (uint32_t)simm))) {
+                  fault= std::make_shared<ProgramTrapInterrupt>();
+               }
+             }
+        }});
+
+        2: tdi({{
+            if(FullSystem) {
+              int64_t val1 = Ra_sd;
+              int64_t val2 = simm;
+              //printf("Val 1 : 0x%016lx val2: 0x%016lx\n", val,val2);
+              if(((TO & 0x10) && (val1 < val2))                    ||
+                ((TO & 0x08) && (val1 > val2))                     ||
+                ((TO & 0x04) && (val1 == val2))                    ||
+                ((TO & 0x02) && ((uint64_t)val1 < (uint64_t)val2)) ||
+                ((TO & 0x01) && ((uint64_t)val1 > (uint64_t)val2))) {
+                fault= std::make_shared<ProgramTrapInterrupt>();
+              }
+            }
+        }});
+      }
+
     format IntImmCompOp {
         11: cmpi({{
             if (length) {
@@ -406,7 +437,37 @@ decode PO default Unknown::unknown() {
         }
 
         format IntArithOp {
-            779: modsw({{
+
+            4: tw({{
+                if(FullSystem) {
+                  int32_t val1 = Ra_sw;
+                  int32_t val2 = Rb_sw;
+                  if(((TO & 0x10) && (val1 < val2))                    ||
+                    ((TO & 0x08) && (val1 > val2))                     ||
+                    ((TO & 0x04) && (val1 == val2))                    ||
+                    ((TO & 0x02) && ((uint32_t)val1 < (uint32_t)val2)) ||
+                    ((TO & 0x01) && ((uint32_t)val1 > (uint32_t)val2))) {
+                    fault= std::make_shared<ProgramTrapInterrupt>();
+                  }
+                }
+
+            }});
+
+            68: td ({{
+                if(FullSystem) {
+                  int64_t val1 = Ra_sd;
+                  int64_t val2 = Rb_sd;
+                  if(((TO & 0x10) && (val1 < val2))                    ||
+                    ((TO & 0x08) && (val1 > val2))                     ||
+                    ((TO & 0x04) && (val1 == val2))                    ||
+                    ((TO & 0x02) && ((uint64_t)val1 < (uint64_t)val2)) ||
+                    ((TO & 0x01) && ((uint64_t)val1 > (uint64_t)val2))) {
+                    fault= std::make_shared<ProgramTrapInterrupt>();
+                  }
+                }
+            }});
+
+                779: modsw({{
                 int64_t src1 = Ra_sw;
                 int64_t src2 = Rb_sw;
                 if ((src1 != INT32_MIN || src2 != -1) && src2 != 0) {