vfp.isa revision 10184
17375Sgblack@eecs.umich.edu// -*- mode:c++ -*-
27375Sgblack@eecs.umich.edu
310037SARM gem5 Developers// Copyright (c) 2010-2013 ARM Limited
47375Sgblack@eecs.umich.edu// All rights reserved
57375Sgblack@eecs.umich.edu//
67375Sgblack@eecs.umich.edu// The license below extends only to copyright in the software and shall
77375Sgblack@eecs.umich.edu// not be construed as granting a license to any other intellectual
87375Sgblack@eecs.umich.edu// property including but not limited to intellectual property relating
97375Sgblack@eecs.umich.edu// to a hardware implementation of the functionality of the software
107375Sgblack@eecs.umich.edu// licensed hereunder.  You may use the software subject to the license
117375Sgblack@eecs.umich.edu// terms below provided that you ensure that this notice is replicated
127375Sgblack@eecs.umich.edu// unmodified and in its entirety in all distributions of the software,
137375Sgblack@eecs.umich.edu// modified or unmodified, in source code or in binary form.
147375Sgblack@eecs.umich.edu//
157375Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without
167375Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are
177375Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright
187375Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer;
197375Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright
207375Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the
217375Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution;
227375Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its
237375Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from
247375Sgblack@eecs.umich.edu// this software without specific prior written permission.
257375Sgblack@eecs.umich.edu//
267375Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
277375Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
287375Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
297375Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
307375Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
317375Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
327375Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
337375Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
347375Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
357375Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
367375Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
377375Sgblack@eecs.umich.edu//
387375Sgblack@eecs.umich.edu// Authors: Gabe Black
397375Sgblack@eecs.umich.edu
407640Sgblack@eecs.umich.edulet {{
417640Sgblack@eecs.umich.edu    vfpEnabledCheckCode = '''
4210037SARM gem5 Developers        uint32_t issEnCheck;
4310037SARM gem5 Developers        bool trapEnCheck;
4410037SARM gem5 Developers        uint32_t seq;
4510037SARM gem5 Developers        if (!vfpNeonEnabled(seq,Hcptr, Nsacr, Cpacr, Cpsr, issEnCheck,
4610037SARM gem5 Developers                            trapEnCheck, xc->tcBase(), Fpexc))
4710037SARM gem5 Developers            {return disabledFault();}
4810037SARM gem5 Developers        if (trapEnCheck) {
4910037SARM gem5 Developers            CPSR cpsrEnCheck = Cpsr;
5010037SARM gem5 Developers            if (cpsrEnCheck.mode == MODE_HYP) {
5110037SARM gem5 Developers                return new UndefinedInstruction(machInst, issEnCheck,
5210037SARM gem5 Developers                                                EC_TRAPPED_HCPTR);
5310037SARM gem5 Developers            } else {
5410037SARM gem5 Developers                if (!inSecureState(Scr, Cpsr)) {
5510037SARM gem5 Developers                    return new HypervisorTrap(machInst, issEnCheck,
5610037SARM gem5 Developers                                              EC_TRAPPED_HCPTR);
5710037SARM gem5 Developers                }
5810037SARM gem5 Developers            }
5910037SARM gem5 Developers        }
6010037SARM gem5 Developers    '''
6110037SARM gem5 Developers
6210037SARM gem5 Developers    vfp64EnabledCheckCode = '''
6310037SARM gem5 Developers        CPSR cpsrEnCheck = Cpsr;
6410037SARM gem5 Developers        ExceptionLevel el = (ExceptionLevel) (uint8_t) cpsrEnCheck.el;
6510037SARM gem5 Developers        if (!vfpNeon64Enabled(Cpacr64, el))
6610037SARM gem5 Developers             return new SupervisorTrap(machInst, 0x1E00000,
6710037SARM gem5 Developers                                       EC_TRAPPED_SIMD_FP);
6810037SARM gem5 Developers
6910037SARM gem5 Developers        if (ArmSystem::haveVirtualization(xc->tcBase()) && el <= EL2) {
7010037SARM gem5 Developers            HCPTR cptrEnCheck = xc->tcBase()->readMiscReg(MISCREG_CPTR_EL2);
7110037SARM gem5 Developers            if (cptrEnCheck.tfp)
7210037SARM gem5 Developers                return new HypervisorTrap(machInst, 0x1E00000,
7310037SARM gem5 Developers                                          EC_TRAPPED_SIMD_FP);
7410037SARM gem5 Developers        }
7510037SARM gem5 Developers
7610037SARM gem5 Developers        if (ArmSystem::haveSecurity(xc->tcBase())) {
7710037SARM gem5 Developers            HCPTR cptrEnCheck = xc->tcBase()->readMiscReg(MISCREG_CPTR_EL3);
7810037SARM gem5 Developers            if (cptrEnCheck.tfp)
7910037SARM gem5 Developers                return new SecureMonitorTrap(machInst, 0x1E00000,
8010037SARM gem5 Developers                                             EC_TRAPPED_SIMD_FP);
8110037SARM gem5 Developers        }
827640Sgblack@eecs.umich.edu    '''
837640Sgblack@eecs.umich.edu
847644Sali.saidi@arm.com    vmsrEnabledCheckCode = '''
8510037SARM gem5 Developers        uint32_t issEnCheck;
8610037SARM gem5 Developers        bool trapEnCheck;
8710037SARM gem5 Developers        uint32_t seq;
8810037SARM gem5 Developers        if (!vfpNeonEnabled(seq,Hcptr, Nsacr, Cpacr, Cpsr, issEnCheck,
8910037SARM gem5 Developers                            trapEnCheck, xc->tcBase()))
907644Sali.saidi@arm.com            if (dest != (int)MISCREG_FPEXC && dest != (int)MISCREG_FPSID)
9110037SARM gem5 Developers                {return disabledFault();}
927644Sali.saidi@arm.com        if (!inPrivilegedMode(Cpsr))
937644Sali.saidi@arm.com            if (dest != (int)MISCREG_FPSCR)
947644Sali.saidi@arm.com                return disabledFault();
9510037SARM gem5 Developers        if (trapEnCheck) {
9610037SARM gem5 Developers            CPSR cpsrEnCheck = Cpsr;
9710037SARM gem5 Developers            if (cpsrEnCheck.mode == MODE_HYP) {
9810037SARM gem5 Developers                return new UndefinedInstruction(machInst, issEnCheck,
9910037SARM gem5 Developers                                                EC_TRAPPED_HCPTR);
10010037SARM gem5 Developers            } else {
10110037SARM gem5 Developers                if (!inSecureState(Scr, Cpsr)) {
10210037SARM gem5 Developers                    return new HypervisorTrap(machInst, issEnCheck,
10310037SARM gem5 Developers                                              EC_TRAPPED_HCPTR);
10410037SARM gem5 Developers                }
10510037SARM gem5 Developers            }
10610037SARM gem5 Developers        }
1077644Sali.saidi@arm.com    '''
1087644Sali.saidi@arm.com
1097644Sali.saidi@arm.com    vmrsEnabledCheckCode = '''
11010037SARM gem5 Developers        uint32_t issEnCheck;
11110037SARM gem5 Developers        bool trapEnCheck;
11210037SARM gem5 Developers        uint32_t seq;
11310037SARM gem5 Developers        if (!vfpNeonEnabled(seq,Hcptr, Nsacr, Cpacr, Cpsr, issEnCheck,
11410037SARM gem5 Developers                            trapEnCheck, xc->tcBase()))
1157644Sali.saidi@arm.com            if (op1 != (int)MISCREG_FPEXC && op1 != (int)MISCREG_FPSID &&
1167644Sali.saidi@arm.com                op1 != (int)MISCREG_MVFR0 && op1 != (int)MISCREG_MVFR1)
11710037SARM gem5 Developers                {return disabledFault();}
1187644Sali.saidi@arm.com        if (!inPrivilegedMode(Cpsr))
1197644Sali.saidi@arm.com            if (op1 != (int)MISCREG_FPSCR)
1207644Sali.saidi@arm.com                return disabledFault();
12110037SARM gem5 Developers        if (trapEnCheck) {
12210037SARM gem5 Developers            CPSR cpsrEnCheck = Cpsr;
12310037SARM gem5 Developers            if (cpsrEnCheck.mode == MODE_HYP) {
12410037SARM gem5 Developers                return new UndefinedInstruction(machInst, issEnCheck,
12510037SARM gem5 Developers                                                EC_TRAPPED_HCPTR);
12610037SARM gem5 Developers            } else {
12710037SARM gem5 Developers                if (!inSecureState(Scr, Cpsr)) {
12810037SARM gem5 Developers                    return new HypervisorTrap(machInst, issEnCheck,
12910037SARM gem5 Developers                                              EC_TRAPPED_HCPTR);
13010037SARM gem5 Developers                }
13110037SARM gem5 Developers            }
13210037SARM gem5 Developers        }
1337640Sgblack@eecs.umich.edu    '''
1348303SAli.Saidi@ARM.com    vmrsApsrEnabledCheckCode = '''
13510037SARM gem5 Developers        uint32_t issEnCheck;
13610037SARM gem5 Developers        bool trapEnCheck;
13710037SARM gem5 Developers        uint32_t seq;
13810037SARM gem5 Developers        if (!vfpNeonEnabled(seq,Hcptr, Nsacr, Cpacr, Cpsr, issEnCheck,
13910037SARM gem5 Developers                            trapEnCheck, xc->tcBase()))
14010037SARM gem5 Developers            {return disabledFault();}
14110037SARM gem5 Developers        if (trapEnCheck) {
14210037SARM gem5 Developers            CPSR cpsrEnCheck = Cpsr;
14310037SARM gem5 Developers            if (cpsrEnCheck.mode == MODE_HYP) {
14410037SARM gem5 Developers                return new UndefinedInstruction(machInst, issEnCheck,
14510037SARM gem5 Developers                                                EC_TRAPPED_HCPTR);
14610037SARM gem5 Developers            } else {
14710037SARM gem5 Developers                if (!inSecureState(Scr, Cpsr)) {
14810037SARM gem5 Developers                    return new HypervisorTrap(machInst, issEnCheck,
14910037SARM gem5 Developers                                              EC_TRAPPED_HCPTR);
15010037SARM gem5 Developers                }
15110037SARM gem5 Developers            }
15210037SARM gem5 Developers        }
1538303SAli.Saidi@ARM.com    '''
1547640Sgblack@eecs.umich.edu}};
1557640Sgblack@eecs.umich.edu
1567396Sgblack@eecs.umich.edudef template FpRegRegOpDeclare {{
1577375Sgblack@eecs.umich.educlass %(class_name)s : public %(base_class)s
1587375Sgblack@eecs.umich.edu{
1597396Sgblack@eecs.umich.edu  public:
1607396Sgblack@eecs.umich.edu    // Constructor
1617396Sgblack@eecs.umich.edu    %(class_name)s(ExtMachInst machInst,
1627396Sgblack@eecs.umich.edu                   IntRegIndex _dest, IntRegIndex _op1,
1637396Sgblack@eecs.umich.edu                   VfpMicroMode mode = VfpNotAMicroop);
1647396Sgblack@eecs.umich.edu    %(BasicExecDeclare)s
1657375Sgblack@eecs.umich.edu};
1667375Sgblack@eecs.umich.edu}};
1677375Sgblack@eecs.umich.edu
1687396Sgblack@eecs.umich.edudef template FpRegRegOpConstructor {{
16910184SCurtis.Dunham@arm.com    %(class_name)s::%(class_name)s(ExtMachInst machInst,
1707375Sgblack@eecs.umich.edu                                          IntRegIndex _dest, IntRegIndex _op1,
1717375Sgblack@eecs.umich.edu                                          VfpMicroMode mode)
1727375Sgblack@eecs.umich.edu        : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
1737375Sgblack@eecs.umich.edu                _dest, _op1, mode)
1747375Sgblack@eecs.umich.edu    {
1757375Sgblack@eecs.umich.edu        %(constructor)s;
1767848SAli.Saidi@ARM.com        if (!(condCode == COND_AL || condCode == COND_UC)) {
1777848SAli.Saidi@ARM.com            for (int x = 0; x < _numDestRegs; x++) {
1787848SAli.Saidi@ARM.com                _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
1797848SAli.Saidi@ARM.com            }
1807848SAli.Saidi@ARM.com        }
1817375Sgblack@eecs.umich.edu    }
1827375Sgblack@eecs.umich.edu}};
1837375Sgblack@eecs.umich.edu
1847396Sgblack@eecs.umich.edudef template FpRegImmOpDeclare {{
1857375Sgblack@eecs.umich.educlass %(class_name)s : public %(base_class)s
1867375Sgblack@eecs.umich.edu{
1877396Sgblack@eecs.umich.edu  public:
1887396Sgblack@eecs.umich.edu    // Constructor
1897396Sgblack@eecs.umich.edu    %(class_name)s(ExtMachInst machInst, IntRegIndex _dest,
1907396Sgblack@eecs.umich.edu            uint64_t _imm, VfpMicroMode mode = VfpNotAMicroop);
1917396Sgblack@eecs.umich.edu    %(BasicExecDeclare)s
1927375Sgblack@eecs.umich.edu};
1937375Sgblack@eecs.umich.edu}};
1947375Sgblack@eecs.umich.edu
1957396Sgblack@eecs.umich.edudef template FpRegImmOpConstructor {{
19610184SCurtis.Dunham@arm.com    %(class_name)s::%(class_name)s(ExtMachInst machInst,
1977375Sgblack@eecs.umich.edu            IntRegIndex _dest, uint64_t _imm, VfpMicroMode mode)
1987375Sgblack@eecs.umich.edu        : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
1997375Sgblack@eecs.umich.edu                _dest, _imm, mode)
2007375Sgblack@eecs.umich.edu    {
2017375Sgblack@eecs.umich.edu        %(constructor)s;
2027848SAli.Saidi@ARM.com        if (!(condCode == COND_AL || condCode == COND_UC)) {
2037848SAli.Saidi@ARM.com            for (int x = 0; x < _numDestRegs; x++) {
2047848SAli.Saidi@ARM.com                _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
2057848SAli.Saidi@ARM.com            }
2067848SAli.Saidi@ARM.com        }
2077375Sgblack@eecs.umich.edu    }
2087375Sgblack@eecs.umich.edu}};
2097375Sgblack@eecs.umich.edu
2107396Sgblack@eecs.umich.edudef template FpRegRegImmOpDeclare {{
2117375Sgblack@eecs.umich.educlass %(class_name)s : public %(base_class)s
2127375Sgblack@eecs.umich.edu{
2137396Sgblack@eecs.umich.edu  public:
2147396Sgblack@eecs.umich.edu    // Constructor
2157396Sgblack@eecs.umich.edu    %(class_name)s(ExtMachInst machInst,
2167396Sgblack@eecs.umich.edu                   IntRegIndex _dest, IntRegIndex _op1,
2177396Sgblack@eecs.umich.edu                   uint64_t _imm, VfpMicroMode mode = VfpNotAMicroop);
2187396Sgblack@eecs.umich.edu    %(BasicExecDeclare)s
2197375Sgblack@eecs.umich.edu};
2207375Sgblack@eecs.umich.edu}};
2217375Sgblack@eecs.umich.edu
2227396Sgblack@eecs.umich.edudef template FpRegRegImmOpConstructor {{
22310184SCurtis.Dunham@arm.com    %(class_name)s::%(class_name)s(ExtMachInst machInst,
2247375Sgblack@eecs.umich.edu                                          IntRegIndex _dest,
2257375Sgblack@eecs.umich.edu                                          IntRegIndex _op1,
2267375Sgblack@eecs.umich.edu                                          uint64_t _imm,
2277375Sgblack@eecs.umich.edu                                          VfpMicroMode mode)
2287375Sgblack@eecs.umich.edu        : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
2297375Sgblack@eecs.umich.edu                         _dest, _op1, _imm, mode)
2307375Sgblack@eecs.umich.edu    {
2317375Sgblack@eecs.umich.edu        %(constructor)s;
2327848SAli.Saidi@ARM.com        if (!(condCode == COND_AL || condCode == COND_UC)) {
2337848SAli.Saidi@ARM.com            for (int x = 0; x < _numDestRegs; x++) {
2347848SAli.Saidi@ARM.com                _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
2357848SAli.Saidi@ARM.com            }
2367848SAli.Saidi@ARM.com        }
2377375Sgblack@eecs.umich.edu    }
2387375Sgblack@eecs.umich.edu}};
2397375Sgblack@eecs.umich.edu
2407396Sgblack@eecs.umich.edudef template FpRegRegRegOpDeclare {{
2417375Sgblack@eecs.umich.educlass %(class_name)s : public %(base_class)s
2427375Sgblack@eecs.umich.edu{
2437396Sgblack@eecs.umich.edu  public:
2447396Sgblack@eecs.umich.edu    // Constructor
2457396Sgblack@eecs.umich.edu    %(class_name)s(ExtMachInst machInst,
2467396Sgblack@eecs.umich.edu                   IntRegIndex _dest, IntRegIndex _op1, IntRegIndex _op2,
2477396Sgblack@eecs.umich.edu                   VfpMicroMode mode = VfpNotAMicroop);
2487396Sgblack@eecs.umich.edu    %(BasicExecDeclare)s
2497375Sgblack@eecs.umich.edu};
2507375Sgblack@eecs.umich.edu}};
2517375Sgblack@eecs.umich.edu
2527396Sgblack@eecs.umich.edudef template FpRegRegRegOpConstructor {{
25310184SCurtis.Dunham@arm.com    %(class_name)s::%(class_name)s(ExtMachInst machInst,
2547375Sgblack@eecs.umich.edu                                          IntRegIndex _dest,
2557375Sgblack@eecs.umich.edu                                          IntRegIndex _op1,
2567375Sgblack@eecs.umich.edu                                          IntRegIndex _op2,
2577375Sgblack@eecs.umich.edu                                          VfpMicroMode mode)
2587375Sgblack@eecs.umich.edu        : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
2597375Sgblack@eecs.umich.edu                         _dest, _op1, _op2, mode)
2607375Sgblack@eecs.umich.edu    {
2617375Sgblack@eecs.umich.edu        %(constructor)s;
2627848SAli.Saidi@ARM.com        if (!(condCode == COND_AL || condCode == COND_UC)) {
2637848SAli.Saidi@ARM.com            for (int x = 0; x < _numDestRegs; x++) {
2647848SAli.Saidi@ARM.com                _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
2657848SAli.Saidi@ARM.com            }
2667848SAli.Saidi@ARM.com        }
2677375Sgblack@eecs.umich.edu    }
2687375Sgblack@eecs.umich.edu}};
269