2 * Copyright (c) 2009 The University of Edinburgh
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Timothy M. Jones
31 #ifndef __ARCH_POWER_INSTS_INTEGER_HH__
32 #define __ARCH_POWER_INSTS_INTEGER_HH__
34 #include "arch/power/insts/static_inst.hh"
35 #include "base/cprintf.hh"
36 #include "base/bitfield.hh"
42 * We provide a base class for integer operations and then inherit for
43 * several other classes. These specialise for instructions using immediate
44 * values and also rotate instructions. We also need to have versions that
45 * consider the Rc and OE bits.
49 * Base class for integer operations.
51 class IntOp : public PowerStaticInst
58 // Needed for srawi only
62 IntOp(const char *mnem, MachInst _machInst, OpClass __opClass)
63 : PowerStaticInst(mnem, _machInst, __opClass),
64 rcSet(false), oeSet(false)
68 /* Compute the CR (condition register) field using signed comparison */
70 makeCRField(int32_t a, int32_t b, uint32_t xerSO) const
74 /* We've pre-shifted the immediate values here */
75 if (a < b) { c += 0x8; }
76 else if (a > b) { c += 0x4; }
81 /* Compute the CR (condition register) field using unsigned comparison */
83 makeCRField(uint32_t a, uint32_t b, uint32_t xerSO) const
87 /* We've pre-shifted the immediate values here */
88 if (a < b) { c += 0x8; }
89 else if (a > b) { c += 0x4; }
94 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
99 * Class for integer immediate (signed and unsigned) operations.
101 class IntImmOp : public IntOp
109 IntImmOp(const char *mnem, MachInst _machInst, OpClass __opClass)
110 : IntOp(mnem, _machInst, __opClass),
111 imm(sext<16>(machInst.si)),
116 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
121 * Class for integer operations with a shift.
123 class IntShiftOp : public IntOp
130 IntShiftOp(const char *mnem, MachInst _machInst, OpClass __opClass)
131 : IntOp(mnem, _machInst, __opClass),
136 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
141 * Class for integer rotate operations.
143 class IntRotateOp : public IntShiftOp
152 IntRotateOp(const char *mnem, MachInst _machInst, OpClass __opClass)
153 : IntShiftOp(mnem, _machInst, __opClass),
158 fullMask = mask(31 - mb, 31 - me);
160 fullMask = ~mask(31 - (me + 1), 31 - (mb - 1));
165 rotateValue(uint32_t rs, uint32_t shift) const
167 uint32_t n = shift & 31;
168 return (rs << n) | (rs >> (32 - n));
171 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
174 } // PowerISA namespace
176 #endif //__ARCH_POWER_INSTS_INTEGER_HH__