arch-power: Added support for Trap instructons
authorKajol Jain <kajoljain797@gmail.com>
Wed, 12 Jun 2019 08:41:04 +0000 (14:11 +0530)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 24 Jan 2021 04:00:56 +0000 (04:00 +0000)
* 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 48f149fb9cf3650bfb909f58fe08a89b6ed70457..24844239cb3362e05cc0901e4067fe0850066cd8 100644 (file)
@@ -33,6 +33,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
 
@@ -203,6 +204,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 a92fd1ce3295e4daf7c1d1c7a9e1f154a72fa044..c3dc787ea90087a61a32a0a3b320cd9eb8dbb90f 100644 (file)
@@ -98,3 +98,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 0edb089c5553d22b3327ba8271c2c931b5c91f6a..d00250085e0b2fbbe77cb6ad72d59352f7cbeaca 100644 (file)
@@ -173,7 +173,6 @@ decode PO default Unknown::unknown() {
             }
             }},
               [ IsSyscall, IsNonSpeculative, IsSerializeAfter ]);
-        2: tdi({{ }});
     }
 
     format LoadDispOp {
@@ -280,6 +279,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) {
@@ -404,7 +435,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) {