ARM: Clean up use of TBit and JBit.
authorAli Saidi <Ali.Saidi@ARM.com>
Fri, 1 Oct 2010 21:02:45 +0000 (16:02 -0500)
committerAli Saidi <Ali.Saidi@ARM.com>
Fri, 1 Oct 2010 21:02:45 +0000 (16:02 -0500)
Rather tha constantly using ULL(1) << PcXBitShift define those directly.
Additionally, add some helper functions to further clean up the code.

src/arch/arm/faults.cc
src/arch/arm/insts/static_inst.hh
src/arch/arm/isa.cc
src/arch/arm/isa/insts/branch.isa
src/arch/arm/isa/insts/misc.isa
src/arch/arm/isa_traits.hh
src/arch/arm/predecoder.cc
src/arch/arm/process.cc
src/arch/arm/utility.hh

index a5ecdad256ed1c4abd16aaecf0e8fcad9857e0fe..6e138119c0cf62789f99a26a41a1c5424a429a3b 100644 (file)
@@ -140,7 +140,7 @@ ArmFault::invoke(ThreadContext *tc, StaticInstPtr inst)
     }
 
     Addr pc M5_VAR_USED = tc->readPC();
-    Addr newPc = getVector(tc) | (sctlr.te ? (ULL(1) << PcTBitShift) : 0);
+    Addr newPc = getVector(tc) | (sctlr.te ? PcTBit : 0);
     DPRINTF(Faults, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x\n",
             name(), cpsr, pc, tc->readIntReg(INTREG_LR), newPc);
     tc->setPC(newPc);
index 7ea3405af50c02f9248b8d10ae7c2d4caa5427d6..ad89a1a79bd158ac392d8c646a50ac73c9a9cc3a 100644 (file)
@@ -43,6 +43,7 @@
 #define __ARCH_ARM_INSTS_STATICINST_HH__
 
 #include "arch/arm/faults.hh"
+#include "arch/arm/utility.hh"
 #include "base/trace.hh"
 #include "cpu/static_inst.hh"
 
@@ -219,8 +220,7 @@ class ArmStaticInst : public StaticInst
     readPC(XC *xc)
     {
         Addr pc = xc->readPC();
-        Addr tBit = pc & (ULL(1) << PcTBitShift);
-        if (tBit)
+        if (isThumb(pc))
             return pc + 4;
         else
             return pc + 8;
@@ -232,7 +232,7 @@ class ArmStaticInst : public StaticInst
     setNextPC(XC *xc, Addr val)
     {
         Addr npc = xc->readNextPC();
-        if (npc & (ULL(1) << PcTBitShift)) {
+        if (isThumb(npc)) {
             val &= ~mask(1);
         } else {
             val &= ~mask(2);
@@ -280,8 +280,8 @@ class ArmStaticInst : public StaticInst
     setIWNextPC(XC *xc, Addr val)
     {
         Addr stateBits = xc->readPC() & PcModeMask;
-        Addr jBit = (ULL(1) << PcJBitShift);
-        Addr tBit = (ULL(1) << PcTBitShift);
+        Addr jBit = PcJBit;
+        Addr tBit = PcTBit;
         bool thumbEE = (stateBits == (tBit | jBit));
 
         Addr newPc = (val & ~PcModeMask);
@@ -312,8 +312,8 @@ class ArmStaticInst : public StaticInst
     setAIWNextPC(XC *xc, Addr val)
     {
         Addr stateBits = xc->readPC() & PcModeMask;
-        Addr jBit = (ULL(1) << PcJBitShift);
-        Addr tBit = (ULL(1) << PcTBitShift);
+        Addr jBit = PcJBit;
+        Addr tBit = PcTBit;
         if (!jBit && !tBit) {
             setIWNextPC(xc, val);
         } else {
index 22447184ed6f57aafdd09ce9417afe95c4e25f74..d557cecbbede9ef9f8f6f7883fdcd07093dbdada 100644 (file)
@@ -173,7 +173,7 @@ ISA::readMiscReg(int misc_reg, ThreadContext *tc)
             cpsr.j = 1;
         else
             cpsr.j = 0;
-        if (pc & (ULL(1) << PcTBitShift))
+        if (isThumb(pc))
             cpsr.t = 1;
         else
             cpsr.t = 0;
@@ -241,9 +241,9 @@ ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
                 miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
         Addr npc = tc->readNextPC() & ~PcModeMask;
         if (cpsr.j)
-            npc = npc | (ULL(1) << PcJBitShift);
+            npc = npc | PcJBit;
         if (cpsr.t)
-            npc = npc | (ULL(1) << PcTBitShift);
+            npc = npc | PcTBit;
 
         tc->setNextPC(npc);
     } else if (misc_reg >= MISCREG_CP15_UNIMP_START &&
index 98e751e1a8163f251f2adcae333f46a9ca37a2a0..e9ddd77b79672c6b3eeb7781fdd2694ce7ff7bd5 100644 (file)
@@ -51,8 +51,7 @@ let {{
         '''
         if (link):
             bCode += '''
-                Addr tBit = curPc & (ULL(1) << PcTBitShift);
-                if (!tBit)
+                if (!isThumb(curPc))
                     LR = curPc - 4;
                 else
                     LR = curPc | 1;
@@ -67,10 +66,7 @@ let {{
 
     # BX, BLX
     blxCode = '''
-    Addr curPc = readPC(xc);
-    Addr tBit = curPc & (ULL(1) << PcTBitShift);
-    bool arm = !tBit;
-    arm = arm; // In case it's not used otherwise.
+    Addr curPc M5_VAR_USED = readPC(xc);
     %(link)s
     // Switch modes
     %(branch)s
@@ -86,7 +82,7 @@ let {{
             Name += "Imm"
             # Since we're switching ISAs, the target ISA will be the opposite
             # of the current ISA. !arm is whether the target is ARM.
-            newPC = '(!arm ? (roundDown(curPc, 4) + imm) : (curPc + imm))'
+            newPC = '(isThumb(curPc) ? (roundDown(curPc, 4) + imm) : (curPc + imm))'
             base = "BranchImmCond"
             declare = BranchImmCondDeclare
             constructor = BranchImmCondConstructor
@@ -101,14 +97,14 @@ let {{
                 // The immediate version of the blx thumb instruction
                 // is 32 bits wide, but "next pc" doesn't reflect that
                 // so we don't want to substract 2 from it at this point
-                if (arm)
+                if (!isThumb(curPc))
                     LR = curPc - 4;
                 else
                     LR = curPc  | 1;
             '''
         elif link:
             linkStr = '''
-                if (arm)
+                if (!isThumb(curPc))
                     LR = curPc - 4;
                 else
                     LR = (curPc - 2) | 1;
@@ -119,7 +115,7 @@ let {{
         if imm and link: #blx with imm
             branchStr = '''
                 Addr tempPc = ((%(newPC)s) & mask(32)) | (curPc & ~mask(32));
-                FNPC = tempPc ^ (ULL(1) << PcTBitShift);
+                FNPC = tempPc ^ PcTBit;
             '''
         else:
             branchStr = "IWNPC = %(newPC)s;"
index 089b7bc86397d8888ec3cfc63f4d7a22ebec8282..f2a80a111c3d738f99194319f83c2241fd73734b 100644 (file)
@@ -638,7 +638,7 @@ let {{
     exec_output += PredOpExecute.subst(mcr15UserIop)
 
     enterxCode = '''
-        FNPC = NPC | (1ULL << PcJBitShift) | (1ULL << PcTBitShift);
+        FNPC = NPC | PcJBit | PcTBit;
     '''
     enterxIop = InstObjParams("enterx", "Enterx", "PredOp",
                               { "code": enterxCode,
@@ -648,7 +648,7 @@ let {{
     exec_output += PredOpExecute.subst(enterxIop)
 
     leavexCode = '''
-        FNPC = (NPC & ~(1ULL << PcJBitShift)) | (1ULL << PcTBitShift);
+        FNPC = (NPC & ~PcJBit) | PcTBit;
     '''
     leavexIop = InstObjParams("leavex", "Leavex", "PredOp",
                               { "code": leavexCode,
index aae7566fefd50ca3d741d8262f350bd27e86d27c..8d3f0ffe3e7193854ec34b0194a7239ab2d005f2 100644 (file)
@@ -127,7 +127,9 @@ namespace ArmISA
     // These otherwise unused bits of the PC are used to select a mode
     // like the J and T bits of the CPSR.
     static const Addr PcJBitShift = 33;
+    static const Addr PcJBit = ULL(1) << PcJBitShift;
     static const Addr PcTBitShift = 34;
+    static const Addr PcTBit = ULL(1) << PcTBitShift;
     static const Addr PcModeMask = (ULL(1) << PcJBitShift) |
                                    (ULL(1) << PcTBitShift);
 };
index 20c7058b0d5bd4aeb81255c2172f311a3557c00c..04cec59b91fe0f933167293df971ab3819cd048b 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "arch/arm/isa_traits.hh"
 #include "arch/arm/predecoder.hh"
+#include "arch/arm/utility.hh"
 #include "base/trace.hh"
 #include "cpu/thread_context.hh"
 
@@ -151,7 +152,7 @@ Predecoder::moreBytes(Addr pc, Addr fetchPC, MachInst inst)
 {
     data = inst;
     offset = (fetchPC >= pc) ? 0 : pc - fetchPC;
-    emi.thumb = (pc & (ULL(1) << PcTBitShift)) ? 1 : 0;
+    emi.thumb = isThumb(pc);
     FPSCR fpscr = tc->readMiscReg(MISCREG_FPSCR);
     emi.fpscrLen = fpscr.len;
     emi.fpscrStride = fpscr.stride;
index 636dd5310c8055c479b3883ec7bbf852092e40ef..bc2aee4c89ad4bbd740e8f45b18ec71b87f47153 100644 (file)
@@ -362,7 +362,7 @@ ArmLiveProcess::argsInit(int intSize, int pageSize)
 
     Addr prog_entry = objFile->entryPoint();
     if (arch == ObjectFile::Thumb)
-        prog_entry = (prog_entry & ~mask(1)) | (ULL(1) << PcTBitShift);
+        prog_entry = (prog_entry & ~mask(1)) | PcTBit;
     tc->setPC(prog_entry);
     tc->setNextPC(prog_entry + sizeof(MachInst));
 
index 7d9365ab6e42f2bcf303f479f282e7f275a8a274..8c2ccd4f66115bcc033e243f5c4de9ed82d07a38 100644 (file)
@@ -45,6 +45,7 @@
 #ifndef __ARCH_ARM_UTILITY_HH__
 #define __ARCH_ARM_UTILITY_HH__
 
+#include "arch/arm/isa_traits.hh"
 #include "arch/arm/miscregs.hh"
 #include "arch/arm/types.hh"
 #include "base/misc.hh"
@@ -92,6 +93,12 @@ namespace ArmISA {
         tc->activate(0);
     }
 
+    static inline bool
+    isThumb(Addr pc)
+    {
+        return (pc & PcTBit);
+    }
+
     static inline void
     copyRegs(ThreadContext *src, ThreadContext *dest)
     {