isa.cc revision 7436
19646SChris.Emmons@arm.com/*
211898Ssudhanshu.jha@arm.com * Copyright (c) 2010 ARM Limited
39646SChris.Emmons@arm.com * All rights reserved
49646SChris.Emmons@arm.com *
59646SChris.Emmons@arm.com * The license below extends only to copyright in the software and shall
69646SChris.Emmons@arm.com * not be construed as granting a license to any other intellectual
79646SChris.Emmons@arm.com * property including but not limited to intellectual property relating
89646SChris.Emmons@arm.com * to a hardware implementation of the functionality of the software
99646SChris.Emmons@arm.com * licensed hereunder.  You may use the software subject to the license
109646SChris.Emmons@arm.com * terms below provided that you ensure that this notice is replicated
119646SChris.Emmons@arm.com * unmodified and in its entirety in all distributions of the software,
129646SChris.Emmons@arm.com * modified or unmodified, in source code or in binary form.
139646SChris.Emmons@arm.com *
149646SChris.Emmons@arm.com * Redistribution and use in source and binary forms, with or without
159646SChris.Emmons@arm.com * modification, are permitted provided that the following conditions are
169646SChris.Emmons@arm.com * met: redistributions of source code must retain the above copyright
179646SChris.Emmons@arm.com * notice, this list of conditions and the following disclaimer;
189646SChris.Emmons@arm.com * redistributions in binary form must reproduce the above copyright
199646SChris.Emmons@arm.com * notice, this list of conditions and the following disclaimer in the
209646SChris.Emmons@arm.com * documentation and/or other materials provided with the distribution;
219646SChris.Emmons@arm.com * neither the name of the copyright holders nor the names of its
229646SChris.Emmons@arm.com * contributors may be used to endorse or promote products derived from
239646SChris.Emmons@arm.com * this software without specific prior written permission.
249646SChris.Emmons@arm.com *
259646SChris.Emmons@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
269646SChris.Emmons@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
279646SChris.Emmons@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
289646SChris.Emmons@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
299646SChris.Emmons@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
309646SChris.Emmons@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
319646SChris.Emmons@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
329646SChris.Emmons@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
339646SChris.Emmons@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
349646SChris.Emmons@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
359646SChris.Emmons@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
369646SChris.Emmons@arm.com *
379646SChris.Emmons@arm.com * Authors: Gabe Black
3811090Sandreas.sandberg@arm.com *          Ali Saidi
399646SChris.Emmons@arm.com */
409646SChris.Emmons@arm.com
419646SChris.Emmons@arm.com#include "arch/arm/isa.hh"
429646SChris.Emmons@arm.com
439646SChris.Emmons@arm.comnamespace ArmISA
449646SChris.Emmons@arm.com{
459646SChris.Emmons@arm.com
469646SChris.Emmons@arm.comvoid
479646SChris.Emmons@arm.comISA::clear()
489646SChris.Emmons@arm.com{
499646SChris.Emmons@arm.com    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
509646SChris.Emmons@arm.com
519646SChris.Emmons@arm.com    memset(miscRegs, 0, sizeof(miscRegs));
529646SChris.Emmons@arm.com    CPSR cpsr = 0;
539646SChris.Emmons@arm.com    cpsr.mode = MODE_USER;
549646SChris.Emmons@arm.com    miscRegs[MISCREG_CPSR] = cpsr;
559646SChris.Emmons@arm.com    updateRegMap(cpsr);
569646SChris.Emmons@arm.com
579646SChris.Emmons@arm.com    SCTLR sctlr = 0;
589646SChris.Emmons@arm.com    sctlr.nmfi = (bool)sctlr_rst.nmfi;
599646SChris.Emmons@arm.com    sctlr.v = (bool)sctlr_rst.v;
609646SChris.Emmons@arm.com    sctlr.u    = 1;
619646SChris.Emmons@arm.com    sctlr.xp = 1;
629646SChris.Emmons@arm.com    sctlr.rao2 = 1;
639646SChris.Emmons@arm.com    sctlr.rao3 = 1;
649646SChris.Emmons@arm.com    sctlr.rao4 = 1;
6511090Sandreas.sandberg@arm.com    miscRegs[MISCREG_SCTLR] = sctlr;
6611090Sandreas.sandberg@arm.com    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
6711090Sandreas.sandberg@arm.com
6811090Sandreas.sandberg@arm.com
6911090Sandreas.sandberg@arm.com    /*
7011090Sandreas.sandberg@arm.com     * Technically this should be 0, but we don't support those
7111090Sandreas.sandberg@arm.com     * settings.
7211090Sandreas.sandberg@arm.com     */
7311090Sandreas.sandberg@arm.com    CPACR cpacr = 0;
749646SChris.Emmons@arm.com    // Enable CP 10, 11
759646SChris.Emmons@arm.com    cpacr.cp10 = 0x3;
769646SChris.Emmons@arm.com    cpacr.cp11 = 0x3;
779646SChris.Emmons@arm.com    miscRegs[MISCREG_CPACR] = cpacr;
789646SChris.Emmons@arm.com
799646SChris.Emmons@arm.com    /* Start with an event in the mailbox */
8010839Sandreas.sandberg@arm.com    miscRegs[MISCREG_SEV_MAILBOX] = 1;
819646SChris.Emmons@arm.com
8210839Sandreas.sandberg@arm.com    /*
8310839Sandreas.sandberg@arm.com     * Implemented = '5' from "M5",
8411359Sandreas@sandberg.pp.se     * Variant = 0,
859646SChris.Emmons@arm.com     */
8611090Sandreas.sandberg@arm.com    miscRegs[MISCREG_MIDR] =
879646SChris.Emmons@arm.com        (0x35 << 24) | //Implementor is '5' from "M5"
889646SChris.Emmons@arm.com        (0 << 20)    | //Variant
899646SChris.Emmons@arm.com        (0xf << 16)  | //Architecture from CPUID scheme
9011090Sandreas.sandberg@arm.com        (0 << 4)     | //Primary part number
9111090Sandreas.sandberg@arm.com        (0 << 0)     | //Revision
929646SChris.Emmons@arm.com        0;
939646SChris.Emmons@arm.com
949646SChris.Emmons@arm.com    // Separate Instruction and Data TLBs.
9511090Sandreas.sandberg@arm.com    miscRegs[MISCREG_TLBTR] = 1;
9611090Sandreas.sandberg@arm.com
9711090Sandreas.sandberg@arm.com    MVFR0 mvfr0 = 0;
989646SChris.Emmons@arm.com    mvfr0.advSimdRegisters = 2;
9911168Sandreas.hansson@arm.com    mvfr0.singlePrecision = 2;
10011091Sandreas.sandberg@arm.com    mvfr0.doublePrecision = 2;
10111168Sandreas.hansson@arm.com    mvfr0.vfpExceptionTrapping = 0;
10211168Sandreas.hansson@arm.com    mvfr0.divide = 1;
10311090Sandreas.sandberg@arm.com    mvfr0.squareRoot = 1;
10411168Sandreas.hansson@arm.com    mvfr0.shortVectors = 1;
10511090Sandreas.sandberg@arm.com    mvfr0.roundingModes = 1;
10611090Sandreas.sandberg@arm.com    miscRegs[MISCREG_MVFR0] = mvfr0;
10711168Sandreas.hansson@arm.com
10811168Sandreas.hansson@arm.com    MVFR1 mvfr1 = 0;
10911090Sandreas.sandberg@arm.com    mvfr1.flushToZero = 1;
11011168Sandreas.hansson@arm.com    mvfr1.defaultNaN = 1;
11111090Sandreas.sandberg@arm.com    mvfr1.advSimdLoadStore = 1;
11211090Sandreas.sandberg@arm.com    mvfr1.advSimdInteger = 1;
11311090Sandreas.sandberg@arm.com    mvfr1.advSimdSinglePrecision = 1;
11411090Sandreas.sandberg@arm.com    mvfr1.advSimdHalfPrecision = 1;
11511090Sandreas.sandberg@arm.com    mvfr1.vfpHalfPrecision = 1;
11611090Sandreas.sandberg@arm.com    miscRegs[MISCREG_MVFR1] = mvfr1;
11711090Sandreas.sandberg@arm.com
11811090Sandreas.sandberg@arm.com    miscRegs[MISCREG_MPIDR] = 0;
11911898Ssudhanshu.jha@arm.com
12011090Sandreas.sandberg@arm.com    // Reset values of PRRR and NMRR are implementation dependent
12111090Sandreas.sandberg@arm.com
1229646SChris.Emmons@arm.com    miscRegs[MISCREG_PRRR] =
1239646SChris.Emmons@arm.com        (1 << 19) | // 19
1249646SChris.Emmons@arm.com        (0 << 18) | // 18
1259646SChris.Emmons@arm.com        (0 << 17) | // 17
1269646SChris.Emmons@arm.com        (1 << 16) | // 16
1279646SChris.Emmons@arm.com        (2 << 14) | // 15:14
1289646SChris.Emmons@arm.com        (0 << 12) | // 13:12
1299646SChris.Emmons@arm.com        (2 << 10) | // 11:10
1309646SChris.Emmons@arm.com        (2 << 8)  | // 9:8
1319646SChris.Emmons@arm.com        (2 << 6)  | // 7:6
1329646SChris.Emmons@arm.com        (2 << 4)  | // 5:4
1339646SChris.Emmons@arm.com        (1 << 2)  | // 3:2
1349646SChris.Emmons@arm.com        0;          // 1:0
1359646SChris.Emmons@arm.com    miscRegs[MISCREG_NMRR] =
1369646SChris.Emmons@arm.com        (1 << 30) | // 31:30
1379646SChris.Emmons@arm.com        (0 << 26) | // 27:26
1389646SChris.Emmons@arm.com        (0 << 24) | // 25:24
1399646SChris.Emmons@arm.com        (3 << 22) | // 23:22
1409646SChris.Emmons@arm.com        (2 << 20) | // 21:20
1419646SChris.Emmons@arm.com        (0 << 18) | // 19:18
1429646SChris.Emmons@arm.com        (0 << 16) | // 17:16
1439646SChris.Emmons@arm.com        (1 << 14) | // 15:14
1449646SChris.Emmons@arm.com        (0 << 12) | // 13:12
1459646SChris.Emmons@arm.com        (2 << 10) | // 11:10
1469646SChris.Emmons@arm.com        (0 << 8)  | // 9:8
14711090Sandreas.sandberg@arm.com        (3 << 6)  | // 7:6
14811090Sandreas.sandberg@arm.com        (2 << 4)  | // 5:4
1499646SChris.Emmons@arm.com        (0 << 2)  | // 3:2
1509646SChris.Emmons@arm.com        0;          // 1:0
15111090Sandreas.sandberg@arm.com
1529646SChris.Emmons@arm.com    //XXX We need to initialize the rest of the state.
1539646SChris.Emmons@arm.com}
15411090Sandreas.sandberg@arm.com
1559646SChris.Emmons@arm.comMiscReg
15611090Sandreas.sandberg@arm.comISA::readMiscRegNoEffect(int misc_reg)
15711090Sandreas.sandberg@arm.com{
1589646SChris.Emmons@arm.com    assert(misc_reg < NumMiscRegs);
1599646SChris.Emmons@arm.com    if (misc_reg == MISCREG_SPSR) {
16011090Sandreas.sandberg@arm.com        CPSR cpsr = miscRegs[MISCREG_CPSR];
1619646SChris.Emmons@arm.com        switch (cpsr.mode) {
16211090Sandreas.sandberg@arm.com          case MODE_USER:
16311090Sandreas.sandberg@arm.com            return miscRegs[MISCREG_SPSR];
16410839Sandreas.sandberg@arm.com          case MODE_FIQ:
1659646SChris.Emmons@arm.com            return miscRegs[MISCREG_SPSR_FIQ];
1669646SChris.Emmons@arm.com          case MODE_IRQ:
1679646SChris.Emmons@arm.com            return miscRegs[MISCREG_SPSR_IRQ];
1689646SChris.Emmons@arm.com          case MODE_SVC:
1699646SChris.Emmons@arm.com            return miscRegs[MISCREG_SPSR_SVC];
1709646SChris.Emmons@arm.com          case MODE_MON:
1719646SChris.Emmons@arm.com            return miscRegs[MISCREG_SPSR_MON];
1729646SChris.Emmons@arm.com          case MODE_ABORT:
1739646SChris.Emmons@arm.com            return miscRegs[MISCREG_SPSR_ABT];
1749646SChris.Emmons@arm.com          case MODE_UNDEFINED:
1759646SChris.Emmons@arm.com            return miscRegs[MISCREG_SPSR_UND];
17611090Sandreas.sandberg@arm.com          default:
17711090Sandreas.sandberg@arm.com            return miscRegs[MISCREG_SPSR];
17811090Sandreas.sandberg@arm.com        }
17911090Sandreas.sandberg@arm.com    }
1809646SChris.Emmons@arm.com    return miscRegs[misc_reg];
1819646SChris.Emmons@arm.com}
1829646SChris.Emmons@arm.com
1839646SChris.Emmons@arm.com
1849646SChris.Emmons@arm.comMiscReg
1859646SChris.Emmons@arm.comISA::readMiscReg(int misc_reg, ThreadContext *tc)
1869646SChris.Emmons@arm.com{
1879646SChris.Emmons@arm.com    if (misc_reg == MISCREG_CPSR) {
1889646SChris.Emmons@arm.com        CPSR cpsr = miscRegs[misc_reg];
1899646SChris.Emmons@arm.com        Addr pc = tc->readPC();
1909646SChris.Emmons@arm.com        if (pc & (ULL(1) << PcJBitShift))
1919646SChris.Emmons@arm.com            cpsr.j = 1;
1929646SChris.Emmons@arm.com        else
1939646SChris.Emmons@arm.com            cpsr.j = 0;
1949646SChris.Emmons@arm.com        if (pc & (ULL(1) << PcTBitShift))
1959646SChris.Emmons@arm.com            cpsr.t = 1;
1969646SChris.Emmons@arm.com        else
1979646SChris.Emmons@arm.com            cpsr.t = 0;
1989646SChris.Emmons@arm.com        return cpsr;
1999646SChris.Emmons@arm.com    }
2009646SChris.Emmons@arm.com    if (misc_reg >= MISCREG_CP15_UNIMP_START &&
2019646SChris.Emmons@arm.com        misc_reg < MISCREG_CP15_END) {
2029646SChris.Emmons@arm.com        panic("Unimplemented CP15 register %s read.\n",
2039646SChris.Emmons@arm.com              miscRegName[misc_reg]);
2049646SChris.Emmons@arm.com    }
2059646SChris.Emmons@arm.com    switch (misc_reg) {
2069646SChris.Emmons@arm.com      case MISCREG_CLIDR:
2079646SChris.Emmons@arm.com        warn("The clidr register always reports 0 caches.\n");
2089646SChris.Emmons@arm.com        break;
2099646SChris.Emmons@arm.com      case MISCREG_CCSIDR:
2109646SChris.Emmons@arm.com        warn("The ccsidr register isn't implemented and "
2119646SChris.Emmons@arm.com                "always reads as 0.\n");
2129646SChris.Emmons@arm.com        break;
2139646SChris.Emmons@arm.com      case MISCREG_ID_PFR0:
2149646SChris.Emmons@arm.com        return 0x1031; // ThumbEE | !Jazelle | Thumb | ARM
2159646SChris.Emmons@arm.com    }
2169646SChris.Emmons@arm.com    return readMiscRegNoEffect(misc_reg);
2179646SChris.Emmons@arm.com}
2189646SChris.Emmons@arm.com
2199646SChris.Emmons@arm.comvoid
2209646SChris.Emmons@arm.comISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
2219646SChris.Emmons@arm.com{
2229646SChris.Emmons@arm.com    assert(misc_reg < NumMiscRegs);
2239646SChris.Emmons@arm.com    if (misc_reg == MISCREG_SPSR) {
2249646SChris.Emmons@arm.com        CPSR cpsr = miscRegs[MISCREG_CPSR];
2259646SChris.Emmons@arm.com        switch (cpsr.mode) {
2269646SChris.Emmons@arm.com          case MODE_USER:
2279646SChris.Emmons@arm.com            miscRegs[MISCREG_SPSR] = val;
2289646SChris.Emmons@arm.com            return;
2299646SChris.Emmons@arm.com          case MODE_FIQ:
2309646SChris.Emmons@arm.com            miscRegs[MISCREG_SPSR_FIQ] = val;
2319646SChris.Emmons@arm.com            return;
2329646SChris.Emmons@arm.com          case MODE_IRQ:
2339646SChris.Emmons@arm.com            miscRegs[MISCREG_SPSR_IRQ] = val;
23411090Sandreas.sandberg@arm.com            return;
23511090Sandreas.sandberg@arm.com          case MODE_SVC:
23611090Sandreas.sandberg@arm.com            miscRegs[MISCREG_SPSR_SVC] = val;
2379646SChris.Emmons@arm.com            return;
2389646SChris.Emmons@arm.com          case MODE_MON:
2399646SChris.Emmons@arm.com            miscRegs[MISCREG_SPSR_MON] = val;
24011090Sandreas.sandberg@arm.com            return;
2419646SChris.Emmons@arm.com          case MODE_ABORT:
2429646SChris.Emmons@arm.com            miscRegs[MISCREG_SPSR_ABT] = val;
2439646SChris.Emmons@arm.com            return;
2449646SChris.Emmons@arm.com          case MODE_UNDEFINED:
2459646SChris.Emmons@arm.com            miscRegs[MISCREG_SPSR_UND] = val;
2469646SChris.Emmons@arm.com            return;
2479646SChris.Emmons@arm.com          default:
2489646SChris.Emmons@arm.com            miscRegs[MISCREG_SPSR] = val;
2499646SChris.Emmons@arm.com            return;
2509646SChris.Emmons@arm.com        }
2519646SChris.Emmons@arm.com    }
2529646SChris.Emmons@arm.com    miscRegs[misc_reg] = val;
2539646SChris.Emmons@arm.com}
2549646SChris.Emmons@arm.com
2559646SChris.Emmons@arm.comvoid
2569646SChris.Emmons@arm.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
2579646SChris.Emmons@arm.com{
25811090Sandreas.sandberg@arm.com    MiscReg newVal = val;
25911090Sandreas.sandberg@arm.com    if (misc_reg == MISCREG_CPSR) {
2609646SChris.Emmons@arm.com        updateRegMap(val);
26111090Sandreas.sandberg@arm.com        CPSR cpsr = val;
26211090Sandreas.sandberg@arm.com        DPRINTF(Arm, "Updating CPSR to %#x f:%d i:%d a:%d mode:%#x\n",
26310839Sandreas.sandberg@arm.com                cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
26411090Sandreas.sandberg@arm.com        Addr npc = tc->readNextPC() & ~PcModeMask;
26511090Sandreas.sandberg@arm.com        if (cpsr.j)
26611090Sandreas.sandberg@arm.com            npc = npc | (ULL(1) << PcJBitShift);
26711090Sandreas.sandberg@arm.com        if (cpsr.t)
26811090Sandreas.sandberg@arm.com            npc = npc | (ULL(1) << PcTBitShift);
26911090Sandreas.sandberg@arm.com
27011090Sandreas.sandberg@arm.com        tc->setNextPC(npc);
27111090Sandreas.sandberg@arm.com    } else if (misc_reg >= MISCREG_CP15_UNIMP_START &&
27211090Sandreas.sandberg@arm.com        misc_reg < MISCREG_CP15_END) {
27311090Sandreas.sandberg@arm.com        panic("Unimplemented CP15 register %s wrote with %#x.\n",
27411090Sandreas.sandberg@arm.com              miscRegName[misc_reg], val);
27511090Sandreas.sandberg@arm.com    } else {
27611090Sandreas.sandberg@arm.com        switch (misc_reg) {
27711090Sandreas.sandberg@arm.com          case MISCREG_ITSTATE:
27811090Sandreas.sandberg@arm.com            {
27911090Sandreas.sandberg@arm.com                ITSTATE itstate = newVal;
28011090Sandreas.sandberg@arm.com                CPSR cpsr = miscRegs[MISCREG_CPSR];
28111090Sandreas.sandberg@arm.com                cpsr.it1 = itstate.bottom2;
28211090Sandreas.sandberg@arm.com                cpsr.it2 = itstate.top6;
28311090Sandreas.sandberg@arm.com                miscRegs[MISCREG_CPSR] = cpsr;
28411090Sandreas.sandberg@arm.com                DPRINTF(MiscRegs,
28511090Sandreas.sandberg@arm.com                        "Updating ITSTATE -> %#x in CPSR -> %#x.\n",
28611090Sandreas.sandberg@arm.com                        (uint8_t)itstate, (uint32_t)cpsr);
28711090Sandreas.sandberg@arm.com            }
28811090Sandreas.sandberg@arm.com            break;
28911090Sandreas.sandberg@arm.com          case MISCREG_CPACR:
29011090Sandreas.sandberg@arm.com            {
29111090Sandreas.sandberg@arm.com                CPACR newCpacr = 0;
29211090Sandreas.sandberg@arm.com                CPACR valCpacr = val;
29311090Sandreas.sandberg@arm.com                newCpacr.cp10 = valCpacr.cp10;
29411090Sandreas.sandberg@arm.com                newCpacr.cp11 = valCpacr.cp11;
29511090Sandreas.sandberg@arm.com                if (newCpacr.cp10 != 0x3 || newCpacr.cp11 != 3) {
29611090Sandreas.sandberg@arm.com                    panic("Disabling coprocessors isn't implemented.\n");
29711090Sandreas.sandberg@arm.com                }
29811090Sandreas.sandberg@arm.com                newVal = newCpacr;
29911090Sandreas.sandberg@arm.com            }
30011090Sandreas.sandberg@arm.com            break;
30111090Sandreas.sandberg@arm.com          case MISCREG_CSSELR:
30211090Sandreas.sandberg@arm.com            warn("The csselr register isn't implemented.\n");
30311090Sandreas.sandberg@arm.com            break;
30411090Sandreas.sandberg@arm.com          case MISCREG_FPSCR:
30511090Sandreas.sandberg@arm.com            {
30611090Sandreas.sandberg@arm.com                const uint32_t ones = (uint32_t)(-1);
30711090Sandreas.sandberg@arm.com                FPSCR fpscrMask = 0;
30811090Sandreas.sandberg@arm.com                fpscrMask.ioc = ones;
30911090Sandreas.sandberg@arm.com                fpscrMask.dzc = ones;
31011090Sandreas.sandberg@arm.com                fpscrMask.ofc = ones;
31111090Sandreas.sandberg@arm.com                fpscrMask.ufc = ones;
31211090Sandreas.sandberg@arm.com                fpscrMask.ixc = ones;
31311090Sandreas.sandberg@arm.com                fpscrMask.idc = ones;
31411090Sandreas.sandberg@arm.com                fpscrMask.len = ones;
31511090Sandreas.sandberg@arm.com                fpscrMask.stride = ones;
31611090Sandreas.sandberg@arm.com                fpscrMask.rMode = ones;
31711090Sandreas.sandberg@arm.com                fpscrMask.fz = ones;
31811090Sandreas.sandberg@arm.com                fpscrMask.dn = ones;
31911090Sandreas.sandberg@arm.com                fpscrMask.ahp = ones;
32011090Sandreas.sandberg@arm.com                fpscrMask.qc = ones;
32111294Sandreas.hansson@arm.com                fpscrMask.v = ones;
32211090Sandreas.sandberg@arm.com                fpscrMask.c = ones;
32311090Sandreas.sandberg@arm.com                fpscrMask.z = ones;
32411090Sandreas.sandberg@arm.com                fpscrMask.n = ones;
32511090Sandreas.sandberg@arm.com                newVal = (newVal & (uint32_t)fpscrMask) |
32611090Sandreas.sandberg@arm.com                         (miscRegs[MISCREG_FPSCR] & ~(uint32_t)fpscrMask);
32711090Sandreas.sandberg@arm.com            }
32811090Sandreas.sandberg@arm.com            break;
32911090Sandreas.sandberg@arm.com          case MISCREG_FPEXC:
33011090Sandreas.sandberg@arm.com            {
33111090Sandreas.sandberg@arm.com                const uint32_t fpexcMask = 0x60000000;
33211090Sandreas.sandberg@arm.com                newVal = (newVal & fpexcMask) |
33311168Sandreas.hansson@arm.com                         (miscRegs[MISCREG_FPEXC] & ~fpexcMask);
33411090Sandreas.sandberg@arm.com            }
33511168Sandreas.hansson@arm.com            break;
33611168Sandreas.hansson@arm.com          case MISCREG_SCTLR:
33711090Sandreas.sandberg@arm.com            {
33811168Sandreas.hansson@arm.com                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
33911090Sandreas.sandberg@arm.com                SCTLR sctlr = miscRegs[MISCREG_SCTLR];
34011090Sandreas.sandberg@arm.com                SCTLR new_sctlr = newVal;
34111090Sandreas.sandberg@arm.com                new_sctlr.nmfi =  (bool)sctlr.nmfi;
34211168Sandreas.hansson@arm.com                miscRegs[MISCREG_SCTLR] = (MiscReg)new_sctlr;
34311090Sandreas.sandberg@arm.com                return;
34411090Sandreas.sandberg@arm.com            }
34511090Sandreas.sandberg@arm.com          case MISCREG_TLBTR:
34611090Sandreas.sandberg@arm.com          case MISCREG_MVFR0:
3479646SChris.Emmons@arm.com          case MISCREG_MVFR1:
34811898Ssudhanshu.jha@arm.com          case MISCREG_MPIDR:
34911898Ssudhanshu.jha@arm.com          case MISCREG_FPSID:
35011898Ssudhanshu.jha@arm.com            return;
35111898Ssudhanshu.jha@arm.com          case MISCREG_TLBIALLIS:
3529646SChris.Emmons@arm.com          case MISCREG_TLBIALL:
35310839Sandreas.sandberg@arm.com            warn("Need to flush all TLBs in MP\n");
3549646SChris.Emmons@arm.com            tc->getITBPtr()->flushAll();
3559646SChris.Emmons@arm.com            tc->getDTBPtr()->flushAll();
35611359Sandreas@sandberg.pp.se            return;
3579646SChris.Emmons@arm.com          case MISCREG_ITLBIALL:
35811090Sandreas.sandberg@arm.com            tc->getITBPtr()->flushAll();
35911090Sandreas.sandberg@arm.com            return;
36011090Sandreas.sandberg@arm.com          case MISCREG_DTLBIALL:
36111090Sandreas.sandberg@arm.com            tc->getDTBPtr()->flushAll();
36211090Sandreas.sandberg@arm.com            return;
36311090Sandreas.sandberg@arm.com          case MISCREG_TLBIMVAIS:
36411090Sandreas.sandberg@arm.com          case MISCREG_TLBIMVA:
3659646SChris.Emmons@arm.com            warn("Need to flush all TLBs in MP\n");
36611090Sandreas.sandberg@arm.com            tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
36711090Sandreas.sandberg@arm.com                    bits(newVal, 7,0));
36811090Sandreas.sandberg@arm.com            tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
36911090Sandreas.sandberg@arm.com                    bits(newVal, 7,0));
3709646SChris.Emmons@arm.com            return;
37111090Sandreas.sandberg@arm.com          case MISCREG_TLBIASIDIS:
37211090Sandreas.sandberg@arm.com          case MISCREG_TLBIASID:
37311090Sandreas.sandberg@arm.com            warn("Need to flush all TLBs in MP\n");
3749646SChris.Emmons@arm.com            tc->getITBPtr()->flushAsid(bits(newVal, 7,0));
37511168Sandreas.hansson@arm.com            tc->getDTBPtr()->flushAsid(bits(newVal, 7,0));
37611168Sandreas.hansson@arm.com            return;
3779646SChris.Emmons@arm.com          case MISCREG_TLBIMVAAIS:
37811090Sandreas.sandberg@arm.com          case MISCREG_TLBIMVAA:
37911168Sandreas.hansson@arm.com            warn("Need to flush all TLBs in MP\n");
38011168Sandreas.hansson@arm.com            tc->getITBPtr()->flushMva(mbits(newVal, 31,12));
3819646SChris.Emmons@arm.com            tc->getDTBPtr()->flushMva(mbits(newVal, 31,12));
38211090Sandreas.sandberg@arm.com            return;
38311090Sandreas.sandberg@arm.com          case MISCREG_ITLBIMVA:
38411090Sandreas.sandberg@arm.com            tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
38511090Sandreas.sandberg@arm.com                    bits(newVal, 7,0));
3869646SChris.Emmons@arm.com            return;
38711090Sandreas.sandberg@arm.com          case MISCREG_DTLBIMVA:
38811090Sandreas.sandberg@arm.com            tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
3899646SChris.Emmons@arm.com                    bits(newVal, 7,0));
3909646SChris.Emmons@arm.com            return;
39111090Sandreas.sandberg@arm.com          case MISCREG_ITLBIASID:
39211091Sandreas.sandberg@arm.com            tc->getITBPtr()->flushAsid(bits(newVal, 7,0));
39311091Sandreas.sandberg@arm.com            return;
39411091Sandreas.sandberg@arm.com          case MISCREG_DTLBIASID:
39511091Sandreas.sandberg@arm.com            tc->getDTBPtr()->flushAsid(bits(newVal, 7,0));
39611091Sandreas.sandberg@arm.com            return;
3979646SChris.Emmons@arm.com          case MISCREG_V2PCWPR:
3989646SChris.Emmons@arm.com          case MISCREG_V2PCWPW:
3999646SChris.Emmons@arm.com          case MISCREG_V2PCWUR:
400          case MISCREG_V2PCWUW:
401          case MISCREG_V2POWPR:
402          case MISCREG_V2POWPW:
403          case MISCREG_V2POWUR:
404          case MISCREG_V2POWUW:
405            {
406              RequestPtr req = new Request;
407              unsigned flags;
408              BaseTLB::Mode mode;
409              Fault fault;
410              switch(misc_reg) {
411                  case MISCREG_V2PCWPR:
412                      flags = TLB::MustBeOne;
413                      mode = BaseTLB::Read;
414                      break;
415                  case MISCREG_V2PCWPW:
416                      flags = TLB::MustBeOne;
417                      mode = BaseTLB::Write;
418                      break;
419                  case MISCREG_V2PCWUR:
420                      flags = TLB::MustBeOne | TLB::UserMode;
421                      mode = BaseTLB::Read;
422                      break;
423                  case MISCREG_V2PCWUW:
424                      flags = TLB::MustBeOne | TLB::UserMode;
425                      mode = BaseTLB::Write;
426                      break;
427                  case MISCREG_V2POWPR:
428                  case MISCREG_V2POWPW:
429                  case MISCREG_V2POWUR:
430                  case MISCREG_V2POWUW:
431                      panic("Security Extensions not implemented!");
432              }
433              req->setVirt(0, val, 1, flags, tc->readPC());
434              fault = tc->getDTBPtr()->translateAtomic(req, tc, mode);
435              if (fault == NoFault) {
436                  miscRegs[MISCREG_PAR] =
437                      (req->getPaddr() & 0xfffff000) |
438                      (tc->getDTBPtr()->getAttr() );
439                  DPRINTF(MiscRegs,
440                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
441                          val, miscRegs[MISCREG_PAR]);
442              }
443              else {
444                  // Set fault bit and FSR
445                  FSR fsr = miscRegs[MISCREG_DFSR];
446                  miscRegs[MISCREG_PAR] =
447                      (fsr.ext << 6) |
448                      (fsr.fsHigh << 5) |
449                      (fsr.fsLow << 1) |
450                      0x1; // F bit
451              }
452              return;
453            }
454        }
455    }
456    setMiscRegNoEffect(misc_reg, newVal);
457}
458
459}
460