pred.isa revision 6265
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
74let {{
75
76    calcCcCode = '''
77        uint16_t _ic, _iv, _iz, _in;
78
79        _in = (resTemp >> 31) & 1;
80        _iz = (resTemp == 0);
81        _iv = %(ivValue)s & 1;
82        _ic = %(icValue)s & 1;
83
84        Cpsr =  _in << 31 | _iz << 30 | _ic << 29 | _iv << 28 |
85            (Cpsr & 0x0FFFFFFF);
86
87        DPRINTF(Arm, "in = %%d\\n", _in);
88        DPRINTF(Arm, "iz = %%d\\n", _iz);
89        DPRINTF(Arm, "ic = %%d\\n", _ic);
90        DPRINTF(Arm, "iv = %%d\\n", _iv);
91        '''
92
93}};
94
95def format DataOp(code, icValue, ivValue) {{
96    code += "resTemp = resTemp;"
97    regCode = re.sub(r'op2', 'shift_rm_rs(Rm, Rs, \
98                              shift, Cpsr<29:0>)', code)
99    immCode = re.sub(r'op2', 'shift_rm_imm(Rm, shift_size, \
100                              shift, Cpsr<29:0>)', code)
101    regIop = InstObjParams(name, Name, 'PredIntOp',
102                           {"code": regCode,
103                            "predicate_test": predicateTest})
104    immIop = InstObjParams(name, Name + "Imm", 'PredIntOp',
105                           {"code": immCode,
106                            "predicate_test": predicateTest})
107    regCcIop = InstObjParams(name, Name + "Cc", 'PredIntOp',
108                             {"code": regCode + calcCcCode % vars(),
109                              "predicate_test": predicateTest})
110    immCcIop = InstObjParams(name, Name + "ImmCc", 'PredIntOp',
111                             {"code": immCode + calcCcCode % vars(),
112                              "predicate_test": predicateTest})
113    header_output = BasicDeclare.subst(regIop) + \
114                    BasicDeclare.subst(immIop) + \
115                    BasicDeclare.subst(regCcIop) + \
116                    BasicDeclare.subst(immCcIop)
117    decoder_output = BasicConstructor.subst(regIop) + \
118                     BasicConstructor.subst(immIop) + \
119                     BasicConstructor.subst(regCcIop) + \
120                     BasicConstructor.subst(immCcIop)
121    exec_output = PredOpExecute.subst(regIop) + \
122                  PredOpExecute.subst(immIop) + \
123                  PredOpExecute.subst(regCcIop) + \
124                  PredOpExecute.subst(immCcIop)
125    decode_block = DataDecode.subst(regIop)
126}};
127
128def format PredOp(code, *opt_flags) {{
129    iop = InstObjParams(name, Name, 'PredOp',
130                        {"code": code,
131                         "predicate_test": predicateTest},
132                        opt_flags)
133    header_output = BasicDeclare.subst(iop)
134    decoder_output = BasicConstructor.subst(iop)
135    decode_block = BasicDecode.subst(iop)
136    exec_output = PredOpExecute.subst(iop)
137}};
138
139def format PredImmOp(code, *opt_flags) {{
140    iop = InstObjParams(name, Name, 'PredImmOp',
141                        {"code": code,
142                         "predicate_test": predicateTest},
143                        opt_flags)
144    header_output = BasicDeclare.subst(iop)
145    decoder_output = BasicConstructor.subst(iop)
146    decode_block = BasicDecode.subst(iop)
147    exec_output = PredOpExecute.subst(iop)
148}};
149
150def format PredImmOpCc(code, icValue, ivValue, *opt_flags) {{
151    ccCode = calcCcCode % vars()
152    code += ccCode;
153    iop = InstObjParams(name, Name, 'PredImmOp',
154                        {"code": code,
155                         "cc_code": ccCode,
156                         "predicate_test": predicateTest},
157                        opt_flags)
158    header_output = BasicDeclare.subst(iop)
159    decoder_output = BasicConstructor.subst(iop)
160    decode_block = BasicDecode.subst(iop)
161    exec_output = PredOpExecute.subst(iop)
162}};
163
164def format PredIntOp(code, *opt_flags) {{
165    new_code = ArmGenericCodeSubs(code)
166    iop = InstObjParams(name, Name, 'PredIntOp',
167                        {"code": new_code,
168                         "predicate_test": predicateTest},
169                        opt_flags)
170    header_output = BasicDeclare.subst(iop)
171    decoder_output = BasicConstructor.subst(iop)
172    decode_block = BasicDecode.subst(iop)
173    exec_output = PredOpExecute.subst(iop)
174}};
175
176def format PredIntOpCc(code, icValue, ivValue, *opt_flags) {{
177    ccCode = calcCcCode % vars()
178    code += ccCode;
179    new_code = ArmGenericCodeSubs(code)
180    iop = InstObjParams(name, Name, 'PredIntOp',
181                        {"code": new_code,
182                         "cc_code": ccCode,
183                         "predicate_test": predicateTest},
184                        opt_flags)
185    header_output = BasicDeclare.subst(iop)
186    decoder_output = BasicConstructor.subst(iop)
187    decode_block = BasicDecode.subst(iop)
188    exec_output = PredOpExecute.subst(iop)
189}};
190
191