isa.cc revision 7408
12810SN/A/*
210764Sandreas.hansson@arm.com * Copyright (c) 2010 ARM Limited
39663Suri.wiener@arm.com * All rights reserved
49663Suri.wiener@arm.com *
59663Suri.wiener@arm.com * The license below extends only to copyright in the software and shall
69663Suri.wiener@arm.com * not be construed as granting a license to any other intellectual
79663Suri.wiener@arm.com * property including but not limited to intellectual property relating
89663Suri.wiener@arm.com * to a hardware implementation of the functionality of the software
99663Suri.wiener@arm.com * licensed hereunder.  You may use the software subject to the license
109663Suri.wiener@arm.com * terms below provided that you ensure that this notice is replicated
119663Suri.wiener@arm.com * unmodified and in its entirety in all distributions of the software,
129663Suri.wiener@arm.com * modified or unmodified, in source code or in binary form.
139663Suri.wiener@arm.com *
142810SN/A * Redistribution and use in source and binary forms, with or without
157636Ssteve.reinhardt@amd.com * modification, are permitted provided that the following conditions are
162810SN/A * met: redistributions of source code must retain the above copyright
172810SN/A * notice, this list of conditions and the following disclaimer;
182810SN/A * redistributions in binary form must reproduce the above copyright
192810SN/A * notice, this list of conditions and the following disclaimer in the
202810SN/A * documentation and/or other materials provided with the distribution;
212810SN/A * neither the name of the copyright holders nor the names of its
222810SN/A * contributors may be used to endorse or promote products derived from
232810SN/A * this software without specific prior written permission.
242810SN/A *
252810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
262810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
272810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
282810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
312810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
322810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
332810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
342810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
352810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
362810SN/A *
372810SN/A * Authors: Gabe Black
382810SN/A *          Ali Saidi
392810SN/A */
402810SN/A
412810SN/A#include "arch/arm/isa.hh"
422810SN/A
432810SN/Anamespace ArmISA
442810SN/A{
452810SN/A
462810SN/AMiscReg
472810SN/AISA::readMiscRegNoEffect(int misc_reg)
482810SN/A{
492810SN/A    assert(misc_reg < NumMiscRegs);
506216Snate@binkert.org    if (misc_reg == MISCREG_SPSR) {
516216Snate@binkert.org        CPSR cpsr = miscRegs[MISCREG_CPSR];
522810SN/A        switch (cpsr.mode) {
532810SN/A          case MODE_USER:
542810SN/A            return miscRegs[MISCREG_SPSR];
556216Snate@binkert.org          case MODE_FIQ:
566216Snate@binkert.org            return miscRegs[MISCREG_SPSR_FIQ];
578232Snate@binkert.org          case MODE_IRQ:
586216Snate@binkert.org            return miscRegs[MISCREG_SPSR_IRQ];
595338Sstever@gmail.com          case MODE_SVC:
606216Snate@binkert.org            return miscRegs[MISCREG_SPSR_SVC];
612810SN/A          case MODE_MON:
622810SN/A            return miscRegs[MISCREG_SPSR_MON];
632810SN/A          case MODE_ABORT:
649725Sandreas.hansson@arm.com            return miscRegs[MISCREG_SPSR_ABT];
6510582SCurtis.Dunham@arm.com          case MODE_UNDEFINED:
6610503SCurtis.Dunham@arm.com            return miscRegs[MISCREG_SPSR_UND];
6710764Sandreas.hansson@arm.com          default:
6810764Sandreas.hansson@arm.com            return miscRegs[MISCREG_SPSR];
6910503SCurtis.Dunham@arm.com        }
702810SN/A    }
712810SN/A    return miscRegs[misc_reg];
722810SN/A}
734903SN/A
744903SN/A
754903SN/AMiscReg
764903SN/AISA::readMiscReg(int misc_reg, ThreadContext *tc)
774903SN/A{
784903SN/A    if (misc_reg == MISCREG_CPSR) {
794903SN/A        CPSR cpsr = miscRegs[misc_reg];
804908SN/A        Addr pc = tc->readPC();
815875Ssteve.reinhardt@amd.com        if (pc & (ULL(1) << PcJBitShift))
824903SN/A            cpsr.j = 1;
835875Ssteve.reinhardt@amd.com        else
844903SN/A            cpsr.j = 0;
854903SN/A        if (pc & (ULL(1) << PcTBitShift))
864903SN/A            cpsr.t = 1;
874903SN/A        else
887669Ssteve.reinhardt@amd.com            cpsr.t = 0;
897669Ssteve.reinhardt@amd.com        return cpsr;
907669Ssteve.reinhardt@amd.com    }
917669Ssteve.reinhardt@amd.com    if (misc_reg >= MISCREG_CP15_UNIMP_START &&
924903SN/A        misc_reg < MISCREG_CP15_END) {
934903SN/A        panic("Unimplemented CP15 register %s read.\n",
945318SN/A              miscRegName[misc_reg]);
954908SN/A    }
965318SN/A    switch (misc_reg) {
979543Ssascha.bischoff@arm.com      case MISCREG_CLIDR:
989543Ssascha.bischoff@arm.com        warn("The clidr register always reports 0 caches.\n");
999543Ssascha.bischoff@arm.com        break;
1009543Ssascha.bischoff@arm.com      case MISCREG_CCSIDR:
1014908SN/A        warn("The ccsidr register isn't implemented and "
1024908SN/A                "always reads as 0.\n");
1034908SN/A        break;
1044908SN/A      case MISCREG_ID_PFR0:
1054903SN/A        return 0x1031; // ThumbEE | !Jazelle | Thumb | ARM
1064903SN/A    }
10710766Sandreas.hansson@arm.com    return readMiscRegNoEffect(misc_reg);
1084903SN/A}
1094903SN/A
1104903SN/Avoid
1117667Ssteve.reinhardt@amd.comISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
1127667Ssteve.reinhardt@amd.com{
1137667Ssteve.reinhardt@amd.com    assert(misc_reg < NumMiscRegs);
1147667Ssteve.reinhardt@amd.com    if (misc_reg == MISCREG_SPSR) {
1157667Ssteve.reinhardt@amd.com        CPSR cpsr = miscRegs[MISCREG_CPSR];
1167667Ssteve.reinhardt@amd.com        switch (cpsr.mode) {
1177667Ssteve.reinhardt@amd.com          case MODE_USER:
1187667Ssteve.reinhardt@amd.com            miscRegs[MISCREG_SPSR] = val;
1197667Ssteve.reinhardt@amd.com            return;
1207669Ssteve.reinhardt@amd.com          case MODE_FIQ:
1217669Ssteve.reinhardt@amd.com            miscRegs[MISCREG_SPSR_FIQ] = val;
1227669Ssteve.reinhardt@amd.com            return;
1237667Ssteve.reinhardt@amd.com          case MODE_IRQ:
1247667Ssteve.reinhardt@amd.com            miscRegs[MISCREG_SPSR_IRQ] = val;
1257667Ssteve.reinhardt@amd.com            return;
1267667Ssteve.reinhardt@amd.com          case MODE_SVC:
1274903SN/A            miscRegs[MISCREG_SPSR_SVC] = val;
1284903SN/A            return;
1294903SN/A          case MODE_MON:
1304903SN/A            miscRegs[MISCREG_SPSR_MON] = val;
1314903SN/A            return;
1324903SN/A          case MODE_ABORT:
13310766Sandreas.hansson@arm.com            miscRegs[MISCREG_SPSR_ABT] = val;
13410766Sandreas.hansson@arm.com            return;
1354903SN/A          case MODE_UNDEFINED:
1364903SN/A            miscRegs[MISCREG_SPSR_UND] = val;
1374903SN/A            return;
1384903SN/A          default:
1394903SN/A            miscRegs[MISCREG_SPSR] = val;
1404903SN/A            return;
1412810SN/A        }
1424908SN/A    }
1434908SN/A    miscRegs[misc_reg] = val;
14410766Sandreas.hansson@arm.com}
14510766Sandreas.hansson@arm.com
1469543Ssascha.bischoff@arm.comvoid
1479543Ssascha.bischoff@arm.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
1489543Ssascha.bischoff@arm.com{
1499543Ssascha.bischoff@arm.com    MiscReg newVal = val;
1509543Ssascha.bischoff@arm.com    if (misc_reg == MISCREG_CPSR) {
1519543Ssascha.bischoff@arm.com        updateRegMap(val);
15210766Sandreas.hansson@arm.com        CPSR cpsr = val;
1535318SN/A        DPRINTF(Arm, "Updating CPSR to %#x f:%d i:%d a:%d mode:%#x\n",
1545318SN/A                cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
1555318SN/A        Addr npc = tc->readNextPC() & ~PcModeMask;
1564908SN/A        if (cpsr.j)
1574908SN/A            npc = npc | (ULL(1) << PcJBitShift);
1584908SN/A        if (cpsr.t)
1594908SN/A            npc = npc | (ULL(1) << PcTBitShift);
1604908SN/A
1614920SN/A        tc->setNextPC(npc);
1624920SN/A    } else if (misc_reg >= MISCREG_CP15_UNIMP_START &&
1634920SN/A        misc_reg < MISCREG_CP15_END) {
16410766Sandreas.hansson@arm.com        panic("Unimplemented CP15 register %s wrote with %#x.\n",
16510766Sandreas.hansson@arm.com              miscRegName[misc_reg], val);
1664920SN/A    } else {
1674920SN/A        switch (misc_reg) {
1684920SN/A          case MISCREG_ITSTATE:
1694920SN/A            {
1704920SN/A                ITSTATE itstate = newVal;
1714920SN/A                CPSR cpsr = miscRegs[MISCREG_CPSR];
1724920SN/A                cpsr.it1 = itstate.bottom2;
1734920SN/A                cpsr.it2 = itstate.top6;
1744908SN/A                miscRegs[MISCREG_CPSR] = cpsr;
17510766Sandreas.hansson@arm.com                DPRINTF(MiscRegs,
17610766Sandreas.hansson@arm.com                        "Updating ITSTATE -> %#x in CPSR -> %#x.\n",
1775314SN/A                        (uint8_t)itstate, (uint32_t)cpsr);
17810766Sandreas.hansson@arm.com            }
1795875Ssteve.reinhardt@amd.com            break;
18010766Sandreas.hansson@arm.com          case MISCREG_CPACR:
1818988SAli.Saidi@ARM.com            {
1828988SAli.Saidi@ARM.com                CPACR newCpacr = 0;
1838988SAli.Saidi@ARM.com                CPACR valCpacr = val;
1848988SAli.Saidi@ARM.com                newCpacr.cp10 = valCpacr.cp10;
1858988SAli.Saidi@ARM.com                newCpacr.cp11 = valCpacr.cp11;
1868988SAli.Saidi@ARM.com                if (newCpacr.cp10 != 0x3 || newCpacr.cp11 != 3) {
1878988SAli.Saidi@ARM.com                    panic("Disabling coprocessors isn't implemented.\n");
1888988SAli.Saidi@ARM.com                }
1898988SAli.Saidi@ARM.com                newVal = newCpacr;
1908988SAli.Saidi@ARM.com            }
1918988SAli.Saidi@ARM.com            break;
1928988SAli.Saidi@ARM.com          case MISCREG_CSSELR:
1935875Ssteve.reinhardt@amd.com            warn("The csselr register isn't implemented.\n");
1945875Ssteve.reinhardt@amd.com            break;
19510766Sandreas.hansson@arm.com          case MISCREG_FPSCR:
1965314SN/A            {
1975314SN/A                const uint32_t ones = (uint32_t)(-1);
1985314SN/A                FPSCR fpscrMask = 0;
1995314SN/A                fpscrMask.ioc = ones;
2005314SN/A                fpscrMask.dzc = ones;
20110764Sandreas.hansson@arm.com                fpscrMask.ofc = ones;
20210764Sandreas.hansson@arm.com                fpscrMask.ufc = ones;
2032810SN/A                fpscrMask.ixc = ones;
20410764Sandreas.hansson@arm.com                fpscrMask.idc = ones;
20510764Sandreas.hansson@arm.com                fpscrMask.len = ones;
20610028SGiacomo.Gabrielli@arm.com                fpscrMask.stride = ones;
20710764Sandreas.hansson@arm.com                fpscrMask.rMode = ones;
2084666SN/A                fpscrMask.fz = ones;
2094626SN/A                fpscrMask.dn = ones;
2105730SSteve.Reinhardt@amd.com                fpscrMask.ahp = ones;
2114626SN/A                fpscrMask.qc = ones;
2124626SN/A                fpscrMask.v = ones;
2134908SN/A                fpscrMask.c = ones;
2144626SN/A                fpscrMask.z = ones;
2159725Sandreas.hansson@arm.com                fpscrMask.n = ones;
2164626SN/A                newVal = (newVal & (uint32_t)fpscrMask) |
2175875Ssteve.reinhardt@amd.com                         (miscRegs[MISCREG_FPSCR] & ~(uint32_t)fpscrMask);
2185875Ssteve.reinhardt@amd.com            }
2195875Ssteve.reinhardt@amd.com            break;
22010764Sandreas.hansson@arm.com          case MISCREG_FPEXC:
2219725Sandreas.hansson@arm.com            {
2224668SN/A                const uint32_t fpexcMask = 0x60000000;
2232810SN/A                newVal = (newVal & fpexcMask) |
2242810SN/A                         (miscRegs[MISCREG_FPEXC] & ~fpexcMask);
2254908SN/A            }
2265318SN/A            break;
2275318SN/A          case MISCREG_SCTLR:
2285318SN/A            {
2295318SN/A                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
2305318SN/A                SCTLR sctlr = miscRegs[MISCREG_SCTLR];
2315318SN/A                SCTLR new_sctlr = newVal;
2325318SN/A                new_sctlr.nmfi =  (bool)sctlr.nmfi;
2339725Sandreas.hansson@arm.com                miscRegs[MISCREG_SCTLR] = (MiscReg)new_sctlr;
2345318SN/A                return;
2355318SN/A            }
2364908SN/A          case MISCREG_TLBTR:
23710679Sandreas.hansson@arm.com          case MISCREG_MVFR0:
2384908SN/A          case MISCREG_MVFR1:
2394908SN/A          case MISCREG_MPIDR:
2405730SSteve.Reinhardt@amd.com          case MISCREG_FPSID:
2414908SN/A            return;
2424908SN/A          case MISCREG_TLBIALLIS:
2434908SN/A          case MISCREG_TLBIALL:
2444908SN/A            warn("Need to flush all TLBs in MP\n");
2454908SN/A            tc->getITBPtr()->flushAll();
2464908SN/A            tc->getDTBPtr()->flushAll();
24710424Sandreas.hansson@arm.com            return;
2484908SN/A          case MISCREG_ITLBIALL:
24910679Sandreas.hansson@arm.com            tc->getITBPtr()->flushAll();
2507667Ssteve.reinhardt@amd.com            return;
2517667Ssteve.reinhardt@amd.com          case MISCREG_DTLBIALL:
2524908SN/A            tc->getDTBPtr()->flushAll();
2534908SN/A            return;
2544908SN/A          case MISCREG_TLBIMVAIS:
2559725Sandreas.hansson@arm.com          case MISCREG_TLBIMVA:
2564908SN/A            warn("Need to flush all TLBs in MP\n");
2574908SN/A            tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
2584908SN/A                    bits(newVal, 7,0));
2594908SN/A            tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
2604908SN/A                    bits(newVal, 7,0));
2612810SN/A            return;
2622810SN/A          case MISCREG_TLBIASIDIS:
2632810SN/A          case MISCREG_TLBIASID:
2649725Sandreas.hansson@arm.com            warn("Need to flush all TLBs in MP\n");
2659725Sandreas.hansson@arm.com            tc->getITBPtr()->flushAsid(bits(newVal, 7,0));
2669725Sandreas.hansson@arm.com            tc->getDTBPtr()->flushAsid(bits(newVal, 7,0));
2672810SN/A            return;
2682810SN/A          case MISCREG_TLBIMVAAIS:
2692810SN/A          case MISCREG_TLBIMVAA:
2702810SN/A            warn("Need to flush all TLBs in MP\n");
2712810SN/A            tc->getITBPtr()->flushMva(mbits(newVal, 31,12));
2722810SN/A            tc->getDTBPtr()->flushMva(mbits(newVal, 31,12));
2732810SN/A            return;
2744903SN/A          case MISCREG_ITLBIMVA:
2752810SN/A            tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
27610768Sandreas.hansson@arm.com                    bits(newVal, 7,0));
27710768Sandreas.hansson@arm.com            return;
27810768Sandreas.hansson@arm.com          case MISCREG_DTLBIMVA:
27910768Sandreas.hansson@arm.com            tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
28010768Sandreas.hansson@arm.com                    bits(newVal, 7,0));
28110768Sandreas.hansson@arm.com            return;
28210768Sandreas.hansson@arm.com          case MISCREG_ITLBIASID:
28310768Sandreas.hansson@arm.com            tc->getITBPtr()->flushAsid(bits(newVal, 7,0));
28410768Sandreas.hansson@arm.com            return;
2854903SN/A          case MISCREG_DTLBIASID:
2864903SN/A            tc->getDTBPtr()->flushAsid(bits(newVal, 7,0));
2874903SN/A            return;
2884903SN/A        }
2894903SN/A    }
2904903SN/A    setMiscRegNoEffect(misc_reg, newVal);
2917667Ssteve.reinhardt@amd.com}
2927667Ssteve.reinhardt@amd.com
2937667Ssteve.reinhardt@amd.com}
2947667Ssteve.reinhardt@amd.com