pred.isa revision 6270
1// -*- mode:c++ -*- 2 3// Copyright (c) 2007-2008 The Florida State University 4// All rights reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are 8// met: redistributions of source code must retain the above copyright 9// notice, this list of conditions and the following disclaimer; 10// redistributions in binary form must reproduce the above copyright 11// notice, this list of conditions and the following disclaimer in the 12// documentation and/or other materials provided with the distribution; 13// neither the name of the copyright holders nor the names of its 14// contributors may be used to endorse or promote products derived from 15// this software without specific prior written permission. 16// 17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28// 29// Authors: Stephen Hines 30 31//////////////////////////////////////////////////////////////////// 32// 33// Predicated Instruction Execution 34// 35 36let {{ 37 predicateTest = 'testPredicate(Cpsr, condCode)' 38}}; 39 40def template PredOpExecute {{ 41 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const 42 { 43 Fault fault = NoFault; 44 %(op_decl)s; 45 %(op_rd)s; 46 47 if (%(predicate_test)s) 48 { 49 %(code)s; 50 if (fault == NoFault) 51 { 52 %(op_wb)s; 53 } 54 } 55 56 return fault; 57 } 58}}; 59 60def template DataDecode {{ 61 if (machInst.opcode4 == 0) { 62 if (machInst.sField == 0) 63 return new %(class_name)sImm(machInst); 64 else 65 return new %(class_name)sImmCc(machInst); 66 } else { 67 if (machInst.sField == 0) 68 return new %(class_name)s(machInst); 69 else 70 return new %(class_name)sCc(machInst); 71 } 72}}; 73 74def template DataImmDecode {{ 75 if (machInst.sField == 0) 76 return new %(class_name)s(machInst); 77 else 78 return new %(class_name)sCc(machInst); 79}}; 80 81let {{ 82 83 calcCcCode = ''' 84 uint16_t _ic, _iv, _iz, _in; 85 86 _in = (resTemp >> 31) & 1; 87 _iz = (resTemp == 0); 88 _iv = %(ivValue)s & 1; 89 _ic = %(icValue)s & 1; 90 91 Cpsr = _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 | 92 (Cpsr & 0x0FFFFFFF); 93 94 DPRINTF(Arm, "in = %%d\\n", _in); 95 DPRINTF(Arm, "iz = %%d\\n", _iz); 96 DPRINTF(Arm, "ic = %%d\\n", _ic); 97 DPRINTF(Arm, "iv = %%d\\n", _iv); 98 ''' 99 100}}; 101 102def format DataOp(code, icValue, ivValue) {{ 103 code += "resTemp = resTemp;" 104 regCode = re.sub(r'op2', 'shift_rm_rs(Rm, Rs, \ 105 shift, Cpsr<29:0>)', code) 106 immCode = re.sub(r'op2', 'shift_rm_imm(Rm, shift_size, \ 107 shift, Cpsr<29:0>)', code) 108 regIop = InstObjParams(name, Name, 'PredIntOp', 109 {"code": regCode, 110 "predicate_test": predicateTest}) 111 immIop = InstObjParams(name, Name + "Imm", 'PredIntOp', 112 {"code": immCode, 113 "predicate_test": predicateTest}) 114 regCcIop = InstObjParams(name, Name + "Cc", 'PredIntOp', 115 {"code": regCode + calcCcCode % vars(), 116 "predicate_test": predicateTest}) 117 immCcIop = InstObjParams(name, Name + "ImmCc", 'PredIntOp', 118 {"code": immCode + calcCcCode % vars(), 119 "predicate_test": predicateTest}) 120 header_output = BasicDeclare.subst(regIop) + \ 121 BasicDeclare.subst(immIop) + \ 122 BasicDeclare.subst(regCcIop) + \ 123 BasicDeclare.subst(immCcIop) 124 decoder_output = BasicConstructor.subst(regIop) + \ 125 BasicConstructor.subst(immIop) + \ 126 BasicConstructor.subst(regCcIop) + \ 127 BasicConstructor.subst(immCcIop) 128 exec_output = PredOpExecute.subst(regIop) + \ 129 PredOpExecute.subst(immIop) + \ 130 PredOpExecute.subst(regCcIop) + \ 131 PredOpExecute.subst(immCcIop) 132 decode_block = DataDecode.subst(regIop) 133}}; 134 135def format DataImmOp(code, icValue, ivValue) {{ 136 code += "resTemp = resTemp;" 137 iop = InstObjParams(name, Name, 'PredImmOp', 138 {"code": code, 139 "predicate_test": predicateTest}) 140 ccIop = InstObjParams(name, Name + "Cc", 'PredImmOp', 141 {"code": code + calcCcCode % vars(), 142 "predicate_test": predicateTest}) 143 header_output = BasicDeclare.subst(iop) + \ 144 BasicDeclare.subst(ccIop) 145 decoder_output = BasicConstructor.subst(iop) + \ 146 BasicConstructor.subst(ccIop) 147 exec_output = PredOpExecute.subst(iop) + \ 148 PredOpExecute.subst(ccIop) 149 decode_block = DataImmDecode.subst(iop) 150}}; 151 152def format PredOp(code, *opt_flags) {{ 153 iop = InstObjParams(name, Name, 'PredOp', 154 {"code": code, 155 "predicate_test": predicateTest}, 156 opt_flags) 157 header_output = BasicDeclare.subst(iop) 158 decoder_output = BasicConstructor.subst(iop) 159 decode_block = BasicDecode.subst(iop) 160 exec_output = PredOpExecute.subst(iop) 161}}; 162 163def format PredImmOp(code, *opt_flags) {{ 164 iop = InstObjParams(name, Name, 'PredImmOp', 165 {"code": code, 166 "predicate_test": predicateTest}, 167 opt_flags) 168 header_output = BasicDeclare.subst(iop) 169 decoder_output = BasicConstructor.subst(iop) 170 decode_block = BasicDecode.subst(iop) 171 exec_output = PredOpExecute.subst(iop) 172}}; 173 174def format PredImmOpCc(code, icValue, ivValue, *opt_flags) {{ 175 ccCode = calcCcCode % vars() 176 code += ccCode; 177 iop = InstObjParams(name, Name, 'PredImmOp', 178 {"code": code, 179 "cc_code": ccCode, 180 "predicate_test": predicateTest}, 181 opt_flags) 182 header_output = BasicDeclare.subst(iop) 183 decoder_output = BasicConstructor.subst(iop) 184 decode_block = BasicDecode.subst(iop) 185 exec_output = PredOpExecute.subst(iop) 186}}; 187 188def format PredIntOp(code, *opt_flags) {{ 189 new_code = ArmGenericCodeSubs(code) 190 iop = InstObjParams(name, Name, 'PredIntOp', 191 {"code": new_code, 192 "predicate_test": predicateTest}, 193 opt_flags) 194 header_output = BasicDeclare.subst(iop) 195 decoder_output = BasicConstructor.subst(iop) 196 decode_block = BasicDecode.subst(iop) 197 exec_output = PredOpExecute.subst(iop) 198}}; 199 200def format PredIntOpCc(code, icValue, ivValue, *opt_flags) {{ 201 ccCode = calcCcCode % vars() 202 code += ccCode; 203 new_code = ArmGenericCodeSubs(code) 204 iop = InstObjParams(name, Name, 'PredIntOp', 205 {"code": new_code, 206 "cc_code": ccCode, 207 "predicate_test": predicateTest}, 208 opt_flags) 209 header_output = BasicDeclare.subst(iop) 210 decoder_output = BasicConstructor.subst(iop) 211 decode_block = BasicDecode.subst(iop) 212 exec_output = PredOpExecute.subst(iop) 213}}; 214 215