ARM: BX instruction can be contitional if last instruction in a IT block
authorGene Wu <Gene.Wu@arm.com>
Mon, 23 Aug 2010 16:18:41 +0000 (11:18 -0500)
committerGene Wu <Gene.Wu@arm.com>
Mon, 23 Aug 2010 16:18:41 +0000 (11:18 -0500)
Branches are allowed to be the last instuction in an IT block. Before it was
assumed that they could not. So Branches in thumb2 were Uncond.

src/arch/arm/isa/formats/branch.isa
src/arch/arm/isa/formats/data.isa
src/arch/arm/isa/formats/uncond.isa
src/arch/arm/isa/insts/branch.isa

index e476652661eeefb6c47ae4989d8ee673a8699f36..f203d52570e088327fce5da0a412581d29cea15c 100644 (file)
@@ -50,7 +50,7 @@ def format ArmBBlxImm() {{
         if (machInst.condCode == 0xF) {
             int32_t imm = (sext<26>(bits(machInst, 23, 0) << 2)) |
                           (bits(machInst, 24) << 1);
-            return new BlxImm(machInst, imm);
+            return new BlxImm(machInst, imm, COND_UC);
         } else {
             return new B(machInst, sext<26>(bits(machInst, 23, 0) << 2),
                          (ConditionCode)(uint32_t)machInst.condCode);
@@ -63,7 +63,7 @@ def format ArmBlBlxImm() {{
         if (machInst.condCode == 0xF) {
             int32_t imm = (sext<26>(bits(machInst, 23, 0) << 2)) |
                           (bits(machInst, 24) << 1);
-            return new BlxImm(machInst, imm);
+            return new BlxImm(machInst, imm, COND_UC);
         } else {
             return new Bl(machInst, sext<26>(bits(machInst, 23, 0) << 2),
                           (ConditionCode)(uint32_t)machInst.condCode);
@@ -236,6 +236,13 @@ def format Thumb32BranchesAndMiscCtrl() {{
             }
           case 0x1:
             {
+                ConditionCode condCode;
+                if(machInst.itstateMask) {
+                  condCode = (ConditionCode)(uint8_t)machInst.itstateCond;
+                } else {
+                  condCode = COND_UC;
+                }
+
                 const uint32_t s = bits(machInst, 26);
                 const uint32_t i1 = !(bits(machInst, 13) ^ s);
                 const uint32_t i2 = !(bits(machInst, 11) ^ s);
@@ -244,13 +251,19 @@ def format Thumb32BranchesAndMiscCtrl() {{
                 const int32_t imm = sext<25>((s << 24) |
                                              (i1 << 23) | (i2 << 22) |
                                              (imm10 << 12) | (imm11 << 1));
-                return new B(machInst, imm, COND_UC);
+                return new B(machInst, imm, condCode);
             }
           case 0x4:
             {
                 if (bits(machInst, 0) == 1) {
                     return new Unknown(machInst);
                 }
+                ConditionCode condCode;
+                if(machInst.itstateMask) {
+                  condCode = (ConditionCode)(uint8_t)machInst.itstateCond;
+                } else {
+                  condCode = COND_UC;
+                }
                 const uint32_t s = bits(machInst, 26);
                 const uint32_t i1 = !(bits(machInst, 13) ^ s);
                 const uint32_t i2 = !(bits(machInst, 11) ^ s);
@@ -259,10 +272,16 @@ def format Thumb32BranchesAndMiscCtrl() {{
                 const int32_t imm = sext<25>((s << 24) |
                                              (i1 << 23) | (i2 << 22) |
                                              (imm10h << 12) | (imm10l << 2));
-                return new BlxImm(machInst, imm);
+                return new BlxImm(machInst, imm, condCode);
             }
           case 0x5:
             {
+                ConditionCode condCode;
+                if(machInst.itstateMask) {
+                  condCode = (ConditionCode)(uint8_t)machInst.itstateCond;
+                } else {
+                  condCode = COND_UC;
+                }
                 const uint32_t s = bits(machInst, 26);
                 const uint32_t i1 = !(bits(machInst, 13) ^ s);
                 const uint32_t i2 = !(bits(machInst, 11) ^ s);
@@ -271,7 +290,7 @@ def format Thumb32BranchesAndMiscCtrl() {{
                 const int32_t imm = sext<25>((s << 24) |
                                              (i1 << 23) | (i2 << 22) |
                                              (imm10 << 12) | (imm11 << 1));
-                return new Bl(machInst, imm, COND_UC);
+                return new Bl(machInst, imm, condCode);
             }
           default:
             break;
index a2e748bcb32d49d280685993538bdc352f66b792..03a585001b84637dc039efd91ba5f12bccc9a9d9 100644 (file)
@@ -1040,13 +1040,25 @@ def format Thumb16SpecDataAndBx() {{
             return new MovReg(machInst, rdn, INTREG_ZERO, rm, 0, LSL);
           case 0x3:
             if (bits(machInst, 7) == 0) {
+                ConditionCode condCode;
+                if(machInst.itstateMask) {
+                  condCode = (ConditionCode)(uint8_t)machInst.itstateCond;
+                } else {
+                  condCode = COND_UC;
+                }
                 return new BxReg(machInst,
                                  (IntRegIndex)(uint32_t)bits(machInst, 6, 3),
-                                 COND_UC);
+                                 condCode);
             } else {
+                ConditionCode condCode;
+                if(machInst.itstateMask) {
+                  condCode = (ConditionCode)(uint8_t)machInst.itstateCond;
+                } else {
+                  condCode = COND_UC;
+                }
                 return new BlxReg(machInst,
                                   (IntRegIndex)(uint32_t)bits(machInst, 6, 3),
-                                  COND_UC);
+                                  condCode);
             }
         }
     }
index 4fa707b2bee3bc83ae4016cce9f9d12cabb5d960..079b472f3c29310581edb7514c50dba0e98d6b09 100644 (file)
@@ -231,7 +231,7 @@ def format ArmUnconditional() {{
                     const uint32_t imm =
                         (sext<26>(bits(machInst, 23, 0) << 2)) |
                         (bits(machInst, 24) << 1);
-                    return new BlxImm(machInst, imm);
+                    return new BlxImm(machInst, imm, COND_UC);
                 }
               case 0x2:
                 if (bits(op1, 4, 0) != 0) {
index 089a2e7d9c90226130d90c0672c1182649d723d7..98e751e1a8163f251f2adcae333f46a9ca37a2a0 100644 (file)
@@ -87,9 +87,9 @@ let {{
             # 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))'
-            base = "BranchImm"
-            declare = BranchImmDeclare
-            constructor = BranchImmConstructor
+            base = "BranchImmCond"
+            declare = BranchImmCondDeclare
+            constructor = BranchImmCondConstructor
         else:
             Name += "Reg"
             newPC = 'Op1'