isa.cc revision 8520
18889Sgeoffrey.blake@arm.com/*
28889Sgeoffrey.blake@arm.com * Copyright (c) 2010 ARM Limited
38889Sgeoffrey.blake@arm.com * All rights reserved
48889Sgeoffrey.blake@arm.com *
58889Sgeoffrey.blake@arm.com * The license below extends only to copyright in the software and shall
68889Sgeoffrey.blake@arm.com * not be construed as granting a license to any other intellectual
78889Sgeoffrey.blake@arm.com * property including but not limited to intellectual property relating
88889Sgeoffrey.blake@arm.com * to a hardware implementation of the functionality of the software
98889Sgeoffrey.blake@arm.com * licensed hereunder.  You may use the software subject to the license
108889Sgeoffrey.blake@arm.com * terms below provided that you ensure that this notice is replicated
118889Sgeoffrey.blake@arm.com * unmodified and in its entirety in all distributions of the software,
128889Sgeoffrey.blake@arm.com * modified or unmodified, in source code or in binary form.
139265SAli.Saidi@ARM.com *
148889Sgeoffrey.blake@arm.com * Redistribution and use in source and binary forms, with or without
158889Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are
168889Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright
178889Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer;
188889Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright
198889Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer in the
208889Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution;
218889Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its
228889Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from
238889Sgeoffrey.blake@arm.com * this software without specific prior written permission.
248889Sgeoffrey.blake@arm.com *
258889Sgeoffrey.blake@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
268889Sgeoffrey.blake@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
278889Sgeoffrey.blake@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
288889Sgeoffrey.blake@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
298889Sgeoffrey.blake@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
308889Sgeoffrey.blake@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
318889Sgeoffrey.blake@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
328889Sgeoffrey.blake@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
338889Sgeoffrey.blake@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
348889Sgeoffrey.blake@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
358889Sgeoffrey.blake@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
368889Sgeoffrey.blake@arm.com *
378889Sgeoffrey.blake@arm.com * Authors: Gabe Black
388889Sgeoffrey.blake@arm.com *          Ali Saidi
398889Sgeoffrey.blake@arm.com */
408889Sgeoffrey.blake@arm.com
418889Sgeoffrey.blake@arm.com#include "arch/arm/isa.hh"
428983Snate@binkert.org#include "debug/Arm.hh"
438889Sgeoffrey.blake@arm.com#include "debug/MiscRegs.hh"
448889Sgeoffrey.blake@arm.com#include "sim/faults.hh"
458889Sgeoffrey.blake@arm.com#include "sim/stat_control.hh"
468889Sgeoffrey.blake@arm.com#include "sim/system.hh"
478889Sgeoffrey.blake@arm.com
488889Sgeoffrey.blake@arm.comnamespace ArmISA
498889Sgeoffrey.blake@arm.com{
508889Sgeoffrey.blake@arm.com
518889Sgeoffrey.blake@arm.comvoid
528889Sgeoffrey.blake@arm.comISA::clear()
538889Sgeoffrey.blake@arm.com{
548889Sgeoffrey.blake@arm.com    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
558889Sgeoffrey.blake@arm.com    uint32_t midr = miscRegs[MISCREG_MIDR];
568889Sgeoffrey.blake@arm.com    memset(miscRegs, 0, sizeof(miscRegs));
578889Sgeoffrey.blake@arm.com    CPSR cpsr = 0;
588889Sgeoffrey.blake@arm.com    cpsr.mode = MODE_USER;
598889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_CPSR] = cpsr;
608889Sgeoffrey.blake@arm.com    updateRegMap(cpsr);
618889Sgeoffrey.blake@arm.com
628889Sgeoffrey.blake@arm.com    SCTLR sctlr = 0;
638889Sgeoffrey.blake@arm.com    sctlr.te = (bool)sctlr_rst.te;
648889Sgeoffrey.blake@arm.com    sctlr.nmfi = (bool)sctlr_rst.nmfi;
658889Sgeoffrey.blake@arm.com    sctlr.v = (bool)sctlr_rst.v;
668889Sgeoffrey.blake@arm.com    sctlr.u    = 1;
678889Sgeoffrey.blake@arm.com    sctlr.xp = 1;
688889Sgeoffrey.blake@arm.com    sctlr.rao2 = 1;
698889Sgeoffrey.blake@arm.com    sctlr.rao3 = 1;
708889Sgeoffrey.blake@arm.com    sctlr.rao4 = 1;
718889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_SCTLR] = sctlr;
728889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
738889Sgeoffrey.blake@arm.com
748889Sgeoffrey.blake@arm.com    // Preserve MIDR accross reset
758889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_MIDR] = midr;
768889Sgeoffrey.blake@arm.com
778889Sgeoffrey.blake@arm.com    /* Start with an event in the mailbox */
788889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_SEV_MAILBOX] = 1;
798889Sgeoffrey.blake@arm.com
808889Sgeoffrey.blake@arm.com    // Separate Instruction and Data TLBs.
818889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_TLBTR] = 1;
828889Sgeoffrey.blake@arm.com
838889Sgeoffrey.blake@arm.com    MVFR0 mvfr0 = 0;
848889Sgeoffrey.blake@arm.com    mvfr0.advSimdRegisters = 2;
858889Sgeoffrey.blake@arm.com    mvfr0.singlePrecision = 2;
868889Sgeoffrey.blake@arm.com    mvfr0.doublePrecision = 2;
878889Sgeoffrey.blake@arm.com    mvfr0.vfpExceptionTrapping = 0;
888889Sgeoffrey.blake@arm.com    mvfr0.divide = 1;
898889Sgeoffrey.blake@arm.com    mvfr0.squareRoot = 1;
908889Sgeoffrey.blake@arm.com    mvfr0.shortVectors = 1;
918889Sgeoffrey.blake@arm.com    mvfr0.roundingModes = 1;
928889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_MVFR0] = mvfr0;
938889Sgeoffrey.blake@arm.com
948889Sgeoffrey.blake@arm.com    MVFR1 mvfr1 = 0;
958889Sgeoffrey.blake@arm.com    mvfr1.flushToZero = 1;
968889Sgeoffrey.blake@arm.com    mvfr1.defaultNaN = 1;
979265SAli.Saidi@ARM.com    mvfr1.advSimdLoadStore = 1;
989265SAli.Saidi@ARM.com    mvfr1.advSimdInteger = 1;
998889Sgeoffrey.blake@arm.com    mvfr1.advSimdSinglePrecision = 1;
1008889Sgeoffrey.blake@arm.com    mvfr1.advSimdHalfPrecision = 1;
1018889Sgeoffrey.blake@arm.com    mvfr1.vfpHalfPrecision = 1;
1028889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_MVFR1] = mvfr1;
1038889Sgeoffrey.blake@arm.com
1048889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_MPIDR] = 0;
1058889Sgeoffrey.blake@arm.com
1068889Sgeoffrey.blake@arm.com    // Reset values of PRRR and NMRR are implementation dependent
1078889Sgeoffrey.blake@arm.com
1088889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_PRRR] =
1099265SAli.Saidi@ARM.com        (1 << 19) | // 19
1109265SAli.Saidi@ARM.com        (0 << 18) | // 18
1118889Sgeoffrey.blake@arm.com        (0 << 17) | // 17
1128889Sgeoffrey.blake@arm.com        (1 << 16) | // 16
1138889Sgeoffrey.blake@arm.com        (2 << 14) | // 15:14
1148889Sgeoffrey.blake@arm.com        (0 << 12) | // 13:12
1158889Sgeoffrey.blake@arm.com        (2 << 10) | // 11:10
1168889Sgeoffrey.blake@arm.com        (2 << 8)  | // 9:8
1178889Sgeoffrey.blake@arm.com        (2 << 6)  | // 7:6
1188889Sgeoffrey.blake@arm.com        (2 << 4)  | // 5:4
1198889Sgeoffrey.blake@arm.com        (1 << 2)  | // 3:2
1208889Sgeoffrey.blake@arm.com        0;          // 1:0
1218889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_NMRR] =
1228889Sgeoffrey.blake@arm.com        (1 << 30) | // 31:30
1238889Sgeoffrey.blake@arm.com        (0 << 26) | // 27:26
1249265SAli.Saidi@ARM.com        (0 << 24) | // 25:24
1259265SAli.Saidi@ARM.com        (3 << 22) | // 23:22
1268889Sgeoffrey.blake@arm.com        (2 << 20) | // 21:20
1278889Sgeoffrey.blake@arm.com        (0 << 18) | // 19:18
1288889Sgeoffrey.blake@arm.com        (0 << 16) | // 17:16
1298889Sgeoffrey.blake@arm.com        (1 << 14) | // 15:14
1308889Sgeoffrey.blake@arm.com        (0 << 12) | // 13:12
1318889Sgeoffrey.blake@arm.com        (2 << 10) | // 11:10
1328889Sgeoffrey.blake@arm.com        (0 << 8)  | // 9:8
1338889Sgeoffrey.blake@arm.com        (3 << 6)  | // 7:6
1348889Sgeoffrey.blake@arm.com        (2 << 4)  | // 5:4
1358889Sgeoffrey.blake@arm.com        (0 << 2)  | // 3:2
1368889Sgeoffrey.blake@arm.com        0;          // 1:0
1378889Sgeoffrey.blake@arm.com
1388889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_CPACR] = 0;
1398889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_FPSID] = 0x410430A0;
1409265SAli.Saidi@ARM.com
1419265SAli.Saidi@ARM.com    // See section B4.1.84 of ARM ARM
1428889Sgeoffrey.blake@arm.com    // All values are latest for ARMv7-A profile
1438889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_ID_ISAR0] = 0x02101111;
1448889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_ID_ISAR1] = 0x02112111;
1458889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_ID_ISAR2] = 0x21232141;
1468889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_ID_ISAR3] = 0x01112131;
1478889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_ID_ISAR4] = 0x10010142;
1488889Sgeoffrey.blake@arm.com    miscRegs[MISCREG_ID_ISAR5] = 0x00000000;
1498889Sgeoffrey.blake@arm.com
1508889Sgeoffrey.blake@arm.com    //XXX We need to initialize the rest of the state.
1518889Sgeoffrey.blake@arm.com}
1528889Sgeoffrey.blake@arm.com
1538889Sgeoffrey.blake@arm.comMiscReg
1548889Sgeoffrey.blake@arm.comISA::readMiscRegNoEffect(int misc_reg)
1558889Sgeoffrey.blake@arm.com{
1569265SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
1578889Sgeoffrey.blake@arm.com
1588889Sgeoffrey.blake@arm.com    int flat_idx;
1598889Sgeoffrey.blake@arm.com    if (misc_reg == MISCREG_SPSR)
1608889Sgeoffrey.blake@arm.com        flat_idx = flattenMiscIndex(misc_reg);
1618889Sgeoffrey.blake@arm.com    else
1628889Sgeoffrey.blake@arm.com        flat_idx = misc_reg;
1638889Sgeoffrey.blake@arm.com    MiscReg val = miscRegs[flat_idx];
1648889Sgeoffrey.blake@arm.com
1658889Sgeoffrey.blake@arm.com    DPRINTF(MiscRegs, "Reading From misc reg %d (%d) : %#x\n",
1668889Sgeoffrey.blake@arm.com            misc_reg, flat_idx, val);
1678889Sgeoffrey.blake@arm.com    return val;
1689055Ssaidi@eecs.umich.edu}
1698889Sgeoffrey.blake@arm.com
1708889Sgeoffrey.blake@arm.com
1718889Sgeoffrey.blake@arm.comMiscReg
1728889Sgeoffrey.blake@arm.comISA::readMiscReg(int misc_reg, ThreadContext *tc)
1739265SAli.Saidi@ARM.com{
1749265SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
1758889Sgeoffrey.blake@arm.com        CPSR cpsr = miscRegs[misc_reg];
1768889Sgeoffrey.blake@arm.com        PCState pc = tc->pcState();
1778889Sgeoffrey.blake@arm.com        cpsr.j = pc.jazelle() ? 1 : 0;
1788983Snate@binkert.org        cpsr.t = pc.thumb() ? 1 : 0;
1799265SAli.Saidi@ARM.com        return cpsr;
1809265SAli.Saidi@ARM.com    }
1818983Snate@binkert.org    if (misc_reg >= MISCREG_CP15_UNIMP_START)
1828983Snate@binkert.org        panic("Unimplemented CP15 register %s read.\n",
1838889Sgeoffrey.blake@arm.com              miscRegName[misc_reg]);
1848889Sgeoffrey.blake@arm.com
1858889Sgeoffrey.blake@arm.com    switch (misc_reg) {
1868889Sgeoffrey.blake@arm.com      case MISCREG_MPIDR:
1878889Sgeoffrey.blake@arm.com        return tc->cpuId();
1888889Sgeoffrey.blake@arm.com        break;
1898889Sgeoffrey.blake@arm.com      case MISCREG_ID_MMFR0:
190        return 0x03; // VMSAv7 support
191      case MISCREG_ID_MMFR2:
192        return 0x01230000; // no HW access | WFI stalling | ISB and DSB
193                           // | all TLB maintenance | no Harvard
194      case MISCREG_ID_MMFR3:
195        return 0xF0102211; // SuperSec | Coherent TLB | Bcast Maint |
196                           // BP Maint | Cache Maint Set/way | Cache Maint MVA
197      case MISCREG_CLIDR:
198        warn_once("The clidr register always reports 0 caches.\n");
199        warn_once("clidr LoUIS field of 0b001 to match current "
200                  "ARM implementations.\n");
201        return 0x00200000;
202      case MISCREG_CCSIDR:
203        warn_once("The ccsidr register isn't implemented and "
204                "always reads as 0.\n");
205        break;
206      case MISCREG_ID_PFR0:
207        warn("Returning thumbEE disabled for now since we don't support CP14"
208             "config registers and jumping to ThumbEE vectors\n");
209        return 0x0031; // !ThumbEE | !Jazelle | Thumb | ARM
210      case MISCREG_ID_PFR1:
211        warn("reading unimplmented register ID_PFR1");
212        return 0;
213      case MISCREG_CTR:
214        return 0x86468006; // V7, 64 byte cache line, load/exclusive is exact
215      case MISCREG_ACTLR:
216        warn("Not doing anything for miscreg ACTLR\n");
217        break;
218      case MISCREG_PMCR:
219      case MISCREG_PMCCNTR:
220      case MISCREG_PMSELR:
221        warn("Not doing anything for read to miscreg %s\n",
222                miscRegName[misc_reg]);
223        break;
224      case MISCREG_CPSR_Q:
225        panic("shouldn't be reading this register seperately\n");
226      case MISCREG_FPSCR_QC:
227        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
228      case MISCREG_FPSCR_EXC:
229        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
230    }
231    return readMiscRegNoEffect(misc_reg);
232}
233
234void
235ISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
236{
237    assert(misc_reg < NumMiscRegs);
238
239    int flat_idx;
240    if (misc_reg == MISCREG_SPSR)
241        flat_idx = flattenMiscIndex(misc_reg);
242    else
243        flat_idx = misc_reg;
244    miscRegs[flat_idx] = val;
245
246    DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n", misc_reg,
247            flat_idx, val);
248}
249
250void
251ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
252{
253
254    MiscReg newVal = val;
255    int x;
256    System *sys;
257    ThreadContext *oc;
258
259    if (misc_reg == MISCREG_CPSR) {
260        updateRegMap(val);
261
262
263        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
264        int old_mode = old_cpsr.mode;
265        CPSR cpsr = val;
266        if (old_mode != cpsr.mode) {
267            tc->getITBPtr()->invalidateMiscReg();
268            tc->getDTBPtr()->invalidateMiscReg();
269        }
270
271        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
272                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
273        PCState pc = tc->pcState();
274        pc.nextThumb(cpsr.t);
275        pc.nextJazelle(cpsr.j);
276        tc->pcState(pc);
277    } else if (misc_reg >= MISCREG_CP15_UNIMP_START &&
278        misc_reg < MISCREG_CP15_END) {
279        panic("Unimplemented CP15 register %s wrote with %#x.\n",
280              miscRegName[misc_reg], val);
281    } else {
282        switch (misc_reg) {
283          case MISCREG_CPACR:
284            {
285
286                const uint32_t ones = (uint32_t)(-1);
287                CPACR cpacrMask = 0;
288                // Only cp10, cp11, and ase are implemented, nothing else should
289                // be writable
290                cpacrMask.cp10 = ones;
291                cpacrMask.cp11 = ones;
292                cpacrMask.asedis = ones;
293                newVal &= cpacrMask;
294                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
295                        miscRegName[misc_reg], newVal);
296            }
297            break;
298          case MISCREG_CSSELR:
299            warn_once("The csselr register isn't implemented.\n");
300            return;
301          case MISCREG_FPSCR:
302            {
303                const uint32_t ones = (uint32_t)(-1);
304                FPSCR fpscrMask = 0;
305                fpscrMask.ioc = ones;
306                fpscrMask.dzc = ones;
307                fpscrMask.ofc = ones;
308                fpscrMask.ufc = ones;
309                fpscrMask.ixc = ones;
310                fpscrMask.idc = ones;
311                fpscrMask.len = ones;
312                fpscrMask.stride = ones;
313                fpscrMask.rMode = ones;
314                fpscrMask.fz = ones;
315                fpscrMask.dn = ones;
316                fpscrMask.ahp = ones;
317                fpscrMask.qc = ones;
318                fpscrMask.v = ones;
319                fpscrMask.c = ones;
320                fpscrMask.z = ones;
321                fpscrMask.n = ones;
322                newVal = (newVal & (uint32_t)fpscrMask) |
323                         (miscRegs[MISCREG_FPSCR] & ~(uint32_t)fpscrMask);
324            }
325            break;
326          case MISCREG_CPSR_Q:
327            {
328                assert(!(newVal & ~CpsrMaskQ));
329                newVal = miscRegs[MISCREG_CPSR] | newVal;
330                misc_reg = MISCREG_CPSR;
331            }
332            break;
333          case MISCREG_FPSCR_QC:
334            {
335                newVal = miscRegs[MISCREG_FPSCR] | (newVal & FpscrQcMask);
336                misc_reg = MISCREG_FPSCR;
337            }
338            break;
339          case MISCREG_FPSCR_EXC:
340            {
341                newVal = miscRegs[MISCREG_FPSCR] | (newVal & FpscrExcMask);
342                misc_reg = MISCREG_FPSCR;
343            }
344            break;
345          case MISCREG_FPEXC:
346            {
347                // vfpv3 architecture, section B.6.1 of DDI04068
348                // bit 29 - valid only if fpexc[31] is 0
349                const uint32_t fpexcMask = 0x60000000;
350                newVal = (newVal & fpexcMask) |
351                         (miscRegs[MISCREG_FPEXC] & ~fpexcMask);
352            }
353            break;
354          case MISCREG_SCTLR:
355            {
356                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
357                SCTLR sctlr = miscRegs[MISCREG_SCTLR];
358                SCTLR new_sctlr = newVal;
359                new_sctlr.nmfi =  (bool)sctlr.nmfi;
360                miscRegs[MISCREG_SCTLR] = (MiscReg)new_sctlr;
361                tc->getITBPtr()->invalidateMiscReg();
362                tc->getDTBPtr()->invalidateMiscReg();
363                return;
364            }
365          case MISCREG_TLBTR:
366          case MISCREG_MVFR0:
367          case MISCREG_MVFR1:
368          case MISCREG_MPIDR:
369          case MISCREG_FPSID:
370            return;
371          case MISCREG_TLBIALLIS:
372          case MISCREG_TLBIALL:
373            sys = tc->getSystemPtr();
374            for (x = 0; x < sys->numContexts(); x++) {
375                oc = sys->getThreadContext(x);
376                assert(oc->getITBPtr() && oc->getDTBPtr());
377                oc->getITBPtr()->flushAll();
378                oc->getDTBPtr()->flushAll();
379            }
380            return;
381          case MISCREG_ITLBIALL:
382            tc->getITBPtr()->flushAll();
383            return;
384          case MISCREG_DTLBIALL:
385            tc->getDTBPtr()->flushAll();
386            return;
387          case MISCREG_TLBIMVAIS:
388          case MISCREG_TLBIMVA:
389            sys = tc->getSystemPtr();
390            for (x = 0; x < sys->numContexts(); x++) {
391                oc = sys->getThreadContext(x);
392                assert(oc->getITBPtr() && oc->getDTBPtr());
393                oc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
394                        bits(newVal, 7,0));
395                oc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
396                        bits(newVal, 7,0));
397            }
398            return;
399          case MISCREG_TLBIASIDIS:
400          case MISCREG_TLBIASID:
401            sys = tc->getSystemPtr();
402            for (x = 0; x < sys->numContexts(); x++) {
403                oc = sys->getThreadContext(x);
404                assert(oc->getITBPtr() && oc->getDTBPtr());
405                oc->getITBPtr()->flushAsid(bits(newVal, 7,0));
406                oc->getDTBPtr()->flushAsid(bits(newVal, 7,0));
407            }
408            return;
409          case MISCREG_TLBIMVAAIS:
410          case MISCREG_TLBIMVAA:
411            sys = tc->getSystemPtr();
412            for (x = 0; x < sys->numContexts(); x++) {
413                oc = sys->getThreadContext(x);
414                assert(oc->getITBPtr() && oc->getDTBPtr());
415                oc->getITBPtr()->flushMva(mbits(newVal, 31,12));
416                oc->getDTBPtr()->flushMva(mbits(newVal, 31,12));
417            }
418            return;
419          case MISCREG_ITLBIMVA:
420            tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
421                    bits(newVal, 7,0));
422            return;
423          case MISCREG_DTLBIMVA:
424            tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
425                    bits(newVal, 7,0));
426            return;
427          case MISCREG_ITLBIASID:
428            tc->getITBPtr()->flushAsid(bits(newVal, 7,0));
429            return;
430          case MISCREG_DTLBIASID:
431            tc->getDTBPtr()->flushAsid(bits(newVal, 7,0));
432            return;
433          case MISCREG_ACTLR:
434            warn("Not doing anything for write of miscreg ACTLR\n");
435            break;
436          case MISCREG_PMCR:
437            {
438              // Performance counters not implemented.  Instead, interpret
439              //   a reset command to this register to reset the simulator
440              //   statistics.
441              // PMCR_E | PMCR_P | PMCR_C
442              const int ResetAndEnableCounters = 0x7;
443              if (newVal == ResetAndEnableCounters) {
444                  inform("Resetting all simobject stats\n");
445                  Stats::schedStatEvent(false, true);
446                  break;
447              }
448            }
449          case MISCREG_PMCCNTR:
450          case MISCREG_PMSELR:
451            warn("Not doing anything for write to miscreg %s\n",
452                    miscRegName[misc_reg]);
453            break;
454          case MISCREG_V2PCWPR:
455          case MISCREG_V2PCWPW:
456          case MISCREG_V2PCWUR:
457          case MISCREG_V2PCWUW:
458          case MISCREG_V2POWPR:
459          case MISCREG_V2POWPW:
460          case MISCREG_V2POWUR:
461          case MISCREG_V2POWUW:
462            {
463              RequestPtr req = new Request;
464              unsigned flags;
465              BaseTLB::Mode mode;
466              Fault fault;
467              switch(misc_reg) {
468                  case MISCREG_V2PCWPR:
469                      flags = TLB::MustBeOne;
470                      mode = BaseTLB::Read;
471                      break;
472                  case MISCREG_V2PCWPW:
473                      flags = TLB::MustBeOne;
474                      mode = BaseTLB::Write;
475                      break;
476                  case MISCREG_V2PCWUR:
477                      flags = TLB::MustBeOne | TLB::UserMode;
478                      mode = BaseTLB::Read;
479                      break;
480                  case MISCREG_V2PCWUW:
481                      flags = TLB::MustBeOne | TLB::UserMode;
482                      mode = BaseTLB::Write;
483                      break;
484                  default:
485                      panic("Security Extensions not implemented!");
486              }
487              warn("Translating via MISCREG in atomic mode! Fix Me!\n");
488              req->setVirt(0, val, 1, flags, tc->pcState().pc());
489              fault = tc->getDTBPtr()->translateAtomic(req, tc, mode);
490              if (fault == NoFault) {
491                  miscRegs[MISCREG_PAR] =
492                      (req->getPaddr() & 0xfffff000) |
493                      (tc->getDTBPtr()->getAttr() );
494                  DPRINTF(MiscRegs,
495                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
496                          val, miscRegs[MISCREG_PAR]);
497              }
498              else {
499                  // Set fault bit and FSR
500                  FSR fsr = miscRegs[MISCREG_DFSR];
501                  miscRegs[MISCREG_PAR] =
502                      (fsr.ext << 6) |
503                      (fsr.fsHigh << 5) |
504                      (fsr.fsLow << 1) |
505                      0x1; // F bit
506              }
507              return;
508            }
509          case MISCREG_CONTEXTIDR:
510          case MISCREG_PRRR:
511          case MISCREG_NMRR:
512          case MISCREG_DACR:
513            tc->getITBPtr()->invalidateMiscReg();
514            tc->getDTBPtr()->invalidateMiscReg();
515            break;
516          case MISCREG_CPSR_MODE:
517            // This miscreg is used by copy*Regs to set the CPSR mode
518            // without updating other CPSR variables. It's used to
519            // make sure the register map is in such a state that we can
520            // see all of the registers for the copy.
521            updateRegMap(val);
522            return;
523        }
524    }
525    setMiscRegNoEffect(misc_reg, newVal);
526}
527
528}
529