arm.isa revision 7161
12SN/A// -*- mode:c++ -*-
21762SN/A
32SN/A// Copyright (c) 2010 ARM Limited
42SN/A// All rights reserved
52SN/A//
62SN/A// The license below extends only to copyright in the software and shall
72SN/A// not be construed as granting a license to any other intellectual
82SN/A// property including but not limited to intellectual property relating
92SN/A// to a hardware implementation of the functionality of the software
102SN/A// licensed hereunder.  You may use the software subject to the license
112SN/A// terms below provided that you ensure that this notice is replicated
122SN/A// unmodified and in its entirety in all distributions of the software,
132SN/A// modified or unmodified, in source code or in binary form.
142SN/A//
152SN/A// Copyright (c) 2007-2008 The Florida State University
162SN/A// All rights reserved.
172SN/A//
182SN/A// Redistribution and use in source and binary forms, with or without
192SN/A// modification, are permitted provided that the following conditions are
202SN/A// met: redistributions of source code must retain the above copyright
212SN/A// notice, this list of conditions and the following disclaimer;
222SN/A// redistributions in binary form must reproduce the above copyright
232SN/A// notice, this list of conditions and the following disclaimer in the
242SN/A// documentation and/or other materials provided with the distribution;
252SN/A// neither the name of the copyright holders nor the names of its
262SN/A// contributors may be used to endorse or promote products derived from
272665Ssaidi@eecs.umich.edu// this software without specific prior written permission.
282665Ssaidi@eecs.umich.edu//
292665Ssaidi@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302665Ssaidi@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3775SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392439SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402439SN/A//
41603SN/A// Authors: Stephen Hines
422986Sgblack@eecs.umich.edu
43603SN/A////////////////////////////////////////////////////////////////////
442520SN/A//
452378SN/A// The actual ARM ISA decoder
462378SN/A// --------------------------
47722SN/A// The following instructions are specified in the ARM ISA
482521SN/A// Specification. Decoding closely follows the style specified
492378SN/A// in the ARM ISA specification document starting with Table B.1 or 3-1
50312SN/A//
511634SN/A//
522680Sktlim@umich.edu
531634SN/A0: decode ENCODING {
542521SN/Aformat DataOp {
552378SN/A    0x0: decode SEVEN_AND_FOUR {
562378SN/A        1: decode MISC_OPCODE {
57803SN/A            0x9: decode PREPOST {
582378SN/A                0: ArmMultAndMultAcc::armMultAndMultAcc();
592SN/A                1: decode PUBWL {
602378SN/A                    0x10: WarnUnimpl::swp();
612SN/A                    0x14: WarnUnimpl::swpb();
622SN/A                    0x18: WarnUnimpl::strex();
632SN/A                    0x19: WarnUnimpl::ldrex();
64603SN/A                }
652901Ssaidi@eecs.umich.edu            }
662901Ssaidi@eecs.umich.edu            0xb, 0xd, 0xf: AddrMode3::addrMode3();
672901Ssaidi@eecs.umich.edu        }
682901Ssaidi@eecs.umich.edu        0: decode IS_MISC {
692901Ssaidi@eecs.umich.edu            0: ArmDataProcReg::armDataProcReg();
702901Ssaidi@eecs.umich.edu            1: decode OPCODE_7 {
712902Ssaidi@eecs.umich.edu                0x0: decode MISC_OPCODE {
722902Ssaidi@eecs.umich.edu                    0x0: decode OPCODE {
732901Ssaidi@eecs.umich.edu                        0x8: PredOp::mrs_cpsr({{
742901Ssaidi@eecs.umich.edu                            Rd = (Cpsr | CondCodes) & 0xF8FF03DF;
752901Ssaidi@eecs.umich.edu                        }});
762901Ssaidi@eecs.umich.edu                        0x9: decode USEIMM {
772901Ssaidi@eecs.umich.edu                            // The mask field is the same as the RN index.
782901Ssaidi@eecs.umich.edu                            0: PredOp::msr_cpsr_reg({{
792901Ssaidi@eecs.umich.edu                                uint32_t newCpsr =
802901Ssaidi@eecs.umich.edu                                    cpsrWriteByInstr(Cpsr | CondCodes,
812901Ssaidi@eecs.umich.edu                                                     Rm, RN, false);
822521SN/A                                Cpsr = ~CondCodesMask & newCpsr;
832SN/A                                CondCodes = CondCodesMask & newCpsr;
842SN/A                            }});
852680Sktlim@umich.edu                            1: PredImmOp::msr_cpsr_imm({{
861806SN/A                                uint32_t newCpsr =
871806SN/A                                    cpsrWriteByInstr(Cpsr | CondCodes,
881806SN/A                                                     rotated_imm, RN, false);
891806SN/A                                Cpsr = ~CondCodesMask & newCpsr;
902680Sktlim@umich.edu                                CondCodes = CondCodesMask & newCpsr;
911806SN/A                            }});
921806SN/A                        }
931806SN/A                        0xa: PredOp::mrs_spsr({{ Rd = Spsr; }});
941806SN/A                        0xb: decode USEIMM {
95180SN/A                            // The mask field is the same as the RN index.
962378SN/A                            0: PredOp::msr_spsr_reg({{
972378SN/A                                Spsr = spsrWriteByInstr(Spsr, Rm, RN, false);
982378SN/A                            }});
992378SN/A                            1: PredImmOp::msr_spsr_imm({{
1002520SN/A                                Spsr = spsrWriteByInstr(Spsr, rotated_imm,
1012520SN/A                                                        RN, false);
1022520SN/A                            }});
1032521SN/A                        }
1042520SN/A                    }
1051885SN/A                    0x1: decode OPCODE {
1061070SN/A                        0x9: ArmBx::armBx();
107954SN/A                        0xb: PredOp::clz({{
1081070SN/A                            Rd = ((Rm == 0) ? 32 : (31 - findMsbSet(Rm)));
1091070SN/A                        }});
1101070SN/A                    }
1111070SN/A                    0x2: decode OPCODE {
1121070SN/A                        0x9: WarnUnimpl::bxj();
1131070SN/A                    }
1141070SN/A                    0x3: decode OPCODE {
1151070SN/A                        0x9: ArmBlxReg::armBlxReg();
1161070SN/A                    }
1171070SN/A                    0x5: decode OPCODE {
1181070SN/A                        0x8: WarnUnimpl::qadd();
1191070SN/A                        0x9: WarnUnimpl::qsub();
1202378SN/A                        0xa: WarnUnimpl::qdadd();
1212378SN/A                        0xb: WarnUnimpl::qdsub();
1222378SN/A                    }
1232378SN/A                }
1242378SN/A                0x1: ArmHalfWordMultAndMultAcc::armHalfWordMultAndMultAcc();
1252378SN/A            }
1262378SN/A        }
1271885SN/A    }
1281885SN/A    0x1: decode IS_MISC {
1292901Ssaidi@eecs.umich.edu        0: ArmDataProcImm::armDataProcImm();
1302901Ssaidi@eecs.umich.edu        1: decode OPCODE {
1312424SN/A            // The following two instructions aren't supposed to be defined
1321885SN/A            0x8: DataOp::movw({{ Rd = IMMED_11_0 | (RN << 12) ; }});
1331885SN/A            0x9: decode RN {
1341885SN/A                0: decode IMM {
1351885SN/A                    0: PredImmOp::nop({{ ; }});
1361885SN/A                    1: WarnUnimpl::yield();
1372158SN/A                    2: WarnUnimpl::wfe();
1381885SN/A                    3: WarnUnimpl::wfi();
1391885SN/A                    4: WarnUnimpl::sev();
1401885SN/A                }
1411885SN/A                default: PredImmOp::msr_i_cpsr({{
1421885SN/A                            uint32_t newCpsr =
1431885SN/A                                cpsrWriteByInstr(Cpsr | CondCodes,
1442989Ssaidi@eecs.umich.edu                                                 rotated_imm, RN, false);
1451885SN/A                            Cpsr = ~CondCodesMask & newCpsr;
1461913SN/A                            CondCodes = CondCodesMask & newCpsr;
1471885SN/A                }});
1481885SN/A            }
1491885SN/A            0xa: PredOp::movt({{ Rd = IMMED_11_0 << 16 | RN << 28 | Rd<15:0>; }});
1501885SN/A            0xb: PredImmOp::msr_i_spsr({{
1511885SN/A                       Spsr = spsrWriteByInstr(Spsr, rotated_imm, RN, false);
1521885SN/A            }});
1531885SN/A        }
1541885SN/A    }
1551885SN/A    0x2: AddrMode2::addrMode2(True);
1561885SN/A    0x3: decode OPCODE_4 {
1571885SN/A        0: AddrMode2::addrMode2(False);
1582989Ssaidi@eecs.umich.edu        1: decode OPCODE_24_23 {
1591885SN/A            0x0: WarnUnimpl::parallel_add_subtract_instructions();
1601885SN/A            0x1: decode MEDIA_OPCODE {
1611885SN/A                0x8: decode MISC_OPCODE {
1621885SN/A                    0x1, 0x9: WarnUnimpl::pkhbt();
1632378SN/A                    0x7: WarnUnimpl::sxtab16();
16477SN/A                    0xb: WarnUnimpl::sel();
1652378SN/A                    0x5, 0xd: WarnUnimpl::pkhtb();
1661070SN/A                    0x3: WarnUnimpl::sign_zero_extend_add();
1671070SN/A                }
1682158SN/A                0xa, 0xb: decode SHIFT {
1692378SN/A                    0x0, 0x2: WarnUnimpl::ssat();
1701070SN/A                    0x1: WarnUnimpl::ssat16();
1711070SN/A                }
1721070SN/A                0xe, 0xf: decode SHIFT {
1731070SN/A                    0x0, 0x2: WarnUnimpl::usat();
1741070SN/A                    0x1: WarnUnimpl::usat16();
1752521SN/A                }
1762902Ssaidi@eecs.umich.edu            }
1772378SN/A            0x2: ArmSignedMultiplies::armSignedMultiplies();
1782378SN/A            0x3: decode MEDIA_OPCODE {
1791634SN/A                0x18: decode RN {
1802567SN/A                    0xf: WarnUnimpl::usada8();
1811070SN/A                    default: WarnUnimpl::usad8();
1821070SN/A                }
1831070SN/A            }
1842158SN/A        }
1852378SN/A    }
1862158SN/A    0x4: ArmMacroMem::armMacroMem();
1871070SN/A    0x5: decode OPCODE_24 {
1882158SN/A        0: ArmBBlxImm::armBBlxImm();
1892158SN/A        1: ArmBlBlxImm::armBlBlxImm();
1901070SN/A    }
1912158SN/A    0x6: decode CPNUM {
1921070SN/A        0xb: decode LOADOP {
1932SN/A            0x0: WarnUnimpl::fstmx();
1942SN/A            0x1: WarnUnimpl::fldmx();
1951129SN/A        }
1961129SN/A    }
1972158SN/A    0x7: decode OPCODE_24 {
1982158SN/A        0: decode OPCODE_4 {
1991070SN/A            0: decode CPNUM {
2002378SN/A                0xa, 0xb: decode OPCODE_23_20 {
2012378SN/A##include "vfp.isa"
2021070SN/A                }
2031070SN/A            } // CPNUM
2041070SN/A            1: decode CPNUM { // 27-24=1110,4 ==1
2051070SN/A                1: decode OPCODE_15_12 {
2061070SN/A                    format FloatOp {
2071070SN/A                        0xf: decode OPCODE_23_21 {
2081070SN/A                            format FloatCmp {
2091070SN/A                                0x4: cmf({{ Fn.df }}, {{ Fm.df }});
2101070SN/A                                0x5: cnf({{ Fn.df }}, {{ -Fm.df }});
2111070SN/A                                0x6: cmfe({{ Fn.df }}, {{ Fm.df}});
2121070SN/A                                0x7: cnfe({{ Fn.df }}, {{ -Fm.df}});
2131070SN/A                            }
2141070SN/A                        }
2151070SN/A                        default: decode OPCODE_23_20 {
2161070SN/A                            0x0: decode OPCODE_7 {
2171070SN/A                                0: flts({{ Fn.sf = (float) Rd.sw; }});
2181070SN/A                                1: fltd({{ Fn.df = (double) Rd.sw; }});
2191070SN/A                            }
2202378SN/A                            0x1: decode OPCODE_7 {
2212378SN/A                                0: fixs({{ Rd = (uint32_t) Fm.sf; }});
2222378SN/A                                1: fixd({{ Rd = (uint32_t) Fm.df; }});
2232378SN/A                            }
2242378SN/A                            0x2: wfs({{ Fpsr = Rd; }});
2252378SN/A                            0x3: rfs({{ Rd = Fpsr; }});
2262680Sktlim@umich.edu                            0x4: FailUnimpl::wfc();
2272680Sktlim@umich.edu                            0x5: FailUnimpl::rfc();
2281070SN/A                        }
2291070SN/A                    } // format FloatOp
2301070SN/A                }
2312SN/A                0xa: decode MISC_OPCODE {
23277SN/A                    0x1: decode MEDIA_OPCODE {
2332SN/A                        0xf: decode RN {
2342SN/A                            0x0: FloatOp::fmrx_fpsid({{ Rd = Fpsid; }});
2352SN/A                            0x1: FloatOp::fmrx_fpscr({{ Rd = Fpscr; }});
2362SN/A                            0x8: FloatOp::fmrx_fpexc({{ Rd = Fpexc; }});
2372SN/A                        }
2382SN/A                        0xe: decode RN {
2392SN/A                            0x0: FloatOp::fmxr_fpsid({{ Fpsid = Rd; }});
2402SN/A                            0x1: FloatOp::fmxr_fpscr({{ Fpscr = Rd; }});
2412SN/A                            0x8: FloatOp::fmxr_fpexc({{ Fpexc = Rd; }});
2422SN/A                        }
2432158SN/A                    } // MEDIA_OPCODE (MISC_OPCODE 0x1)
2442158SN/A                } // MISC_OPCODE (CPNUM 0xA)
2452SN/A                0xf: decode RN {
2462SN/A                    // Barrriers, Cache Maintence, NOPS
2472SN/A                    7: decode OPCODE_23_21 {
248                        0: decode RM {
249                            0: decode OPC2 {
250                                4: decode OPCODE_20 {
251                                    0: PredOp::mcr_cp15_nop1({{ }}); // was wfi
252                                }
253                            }
254                            1: WarnUnimpl::cp15_cache_maint();
255                            4: WarnUnimpl::cp15_par();
256                            5: decode OPC2 {
257                                0,1: WarnUnimpl::cp15_cache_maint2();
258                                4: PredOp::cp15_isb({{ ; }}, IsMemBarrier, IsSerializeBefore);
259                                6,7: WarnUnimpl::cp15_bp_maint();
260                            }
261                            6: WarnUnimpl::cp15_cache_maint3();
262                            8: WarnUnimpl::cp15_va_to_pa();
263                            10: decode OPC2 {
264                                1,2: WarnUnimpl::cp15_cache_maint3();
265                                4: PredOp::cp15_dsb({{ ; }}, IsMemBarrier, IsSerializeBefore);
266                                5: PredOp::cp15_dmb({{ ; }}, IsMemBarrier, IsSerializeBefore);
267                            }
268                            11: WarnUnimpl::cp15_cache_maint4();
269                            13: decode OPC2 {
270                                1: decode OPCODE_20 {
271                                    0: PredOp::mcr_cp15_nop2({{ }}); // was prefetch
272                                }
273                            }
274                            14: WarnUnimpl::cp15_cache_maint5();
275                        } // RM
276                    } // OPCODE_23_21 CR
277
278                    // Thread ID and context ID registers
279                    // Thread ID register needs cheaper access than miscreg
280                    13: WarnUnimpl::mcr_mrc_cp15_c7();
281
282                    // All the rest
283                    default: decode OPCODE_20 {
284                        0: PredOp::mcr_cp15({{
285                               fault = setCp15Register(Rd, RN, OPCODE_23_21, RM, OPC2);
286                        }});
287                        1: PredOp::mrc_cp15({{
288                               fault = readCp15Register(Rd, RN, OPCODE_23_21, RM, OPC2);
289                        }});
290                    }
291                }  // RN
292            } // CPNUM  (OP4 == 1)
293        } //OPCODE_4
294
295#if FULL_SYSTEM
296        1: PredOp::swi({{ fault = new SupervisorCall; }}, IsSerializeAfter, IsNonSpeculative, IsSyscall);
297#else
298        1: PredOp::swi({{ if (testPredicate(CondCodes, condCode))
299            {
300                if (IMMED_23_0)
301                    xc->syscall(IMMED_23_0);
302                else
303                    xc->syscall(R7);
304            }
305        }});
306#endif // FULL_SYSTEM
307    } // OPCODE_24
308
309}
310}
311
312