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.
29 #include "arch/alpha/tlb.hh"
30 #include "arch/alpha/isa_traits.hh"
31 #include "arch/alpha/osfpal.hh"
32 #include "base/kgdb.h"
33 #include "base/remote_gdb.hh"
34 #include "base/stats/events.hh"
35 #include "config/full_system.hh"
36 #include "cpu/base.hh"
37 #include "cpu/exec_context.hh"
38 #include "cpu/fast/cpu.hh"
39 #include "kern/kernel_stats.hh"
40 #include "sim/debug.hh"
41 #include "sim/sim_events.hh"
47 ////////////////////////////////////////////////////////////////////////
52 AlphaISA::swap_palshadow(RegFile
*regs
, bool use_shadow
)
54 if (regs
->pal_shadow
== use_shadow
)
55 panic("swap_palshadow: wrong PAL shadow state");
57 regs
->pal_shadow
= use_shadow
;
59 for (int i
= 0; i
< NumIntRegs
; i
++) {
61 IntReg temp
= regs
->intRegFile
[i
];
62 regs
->intRegFile
[i
] = regs
->palregs
[i
];
63 regs
->palregs
[i
] = temp
;
68 ////////////////////////////////////////////////////////////////////////
70 // Machine dependent functions
73 AlphaISA::initCPU(RegFile
*regs
, int cpuId
)
75 initIPRs(®s
->miscRegs
, cpuId
);
76 // CPU comes up with PAL regs enabled
77 swap_palshadow(regs
, true);
79 regs
->intRegFile
[16] = cpuId
;
80 regs
->intRegFile
[0] = cpuId
;
82 regs
->pc
= regs
->miscRegs
.readReg(IPR_PAL_BASE
) + (new ResetFault
)->vect();
83 regs
->npc
= regs
->pc
+ sizeof(MachInst
);
86 const int AlphaISA::reg_redir
[AlphaISA::NumIntRegs
] = {
87 /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0,
88 /* 8 */ 1, 1, 1, 1, 1, 1, 1, 0,
89 /* 16 */ 0, 0, 0, 0, 0, 0, 0, 0,
90 /* 24 */ 0, 1, 0, 0, 0, 0, 0, 0 };
92 ////////////////////////////////////////////////////////////////////////
97 AlphaISA::initIPRs(MiscRegFile
*miscRegs
, int cpuId
)
99 miscRegs
->clearIprs();
101 miscRegs
->setReg(IPR_PAL_BASE
, PalBase
);
102 miscRegs
->setReg(IPR_MCSR
, 0x6);
103 miscRegs
->setReg(IPR_PALtemp16
, cpuId
);
109 AlphaISA::processInterrupts(CPU
*cpu
)
111 //Check if there are any outstanding interrupts
112 //Handle the interrupts
116 cpu
->checkInterrupts
= false;
118 if (cpu
->readMiscReg(IPR_ASTRR
))
119 panic("asynchronous traps not implemented\n");
121 if (cpu
->readMiscReg(IPR_SIRR
)) {
122 for (int i
= INTLEVEL_SOFTWARE_MIN
;
123 i
< INTLEVEL_SOFTWARE_MAX
; i
++) {
124 if (cpu
->readMiscReg(IPR_SIRR
) & (ULL(1) << i
)) {
125 // See table 4-19 of the 21164 hardware reference
126 ipl
= (i
- INTLEVEL_SOFTWARE_MIN
) + 1;
127 summary
|= (ULL(1) << i
);
132 uint64_t interrupts
= cpu
->intr_status();
135 for (int i
= INTLEVEL_EXTERNAL_MIN
;
136 i
< INTLEVEL_EXTERNAL_MAX
; i
++) {
137 if (interrupts
& (ULL(1) << i
)) {
138 // See table 4-19 of the 21164 hardware reference
140 summary
|= (ULL(1) << i
);
145 if (ipl
&& ipl
> cpu
->readMiscReg(IPR_IPLR
)) {
146 cpu
->setMiscReg(IPR_ISR
, summary
);
147 cpu
->setMiscReg(IPR_INTID
, ipl
);
148 cpu
->trap(new InterruptFault
);
149 DPRINTF(Flow
, "Interrupt! IPLR=%d ipl=%d summary=%x\n",
150 cpu
->readMiscReg(IPR_IPLR
), ipl
, summary
);
157 AlphaISA::zeroRegisters(CPU
*cpu
)
159 // Insure ISA semantics
160 // (no longer very clean due to the change in setIntReg() in the
161 // cpu model. Consider changing later.)
162 cpu
->xc
->setIntReg(ZeroReg
, 0);
163 cpu
->xc
->setFloatRegDouble(ZeroReg
, 0.0);
167 AlphaISA::intr_post(RegFile
*regs
, Fault fault
, Addr pc
)
169 /* bool use_pc = (fault == NoFault);
171 if (fault->isA<ArithmeticFault>())
172 panic("arithmetic faults NYI...");
174 // compute exception restart address
175 if (use_pc || fault->isA<PalFault>() || fault->isA<ArithmeticFault>()) {
176 // traps... skip faulting instruction
177 regs->miscRegs.setReg(IPR_EXC_ADDR, regs->pc + 4);
179 // fault, post fault at excepting instruction
180 regs->miscRegs.setReg(IPR_EXC_ADDR, regs->pc);
183 // jump to expection address (PAL PC bit set here as well...)
185 regs->npc = regs->miscRegs.readReg(IPR_PAL_BASE) +
186 (dynamic_cast<AlphaFault *>(fault.get()))->vect();
188 regs->npc = regs->miscRegs.readReg(IPR_PAL_BASE) + pc;
190 // that's it! (orders of magnitude less painful than x86)
197 return new UnimplementedOpcodeFault
;
199 setNextPC(readMiscReg(AlphaISA::IPR_EXC_ADDR
));
201 if (!misspeculating()) {
202 kernelStats
->hwrei();
204 if ((readMiscReg(AlphaISA::IPR_EXC_ADDR
) & 1) == 0)
205 AlphaISA::swap_palshadow(®s
, false);
207 cpu
->checkInterrupts
= true;
210 // FIXME: XXX check for interrupts? XXX
215 AlphaISA::MiscRegFile::clearIprs()
217 bzero((char *)ipr
, NumInternalProcRegs
* sizeof(InternalProcReg
));
221 AlphaISA::MiscRegFile::readIpr(int idx
, Fault
&fault
, ExecContext
*xc
)
223 uint64_t retval
= 0; // return value, default 0
226 case AlphaISA::IPR_PALtemp0
:
227 case AlphaISA::IPR_PALtemp1
:
228 case AlphaISA::IPR_PALtemp2
:
229 case AlphaISA::IPR_PALtemp3
:
230 case AlphaISA::IPR_PALtemp4
:
231 case AlphaISA::IPR_PALtemp5
:
232 case AlphaISA::IPR_PALtemp6
:
233 case AlphaISA::IPR_PALtemp7
:
234 case AlphaISA::IPR_PALtemp8
:
235 case AlphaISA::IPR_PALtemp9
:
236 case AlphaISA::IPR_PALtemp10
:
237 case AlphaISA::IPR_PALtemp11
:
238 case AlphaISA::IPR_PALtemp12
:
239 case AlphaISA::IPR_PALtemp13
:
240 case AlphaISA::IPR_PALtemp14
:
241 case AlphaISA::IPR_PALtemp15
:
242 case AlphaISA::IPR_PALtemp16
:
243 case AlphaISA::IPR_PALtemp17
:
244 case AlphaISA::IPR_PALtemp18
:
245 case AlphaISA::IPR_PALtemp19
:
246 case AlphaISA::IPR_PALtemp20
:
247 case AlphaISA::IPR_PALtemp21
:
248 case AlphaISA::IPR_PALtemp22
:
249 case AlphaISA::IPR_PALtemp23
:
250 case AlphaISA::IPR_PAL_BASE
:
252 case AlphaISA::IPR_IVPTBR
:
253 case AlphaISA::IPR_DC_MODE
:
254 case AlphaISA::IPR_MAF_MODE
:
255 case AlphaISA::IPR_ISR
:
256 case AlphaISA::IPR_EXC_ADDR
:
257 case AlphaISA::IPR_IC_PERR_STAT
:
258 case AlphaISA::IPR_DC_PERR_STAT
:
259 case AlphaISA::IPR_MCSR
:
260 case AlphaISA::IPR_ASTRR
:
261 case AlphaISA::IPR_ASTER
:
262 case AlphaISA::IPR_SIRR
:
263 case AlphaISA::IPR_ICSR
:
264 case AlphaISA::IPR_ICM
:
265 case AlphaISA::IPR_DTB_CM
:
266 case AlphaISA::IPR_IPLR
:
267 case AlphaISA::IPR_INTID
:
268 case AlphaISA::IPR_PMCTR
:
273 case AlphaISA::IPR_CC
:
274 retval
|= ipr
[idx
] & ULL(0xffffffff00000000);
275 retval
|= xc
->cpu
->curCycle() & ULL(0x00000000ffffffff);
278 case AlphaISA::IPR_VA
:
282 case AlphaISA::IPR_VA_FORM
:
283 case AlphaISA::IPR_MM_STAT
:
284 case AlphaISA::IPR_IFAULT_VA_FORM
:
285 case AlphaISA::IPR_EXC_MASK
:
286 case AlphaISA::IPR_EXC_SUM
:
290 case AlphaISA::IPR_DTB_PTE
:
292 AlphaISA::PTE
&pte
= xc
->dtb
->index(!xc
->misspeculating());
294 retval
|= ((u_int64_t
)pte
.ppn
& ULL(0x7ffffff)) << 32;
295 retval
|= ((u_int64_t
)pte
.xre
& ULL(0xf)) << 8;
296 retval
|= ((u_int64_t
)pte
.xwe
& ULL(0xf)) << 12;
297 retval
|= ((u_int64_t
)pte
.fonr
& ULL(0x1)) << 1;
298 retval
|= ((u_int64_t
)pte
.fonw
& ULL(0x1))<< 2;
299 retval
|= ((u_int64_t
)pte
.asma
& ULL(0x1)) << 4;
300 retval
|= ((u_int64_t
)pte
.asn
& ULL(0x7f)) << 57;
304 // write only registers
305 case AlphaISA::IPR_HWINT_CLR
:
306 case AlphaISA::IPR_SL_XMIT
:
307 case AlphaISA::IPR_DC_FLUSH
:
308 case AlphaISA::IPR_IC_FLUSH
:
309 case AlphaISA::IPR_ALT_MODE
:
310 case AlphaISA::IPR_DTB_IA
:
311 case AlphaISA::IPR_DTB_IAP
:
312 case AlphaISA::IPR_ITB_IA
:
313 case AlphaISA::IPR_ITB_IAP
:
314 fault
= new UnimplementedOpcodeFault
;
319 fault
= new UnimplementedOpcodeFault
;
327 // Cause the simulator to break when changing to the following IPL
332 AlphaISA::MiscRegFile::setIpr(int idx
, uint64_t val
, ExecContext
*xc
)
336 if (xc
->misspeculating())
340 case AlphaISA::IPR_PALtemp0
:
341 case AlphaISA::IPR_PALtemp1
:
342 case AlphaISA::IPR_PALtemp2
:
343 case AlphaISA::IPR_PALtemp3
:
344 case AlphaISA::IPR_PALtemp4
:
345 case AlphaISA::IPR_PALtemp5
:
346 case AlphaISA::IPR_PALtemp6
:
347 case AlphaISA::IPR_PALtemp7
:
348 case AlphaISA::IPR_PALtemp8
:
349 case AlphaISA::IPR_PALtemp9
:
350 case AlphaISA::IPR_PALtemp10
:
351 case AlphaISA::IPR_PALtemp11
:
352 case AlphaISA::IPR_PALtemp12
:
353 case AlphaISA::IPR_PALtemp13
:
354 case AlphaISA::IPR_PALtemp14
:
355 case AlphaISA::IPR_PALtemp15
:
356 case AlphaISA::IPR_PALtemp16
:
357 case AlphaISA::IPR_PALtemp17
:
358 case AlphaISA::IPR_PALtemp18
:
359 case AlphaISA::IPR_PALtemp19
:
360 case AlphaISA::IPR_PALtemp20
:
361 case AlphaISA::IPR_PALtemp21
:
362 case AlphaISA::IPR_PALtemp22
:
363 case AlphaISA::IPR_PAL_BASE
:
364 case AlphaISA::IPR_IC_PERR_STAT
:
365 case AlphaISA::IPR_DC_PERR_STAT
:
366 case AlphaISA::IPR_PMCTR
:
367 // write entire quad w/ no side-effect
371 case AlphaISA::IPR_CC_CTL
:
372 // This IPR resets the cycle counter. We assume this only
373 // happens once... let's verify that.
374 assert(ipr
[idx
] == 0);
378 case AlphaISA::IPR_CC
:
379 // This IPR only writes the upper 64 bits. It's ok to write
380 // all 64 here since we mask out the lower 32 in rpcc (see
385 case AlphaISA::IPR_PALtemp23
:
386 // write entire quad w/ no side-effect
389 xc
->kernelStats
->context(old
, val
);
392 case AlphaISA::IPR_DTB_PTE
:
393 // write entire quad w/ no side-effect, tag is forthcoming
397 case AlphaISA::IPR_EXC_ADDR
:
398 // second least significant bit in PC is always zero
402 case AlphaISA::IPR_ASTRR
:
403 case AlphaISA::IPR_ASTER
:
404 // only write least significant four bits - privilege mask
405 ipr
[idx
] = val
& 0xf;
408 case AlphaISA::IPR_IPLR
:
410 if (break_ipl
!= -1 && break_ipl
== (val
& 0x1f))
414 // only write least significant five bits - interrupt level
415 ipr
[idx
] = val
& 0x1f;
416 xc
->kernelStats
->swpipl(ipr
[idx
]);
419 case AlphaISA::IPR_DTB_CM
:
421 xc
->kernelStats
->mode(Kernel::user
);
423 xc
->kernelStats
->mode(Kernel::kernel
);
425 case AlphaISA::IPR_ICM
:
426 // only write two mode bits - processor mode
427 ipr
[idx
] = val
& 0x18;
430 case AlphaISA::IPR_ALT_MODE
:
431 // only write two mode bits - processor mode
432 ipr
[idx
] = val
& 0x18;
435 case AlphaISA::IPR_MCSR
:
436 // more here after optimization...
440 case AlphaISA::IPR_SIRR
:
441 // only write software interrupt mask
442 ipr
[idx
] = val
& 0x7fff0;
445 case AlphaISA::IPR_ICSR
:
446 ipr
[idx
] = val
& ULL(0xffffff0300);
449 case AlphaISA::IPR_IVPTBR
:
450 case AlphaISA::IPR_MVPTBR
:
451 ipr
[idx
] = val
& ULL(0xffffffffc0000000);
454 case AlphaISA::IPR_DC_TEST_CTL
:
455 ipr
[idx
] = val
& 0x1ffb;
458 case AlphaISA::IPR_DC_MODE
:
459 case AlphaISA::IPR_MAF_MODE
:
460 ipr
[idx
] = val
& 0x3f;
463 case AlphaISA::IPR_ITB_ASN
:
464 ipr
[idx
] = val
& 0x7f0;
467 case AlphaISA::IPR_DTB_ASN
:
468 ipr
[idx
] = val
& ULL(0xfe00000000000000);
471 case AlphaISA::IPR_EXC_SUM
:
472 case AlphaISA::IPR_EXC_MASK
:
473 // any write to this register clears it
477 case AlphaISA::IPR_INTID
:
478 case AlphaISA::IPR_SL_RCV
:
479 case AlphaISA::IPR_MM_STAT
:
480 case AlphaISA::IPR_ITB_PTE_TEMP
:
481 case AlphaISA::IPR_DTB_PTE_TEMP
:
482 // read-only registers
483 return new UnimplementedOpcodeFault
;
485 case AlphaISA::IPR_HWINT_CLR
:
486 case AlphaISA::IPR_SL_XMIT
:
487 case AlphaISA::IPR_DC_FLUSH
:
488 case AlphaISA::IPR_IC_FLUSH
:
489 // the following are write only
493 case AlphaISA::IPR_DTB_IA
:
494 // really a control write
500 case AlphaISA::IPR_DTB_IAP
:
501 // really a control write
504 xc
->dtb
->flushProcesses();
507 case AlphaISA::IPR_DTB_IS
:
508 // really a control write
511 xc
->dtb
->flushAddr(val
, DTB_ASN_ASN(ipr
[AlphaISA::IPR_DTB_ASN
]));
514 case AlphaISA::IPR_DTB_TAG
: {
515 struct AlphaISA::PTE pte
;
517 // FIXME: granularity hints NYI...
518 if (DTB_PTE_GH(ipr
[AlphaISA::IPR_DTB_PTE
]) != 0)
519 panic("PTE GH field != 0");
524 // construct PTE for new entry
525 pte
.ppn
= DTB_PTE_PPN(ipr
[AlphaISA::IPR_DTB_PTE
]);
526 pte
.xre
= DTB_PTE_XRE(ipr
[AlphaISA::IPR_DTB_PTE
]);
527 pte
.xwe
= DTB_PTE_XWE(ipr
[AlphaISA::IPR_DTB_PTE
]);
528 pte
.fonr
= DTB_PTE_FONR(ipr
[AlphaISA::IPR_DTB_PTE
]);
529 pte
.fonw
= DTB_PTE_FONW(ipr
[AlphaISA::IPR_DTB_PTE
]);
530 pte
.asma
= DTB_PTE_ASMA(ipr
[AlphaISA::IPR_DTB_PTE
]);
531 pte
.asn
= DTB_ASN_ASN(ipr
[AlphaISA::IPR_DTB_ASN
]);
533 // insert new TAG/PTE value into data TLB
534 xc
->dtb
->insert(val
, pte
);
538 case AlphaISA::IPR_ITB_PTE
: {
539 struct AlphaISA::PTE pte
;
541 // FIXME: granularity hints NYI...
542 if (ITB_PTE_GH(val
) != 0)
543 panic("PTE GH field != 0");
548 // construct PTE for new entry
549 pte
.ppn
= ITB_PTE_PPN(val
);
550 pte
.xre
= ITB_PTE_XRE(val
);
552 pte
.fonr
= ITB_PTE_FONR(val
);
553 pte
.fonw
= ITB_PTE_FONW(val
);
554 pte
.asma
= ITB_PTE_ASMA(val
);
555 pte
.asn
= ITB_ASN_ASN(ipr
[AlphaISA::IPR_ITB_ASN
]);
557 // insert new TAG/PTE value into data TLB
558 xc
->itb
->insert(ipr
[AlphaISA::IPR_ITB_TAG
], pte
);
562 case AlphaISA::IPR_ITB_IA
:
563 // really a control write
569 case AlphaISA::IPR_ITB_IAP
:
570 // really a control write
573 xc
->itb
->flushProcesses();
576 case AlphaISA::IPR_ITB_IS
:
577 // really a control write
580 xc
->itb
->flushAddr(val
, ITB_ASN_ASN(ipr
[AlphaISA::IPR_ITB_ASN
]));
585 return new UnimplementedOpcodeFault
;
593 * Check for special simulator handling of specific PAL calls.
594 * If return value is false, actual PAL call will be suppressed.
597 ExecContext::simPalCheck(int palFunc
)
599 kernelStats
->callpal(palFunc
);
604 if (--System::numSystemsRunning
== 0)
605 new SimExitEvent("all cpus halted");
610 if (system
->breakpoint())
618 //Forward instantiation for FastCPU object
620 void AlphaISA::processInterrupts(FastCPU
*xc
);
622 //Forward instantiation for FastCPU object
624 void AlphaISA::zeroRegisters(FastCPU
*xc
);
626 #endif // FULL_SYSTEM