Deleted Added
sdiff udiff text old ( 6273:e46f6767b2c0 ) new ( 6276:11dab30a70e8 )
full compact
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 uint64_t resTemp = 0;
45 resTemp = resTemp;
46 %(op_decl)s;
47 %(op_rd)s;
48
49 if (%(predicate_test)s)
50 {
51 %(code)s;
52 if (fault == NoFault)
53 {
54 %(op_wb)s;
55 }
56 }
57
58 return fault;
59 }
60}};
61
62def template DataDecode {{
63 if (machInst.opcode4 == 0) {
64 if (machInst.sField == 0)
65 return new %(class_name)sImm(machInst);
66 else
67 return new %(class_name)sImmCc(machInst);
68 } else {
69 if (machInst.sField == 0)
70 return new %(class_name)s(machInst);
71 else
72 return new %(class_name)sCc(machInst);
73 }
74}};
75
76def template DataImmDecode {{
77 if (machInst.sField == 0)
78 return new %(class_name)s(machInst);
79 else
80 return new %(class_name)sCc(machInst);
81}};
82
83let {{
84
85 calcCcCode = '''
86 uint16_t _ic, _iv, _iz, _in;
87
88 _in = (resTemp >> 31) & 1;
89 _iz = (resTemp == 0);
90 _iv = %(ivValue)s & 1;
91 _ic = %(icValue)s & 1;
92
93 Cpsr = _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 |
94 (Cpsr & 0x0FFFFFFF);
95
96 DPRINTF(Arm, "in = %%d\\n", _in);
97 DPRINTF(Arm, "iz = %%d\\n", _iz);
98 DPRINTF(Arm, "ic = %%d\\n", _ic);
99 DPRINTF(Arm, "iv = %%d\\n", _iv);
100 '''
101
102}};
103
104def format DataOp(code, icValue = {{ }},
105 ivValue = {{ Cpsr<28:> }}) {{
106 regCode = '''uint32_t op2 = shift_rm_rs(Rm, Rs,
107 shift, Cpsr<29:0>);
108 op2 = op2;''' + code
109 immCode = '''uint32_t op2 = shift_rm_imm(Rm, shift_size,
110 shift, Cpsr<29:0>);
111 op2 = op2;''' + code
112 if icValue == " ":
113 icValueReg = 'shift_carry_rs(Rm, Rs, shift, Cpsr<29:>)'
114 icValueImm = 'shift_carry_imm(Rm, shift_size, shift, Cpsr<29:>)'
115 else:
116 icValueReg = icValue
117 icValueImm = icValue
118 regCcCode = calcCcCode % {"icValue" : icValueReg,
119 "ivValue" : ivValue}
120 immCcCode = calcCcCode % {"icValue" : icValueImm,
121 "ivValue" : ivValue}
122 regIop = InstObjParams(name, Name, 'PredIntOp',
123 {"code": regCode,
124 "predicate_test": predicateTest})
125 immIop = InstObjParams(name, Name + "Imm", 'PredIntOp',
126 {"code": immCode,
127 "predicate_test": predicateTest})
128 regCcIop = InstObjParams(name, Name + "Cc", 'PredIntOp',
129 {"code": regCode + regCcCode,
130 "predicate_test": predicateTest})
131 immCcIop = InstObjParams(name, Name + "ImmCc", 'PredIntOp',
132 {"code": immCode + immCcCode,
133 "predicate_test": predicateTest})
134 header_output = BasicDeclare.subst(regIop) + \
135 BasicDeclare.subst(immIop) + \
136 BasicDeclare.subst(regCcIop) + \
137 BasicDeclare.subst(immCcIop)
138 decoder_output = BasicConstructor.subst(regIop) + \
139 BasicConstructor.subst(immIop) + \
140 BasicConstructor.subst(regCcIop) + \
141 BasicConstructor.subst(immCcIop)
142 exec_output = PredOpExecute.subst(regIop) + \
143 PredOpExecute.subst(immIop) + \
144 PredOpExecute.subst(regCcIop) + \
145 PredOpExecute.subst(immCcIop)
146 decode_block = DataDecode.subst(regIop)
147}};
148
149def format DataImmOp(code,
150 icValue = {{ (rotate ? rotated_carry:Cpsr<29:>) }},
151 ivValue = {{ Cpsr<28:> }}) {{
152 code += "resTemp = resTemp;"
153 iop = InstObjParams(name, Name, 'PredImmOp',
154 {"code": code,
155 "predicate_test": predicateTest})
156 ccIop = InstObjParams(name, Name + "Cc", 'PredImmOp',
157 {"code": code + calcCcCode % vars(),
158 "predicate_test": predicateTest})
159 header_output = BasicDeclare.subst(iop) + \
160 BasicDeclare.subst(ccIop)
161 decoder_output = BasicConstructor.subst(iop) + \
162 BasicConstructor.subst(ccIop)
163 exec_output = PredOpExecute.subst(iop) + \
164 PredOpExecute.subst(ccIop)
165 decode_block = DataImmDecode.subst(iop)
166}};
167
168def format PredOp(code, *opt_flags) {{
169 iop = InstObjParams(name, Name, 'PredOp',
170 {"code": code,
171 "predicate_test": predicateTest},
172 opt_flags)
173 header_output = BasicDeclare.subst(iop)
174 decoder_output = BasicConstructor.subst(iop)
175 decode_block = BasicDecode.subst(iop)
176 exec_output = PredOpExecute.subst(iop)
177}};
178
179def format PredImmOp(code, *opt_flags) {{
180 iop = InstObjParams(name, Name, 'PredImmOp',
181 {"code": code,
182 "predicate_test": predicateTest},
183 opt_flags)
184 header_output = BasicDeclare.subst(iop)
185 decoder_output = BasicConstructor.subst(iop)
186 decode_block = BasicDecode.subst(iop)
187 exec_output = PredOpExecute.subst(iop)
188}};
189
190def format PredImmOpCc(code, icValue, ivValue, *opt_flags) {{
191 ccCode = calcCcCode % vars()
192 code += ccCode;
193 iop = InstObjParams(name, Name, 'PredImmOp',
194 {"code": code,
195 "cc_code": ccCode,
196 "predicate_test": predicateTest},
197 opt_flags)
198 header_output = BasicDeclare.subst(iop)
199 decoder_output = BasicConstructor.subst(iop)
200 decode_block = BasicDecode.subst(iop)
201 exec_output = PredOpExecute.subst(iop)
202}};
203
204def format PredIntOp(code, *opt_flags) {{
205 new_code = ArmGenericCodeSubs(code)
206 iop = InstObjParams(name, Name, 'PredIntOp',
207 {"code": new_code,
208 "predicate_test": predicateTest},
209 opt_flags)
210 header_output = BasicDeclare.subst(iop)
211 decoder_output = BasicConstructor.subst(iop)
212 decode_block = BasicDecode.subst(iop)
213 exec_output = PredOpExecute.subst(iop)
214}};
215
216def format PredIntOpCc(code, icValue, ivValue, *opt_flags) {{
217 ccCode = calcCcCode % vars()
218 code += ccCode;
219 new_code = ArmGenericCodeSubs(code)
220 iop = InstObjParams(name, Name, 'PredIntOp',
221 {"code": new_code,
222 "cc_code": ccCode,
223 "predicate_test": predicateTest},
224 opt_flags)
225 header_output = BasicDeclare.subst(iop)
226 decoder_output = BasicConstructor.subst(iop)
227 decode_block = BasicDecode.subst(iop)
228 exec_output = PredOpExecute.subst(iop)
229}};
230