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 ////////////////////////////////////////////////////////////////////////
69 initIPRs(ThreadContext
*tc
, int cpuId
)
71 for (int i
= 0; i
< NumInternalProcRegs
; ++i
) {
72 tc
->setMiscRegNoEffect(i
, 0);
75 tc
->setMiscRegNoEffect(IPR_PAL_BASE
, PalBase
);
76 tc
->setMiscRegNoEffect(IPR_MCSR
, 0x6);
77 tc
->setMiscRegNoEffect(IPR_PALtemp16
, cpuId
);
81 ISA::readIpr(int idx
, ThreadContext
*tc
)
83 uint64_t retval
= 0; // return value, default 0
117 case IPR_IC_PERR_STAT
:
118 case IPR_DC_PERR_STAT
:
134 retval
|= ipr
[idx
] & ULL(0xffffffff00000000);
135 retval
|= tc
->getCpuPtr()->curCycle() & ULL(0x00000000ffffffff);
144 case IPR_IFAULT_VA_FORM
:
152 TlbEntry
&entry
= getDTBPtr(tc
)->index(1);
154 retval
|= ((uint64_t)entry
.ppn
& ULL(0x7ffffff)) << 32;
155 retval
|= ((uint64_t)entry
.xre
& ULL(0xf)) << 8;
156 retval
|= ((uint64_t)entry
.xwe
& ULL(0xf)) << 12;
157 retval
|= ((uint64_t)entry
.fonr
& ULL(0x1)) << 1;
158 retval
|= ((uint64_t)entry
.fonw
& ULL(0x1))<< 2;
159 retval
|= ((uint64_t)entry
.asma
& ULL(0x1)) << 4;
160 retval
|= ((uint64_t)entry
.asn
& ULL(0x7f)) << 57;
164 // write only registers
174 panic("Tried to read write only register %d\n", idx
);
179 panic("Tried to read from invalid ipr %d\n", idx
);
186 // Cause the simulator to break when changing to the following IPL
190 ISA::setIpr(int idx
, uint64_t val
, ThreadContext
*tc
)
192 auto *stats
= dynamic_cast<AlphaISA::Kernel::Statistics
*>(
193 tc
->getKernelStats());
194 assert(stats
|| !tc
->getKernelStats());
220 case IPR_IC_PERR_STAT
:
221 case IPR_DC_PERR_STAT
:
223 // write entire quad w/ no side-effect
228 // This IPR resets the cycle counter. We assume this only
229 // happens once... let's verify that.
230 assert(ipr
[idx
] == 0);
235 // This IPR only writes the upper 64 bits. It's ok to write
236 // all 64 here since we mask out the lower 32 in rpcc (see
242 // write entire quad w/ no side-effect
244 stats
->context(ipr
[idx
], val
, tc
);
249 // write entire quad w/ no side-effect, tag is forthcoming
254 // second least significant bit in PC is always zero
260 // only write least significant four bits - privilege mask
261 ipr
[idx
] = val
& 0xf;
265 // only write least significant five bits - interrupt level
266 ipr
[idx
] = val
& 0x1f;
268 stats
->swpipl(ipr
[idx
]);
274 stats
->mode(Kernel::user
, tc
);
277 stats
->mode(Kernel::kernel
, tc
);
282 // only write two mode bits - processor mode
283 ipr
[idx
] = val
& 0x18;
287 // only write two mode bits - processor mode
288 ipr
[idx
] = val
& 0x18;
292 // more here after optimization...
297 // only write software interrupt mask
298 ipr
[idx
] = val
& 0x7fff0;
302 ipr
[idx
] = val
& ULL(0xffffff0300);
307 ipr
[idx
] = val
& ULL(0xffffffffc0000000);
310 case IPR_DC_TEST_CTL
:
311 ipr
[idx
] = val
& 0x1ffb;
316 ipr
[idx
] = val
& 0x3f;
320 ipr
[idx
] = val
& 0x7f0;
324 ipr
[idx
] = val
& ULL(0xfe00000000000000);
329 // any write to this register clears it
336 case IPR_ITB_PTE_TEMP
:
337 case IPR_DTB_PTE_TEMP
:
338 // read-only registers
339 panic("Tried to write read only ipr %d\n", idx
);
345 // the following are write only
350 // really a control write
353 getDTBPtr(tc
)->flushAll();
357 // really a control write
360 getDTBPtr(tc
)->flushProcesses();
364 // really a control write
367 getDTBPtr(tc
)->flushAddr(val
, DTB_ASN_ASN(ipr
[IPR_DTB_ASN
]));
371 struct TlbEntry entry
;
373 // FIXME: granularity hints NYI...
374 if (DTB_PTE_GH(ipr
[IPR_DTB_PTE
]) != 0)
375 panic("PTE GH field != 0");
380 // construct PTE for new entry
381 entry
.ppn
= DTB_PTE_PPN(ipr
[IPR_DTB_PTE
]);
382 entry
.xre
= DTB_PTE_XRE(ipr
[IPR_DTB_PTE
]);
383 entry
.xwe
= DTB_PTE_XWE(ipr
[IPR_DTB_PTE
]);
384 entry
.fonr
= DTB_PTE_FONR(ipr
[IPR_DTB_PTE
]);
385 entry
.fonw
= DTB_PTE_FONW(ipr
[IPR_DTB_PTE
]);
386 entry
.asma
= DTB_PTE_ASMA(ipr
[IPR_DTB_PTE
]);
387 entry
.asn
= DTB_ASN_ASN(ipr
[IPR_DTB_ASN
]);
389 // insert new TAG/PTE value into data TLB
390 getDTBPtr(tc
)->insert(val
, entry
);
395 struct TlbEntry entry
;
397 // FIXME: granularity hints NYI...
398 if (ITB_PTE_GH(val
) != 0)
399 panic("PTE GH field != 0");
404 // construct PTE for new entry
405 entry
.ppn
= ITB_PTE_PPN(val
);
406 entry
.xre
= ITB_PTE_XRE(val
);
408 entry
.fonr
= ITB_PTE_FONR(val
);
409 entry
.fonw
= ITB_PTE_FONW(val
);
410 entry
.asma
= ITB_PTE_ASMA(val
);
411 entry
.asn
= ITB_ASN_ASN(ipr
[IPR_ITB_ASN
]);
413 // insert new TAG/PTE value into data TLB
414 getITBPtr(tc
)->insert(ipr
[IPR_ITB_TAG
], entry
);
419 // really a control write
422 getITBPtr(tc
)->flushAll();
426 // really a control write
429 getITBPtr(tc
)->flushProcesses();
433 // really a control write
436 getITBPtr(tc
)->flushAddr(val
, ITB_ASN_ASN(ipr
[IPR_ITB_ASN
]));
441 panic("Tried to write to invalid ipr %d\n", idx
);
448 copyIprs(ThreadContext
*src
, ThreadContext
*dest
)
450 for (int i
= 0; i
< NumInternalProcRegs
; ++i
)
451 dest
->setMiscRegNoEffect(i
, src
->readMiscRegNoEffect(i
));
454 } // namespace AlphaISA