arm.isa revision 7179:f9151566ca6e
1// -*- mode:c++ -*- 2 3// Copyright (c) 2010 ARM Limited 4// All rights reserved 5// 6// The license below extends only to copyright in the software and shall 7// not be construed as granting a license to any other intellectual 8// property including but not limited to intellectual property relating 9// to a hardware implementation of the functionality of the software 10// licensed hereunder. You may use the software subject to the license 11// terms below provided that you ensure that this notice is replicated 12// unmodified and in its entirety in all distributions of the software, 13// modified or unmodified, in source code or in binary form. 14// 15// Copyright (c) 2007-2008 The Florida State University 16// All rights reserved. 17// 18// Redistribution and use in source and binary forms, with or without 19// modification, are permitted provided that the following conditions are 20// met: redistributions of source code must retain the above copyright 21// notice, this list of conditions and the following disclaimer; 22// redistributions in binary form must reproduce the above copyright 23// notice, this list of conditions and the following disclaimer in the 24// documentation and/or other materials provided with the distribution; 25// neither the name of the copyright holders nor the names of its 26// contributors may be used to endorse or promote products derived from 27// this software without specific prior written permission. 28// 29// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40// 41// Authors: Stephen Hines 42 43//////////////////////////////////////////////////////////////////// 44// 45// The actual ARM ISA decoder 46// -------------------------- 47// The following instructions are specified in the ARM ISA 48// Specification. Decoding closely follows the style specified 49// in the ARM ISA specification document starting with Table B.1 or 3-1 50// 51// 52 530: decode ENCODING { 54format DataOp { 55 0x0: decode SEVEN_AND_FOUR { 56 1: decode MISC_OPCODE { 57 0x9: decode PREPOST { 58 0: ArmMultAndMultAcc::armMultAndMultAcc(); 59 1: decode PUBWL { 60 0x10: WarnUnimpl::swp(); 61 0x14: WarnUnimpl::swpb(); 62 0x18: WarnUnimpl::strex(); 63 0x19: WarnUnimpl::ldrex(); 64 } 65 } 66 0xb, 0xd, 0xf: AddrMode3::addrMode3(); 67 } 68 0: decode IS_MISC { 69 0: ArmDataProcReg::armDataProcReg(); 70 1: decode OPCODE_7 { 71 0x0: decode MISC_OPCODE { 72 0x0: decode OPCODE { 73 0x8: PredOp::mrs_cpsr({{ 74 Rd = (Cpsr | CondCodes) & 0xF8FF03DF; 75 }}); 76 0x9: decode USEIMM { 77 // The mask field is the same as the RN index. 78 0: PredOp::msr_cpsr_reg({{ 79 uint32_t newCpsr = 80 cpsrWriteByInstr(Cpsr | CondCodes, 81 Rm, RN, false); 82 Cpsr = ~CondCodesMask & newCpsr; 83 CondCodes = CondCodesMask & newCpsr; 84 }}); 85 1: PredImmOp::msr_cpsr_imm({{ 86 uint32_t newCpsr = 87 cpsrWriteByInstr(Cpsr | CondCodes, 88 rotated_imm, RN, false); 89 Cpsr = ~CondCodesMask & newCpsr; 90 CondCodes = CondCodesMask & newCpsr; 91 }}); 92 } 93 0xa: PredOp::mrs_spsr({{ Rd = Spsr; }}); 94 0xb: decode USEIMM { 95 // The mask field is the same as the RN index. 96 0: PredOp::msr_spsr_reg({{ 97 Spsr = spsrWriteByInstr(Spsr, Rm, RN, false); 98 }}); 99 1: PredImmOp::msr_spsr_imm({{ 100 Spsr = spsrWriteByInstr(Spsr, rotated_imm, 101 RN, false); 102 }}); 103 } 104 } 105 0x1: decode OPCODE { 106 0x9: ArmBx::armBx(); 107 0xb: PredOp::clz({{ 108 Rd = ((Rm == 0) ? 32 : (31 - findMsbSet(Rm))); 109 }}); 110 } 111 0x2: decode OPCODE { 112 0x9: WarnUnimpl::bxj(); 113 } 114 0x3: decode OPCODE { 115 0x9: ArmBlxReg::armBlxReg(); 116 } 117 0x5: decode OPCODE { 118 0x8: WarnUnimpl::qadd(); 119 0x9: WarnUnimpl::qsub(); 120 0xa: WarnUnimpl::qdadd(); 121 0xb: WarnUnimpl::qdsub(); 122 } 123 } 124 0x1: ArmHalfWordMultAndMultAcc::armHalfWordMultAndMultAcc(); 125 } 126 } 127 } 128 0x1: decode IS_MISC { 129 0: ArmDataProcImm::armDataProcImm(); 130 1: decode OPCODE { 131 // The following two instructions aren't supposed to be defined 132 0x8: DataOp::movw({{ Rd = IMMED_11_0 | (RN << 12) ; }}); 133 0x9: decode RN { 134 0: decode IMM { 135 0: PredImmOp::nop({{ ; }}); 136 1: WarnUnimpl::yield(); 137 2: WarnUnimpl::wfe(); 138 3: WarnUnimpl::wfi(); 139 4: WarnUnimpl::sev(); 140 } 141 default: PredImmOp::msr_i_cpsr({{ 142 uint32_t newCpsr = 143 cpsrWriteByInstr(Cpsr | CondCodes, 144 rotated_imm, RN, false); 145 Cpsr = ~CondCodesMask & newCpsr; 146 CondCodes = CondCodesMask & newCpsr; 147 }}); 148 } 149 0xa: PredOp::movt({{ Rd = IMMED_11_0 << 16 | RN << 28 | Rd<15:0>; }}); 150 0xb: PredImmOp::msr_i_spsr({{ 151 Spsr = spsrWriteByInstr(Spsr, rotated_imm, RN, false); 152 }}); 153 } 154 } 155 0x2: AddrMode2::addrMode2(True); 156 0x3: decode OPCODE_4 { 157 0: AddrMode2::addrMode2(False); 158 1: decode OPCODE_24_23 { 159 0x0: WarnUnimpl::parallel_add_subtract_instructions(); 160 0x1: decode MEDIA_OPCODE { 161 0x8: decode MISC_OPCODE { 162 0x1, 0x9: WarnUnimpl::pkhbt(); 163 0x7: WarnUnimpl::sxtab16(); 164 0xb: WarnUnimpl::sel(); 165 0x5, 0xd: WarnUnimpl::pkhtb(); 166 0x3: WarnUnimpl::sign_zero_extend_add(); 167 } 168 0xa, 0xb: decode SHIFT { 169 0x0, 0x2: WarnUnimpl::ssat(); 170 0x1: WarnUnimpl::ssat16(); 171 } 172 0xe, 0xf: decode SHIFT { 173 0x0, 0x2: WarnUnimpl::usat(); 174 0x1: WarnUnimpl::usat16(); 175 } 176 } 177 0x2: ArmSignedMultiplies::armSignedMultiplies(); 178 0x3: decode MEDIA_OPCODE { 179 0x18: decode RN { 180 0xf: WarnUnimpl::usada8(); 181 default: WarnUnimpl::usad8(); 182 } 183 } 184 } 185 } 186 0x4: ArmMacroMem::armMacroMem(); 187 0x5: decode OPCODE_24 { 188 0: ArmBBlxImm::armBBlxImm(); 189 1: ArmBlBlxImm::armBlBlxImm(); 190 } 191 0x6: decode CPNUM { 192 0xb: ExtensionRegLoadStore::extensionRegLoadStore(); 193 } 194 0x7: decode OPCODE_24 { 195 0: decode OPCODE_4 { 196 0: decode CPNUM { 197 0xa, 0xb: decode OPCODE_23_20 { 198##include "vfp.isa" 199 } 200 } // CPNUM 201 1: decode CPNUM { // 27-24=1110,4 ==1 202 1: decode OPCODE_15_12 { 203 format FloatOp { 204 0xf: decode OPCODE_23_21 { 205 format FloatCmp { 206 0x4: cmf({{ Fn.df }}, {{ Fm.df }}); 207 0x5: cnf({{ Fn.df }}, {{ -Fm.df }}); 208 0x6: cmfe({{ Fn.df }}, {{ Fm.df}}); 209 0x7: cnfe({{ Fn.df }}, {{ -Fm.df}}); 210 } 211 } 212 default: decode OPCODE_23_20 { 213 0x0: decode OPCODE_7 { 214 0: flts({{ Fn.sf = (float) Rd.sw; }}); 215 1: fltd({{ Fn.df = (double) Rd.sw; }}); 216 } 217 0x1: decode OPCODE_7 { 218 0: fixs({{ Rd = (uint32_t) Fm.sf; }}); 219 1: fixd({{ Rd = (uint32_t) Fm.df; }}); 220 } 221 0x2: wfs({{ Fpsr = Rd; }}); 222 0x3: rfs({{ Rd = Fpsr; }}); 223 0x4: FailUnimpl::wfc(); 224 0x5: FailUnimpl::rfc(); 225 } 226 } // format FloatOp 227 } 228 0xa: decode MISC_OPCODE { 229 0x1: decode MEDIA_OPCODE { 230 0xf: decode RN { 231 0x0: FloatOp::fmrx_fpsid({{ Rd = Fpsid; }}); 232 0x1: FloatOp::fmrx_fpscr({{ Rd = Fpscr; }}); 233 0x8: FloatOp::fmrx_fpexc({{ Rd = Fpexc; }}); 234 } 235 0xe: decode RN { 236 0x0: FloatOp::fmxr_fpsid({{ Fpsid = Rd; }}); 237 0x1: FloatOp::fmxr_fpscr({{ Fpscr = Rd; }}); 238 0x8: FloatOp::fmxr_fpexc({{ Fpexc = Rd; }}); 239 } 240 } // MEDIA_OPCODE (MISC_OPCODE 0x1) 241 } // MISC_OPCODE (CPNUM 0xA) 242 0xf: decode RN { 243 // Barrriers, Cache Maintence, NOPS 244 7: decode OPCODE_23_21 { 245 0: decode RM { 246 0: decode OPC2 { 247 4: decode OPCODE_20 { 248 0: PredOp::mcr_cp15_nop1({{ }}); // was wfi 249 } 250 } 251 1: WarnUnimpl::cp15_cache_maint(); 252 4: WarnUnimpl::cp15_par(); 253 5: decode OPC2 { 254 0,1: WarnUnimpl::cp15_cache_maint2(); 255 4: PredOp::cp15_isb({{ ; }}, IsMemBarrier, IsSerializeBefore); 256 6,7: WarnUnimpl::cp15_bp_maint(); 257 } 258 6: WarnUnimpl::cp15_cache_maint3(); 259 8: WarnUnimpl::cp15_va_to_pa(); 260 10: decode OPC2 { 261 1,2: WarnUnimpl::cp15_cache_maint3(); 262 4: PredOp::cp15_dsb({{ ; }}, IsMemBarrier, IsSerializeBefore); 263 5: PredOp::cp15_dmb({{ ; }}, IsMemBarrier, IsSerializeBefore); 264 } 265 11: WarnUnimpl::cp15_cache_maint4(); 266 13: decode OPC2 { 267 1: decode OPCODE_20 { 268 0: PredOp::mcr_cp15_nop2({{ }}); // was prefetch 269 } 270 } 271 14: WarnUnimpl::cp15_cache_maint5(); 272 } // RM 273 } // OPCODE_23_21 CR 274 275 // Thread ID and context ID registers 276 // Thread ID register needs cheaper access than miscreg 277 13: WarnUnimpl::mcr_mrc_cp15_c7(); 278 279 // All the rest 280 default: decode OPCODE_20 { 281 0: PredOp::mcr_cp15({{ 282 fault = setCp15Register(Rd, RN, OPCODE_23_21, RM, OPC2); 283 }}); 284 1: PredOp::mrc_cp15({{ 285 fault = readCp15Register(Rd, RN, OPCODE_23_21, RM, OPC2); 286 }}); 287 } 288 } // RN 289 } // CPNUM (OP4 == 1) 290 } //OPCODE_4 291 292#if FULL_SYSTEM 293 1: PredOp::swi({{ fault = new SupervisorCall; }}, IsSerializeAfter, IsNonSpeculative, IsSyscall); 294#else 295 1: PredOp::swi({{ if (testPredicate(CondCodes, condCode)) 296 { 297 if (IMMED_23_0) 298 xc->syscall(IMMED_23_0); 299 else 300 xc->syscall(R7); 301 } 302 }}); 303#endif // FULL_SYSTEM 304 } // OPCODE_24 305 306} 307} 308 309