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/alpha_memory.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
) + fault_addr(ResetFault
);
83 regs
->npc
= regs
->pc
+ sizeof(MachInst
);
86 ////////////////////////////////////////////////////////////////////////
88 // alpha exceptions - value equals trap address, update with MD_FAULT_TYPE
91 AlphaISA::fault_addr(Fault fault
)
93 //Check for the system wide faults
94 if(fault
== NoFault
) return 0x0000;
95 else if(fault
== MachineCheckFault
) return 0x0401;
96 else if(fault
== AlignmentFault
) return 0x0301;
97 //Deal with the alpha specific faults
98 return ((AlphaFault
*)fault
)->vect
;
101 const int AlphaISA::reg_redir
[AlphaISA::NumIntRegs
] = {
102 /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0,
103 /* 8 */ 1, 1, 1, 1, 1, 1, 1, 0,
104 /* 16 */ 0, 0, 0, 0, 0, 0, 0, 0,
105 /* 24 */ 0, 1, 0, 0, 0, 0, 0, 0 };
107 ////////////////////////////////////////////////////////////////////////
112 AlphaISA::initIPRs(MiscRegFile
*miscRegs
, int cpuId
)
114 miscRegs
->clearIprs();
116 miscRegs
->setReg(IPR_PAL_BASE
, PalBase
);
117 miscRegs
->setReg(IPR_MCSR
, 0x6);
118 miscRegs
->setReg(IPR_PALtemp16
, cpuId
);
124 AlphaISA::processInterrupts(CPU
*cpu
)
126 //Check if there are any outstanding interrupts
127 //Handle the interrupts
131 cpu
->checkInterrupts
= false;
133 if (cpu
->readMiscReg(IPR_ASTRR
))
134 panic("asynchronous traps not implemented\n");
136 if (cpu
->readMiscReg(IPR_SIRR
)) {
137 for (int i
= INTLEVEL_SOFTWARE_MIN
;
138 i
< INTLEVEL_SOFTWARE_MAX
; i
++) {
139 if (cpu
->readMiscReg(IPR_SIRR
) & (ULL(1) << i
)) {
140 // See table 4-19 of the 21164 hardware reference
141 ipl
= (i
- INTLEVEL_SOFTWARE_MIN
) + 1;
142 summary
|= (ULL(1) << i
);
147 uint64_t interrupts
= cpu
->intr_status();
150 for (int i
= INTLEVEL_EXTERNAL_MIN
;
151 i
< INTLEVEL_EXTERNAL_MAX
; i
++) {
152 if (interrupts
& (ULL(1) << i
)) {
153 // See table 4-19 of the 21164 hardware reference
155 summary
|= (ULL(1) << i
);
160 if (ipl
&& ipl
> cpu
->readMiscReg(IPR_IPLR
)) {
161 cpu
->setMiscReg(IPR_ISR
, summary
);
162 cpu
->setMiscReg(IPR_INTID
, ipl
);
163 cpu
->trap(InterruptFault
);
164 DPRINTF(Flow
, "Interrupt! IPLR=%d ipl=%d summary=%x\n",
165 cpu
->readMiscReg(IPR_IPLR
), ipl
, summary
);
172 AlphaISA::zeroRegisters(CPU
*cpu
)
174 // Insure ISA semantics
175 // (no longer very clean due to the change in setIntReg() in the
176 // cpu model. Consider changing later.)
177 cpu
->xc
->setIntReg(ZeroReg
, 0);
178 cpu
->xc
->setFloatRegDouble(ZeroReg
, 0.0);
182 ExecContext::ev5_trap(Fault fault
)
184 DPRINTF(Fault
, "Fault %s at PC: %#x\n", fault
->name
, regs
.pc
);
185 cpu
->recordEvent(csprintf("Fault %s", fault
->name
));
187 assert(!misspeculating());
188 kernelStats
->fault(fault
);
190 if (fault
== ArithmeticFault
)
191 panic("Arithmetic traps are unimplemented!");
193 // exception restart address
194 if (fault
!= InterruptFault
|| !inPalMode())
195 setMiscReg(AlphaISA::IPR_EXC_ADDR
, regs
.pc
);
197 if (fault
== PalFault
|| fault
== ArithmeticFault
/* ||
198 fault == InterruptFault && !inPalMode() */) {
199 // traps... skip faulting instruction
200 setMiscReg(AlphaISA::IPR_EXC_ADDR
,
201 readMiscReg(AlphaISA::IPR_EXC_ADDR
) + 4);
205 AlphaISA::swap_palshadow(®s
, true);
207 regs
.pc
= readMiscReg(AlphaISA::IPR_PAL_BASE
) + AlphaISA::fault_addr(fault
);
208 regs
.npc
= regs
.pc
+ sizeof(MachInst
);
213 AlphaISA::intr_post(RegFile
*regs
, Fault fault
, Addr pc
)
215 bool use_pc
= (fault
== NoFault
);
217 if (fault
== ArithmeticFault
)
218 panic("arithmetic faults NYI...");
220 // compute exception restart address
221 if (use_pc
|| fault
== PalFault
|| fault
== ArithmeticFault
) {
222 // traps... skip faulting instruction
223 regs
->miscRegs
.setReg(IPR_EXC_ADDR
, regs
->pc
+ 4);
225 // fault, post fault at excepting instruction
226 regs
->miscRegs
.setReg(IPR_EXC_ADDR
, regs
->pc
);
229 // jump to expection address (PAL PC bit set here as well...)
231 regs
->npc
= regs
->miscRegs
.readReg(IPR_PAL_BASE
) +
234 regs
->npc
= regs
->miscRegs
.readReg(IPR_PAL_BASE
) + pc
;
236 // that's it! (orders of magnitude less painful than x86)
243 return UnimplementedOpcodeFault
;
245 setNextPC(readMiscReg(AlphaISA::IPR_EXC_ADDR
));
247 if (!misspeculating()) {
248 kernelStats
->hwrei();
250 if ((readMiscReg(AlphaISA::IPR_EXC_ADDR
) & 1) == 0)
251 AlphaISA::swap_palshadow(®s
, false);
253 cpu
->checkInterrupts
= true;
256 // FIXME: XXX check for interrupts? XXX
261 AlphaISA::MiscRegFile::clearIprs()
263 bzero((char *)ipr
, NumInternalProcRegs
* sizeof(InternalProcReg
));
267 AlphaISA::MiscRegFile::readIpr(int idx
, Fault
&fault
, ExecContext
*xc
)
269 uint64_t retval
= 0; // return value, default 0
272 case AlphaISA::IPR_PALtemp0
:
273 case AlphaISA::IPR_PALtemp1
:
274 case AlphaISA::IPR_PALtemp2
:
275 case AlphaISA::IPR_PALtemp3
:
276 case AlphaISA::IPR_PALtemp4
:
277 case AlphaISA::IPR_PALtemp5
:
278 case AlphaISA::IPR_PALtemp6
:
279 case AlphaISA::IPR_PALtemp7
:
280 case AlphaISA::IPR_PALtemp8
:
281 case AlphaISA::IPR_PALtemp9
:
282 case AlphaISA::IPR_PALtemp10
:
283 case AlphaISA::IPR_PALtemp11
:
284 case AlphaISA::IPR_PALtemp12
:
285 case AlphaISA::IPR_PALtemp13
:
286 case AlphaISA::IPR_PALtemp14
:
287 case AlphaISA::IPR_PALtemp15
:
288 case AlphaISA::IPR_PALtemp16
:
289 case AlphaISA::IPR_PALtemp17
:
290 case AlphaISA::IPR_PALtemp18
:
291 case AlphaISA::IPR_PALtemp19
:
292 case AlphaISA::IPR_PALtemp20
:
293 case AlphaISA::IPR_PALtemp21
:
294 case AlphaISA::IPR_PALtemp22
:
295 case AlphaISA::IPR_PALtemp23
:
296 case AlphaISA::IPR_PAL_BASE
:
298 case AlphaISA::IPR_IVPTBR
:
299 case AlphaISA::IPR_DC_MODE
:
300 case AlphaISA::IPR_MAF_MODE
:
301 case AlphaISA::IPR_ISR
:
302 case AlphaISA::IPR_EXC_ADDR
:
303 case AlphaISA::IPR_IC_PERR_STAT
:
304 case AlphaISA::IPR_DC_PERR_STAT
:
305 case AlphaISA::IPR_MCSR
:
306 case AlphaISA::IPR_ASTRR
:
307 case AlphaISA::IPR_ASTER
:
308 case AlphaISA::IPR_SIRR
:
309 case AlphaISA::IPR_ICSR
:
310 case AlphaISA::IPR_ICM
:
311 case AlphaISA::IPR_DTB_CM
:
312 case AlphaISA::IPR_IPLR
:
313 case AlphaISA::IPR_INTID
:
314 case AlphaISA::IPR_PMCTR
:
319 case AlphaISA::IPR_CC
:
320 retval
|= ipr
[idx
] & ULL(0xffffffff00000000);
321 retval
|= xc
->cpu
->curCycle() & ULL(0x00000000ffffffff);
324 case AlphaISA::IPR_VA
:
328 case AlphaISA::IPR_VA_FORM
:
329 case AlphaISA::IPR_MM_STAT
:
330 case AlphaISA::IPR_IFAULT_VA_FORM
:
331 case AlphaISA::IPR_EXC_MASK
:
332 case AlphaISA::IPR_EXC_SUM
:
336 case AlphaISA::IPR_DTB_PTE
:
338 AlphaISA::PTE
&pte
= xc
->dtb
->index(!xc
->misspeculating());
340 retval
|= ((u_int64_t
)pte
.ppn
& ULL(0x7ffffff)) << 32;
341 retval
|= ((u_int64_t
)pte
.xre
& ULL(0xf)) << 8;
342 retval
|= ((u_int64_t
)pte
.xwe
& ULL(0xf)) << 12;
343 retval
|= ((u_int64_t
)pte
.fonr
& ULL(0x1)) << 1;
344 retval
|= ((u_int64_t
)pte
.fonw
& ULL(0x1))<< 2;
345 retval
|= ((u_int64_t
)pte
.asma
& ULL(0x1)) << 4;
346 retval
|= ((u_int64_t
)pte
.asn
& ULL(0x7f)) << 57;
350 // write only registers
351 case AlphaISA::IPR_HWINT_CLR
:
352 case AlphaISA::IPR_SL_XMIT
:
353 case AlphaISA::IPR_DC_FLUSH
:
354 case AlphaISA::IPR_IC_FLUSH
:
355 case AlphaISA::IPR_ALT_MODE
:
356 case AlphaISA::IPR_DTB_IA
:
357 case AlphaISA::IPR_DTB_IAP
:
358 case AlphaISA::IPR_ITB_IA
:
359 case AlphaISA::IPR_ITB_IAP
:
360 fault
= UnimplementedOpcodeFault
;
365 fault
= UnimplementedOpcodeFault
;
373 // Cause the simulator to break when changing to the following IPL
378 AlphaISA::MiscRegFile::setIpr(int idx
, uint64_t val
, ExecContext
*xc
)
382 if (xc
->misspeculating())
386 case AlphaISA::IPR_PALtemp0
:
387 case AlphaISA::IPR_PALtemp1
:
388 case AlphaISA::IPR_PALtemp2
:
389 case AlphaISA::IPR_PALtemp3
:
390 case AlphaISA::IPR_PALtemp4
:
391 case AlphaISA::IPR_PALtemp5
:
392 case AlphaISA::IPR_PALtemp6
:
393 case AlphaISA::IPR_PALtemp7
:
394 case AlphaISA::IPR_PALtemp8
:
395 case AlphaISA::IPR_PALtemp9
:
396 case AlphaISA::IPR_PALtemp10
:
397 case AlphaISA::IPR_PALtemp11
:
398 case AlphaISA::IPR_PALtemp12
:
399 case AlphaISA::IPR_PALtemp13
:
400 case AlphaISA::IPR_PALtemp14
:
401 case AlphaISA::IPR_PALtemp15
:
402 case AlphaISA::IPR_PALtemp16
:
403 case AlphaISA::IPR_PALtemp17
:
404 case AlphaISA::IPR_PALtemp18
:
405 case AlphaISA::IPR_PALtemp19
:
406 case AlphaISA::IPR_PALtemp20
:
407 case AlphaISA::IPR_PALtemp21
:
408 case AlphaISA::IPR_PALtemp22
:
409 case AlphaISA::IPR_PAL_BASE
:
410 case AlphaISA::IPR_IC_PERR_STAT
:
411 case AlphaISA::IPR_DC_PERR_STAT
:
412 case AlphaISA::IPR_PMCTR
:
413 // write entire quad w/ no side-effect
417 case AlphaISA::IPR_CC_CTL
:
418 // This IPR resets the cycle counter. We assume this only
419 // happens once... let's verify that.
420 assert(ipr
[idx
] == 0);
424 case AlphaISA::IPR_CC
:
425 // This IPR only writes the upper 64 bits. It's ok to write
426 // all 64 here since we mask out the lower 32 in rpcc (see
431 case AlphaISA::IPR_PALtemp23
:
432 // write entire quad w/ no side-effect
435 xc
->kernelStats
->context(old
, val
);
438 case AlphaISA::IPR_DTB_PTE
:
439 // write entire quad w/ no side-effect, tag is forthcoming
443 case AlphaISA::IPR_EXC_ADDR
:
444 // second least significant bit in PC is always zero
448 case AlphaISA::IPR_ASTRR
:
449 case AlphaISA::IPR_ASTER
:
450 // only write least significant four bits - privilege mask
451 ipr
[idx
] = val
& 0xf;
454 case AlphaISA::IPR_IPLR
:
456 if (break_ipl
!= -1 && break_ipl
== (val
& 0x1f))
460 // only write least significant five bits - interrupt level
461 ipr
[idx
] = val
& 0x1f;
462 xc
->kernelStats
->swpipl(ipr
[idx
]);
465 case AlphaISA::IPR_DTB_CM
:
467 xc
->kernelStats
->mode(Kernel::user
);
469 xc
->kernelStats
->mode(Kernel::kernel
);
471 case AlphaISA::IPR_ICM
:
472 // only write two mode bits - processor mode
473 ipr
[idx
] = val
& 0x18;
476 case AlphaISA::IPR_ALT_MODE
:
477 // only write two mode bits - processor mode
478 ipr
[idx
] = val
& 0x18;
481 case AlphaISA::IPR_MCSR
:
482 // more here after optimization...
486 case AlphaISA::IPR_SIRR
:
487 // only write software interrupt mask
488 ipr
[idx
] = val
& 0x7fff0;
491 case AlphaISA::IPR_ICSR
:
492 ipr
[idx
] = val
& ULL(0xffffff0300);
495 case AlphaISA::IPR_IVPTBR
:
496 case AlphaISA::IPR_MVPTBR
:
497 ipr
[idx
] = val
& ULL(0xffffffffc0000000);
500 case AlphaISA::IPR_DC_TEST_CTL
:
501 ipr
[idx
] = val
& 0x1ffb;
504 case AlphaISA::IPR_DC_MODE
:
505 case AlphaISA::IPR_MAF_MODE
:
506 ipr
[idx
] = val
& 0x3f;
509 case AlphaISA::IPR_ITB_ASN
:
510 ipr
[idx
] = val
& 0x7f0;
513 case AlphaISA::IPR_DTB_ASN
:
514 ipr
[idx
] = val
& ULL(0xfe00000000000000);
517 case AlphaISA::IPR_EXC_SUM
:
518 case AlphaISA::IPR_EXC_MASK
:
519 // any write to this register clears it
523 case AlphaISA::IPR_INTID
:
524 case AlphaISA::IPR_SL_RCV
:
525 case AlphaISA::IPR_MM_STAT
:
526 case AlphaISA::IPR_ITB_PTE_TEMP
:
527 case AlphaISA::IPR_DTB_PTE_TEMP
:
528 // read-only registers
529 return UnimplementedOpcodeFault
;
531 case AlphaISA::IPR_HWINT_CLR
:
532 case AlphaISA::IPR_SL_XMIT
:
533 case AlphaISA::IPR_DC_FLUSH
:
534 case AlphaISA::IPR_IC_FLUSH
:
535 // the following are write only
539 case AlphaISA::IPR_DTB_IA
:
540 // really a control write
546 case AlphaISA::IPR_DTB_IAP
:
547 // really a control write
550 xc
->dtb
->flushProcesses();
553 case AlphaISA::IPR_DTB_IS
:
554 // really a control write
557 xc
->dtb
->flushAddr(val
, DTB_ASN_ASN(ipr
[AlphaISA::IPR_DTB_ASN
]));
560 case AlphaISA::IPR_DTB_TAG
: {
561 struct AlphaISA::PTE pte
;
563 // FIXME: granularity hints NYI...
564 if (DTB_PTE_GH(ipr
[AlphaISA::IPR_DTB_PTE
]) != 0)
565 panic("PTE GH field != 0");
570 // construct PTE for new entry
571 pte
.ppn
= DTB_PTE_PPN(ipr
[AlphaISA::IPR_DTB_PTE
]);
572 pte
.xre
= DTB_PTE_XRE(ipr
[AlphaISA::IPR_DTB_PTE
]);
573 pte
.xwe
= DTB_PTE_XWE(ipr
[AlphaISA::IPR_DTB_PTE
]);
574 pte
.fonr
= DTB_PTE_FONR(ipr
[AlphaISA::IPR_DTB_PTE
]);
575 pte
.fonw
= DTB_PTE_FONW(ipr
[AlphaISA::IPR_DTB_PTE
]);
576 pte
.asma
= DTB_PTE_ASMA(ipr
[AlphaISA::IPR_DTB_PTE
]);
577 pte
.asn
= DTB_ASN_ASN(ipr
[AlphaISA::IPR_DTB_ASN
]);
579 // insert new TAG/PTE value into data TLB
580 xc
->dtb
->insert(val
, pte
);
584 case AlphaISA::IPR_ITB_PTE
: {
585 struct AlphaISA::PTE pte
;
587 // FIXME: granularity hints NYI...
588 if (ITB_PTE_GH(val
) != 0)
589 panic("PTE GH field != 0");
594 // construct PTE for new entry
595 pte
.ppn
= ITB_PTE_PPN(val
);
596 pte
.xre
= ITB_PTE_XRE(val
);
598 pte
.fonr
= ITB_PTE_FONR(val
);
599 pte
.fonw
= ITB_PTE_FONW(val
);
600 pte
.asma
= ITB_PTE_ASMA(val
);
601 pte
.asn
= ITB_ASN_ASN(ipr
[AlphaISA::IPR_ITB_ASN
]);
603 // insert new TAG/PTE value into data TLB
604 xc
->itb
->insert(ipr
[AlphaISA::IPR_ITB_TAG
], pte
);
608 case AlphaISA::IPR_ITB_IA
:
609 // really a control write
615 case AlphaISA::IPR_ITB_IAP
:
616 // really a control write
619 xc
->itb
->flushProcesses();
622 case AlphaISA::IPR_ITB_IS
:
623 // really a control write
626 xc
->itb
->flushAddr(val
, ITB_ASN_ASN(ipr
[AlphaISA::IPR_ITB_ASN
]));
631 return UnimplementedOpcodeFault
;
639 * Check for special simulator handling of specific PAL calls.
640 * If return value is false, actual PAL call will be suppressed.
643 ExecContext::simPalCheck(int palFunc
)
645 kernelStats
->callpal(palFunc
);
650 if (--System::numSystemsRunning
== 0)
651 new SimExitEvent("all cpus halted");
656 if (system
->breakpoint())
664 //Forward instantiation for FastCPU object
666 void AlphaISA::processInterrupts(FastCPU
*xc
);
668 //Forward instantiation for FastCPU object
670 void AlphaISA::zeroRegisters(FastCPU
*xc
);
672 #endif // FULL_SYSTEM