3 // Copyright (c) 2003-2005 The Regents of The University of Michigan
4 // Copyright (c) 2009 The University of Edinburgh
5 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met: redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer;
11 // redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution;
14 // neither the name of the copyright holders nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // Some instructions ignore the contents of Ra if Ra == 0,
32 def template CheckRaDecode {{
35 return new %(class_name)sRaZero(machInst);
37 return new %(class_name)s(machInst);
43 // Some instructions have extra behaviour if Rc is set.
44 def template CheckRcDecode {{
47 return new %(class_name)s(machInst);
49 return new %(class_name)sRcSet(machInst);
55 // Some instructions have extra behaviour if Rc and OE are set.
56 def template CheckRcOeDecode {{
60 return new %(class_name)s(machInst);
62 return new %(class_name)sOeSet(machInst);
66 return new %(class_name)sRcSet(machInst);
68 return new %(class_name)sRcSetOeSet(machInst);
74 // Branch instructions always have two versions, one which sets the link
76 def template CheckLkDecode {{
79 return new %(class_name)s(machInst);
81 return new %(class_name)sUpdateLr(machInst);
89 def LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
91 decode_template = BasicDecode, exec_template_base = ''):
92 # Make sure flags are in lists (convert to lists if not).
93 mem_flags = makeList(mem_flags)
94 inst_flags = makeList(inst_flags)
96 # Generate InstObjParams for the memory access.
97 iop = InstObjParams(name, Name, base_class,
99 'memacc_code': memacc_code},
103 s = '\n\tmemAccessFlags = ' + string.join(mem_flags, '|') + ';'
106 fullExecTemplate = eval(exec_template_base + 'Execute')
107 initiateAccTemplate = eval(exec_template_base + 'InitiateAcc')
108 completeAccTemplate = eval(exec_template_base + 'CompleteAcc')
110 # (header_output, decoder_output, decode_block, exec_output)
111 return (LoadStoreDeclare.subst(iop),
112 LoadStoreConstructor.subst(iop),
113 decode_template.subst(iop),
114 fullExecTemplate.subst(iop)
115 + initiateAccTemplate.subst(iop)
116 + completeAccTemplate.subst(iop))
119 # The generic ALU instruction generator. Integer and fp formats calls this
120 # to generate the different output sections.
121 def GenAluOp(name, Name, base_class, code, inst_flags, decode_template,
122 constructor_template):
123 iop = InstObjParams(name, Name, base_class,
126 header_output = BasicDeclare.subst(iop)
127 exec_output = BasicExecute.subst(iop)
129 # We use constructors dependent on the Rc and OE bits being set
130 decoder_output = constructor_template.subst(iop)
132 # The decode block defines which version to use
133 decode_block = decode_template.subst(iop)
134 return (header_output, decoder_output, decode_block, exec_output)
141 inst2string(MachInst machInst);
147 inst2string(MachInst machInst)
149 std::string str = "";
150 uint32_t mask = 0x80000000;
152 for(int i=0; i < 32; i++) {
153 if ((machInst & mask) == 0) {