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 "config/full_system.hh"
40 #include "cpu/base.hh"
41 #include "cpu/simple_thread.hh"
42 #include "cpu/thread_context.hh"
43 #include "sim/sim_exit.hh"
49 ////////////////////////////////////////////////////////////////////////
51 // Machine dependent functions
54 initCPU(ThreadContext
*tc
, int cpuId
)
58 tc
->setIntReg(16, cpuId
);
59 tc
->setIntReg(0, cpuId
);
61 AlphaFault
*reset
= new ResetFault
;
63 tc
->setPC(tc
->readMiscRegNoEffect(IPR_PAL_BASE
) + reset
->vect());
64 tc
->setNextPC(tc
->readPC() + sizeof(MachInst
));
72 processInterrupts(CPU
*cpu
)
74 //Check if there are any outstanding interrupts
75 //Handle the interrupts
79 if (cpu
->readMiscRegNoEffect(IPR_ASTRR
))
80 panic("asynchronous traps not implemented\n");
82 if (cpu
->readMiscRegNoEffect(IPR_SIRR
)) {
83 for (int i
= INTLEVEL_SOFTWARE_MIN
;
84 i
< INTLEVEL_SOFTWARE_MAX
; i
++) {
85 if (cpu
->readMiscRegNoEffect(IPR_SIRR
) & (ULL(1) << i
)) {
86 // See table 4-19 of the 21164 hardware reference
87 ipl
= (i
- INTLEVEL_SOFTWARE_MIN
) + 1;
88 summary
|= (ULL(1) << i
);
93 uint64_t interrupts
= cpu
->intr_status();
96 for (int i
= INTLEVEL_EXTERNAL_MIN
;
97 i
< INTLEVEL_EXTERNAL_MAX
; i
++) {
98 if (interrupts
& (ULL(1) << i
)) {
99 // See table 4-19 of the 21164 hardware reference
101 summary
|= (ULL(1) << i
);
106 if (ipl
&& ipl
> cpu
->readMiscRegNoEffect(IPR_IPLR
)) {
107 cpu
->setMiscRegNoEffect(IPR_ISR
, summary
);
108 cpu
->setMiscRegNoEffect(IPR_INTID
, ipl
);
109 cpu
->trap(new InterruptFault
);
110 DPRINTF(Flow
, "Interrupt! IPLR=%d ipl=%d summary=%x\n",
111 cpu
->readMiscRegNoEffect(IPR_IPLR
), ipl
, summary
);
118 zeroRegisters(CPU
*cpu
)
120 // Insure ISA semantics
121 // (no longer very clean due to the change in setIntReg() in the
122 // cpu model. Consider changing later.)
123 cpu
->thread
->setIntReg(ZeroReg
, 0);
124 cpu
->thread
->setFloatReg(ZeroReg
, 0.0);
129 ////////////////////////////////////////////////////////////////////////
134 initIPRs(ThreadContext
*tc
, int cpuId
)
136 for (int i
= 0; i
< NumInternalProcRegs
; ++i
) {
137 tc
->setMiscRegNoEffect(i
, 0);
140 tc
->setMiscRegNoEffect(IPR_PAL_BASE
, PalBase
);
141 tc
->setMiscRegNoEffect(IPR_MCSR
, 0x6);
142 tc
->setMiscRegNoEffect(IPR_PALtemp16
, cpuId
);
146 ISA::readIpr(int idx
, ThreadContext
*tc
)
148 uint64_t retval
= 0; // return value, default 0
182 case IPR_IC_PERR_STAT
:
183 case IPR_DC_PERR_STAT
:
199 retval
|= ipr
[idx
] & ULL(0xffffffff00000000);
200 retval
|= tc
->getCpuPtr()->curCycle() & ULL(0x00000000ffffffff);
209 case IPR_IFAULT_VA_FORM
:
218 = tc
->getDTBPtr()->index(!tc
->misspeculating());
220 retval
|= ((uint64_t)entry
.ppn
& ULL(0x7ffffff)) << 32;
221 retval
|= ((uint64_t)entry
.xre
& ULL(0xf)) << 8;
222 retval
|= ((uint64_t)entry
.xwe
& ULL(0xf)) << 12;
223 retval
|= ((uint64_t)entry
.fonr
& ULL(0x1)) << 1;
224 retval
|= ((uint64_t)entry
.fonw
& ULL(0x1))<< 2;
225 retval
|= ((uint64_t)entry
.asma
& ULL(0x1)) << 4;
226 retval
|= ((uint64_t)entry
.asn
& ULL(0x7f)) << 57;
230 // write only registers
240 panic("Tried to read write only register %d\n", idx
);
245 panic("Tried to read from invalid ipr %d\n", idx
);
253 // Cause the simulator to break when changing to the following IPL
258 ISA::setIpr(int idx
, uint64_t val
, ThreadContext
*tc
)
262 if (tc
->misspeculating())
290 case IPR_IC_PERR_STAT
:
291 case IPR_DC_PERR_STAT
:
293 // write entire quad w/ no side-effect
298 // This IPR resets the cycle counter. We assume this only
299 // happens once... let's verify that.
300 assert(ipr
[idx
] == 0);
305 // This IPR only writes the upper 64 bits. It's ok to write
306 // all 64 here since we mask out the lower 32 in rpcc (see
312 // write entire quad w/ no side-effect
316 if (tc
->getKernelStats())
317 tc
->getKernelStats()->context(old
, val
, tc
);
322 // write entire quad w/ no side-effect, tag is forthcoming
327 // second least significant bit in PC is always zero
333 // only write least significant four bits - privilege mask
334 ipr
[idx
] = val
& 0xf;
339 if (break_ipl
!= -1 && break_ipl
== (int)(val
& 0x1f))
343 // only write least significant five bits - interrupt level
344 ipr
[idx
] = val
& 0x1f;
346 if (tc
->getKernelStats())
347 tc
->getKernelStats()->swpipl(ipr
[idx
]);
354 if (tc
->getKernelStats())
355 tc
->getKernelStats()->mode(Kernel::user
, tc
);
357 if (tc
->getKernelStats())
358 tc
->getKernelStats()->mode(Kernel::kernel
, tc
);
363 // only write two mode bits - processor mode
364 ipr
[idx
] = val
& 0x18;
368 // only write two mode bits - processor mode
369 ipr
[idx
] = val
& 0x18;
373 // more here after optimization...
378 // only write software interrupt mask
379 ipr
[idx
] = val
& 0x7fff0;
383 ipr
[idx
] = val
& ULL(0xffffff0300);
388 ipr
[idx
] = val
& ULL(0xffffffffc0000000);
391 case IPR_DC_TEST_CTL
:
392 ipr
[idx
] = val
& 0x1ffb;
397 ipr
[idx
] = val
& 0x3f;
401 ipr
[idx
] = val
& 0x7f0;
405 ipr
[idx
] = val
& ULL(0xfe00000000000000);
410 // any write to this register clears it
417 case IPR_ITB_PTE_TEMP
:
418 case IPR_DTB_PTE_TEMP
:
419 // read-only registers
420 panic("Tried to write read only ipr %d\n", idx
);
426 // the following are write only
431 // really a control write
434 tc
->getDTBPtr()->flushAll();
438 // really a control write
441 tc
->getDTBPtr()->flushProcesses();
445 // really a control write
448 tc
->getDTBPtr()->flushAddr(val
, DTB_ASN_ASN(ipr
[IPR_DTB_ASN
]));
452 struct TlbEntry entry
;
454 // FIXME: granularity hints NYI...
455 if (DTB_PTE_GH(ipr
[IPR_DTB_PTE
]) != 0)
456 panic("PTE GH field != 0");
461 // construct PTE for new entry
462 entry
.ppn
= DTB_PTE_PPN(ipr
[IPR_DTB_PTE
]);
463 entry
.xre
= DTB_PTE_XRE(ipr
[IPR_DTB_PTE
]);
464 entry
.xwe
= DTB_PTE_XWE(ipr
[IPR_DTB_PTE
]);
465 entry
.fonr
= DTB_PTE_FONR(ipr
[IPR_DTB_PTE
]);
466 entry
.fonw
= DTB_PTE_FONW(ipr
[IPR_DTB_PTE
]);
467 entry
.asma
= DTB_PTE_ASMA(ipr
[IPR_DTB_PTE
]);
468 entry
.asn
= DTB_ASN_ASN(ipr
[IPR_DTB_ASN
]);
470 // insert new TAG/PTE value into data TLB
471 tc
->getDTBPtr()->insert(val
, entry
);
476 struct TlbEntry entry
;
478 // FIXME: granularity hints NYI...
479 if (ITB_PTE_GH(val
) != 0)
480 panic("PTE GH field != 0");
485 // construct PTE for new entry
486 entry
.ppn
= ITB_PTE_PPN(val
);
487 entry
.xre
= ITB_PTE_XRE(val
);
489 entry
.fonr
= ITB_PTE_FONR(val
);
490 entry
.fonw
= ITB_PTE_FONW(val
);
491 entry
.asma
= ITB_PTE_ASMA(val
);
492 entry
.asn
= ITB_ASN_ASN(ipr
[IPR_ITB_ASN
]);
494 // insert new TAG/PTE value into data TLB
495 tc
->getITBPtr()->insert(ipr
[IPR_ITB_TAG
], entry
);
500 // really a control write
503 tc
->getITBPtr()->flushAll();
507 // really a control write
510 tc
->getITBPtr()->flushProcesses();
514 // really a control write
517 tc
->getITBPtr()->flushAddr(val
, ITB_ASN_ASN(ipr
[IPR_ITB_ASN
]));
522 panic("Tried to write to invalid ipr %d\n", idx
);
529 copyIprs(ThreadContext
*src
, ThreadContext
*dest
)
531 for (int i
= 0; i
< NumInternalProcRegs
; ++i
)
532 dest
->setMiscRegNoEffect(i
, src
->readMiscRegNoEffect(i
));
535 } // namespace AlphaISA
539 using namespace AlphaISA
;
542 SimpleThread::hwrei()
544 if (!(readPC() & 0x3))
545 return new UnimplementedOpcodeFault
;
547 setNextPC(readMiscRegNoEffect(IPR_EXC_ADDR
));
549 CPA::cpa()->swAutoBegin(tc
, readNextPC());
551 if (!misspeculating()) {
553 kernelStats
->hwrei();
556 // FIXME: XXX check for interrupts? XXX
561 * Check for special simulator handling of specific PAL calls.
562 * If return value is false, actual PAL call will be suppressed.
565 SimpleThread::simPalCheck(int palFunc
)
568 kernelStats
->callpal(palFunc
, tc
);
573 if (--System::numSystemsRunning
== 0)
574 exitSimLoop("all cpus halted");
579 if (system
->breakpoint())
587 #endif // FULL_SYSTEM