6a5d6afdcfa4aa1411f1f96e00cbe2f1f581423d
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Steve Reinhardt
32 #include "arch/alpha/faults.hh"
33 #include "arch/alpha/isa_traits.hh"
34 #include "arch/alpha/kernel_stats.hh"
35 #include "arch/alpha/osfpal.hh"
36 #include "arch/alpha/tlb.hh"
37 #include "base/cp_annotate.hh"
38 #include "base/debug.hh"
39 #include "cpu/base.hh"
40 #include "cpu/simple_thread.hh"
41 #include "cpu/thread_context.hh"
42 #include "sim/sim_exit.hh"
50 auto tlb
= dynamic_cast<TLB
*>(tc
->getITBPtr());
59 auto tlb
= dynamic_cast<TLB
*>(tc
->getDTBPtr());
64 ////////////////////////////////////////////////////////////////////////
66 // Machine dependent functions
69 initCPU(ThreadContext
*tc
, int cpuId
)
73 tc
->setIntReg(16, cpuId
);
74 tc
->setIntReg(0, cpuId
);
76 AlphaFault
*reset
= new ResetFault
;
78 tc
->pcState(tc
->readMiscRegNoEffect(IPR_PAL_BASE
) + reset
->vect());
85 zeroRegisters(CPU
*cpu
)
87 // Insure ISA semantics
88 // (no longer very clean due to the change in setIntReg() in the
89 // cpu model. Consider changing later.)
90 cpu
->thread
->setIntReg(ZeroReg
, 0);
91 cpu
->thread
->setFloatRegBits(ZeroReg
, 0);
94 ////////////////////////////////////////////////////////////////////////
99 initIPRs(ThreadContext
*tc
, int cpuId
)
101 for (int i
= 0; i
< NumInternalProcRegs
; ++i
) {
102 tc
->setMiscRegNoEffect(i
, 0);
105 tc
->setMiscRegNoEffect(IPR_PAL_BASE
, PalBase
);
106 tc
->setMiscRegNoEffect(IPR_MCSR
, 0x6);
107 tc
->setMiscRegNoEffect(IPR_PALtemp16
, cpuId
);
111 ISA::readIpr(int idx
, ThreadContext
*tc
)
113 uint64_t retval
= 0; // return value, default 0
147 case IPR_IC_PERR_STAT
:
148 case IPR_DC_PERR_STAT
:
164 retval
|= ipr
[idx
] & ULL(0xffffffff00000000);
165 retval
|= tc
->getCpuPtr()->curCycle() & ULL(0x00000000ffffffff);
174 case IPR_IFAULT_VA_FORM
:
182 TlbEntry
&entry
= getDTBPtr(tc
)->index(1);
184 retval
|= ((uint64_t)entry
.ppn
& ULL(0x7ffffff)) << 32;
185 retval
|= ((uint64_t)entry
.xre
& ULL(0xf)) << 8;
186 retval
|= ((uint64_t)entry
.xwe
& ULL(0xf)) << 12;
187 retval
|= ((uint64_t)entry
.fonr
& ULL(0x1)) << 1;
188 retval
|= ((uint64_t)entry
.fonw
& ULL(0x1))<< 2;
189 retval
|= ((uint64_t)entry
.asma
& ULL(0x1)) << 4;
190 retval
|= ((uint64_t)entry
.asn
& ULL(0x7f)) << 57;
194 // write only registers
204 panic("Tried to read write only register %d\n", idx
);
209 panic("Tried to read from invalid ipr %d\n", idx
);
216 // Cause the simulator to break when changing to the following IPL
220 ISA::setIpr(int idx
, uint64_t val
, ThreadContext
*tc
)
247 case IPR_IC_PERR_STAT
:
248 case IPR_DC_PERR_STAT
:
250 // write entire quad w/ no side-effect
255 // This IPR resets the cycle counter. We assume this only
256 // happens once... let's verify that.
257 assert(ipr
[idx
] == 0);
262 // This IPR only writes the upper 64 bits. It's ok to write
263 // all 64 here since we mask out the lower 32 in rpcc (see
269 // write entire quad w/ no side-effect
270 if (tc
->getKernelStats())
271 tc
->getKernelStats()->context(ipr
[idx
], val
, tc
);
276 // write entire quad w/ no side-effect, tag is forthcoming
281 // second least significant bit in PC is always zero
287 // only write least significant four bits - privilege mask
288 ipr
[idx
] = val
& 0xf;
292 // only write least significant five bits - interrupt level
293 ipr
[idx
] = val
& 0x1f;
294 if (tc
->getKernelStats())
295 tc
->getKernelStats()->swpipl(ipr
[idx
]);
300 if (tc
->getKernelStats())
301 tc
->getKernelStats()->mode(Kernel::user
, tc
);
303 if (tc
->getKernelStats())
304 tc
->getKernelStats()->mode(Kernel::kernel
, tc
);
309 // only write two mode bits - processor mode
310 ipr
[idx
] = val
& 0x18;
314 // only write two mode bits - processor mode
315 ipr
[idx
] = val
& 0x18;
319 // more here after optimization...
324 // only write software interrupt mask
325 ipr
[idx
] = val
& 0x7fff0;
329 ipr
[idx
] = val
& ULL(0xffffff0300);
334 ipr
[idx
] = val
& ULL(0xffffffffc0000000);
337 case IPR_DC_TEST_CTL
:
338 ipr
[idx
] = val
& 0x1ffb;
343 ipr
[idx
] = val
& 0x3f;
347 ipr
[idx
] = val
& 0x7f0;
351 ipr
[idx
] = val
& ULL(0xfe00000000000000);
356 // any write to this register clears it
363 case IPR_ITB_PTE_TEMP
:
364 case IPR_DTB_PTE_TEMP
:
365 // read-only registers
366 panic("Tried to write read only ipr %d\n", idx
);
372 // the following are write only
377 // really a control write
380 getDTBPtr(tc
)->flushAll();
384 // really a control write
387 getDTBPtr(tc
)->flushProcesses();
391 // really a control write
394 getDTBPtr(tc
)->flushAddr(val
, DTB_ASN_ASN(ipr
[IPR_DTB_ASN
]));
398 struct TlbEntry entry
;
400 // FIXME: granularity hints NYI...
401 if (DTB_PTE_GH(ipr
[IPR_DTB_PTE
]) != 0)
402 panic("PTE GH field != 0");
407 // construct PTE for new entry
408 entry
.ppn
= DTB_PTE_PPN(ipr
[IPR_DTB_PTE
]);
409 entry
.xre
= DTB_PTE_XRE(ipr
[IPR_DTB_PTE
]);
410 entry
.xwe
= DTB_PTE_XWE(ipr
[IPR_DTB_PTE
]);
411 entry
.fonr
= DTB_PTE_FONR(ipr
[IPR_DTB_PTE
]);
412 entry
.fonw
= DTB_PTE_FONW(ipr
[IPR_DTB_PTE
]);
413 entry
.asma
= DTB_PTE_ASMA(ipr
[IPR_DTB_PTE
]);
414 entry
.asn
= DTB_ASN_ASN(ipr
[IPR_DTB_ASN
]);
416 // insert new TAG/PTE value into data TLB
417 getDTBPtr(tc
)->insert(val
, entry
);
422 struct TlbEntry entry
;
424 // FIXME: granularity hints NYI...
425 if (ITB_PTE_GH(val
) != 0)
426 panic("PTE GH field != 0");
431 // construct PTE for new entry
432 entry
.ppn
= ITB_PTE_PPN(val
);
433 entry
.xre
= ITB_PTE_XRE(val
);
435 entry
.fonr
= ITB_PTE_FONR(val
);
436 entry
.fonw
= ITB_PTE_FONW(val
);
437 entry
.asma
= ITB_PTE_ASMA(val
);
438 entry
.asn
= ITB_ASN_ASN(ipr
[IPR_ITB_ASN
]);
440 // insert new TAG/PTE value into data TLB
441 getITBPtr(tc
)->insert(ipr
[IPR_ITB_TAG
], entry
);
446 // really a control write
449 getITBPtr(tc
)->flushAll();
453 // really a control write
456 getITBPtr(tc
)->flushProcesses();
460 // really a control write
463 getITBPtr(tc
)->flushAddr(val
, ITB_ASN_ASN(ipr
[IPR_ITB_ASN
]));
468 panic("Tried to write to invalid ipr %d\n", idx
);
475 copyIprs(ThreadContext
*src
, ThreadContext
*dest
)
477 for (int i
= 0; i
< NumInternalProcRegs
; ++i
)
478 dest
->setMiscRegNoEffect(i
, src
->readMiscRegNoEffect(i
));
481 } // namespace AlphaISA
483 using namespace AlphaISA
;
486 SimpleThread::hwrei()
488 PCState pc
= pcState();
489 if (!(pc
.pc() & 0x3))
490 return std::make_shared
<UnimplementedOpcodeFault
>();
492 pc
.npc(readMiscRegNoEffect(IPR_EXC_ADDR
));
495 CPA::cpa()->swAutoBegin(tc
, pc
.npc());
498 kernelStats
->hwrei();
500 // FIXME: XXX check for interrupts? XXX
505 * Check for special simulator handling of specific PAL calls.
506 * If return value is false, actual PAL call will be suppressed.
509 SimpleThread::simPalCheck(int palFunc
)
512 kernelStats
->callpal(palFunc
, tc
);
517 if (--System::numSystemsRunning
== 0)
518 exitSimLoop("all cpus halted");
523 if (system
->breakpoint())