1// Copyright (c) 2006-2007 The Regents of The University of Michigan 2// All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions are 6// met: redistributions of source code must retain the above copyright 7// notice, this list of conditions and the following disclaimer; 8// redistributions in binary form must reproduce the above copyright --- 169 unchanged lines hidden (view full) --- 178 else 179 ccprintf(response, ">"); 180 } 181 182 return response.str(); 183 } 184}}; 185 |
186def template JumpExecute {{ |
187 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 188 Trace::InstRecord *traceData) const 189 { 190 //Attempt to execute the instruction 191 Fault fault = NoFault; 192 193 %(op_decl)s; 194 %(op_rd)s; --- 6 unchanged lines hidden (view full) --- 201 //Write the resulting state to the execution context 202 %(op_wb)s; 203 } 204 205 return fault; 206 } 207}}; 208 |
209def template BranchExecute {{ 210 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 211 Trace::InstRecord *traceData) const |
212 { |
213 //Attempt to execute the instruction 214 Fault fault = NoFault; 215 216 %(op_decl)s; 217 %(op_rd)s; 218 219 if (%(cond)s) { 220 %(code)s; 221 } else { 222 %(fail)s; 223 } 224 225 if(fault == NoFault) 226 { 227 //Write the resulting state to the execution context 228 %(op_wb)s; 229 } 230 231 return fault; |
232 } |
233}}; 234 |
235def template BranchDecode {{ 236 if (A) 237 return new %(class_name)sAnnul("%(mnemonic)s,a", machInst); 238 else 239 return new %(class_name)s("%(mnemonic)s", machInst); 240}}; 241 |
242// Primary format for branch instructions: 243def format Branch(code, *opt_flags) {{ |
244 (usesImm, code, immCode, 245 rString, iString) = splitOutImm(code) 246 iop = InstObjParams(name, Name, 'Branch', code, opt_flags) 247 header_output = BasicDeclare.subst(iop) 248 decoder_output = BasicConstructor.subst(iop) 249 exec_output = JumpExecute.subst(iop) 250 if usesImm: 251 imm_iop = InstObjParams(name, Name + 'Imm', 'BranchImm' + iString, 252 immCode, opt_flags) 253 header_output += BasicDeclare.subst(imm_iop) 254 decoder_output += BasicConstructor.subst(imm_iop) 255 exec_output += JumpExecute.subst(imm_iop) 256 decode_block = ROrImmDecode.subst(iop) 257 else: 258 decode_block = BasicDecode.subst(iop) 259}}; 260 261let {{ 262 def doBranch(name, Name, base, cond, 263 code, annul_code, fail, annul_fail, opt_flags): 264 iop = InstObjParams(name, Name, base, 265 {"code": code, 266 "fail": fail, 267 "cond": cond 268 }, 269 opt_flags) 270 header_output = BasicDeclareWithMnemonic.subst(iop) 271 decoder_output = BasicConstructorWithMnemonic.subst(iop) |
272 exec_output = BranchExecute.subst(iop) |
273 if annul_code == "None": 274 decode_block = BasicDecodeWithMnemonic.subst(iop) |
275 else: |
276 decode_block = BranchDecode.subst(iop) 277 278 if annul_code != "None": 279 iop = InstObjParams(name + ',a', Name + 'Annul', base, 280 {"code": annul_code, 281 "fail": annul_fail, 282 "cond": cond 283 }, 284 opt_flags) 285 header_output += BasicDeclareWithMnemonic.subst(iop) 286 decoder_output += BasicConstructorWithMnemonic.subst(iop) 287 exec_output += BranchExecute.subst(iop) 288 return (header_output, decoder_output, exec_output, decode_block) 289 290 def doCondBranch(name, Name, base, cond, code, opt_flags): 291 return doBranch(name, Name, base, cond, code, code, 292 'NPC = NPC; NNPC = NNPC;', 293 'NNPC = NPC + 8; NPC = NPC + 4', 294 opt_flags) 295 296 def doUncondBranch(name, Name, base, code, annul_code, opt_flags): 297 return doBranch(name, Name, base, "true", code, annul_code, 298 ";", ";", opt_flags) 299 300 default_branch_code = "NNPC = xc->readPC() + disp;" |
301}}; 302 |
303// Format for branch instructions with n bit displacements: 304def format BranchN(bits, code=default_branch_code, 305 test=None, annul_code=None, *opt_flags) {{ 306 if code == "default_branch_code": 307 code = default_branch_code 308 if test != "None": 309 (header_output, 310 decoder_output, 311 exec_output, 312 decode_block) = doCondBranch(name, Name, 313 "BranchNBits<%d>" % bits, test, code, opt_flags) 314 else: 315 (header_output, 316 decoder_output, 317 exec_output, 318 decode_block) = doUncondBranch(name, Name, 319 "BranchNBits<%d>" % bits, code, annul_code, opt_flags) |
320}}; 321 |
322// Format for branch instructions with split displacements: 323def format BranchSplit(code=default_branch_code, 324 test=None, annul_code=None, *opt_flags) {{ 325 if code == "default_branch_code": 326 code = default_branch_code 327 if test != "None": 328 (header_output, 329 decoder_output, 330 exec_output, 331 decode_block) = doCondBranch(name, Name, 332 "BranchSplit", test, code, opt_flags) 333 else: 334 (header_output, 335 decoder_output, 336 exec_output, 337 decode_block) = doUncondBranch(name, Name, 338 "BranchSplit", code, annul_code, opt_flags) |
339}}; 340 |