pal.isa revision 2649:2fb859a457a2
1// -*- mode:c++ -*- 2 3// Copyright (c) 2003-2005 The Regents of The University of Michigan 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//////////////////////////////////////////////////////////////////// 30// 31// PAL calls & PAL-specific instructions 32// 33 34output header {{ 35 /** 36 * Base class for emulated call_pal calls (used only in 37 * non-full-system mode). 38 */ 39 class EmulatedCallPal : public AlphaStaticInst 40 { 41 protected: 42 43 /// Constructor. 44 EmulatedCallPal(const char *mnem, ExtMachInst _machInst, 45 OpClass __opClass) 46 : AlphaStaticInst(mnem, _machInst, __opClass) 47 { 48 } 49 50 std::string 51 generateDisassembly(Addr pc, const SymbolTable *symtab) const; 52 }; 53}}; 54 55output decoder {{ 56 std::string 57 EmulatedCallPal::generateDisassembly(Addr pc, 58 const SymbolTable *symtab) const 59 { 60#ifdef SS_COMPATIBLE_DISASSEMBLY 61 return csprintf("%s %s", "call_pal", mnemonic); 62#else 63 return csprintf("%-10s %s", "call_pal", mnemonic); 64#endif 65 } 66}}; 67 68def format EmulatedCallPal(code, *flags) {{ 69 iop = InstObjParams(name, Name, 'EmulatedCallPal', CodeBlock(code), flags) 70 header_output = BasicDeclare.subst(iop) 71 decoder_output = BasicConstructor.subst(iop) 72 decode_block = BasicDecode.subst(iop) 73 exec_output = BasicExecute.subst(iop) 74}}; 75 76output header {{ 77 /** 78 * Base class for full-system-mode call_pal instructions. 79 * Probably could turn this into a leaf class and get rid of the 80 * parser template. 81 */ 82 class CallPalBase : public AlphaStaticInst 83 { 84 protected: 85 int palFunc; ///< Function code part of instruction 86 int palOffset; ///< Target PC, offset from IPR_PAL_BASE 87 bool palValid; ///< is the function code valid? 88 bool palPriv; ///< is this call privileged? 89 90 /// Constructor. 91 CallPalBase(const char *mnem, ExtMachInst _machInst, 92 OpClass __opClass); 93 94 std::string 95 generateDisassembly(Addr pc, const SymbolTable *symtab) const; 96 }; 97}}; 98 99output decoder {{ 100 inline 101 CallPalBase::CallPalBase(const char *mnem, ExtMachInst _machInst, 102 OpClass __opClass) 103 : AlphaStaticInst(mnem, _machInst, __opClass), 104 palFunc(PALFUNC) 105 { 106 // From the 21164 HRM (paraphrased): 107 // Bit 7 of the function code (mask 0x80) indicates 108 // whether the call is privileged (bit 7 == 0) or 109 // unprivileged (bit 7 == 1). The privileged call table 110 // starts at 0x2000, the unprivielged call table starts at 111 // 0x3000. Bits 5-0 (mask 0x3f) are used to calculate the 112 // offset. 113 const int palPrivMask = 0x80; 114 const int palOffsetMask = 0x3f; 115 116 // Pal call is invalid unless all other bits are 0 117 palValid = ((machInst & ~(palPrivMask | palOffsetMask)) == 0); 118 palPriv = ((machInst & palPrivMask) == 0); 119 int shortPalFunc = (machInst & palOffsetMask); 120 // Add 1 to base to set pal-mode bit 121 palOffset = (palPriv ? 0x2001 : 0x3001) + (shortPalFunc << 6); 122 } 123 124 std::string 125 CallPalBase::generateDisassembly(Addr pc, const SymbolTable *symtab) const 126 { 127 return csprintf("%-10s %#x", "call_pal", palFunc); 128 } 129}}; 130 131def format CallPal(code, *flags) {{ 132 iop = InstObjParams(name, Name, 'CallPalBase', CodeBlock(code), flags) 133 header_output = BasicDeclare.subst(iop) 134 decoder_output = BasicConstructor.subst(iop) 135 decode_block = BasicDecode.subst(iop) 136 exec_output = BasicExecute.subst(iop) 137}}; 138 139//////////////////////////////////////////////////////////////////// 140// 141// hw_ld, hw_st 142// 143 144output header {{ 145 /** 146 * Base class for hw_ld and hw_st. 147 */ 148 class HwLoadStore : public Memory 149 { 150 protected: 151 152 /// Displacement for EA calculation (signed). 153 int16_t disp; 154 155 /// Constructor 156 HwLoadStore(const char *mnem, ExtMachInst _machInst, OpClass __opClass, 157 StaticInstPtr _eaCompPtr = nullStaticInstPtr, 158 StaticInstPtr _memAccPtr = nullStaticInstPtr); 159 160 std::string 161 generateDisassembly(Addr pc, const SymbolTable *symtab) const; 162 }; 163}}; 164 165 166output decoder {{ 167 inline 168 HwLoadStore::HwLoadStore(const char *mnem, ExtMachInst _machInst, 169 OpClass __opClass, 170 StaticInstPtr _eaCompPtr, 171 StaticInstPtr _memAccPtr) 172 : Memory(mnem, _machInst, __opClass, _eaCompPtr, _memAccPtr), 173 disp(HW_LDST_DISP) 174 { 175 memAccessFlags = 0; 176 if (HW_LDST_PHYS) memAccessFlags |= PHYSICAL; 177 if (HW_LDST_ALT) memAccessFlags |= ALTMODE; 178 if (HW_LDST_VPTE) memAccessFlags |= VPTE; 179 if (HW_LDST_LOCK) memAccessFlags |= LOCKED; 180 } 181 182 std::string 183 HwLoadStore::generateDisassembly(Addr pc, const SymbolTable *symtab) const 184 { 185#ifdef SS_COMPATIBLE_DISASSEMBLY 186 return csprintf("%-10s r%d,%d(r%d)", mnemonic, RA, disp, RB); 187#else 188 // HW_LDST_LOCK and HW_LDST_COND are the same bit. 189 const char *lock_str = 190 (HW_LDST_LOCK) ? (flags[IsLoad] ? ",LOCK" : ",COND") : ""; 191 192 return csprintf("%-10s r%d,%d(r%d)%s%s%s%s%s", 193 mnemonic, RA, disp, RB, 194 HW_LDST_PHYS ? ",PHYS" : "", 195 HW_LDST_ALT ? ",ALT" : "", 196 HW_LDST_QUAD ? ",QUAD" : "", 197 HW_LDST_VPTE ? ",VPTE" : "", 198 lock_str); 199#endif 200 } 201}}; 202 203def format HwLoad(ea_code, memacc_code, class_ext, *flags) {{ 204 (header_output, decoder_output, decode_block, exec_output) = \ 205 LoadStoreBase(name, Name + class_ext, ea_code, memacc_code, 206 mem_flags = [], inst_flags = flags, 207 base_class = 'HwLoadStore', exec_template_base = 'Load') 208}}; 209 210 211def format HwStore(ea_code, memacc_code, class_ext, *flags) {{ 212 (header_output, decoder_output, decode_block, exec_output) = \ 213 LoadStoreBase(name, Name + class_ext, ea_code, memacc_code, 214 mem_flags = [], inst_flags = flags, 215 base_class = 'HwLoadStore', exec_template_base = 'Store') 216}}; 217 218 219def format HwStoreCond(ea_code, memacc_code, postacc_code, class_ext, 220 *flags) {{ 221 (header_output, decoder_output, decode_block, exec_output) = \ 222 LoadStoreBase(name, Name + class_ext, ea_code, memacc_code, 223 postacc_code, mem_flags = [], inst_flags = flags, 224 base_class = 'HwLoadStore') 225}}; 226 227 228output header {{ 229 /** 230 * Base class for hw_mfpr and hw_mtpr. 231 */ 232 class HwMoveIPR : public AlphaStaticInst 233 { 234 protected: 235 /// Index of internal processor register. 236 int ipr_index; 237 238 /// Constructor 239 HwMoveIPR(const char *mnem, ExtMachInst _machInst, OpClass __opClass) 240 : AlphaStaticInst(mnem, _machInst, __opClass), 241 ipr_index(HW_IPR_IDX) 242 { 243 } 244 245 std::string 246 generateDisassembly(Addr pc, const SymbolTable *symtab) const; 247 }; 248}}; 249 250output decoder {{ 251 std::string 252 HwMoveIPR::generateDisassembly(Addr pc, const SymbolTable *symtab) const 253 { 254 if (_numSrcRegs > 0) { 255 // must be mtpr 256 return csprintf("%-10s r%d,IPR(%#x)", 257 mnemonic, RA, ipr_index); 258 } 259 else { 260 // must be mfpr 261 return csprintf("%-10s IPR(%#x),r%d", 262 mnemonic, ipr_index, RA); 263 } 264 } 265}}; 266 267def format HwMoveIPR(code) {{ 268 iop = InstObjParams(name, Name, 'HwMoveIPR', CodeBlock(code), 269 ['IprAccessOp']) 270 header_output = BasicDeclare.subst(iop) 271 decoder_output = BasicConstructor.subst(iop) 272 decode_block = BasicDecode.subst(iop) 273 exec_output = BasicExecute.subst(iop) 274}}; 275 276 277