branch.isa (7797:998b217dcae7) branch.isa (8146:18368caa8489)
1// -*- mode:c++ -*-
2
3// Copyright (c) 2010 ARM Limited
4// All rights reserved
5//
6// The license below extends only to copyright in the software and shall
7// not be construed as granting a license to any other intellectual
8// property including but not limited to intellectual property relating

--- 34 unchanged lines hidden (view full) ---

43 decoder_output = ""
44 exec_output = ""
45
46 # B, BL
47 for (mnem, link) in (("b", False), ("bl", True)):
48 bCode = '''
49 NPC = (uint32_t)(PC + imm);
50 '''
1// -*- mode:c++ -*-
2
3// Copyright (c) 2010 ARM Limited
4// All rights reserved
5//
6// The license below extends only to copyright in the software and shall
7// not be construed as granting a license to any other intellectual
8// property including but not limited to intellectual property relating

--- 34 unchanged lines hidden (view full) ---

43 decoder_output = ""
44 exec_output = ""
45
46 # B, BL
47 for (mnem, link) in (("b", False), ("bl", True)):
48 bCode = '''
49 NPC = (uint32_t)(PC + imm);
50 '''
51 br_tgt_code = '''pcs.instNPC(branchPC.instPC() + imm);'''
52 instFlags = ["IsDirectControl"]
51 if (link):
52 bCode += '''
53 if (Thumb)
54 LR = PC | 1;
55 else
56 LR = PC - 4;
57 '''
53 if (link):
54 bCode += '''
55 if (Thumb)
56 LR = PC | 1;
57 else
58 LR = PC - 4;
59 '''
60 instFlags += ["IsCall"]
58
61
62
59 bIop = InstObjParams(mnem, mnem.capitalize(), "BranchImmCond",
63 bIop = InstObjParams(mnem, mnem.capitalize(), "BranchImmCond",
60 {"code": bCode,
61 "predicate_test": predicateTest})
64 {"code": bCode, "predicate_test": predicateTest,
65 "brTgtCode" : br_tgt_code}, instFlags)
62 header_output += BranchImmCondDeclare.subst(bIop)
66 header_output += BranchImmCondDeclare.subst(bIop)
63 decoder_output += BranchImmCondConstructor.subst(bIop)
67 decoder_output += BranchImmCondConstructor.subst(bIop) + \
68 BranchTarget.subst(bIop)
64 exec_output += PredOpExecute.subst(bIop)
65
66 # BX, BLX
67 blxCode = '''
68 %(link)s
69 // Switch modes
70 %(branch)s
71 '''

--- 4 unchanged lines hidden (view full) ---

76
77 for (mnem, imm, link) in blxList:
78 Name = mnem.capitalize()
79 if imm:
80 Name += "Imm"
81 # Since we're switching ISAs, the target ISA will be the opposite
82 # of the current ISA. Thumb is whether the target is ARM.
83 newPC = '(Thumb ? (roundDown(PC, 4) + imm) : (PC + imm))'
69 exec_output += PredOpExecute.subst(bIop)
70
71 # BX, BLX
72 blxCode = '''
73 %(link)s
74 // Switch modes
75 %(branch)s
76 '''

--- 4 unchanged lines hidden (view full) ---

81
82 for (mnem, imm, link) in blxList:
83 Name = mnem.capitalize()
84 if imm:
85 Name += "Imm"
86 # Since we're switching ISAs, the target ISA will be the opposite
87 # of the current ISA. Thumb is whether the target is ARM.
88 newPC = '(Thumb ? (roundDown(PC, 4) + imm) : (PC + imm))'
89 br_tgt_code = '''
90 pcs.instNPC((branchPC.thumb() ? (roundDown(branchPC.instPC(),4) + imm) :
91 (branchPC.instPC() + imm)));
92 '''
84 base = "BranchImmCond"
85 declare = BranchImmCondDeclare
86 constructor = BranchImmCondConstructor
93 base = "BranchImmCond"
94 declare = BranchImmCondDeclare
95 constructor = BranchImmCondConstructor
96 instFlags = ["IsDirectControl"]
87 else:
88 Name += "Reg"
89 newPC = 'Op1'
97 else:
98 Name += "Reg"
99 newPC = 'Op1'
100 br_tgt_code = ''
90 base = "BranchRegCond"
91 declare = BranchRegCondDeclare
92 constructor = BranchRegCondConstructor
101 base = "BranchRegCond"
102 declare = BranchRegCondDeclare
103 constructor = BranchRegCondConstructor
104 instFlags = ["IsIndirectControl"]
93 if link and imm:
94 linkStr = '''
95 // The immediate version of the blx thumb instruction
96 // is 32 bits wide, but "next pc" doesn't reflect that
97 // so we don't want to substract 2 from it at this point
98 if (Thumb)
99 LR = PC | 1;
100 else
101 LR = PC - 4;
102 '''
105 if link and imm:
106 linkStr = '''
107 // The immediate version of the blx thumb instruction
108 // is 32 bits wide, but "next pc" doesn't reflect that
109 // so we don't want to substract 2 from it at this point
110 if (Thumb)
111 LR = PC | 1;
112 else
113 LR = PC - 4;
114 '''
115 instFlags += ["IsCall"]
103 elif link:
104 linkStr = '''
105 if (Thumb)
106 LR = (PC - 2) | 1;
107 else
108 LR = PC - 4;
109 '''
116 elif link:
117 linkStr = '''
118 if (Thumb)
119 LR = (PC - 2) | 1;
120 else
121 LR = PC - 4;
122 '''
123 instFlags += ["IsCall"]
110 else:
111 linkStr = ""
124 else:
125 linkStr = ""
126 instFlags += ["IsReturn"]
112
113 if imm and link: #blx with imm
114 branchStr = '''
115 NextThumb = !Thumb;
116 NPC = %(newPC)s;
117 '''
127
128 if imm and link: #blx with imm
129 branchStr = '''
130 NextThumb = !Thumb;
131 NPC = %(newPC)s;
132 '''
133 br_tgt_code = '''pcs.nextThumb(!branchPC.thumb());\n''' + \
134 br_tgt_code
118 else:
119 branchStr = "IWNPC = %(newPC)s;"
120 branchStr = branchStr % { "newPC" : newPC }
121
122 code = blxCode % {"link": linkStr,
123 "newPC": newPC,
124 "branch": branchStr}
125 blxIop = InstObjParams(mnem, Name, base,
135 else:
136 branchStr = "IWNPC = %(newPC)s;"
137 branchStr = branchStr % { "newPC" : newPC }
138
139 code = blxCode % {"link": linkStr,
140 "newPC": newPC,
141 "branch": branchStr}
142 blxIop = InstObjParams(mnem, Name, base,
126 {"code": code,
127 "predicate_test": predicateTest})
143 {"code": code, "brTgtCode" : br_tgt_code,
144 "predicate_test": predicateTest}, instFlags)
128 header_output += declare.subst(blxIop)
129 decoder_output += constructor.subst(blxIop)
130 exec_output += PredOpExecute.subst(blxIop)
145 header_output += declare.subst(blxIop)
146 decoder_output += constructor.subst(blxIop)
147 exec_output += PredOpExecute.subst(blxIop)
148 if imm:
149 decoder_output += BranchTarget.subst(blxIop)
131
132 #Ignore BXJ for now
133
134 #CBNZ, CBZ. These are always unconditional as far as predicates
135 for (mnem, test) in (("cbz", "=="), ("cbnz", "!=")):
136 code = 'NPC = (uint32_t)(PC + imm);\n'
137 predTest = "Op1 %(test)s 0" % {"test": test}
138 iop = InstObjParams(mnem, mnem.capitalize(), "BranchImmReg",
150
151 #Ignore BXJ for now
152
153 #CBNZ, CBZ. These are always unconditional as far as predicates
154 for (mnem, test) in (("cbz", "=="), ("cbnz", "!=")):
155 code = 'NPC = (uint32_t)(PC + imm);\n'
156 predTest = "Op1 %(test)s 0" % {"test": test}
157 iop = InstObjParams(mnem, mnem.capitalize(), "BranchImmReg",
139 {"code": code, "predicate_test": predTest})
158 {"code": code, "predicate_test": predTest},
159 ["IsIndirectControl"])
140 header_output += BranchImmRegDeclare.subst(iop)
141 decoder_output += BranchImmRegConstructor.subst(iop)
142 exec_output += PredOpExecute.subst(iop)
143
144 #TBB, TBH
145 for isTbh in (0, 1):
146 if isTbh:
147 eaCode = '''

--- 11 unchanged lines hidden (view full) ---

159 ArmISA::TLB::MustBeOne;
160 EA = Op1 + Op2
161 '''
162 accCode = 'NPC = PC + 2 * (Mem.ub)'
163 mnem = "tbb"
164 iop = InstObjParams(mnem, mnem.capitalize(), "BranchRegReg",
165 {'ea_code': eaCode,
166 'memacc_code': accCode,
160 header_output += BranchImmRegDeclare.subst(iop)
161 decoder_output += BranchImmRegConstructor.subst(iop)
162 exec_output += PredOpExecute.subst(iop)
163
164 #TBB, TBH
165 for isTbh in (0, 1):
166 if isTbh:
167 eaCode = '''

--- 11 unchanged lines hidden (view full) ---

179 ArmISA::TLB::MustBeOne;
180 EA = Op1 + Op2
181 '''
182 accCode = 'NPC = PC + 2 * (Mem.ub)'
183 mnem = "tbb"
184 iop = InstObjParams(mnem, mnem.capitalize(), "BranchRegReg",
185 {'ea_code': eaCode,
186 'memacc_code': accCode,
167 'predicate_test': predicateTest})
187 'predicate_test': predicateTest},
188 ["IsIndirectControl"])
168 header_output += BranchTableDeclare.subst(iop)
169 decoder_output += BranchRegRegConstructor.subst(iop)
170 exec_output += LoadExecute.subst(iop) + \
171 LoadInitiateAcc.subst(iop) + \
172 LoadCompleteAcc.subst(iop)
173}};
189 header_output += BranchTableDeclare.subst(iop)
190 decoder_output += BranchRegRegConstructor.subst(iop)
191 exec_output += LoadExecute.subst(iop) + \
192 LoadInitiateAcc.subst(iop) + \
193 LoadCompleteAcc.subst(iop)
194}};