2 * Copyright (c) 2001-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.
31 #include "arch/sparc/asi.hh"
32 #include "arch/sparc/miscregfile.hh"
33 #include "arch/sparc/tlb.hh"
34 #include "base/bitfield.hh"
35 #include "base/trace.hh"
36 #include "cpu/thread_context.hh"
37 #include "cpu/base.hh"
38 #include "mem/packet_access.hh"
39 #include "mem/request.hh"
40 #include "sim/builder.hh"
42 /* @todo remove some of the magic constants. -- ali
47 TLB::TLB(const std::string
&name
, int s
)
48 : SimObject(name
), size(s
)
50 // To make this work you'll have to change the hypervisor and OS
52 fatal("SPARC T1 TLB registers don't support more than 64 TLB entries.");
54 tlb
= new TlbEntry
[size
];
55 memset(tlb
, 0, sizeof(TlbEntry
) * size
);
62 for (i
= lookupTable
.begin(); i
!= lookupTable
.end();) {
63 TlbEntry
*t
= i
->second
;
64 if (!t
->pte
.locked()) {
73 TLB::insert(Addr va
, int partition_id
, int context_id
, bool real
,
74 const PageTableEntry
& PTE
, int entry
)
79 TlbEntry
*new_entry
= NULL
;
82 DPRINTF(TLB
, "TLB: Inserting TLB Entry; va=%#x pa=%#x pid=%d cid=%d r=%d\n",
83 va
, PTE
.paddr(), partition_id
, context_id
, (int)real
);
86 assert(entry
< size
&& entry
>= 0);
87 new_entry
= &tlb
[entry
];
89 for (x
= 0; x
< size
; x
++) {
90 if (!tlb
[x
].valid
|| !tlb
[x
].used
) {
97 // Update the last ently if their all locked
99 new_entry
= &tlb
[size
-1];
102 new_entry
->range
.va
= va
;
103 new_entry
->range
.size
= PTE
.size();
104 new_entry
->range
.partitionId
= partition_id
;
105 new_entry
->range
.contextId
= context_id
;
106 new_entry
->range
.real
= real
;
107 new_entry
->pte
= PTE
;
108 new_entry
->used
= true;;
109 new_entry
->valid
= true;
113 // Demap any entry that conflicts
114 i
= lookupTable
.find(new_entry
->range
);
115 if (i
!= lookupTable
.end()) {
116 i
->second
->valid
= false;
117 if (i
->second
->used
) {
118 i
->second
->used
= false;
121 DPRINTF(TLB
, "TLB: Found conflicting entry, deleting it\n");
122 lookupTable
.erase(i
);
125 lookupTable
.insert(new_entry
->range
, new_entry
);;
127 // If all entries have there used bit set, clear it on them all, but the
128 // one we just inserted
129 if (usedEntries
== size
) {
131 new_entry
->used
= true;
139 TLB::lookup(Addr va
, int partition_id
, bool real
, int context_id
)
145 DPRINTF(TLB
, "TLB: Looking up entry va=%#x pid=%d cid=%d r=%d\n",
146 va
, partition_id
, context_id
, real
);
147 // Assemble full address structure
149 tr
.size
= va
+ MachineBytes
;
150 tr
.contextId
= context_id
;
151 tr
.partitionId
= partition_id
;
154 // Try to find the entry
155 i
= lookupTable
.find(tr
);
156 if (i
== lookupTable
.end()) {
157 DPRINTF(TLB
, "TLB: No valid entry found\n");
161 // Mark the entries used bit and clear other used bits in needed
163 DPRINTF(TLB
, "TLB: Valid entry found pa: %#x size: %#x\n", t
->pte
.paddr(),
168 if (usedEntries
== size
) {
181 for (int x
= 0; x
< size
; x
++) {
183 DPRINTFN("%4d: %#2x:%#2x %c %#4x %#8x %#8x %#16x\n",
184 x
, tlb
[x
].range
.partitionId
, tlb
[x
].range
.contextId
,
185 tlb
[x
].range
.real
? 'R' : ' ', tlb
[x
].range
.size
,
186 tlb
[x
].range
.va
, tlb
[x
].pte
.paddr(), tlb
[x
].pte());
192 TLB::demapPage(Addr va
, int partition_id
, bool real
, int context_id
)
197 // Assemble full address structure
199 tr
.size
= va
+ MachineBytes
;
200 tr
.contextId
= context_id
;
201 tr
.partitionId
= partition_id
;
204 // Demap any entry that conflicts
205 i
= lookupTable
.find(tr
);
206 if (i
!= lookupTable
.end()) {
207 i
->second
->valid
= false;
208 if (i
->second
->used
) {
209 i
->second
->used
= false;
212 lookupTable
.erase(i
);
217 TLB::demapContext(int partition_id
, int context_id
)
220 for (x
= 0; x
< size
; x
++) {
221 if (tlb
[x
].range
.contextId
== context_id
&&
222 tlb
[x
].range
.partitionId
== partition_id
) {
223 tlb
[x
].valid
= false;
228 lookupTable
.erase(tlb
[x
].range
);
234 TLB::demapAll(int partition_id
)
237 for (x
= 0; x
< size
; x
++) {
238 if (!tlb
[x
].pte
.locked() && tlb
[x
].range
.partitionId
== partition_id
) {
239 tlb
[x
].valid
= false;
244 lookupTable
.erase(tlb
[x
].range
);
253 for (x
= 0; x
< size
; x
++) {
254 tlb
[x
].valid
= false;
260 TLB::TteRead(int entry
) {
261 assert(entry
< size
);
262 return tlb
[entry
].pte();
266 TLB::TagRead(int entry
) {
267 assert(entry
< size
);
270 tag
= tlb
[entry
].range
.contextId
| tlb
[entry
].range
.va
|
271 (uint64_t)tlb
[entry
].range
.partitionId
<< 61;
272 tag
|= tlb
[entry
].range
.real
? ULL(1) << 60 : 0;
273 tag
|= (uint64_t)~tlb
[entry
].pte
._size() << 56;
278 TLB::validVirtualAddress(Addr va
, bool am
)
282 if (va
>= StartVAddrHole
&& va
<= EndVAddrHole
)
288 TLB::writeSfsr(ThreadContext
*tc
, int reg
, bool write
, ContextType ct
,
289 bool se
, FaultTypes ft
, int asi
)
292 sfsr
= tc
->readMiscReg(reg
);
306 tc
->setMiscRegWithEffect(reg
, sfsr
);
310 TLB::writeTagAccess(ThreadContext
*tc
, int reg
, Addr va
, int context
)
312 tc
->setMiscRegWithEffect(reg
, mbits(va
, 63,13) | mbits(context
,12,0));
316 ITB::writeSfsr(ThreadContext
*tc
, bool write
, ContextType ct
,
317 bool se
, FaultTypes ft
, int asi
)
319 DPRINTF(TLB
, "TLB: ITB Fault: w=%d ct=%d ft=%d asi=%d\n",
320 (int)write
, ct
, ft
, asi
);
321 TLB::writeSfsr(tc
, MISCREG_MMU_ITLB_SFSR
, write
, ct
, se
, ft
, asi
);
325 ITB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
327 TLB::writeTagAccess(tc
, MISCREG_MMU_ITLB_TAG_ACCESS
, va
, context
);
331 DTB::writeSfr(ThreadContext
*tc
, Addr a
, bool write
, ContextType ct
,
332 bool se
, FaultTypes ft
, int asi
)
334 DPRINTF(TLB
, "TLB: DTB Fault: A=%#x w=%d ct=%d ft=%d asi=%d\n",
335 a
, (int)write
, ct
, ft
, asi
);
336 TLB::writeSfsr(tc
, MISCREG_MMU_DTLB_SFSR
, write
, ct
, se
, ft
, asi
);
337 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
, a
);
341 DTB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
343 TLB::writeTagAccess(tc
, MISCREG_MMU_DTLB_TAG_ACCESS
, va
, context
);
349 ITB::translate(RequestPtr
&req
, ThreadContext
*tc
)
351 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
353 bool hpriv
= bits(tlbdata
,0,0);
354 bool red
= bits(tlbdata
,1,1);
355 bool priv
= bits(tlbdata
,2,2);
356 bool addr_mask
= bits(tlbdata
,3,3);
357 bool lsu_im
= bits(tlbdata
,4,4);
359 int part_id
= bits(tlbdata
,15,8);
360 int tl
= bits(tlbdata
,18,16);
361 int pri_context
= bits(tlbdata
,47,32);
363 Addr vaddr
= req
->getVaddr();
370 DPRINTF(TLB
, "TLB: ITB Request to translate va=%#x size=%d\n",
371 vaddr
, req
->getSize());
372 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsuim:%d part_id: %#X\n",
373 priv
, hpriv
, red
, lsu_im
, part_id
);
375 assert(req
->getAsi() == ASI_IMPLICIT
);
384 context
= pri_context
;
387 if ( hpriv
|| red
) {
388 req
->setPaddr(req
->getVaddr() & PAddrImplMask
);
392 // If the asi is unaligned trap
393 if (vaddr
& req
->getSize()-1) {
394 writeSfsr(tc
, false, ct
, false, OtherFault
, asi
);
395 return new MemAddressNotAligned
;
399 vaddr
= vaddr
& VAddrAMask
;
401 if (!validVirtualAddress(vaddr
, addr_mask
)) {
402 writeSfsr(tc
, false, ct
, false, VaOutOfRange
, asi
);
403 return new InstructionAccessException
;
407 e
= lookup(req
->getVaddr(), part_id
, true);
411 e
= lookup(vaddr
, part_id
, false, context
);
414 if (e
== NULL
|| !e
->valid
) {
415 tc
->setMiscReg(MISCREG_MMU_ITLB_TAG_ACCESS
,
416 vaddr
& ~BytesInPageMask
| context
);
418 return new InstructionRealTranslationMiss
;
420 return new FastInstructionAccessMMUMiss
;
423 // were not priviledged accesing priv page
424 if (!priv
&& e
->pte
.priv()) {
425 writeSfsr(tc
, false, ct
, false, PrivViolation
, asi
);
426 return new InstructionAccessException
;
429 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
430 req
->getVaddr() & e
->pte
.size()-1 );
431 DPRINTF(TLB
, "TLB: %#X -> %#X\n", req
->getVaddr(), req
->getPaddr());
438 DTB::translate(RequestPtr
&req
, ThreadContext
*tc
, bool write
)
440 /* @todo this could really use some profiling and fixing to make it faster! */
441 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
443 bool hpriv
= bits(tlbdata
,0,0);
444 bool red
= bits(tlbdata
,1,1);
445 bool priv
= bits(tlbdata
,2,2);
446 bool addr_mask
= bits(tlbdata
,3,3);
447 bool lsu_dm
= bits(tlbdata
,5,5);
449 int part_id
= bits(tlbdata
,15,8);
450 int tl
= bits(tlbdata
,18,16);
451 int pri_context
= bits(tlbdata
,47,32);
452 int sec_context
= bits(tlbdata
,47,32);
454 bool implicit
= false;
456 Addr vaddr
= req
->getVaddr();
457 Addr size
= req
->getSize();
458 ContextType ct
= Primary
;
464 asi
= (ASI
)req
->getAsi();
465 DPRINTF(TLB
, "TLB: DTB Request to translate va=%#x size=%d asi=%#x\n",
467 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsudm:%d part_id: %#X\n",
468 priv
, hpriv
, red
, lsu_dm
, part_id
);
469 if (asi
== ASI_IMPLICIT
)
480 context
= pri_context
;
482 } else if (!hpriv
&& !red
) {
483 if (tl
> 0 || AsiIsNucleus(asi
)) {
486 } else if (AsiIsSecondary(asi
)) {
488 context
= sec_context
;
490 context
= pri_context
;
494 // We need to check for priv level/asi priv
495 if (!priv
&& !AsiIsUnPriv(asi
)) {
496 // It appears that context should be Nucleus in these cases?
497 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
498 return new PrivilegedAction
;
500 if (priv
&& AsiIsHPriv(asi
)) {
501 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
502 return new DataAccessException
;
508 context
= pri_context
;
509 goto continueDtbFlow
;
514 if (AsiIsLittle(asi
))
515 panic("Little Endian ASIs not supported\n");
517 panic("Block ASIs not supported\n");
518 if (AsiIsNoFault(asi
))
519 panic("No Fault ASIs not supported\n");
520 if (write
&& asi
== ASI_LDTX_P
)
521 // block init store (like write hint64)
522 goto continueDtbFlow
;
524 panic("Twin ASIs not supported\n");
525 if (AsiIsPartialStore(asi
))
526 panic("Partial Store ASIs not supported\n");
527 if (AsiIsInterrupt(asi
))
528 panic("Interrupt ASIs not supported\n");
531 goto handleMmuRegAccess
;
532 if (AsiIsScratchPad(asi
))
533 goto handleScratchRegAccess
;
535 goto handleQueueRegAccess
;
536 if (AsiIsSparcError(asi
))
537 goto handleSparcErrorRegAccess
;
539 if (!AsiIsReal(asi
) && !AsiIsNucleus(asi
))
540 panic("Accessing ASI %#X. Should we?\n", asi
);
544 // If the asi is unaligned trap
545 if (vaddr
& size
-1) {
546 writeSfr(tc
, vaddr
, false, ct
, false, OtherFault
, asi
);
547 return new MemAddressNotAligned
;
551 vaddr
= vaddr
& VAddrAMask
;
553 if (!validVirtualAddress(vaddr
, addr_mask
)) {
554 writeSfr(tc
, vaddr
, false, ct
, true, VaOutOfRange
, asi
);
555 return new DataAccessException
;
559 if ((!lsu_dm
&& !hpriv
) || AsiIsReal(asi
)) {
564 if (hpriv
&& (implicit
|| (!AsiIsAsIfUser(asi
) && !AsiIsReal(asi
)))) {
565 req
->setPaddr(req
->getVaddr() & PAddrImplMask
);
569 e
= lookup(req
->getVaddr(), part_id
, real
, context
);
571 if (e
== NULL
|| !e
->valid
) {
572 tc
->setMiscReg(MISCREG_MMU_DTLB_TAG_ACCESS
,
573 vaddr
& ~BytesInPageMask
| context
);
574 DPRINTF(TLB
, "TLB: DTB Failed to find matching TLB entry\n");
576 return new DataRealTranslationMiss
;
578 return new FastDataAccessMMUMiss
;
583 if (write
&& !e
->pte
.writable()) {
584 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), OtherFault
, asi
);
585 return new FastDataAccessProtection
;
588 if (e
->pte
.nofault() && !AsiIsNoFault(asi
)) {
589 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), LoadFromNfo
, asi
);
590 return new DataAccessException
;
593 if (e
->pte
.sideffect())
594 req
->setFlags(req
->getFlags() | UNCACHEABLE
);
597 if (!priv
&& e
->pte
.priv()) {
598 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), PrivViolation
, asi
);
599 return new DataAccessException
;
602 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
603 req
->getVaddr() & e
->pte
.size()-1);
604 DPRINTF(TLB
, "TLB: %#X -> %#X\n", req
->getVaddr(), req
->getPaddr());
606 /** Normal flow ends here. */
608 handleScratchRegAccess
:
609 if (vaddr
> 0x38 || (vaddr
>= 0x20 && vaddr
< 0x30 && !hpriv
)) {
610 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
611 return new DataAccessException
;
615 handleQueueRegAccess
:
616 if (!priv
&& !hpriv
) {
617 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
618 return new PrivilegedAction
;
620 if (priv
&& vaddr
& 0xF || vaddr
> 0x3f8 || vaddr
< 0x3c0) {
621 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
622 return new DataAccessException
;
626 handleSparcErrorRegAccess
:
629 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
630 return new DataAccessException
;
632 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
633 return new PrivilegedAction
;
641 DPRINTF(TLB
, "TLB: DTB Translating MM IPR access\n");
642 req
->setMmapedIpr(true);
643 req
->setPaddr(req
->getVaddr());
648 DTB::doMmuRegRead(ThreadContext
*tc
, Packet
*pkt
)
650 Addr va
= pkt
->getAddr();
651 ASI asi
= (ASI
)pkt
->req
->getAsi();
653 uint64_t tsbtemp
, cnftemp
;
655 DPRINTF(IPR
, "Memory Mapped IPR Read: asi=%#X a=%#x\n",
656 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr());
659 case ASI_LSU_CONTROL_REG
:
661 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
));
666 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
));
669 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
));
676 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
679 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
681 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
));
683 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
685 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
));
687 case ASI_DMMU_CTXT_ZERO_CONFIG
:
689 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
));
691 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
693 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
));
695 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
697 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
));
699 case ASI_IMMU_CTXT_ZERO_CONFIG
:
701 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
));
703 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
705 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
));
707 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
709 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
));
711 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
713 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
715 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
717 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
));
719 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
721 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
));
723 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
725 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
727 case ASI_SPARC_ERROR_STATUS_REG
:
728 warn("returning 0 for SPARC ERROR regsiter read\n");
731 case ASI_HYP_SCRATCHPAD
:
733 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3)));
738 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
739 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
742 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
));
751 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
752 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
755 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
));
758 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
));
764 case ASI_DMMU_TSB_PS0_PTR_REG
:
765 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
766 if (bits(temp
,12,0) == 0) {
767 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
);
768 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
);
770 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
);
771 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
);
773 data
= mbits(tsbtemp
,63,13);
774 data
|= temp
>> (9 + bits(cnftemp
,2,0) * 3) &
775 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
776 warn("base addr: %#X tag access: %#X page size: %#X tsb size: %#X\n",
777 bits(tsbtemp
,63,13), temp
, bits(cnftemp
,2,0), bits(tsbtemp
,3,0));
780 case ASI_DMMU_TSB_PS1_PTR_REG
:
781 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
782 if (bits(temp
,12,0) == 0) {
783 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
);
784 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
);
786 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
);
787 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
);
789 data
= mbits(tsbtemp
,63,13);
790 if (bits(tsbtemp
,12,12))
791 data
|= ULL(1) << (13+bits(tsbtemp
,3,0));
792 data
|= temp
>> (9 + bits(cnftemp
,2,0) * 3) &
793 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
799 panic("need to impl DTB::doMmuRegRead() got asi=%#x, va=%#x\n",
802 pkt
->result
= Packet::Success
;
803 return tc
->getCpuPtr()->cycles(1);
807 DTB::doMmuRegWrite(ThreadContext
*tc
, Packet
*pkt
)
809 uint64_t data
= gtoh(pkt
->get
<uint64_t>());
810 Addr va
= pkt
->getAddr();
811 ASI asi
= (ASI
)pkt
->req
->getAsi();
817 int entry_insert
= -1;
821 DPRINTF(IPR
, "Memory Mapped IPR Write: asi=%#X a=%#x d=%#X\n",
822 (uint32_t)asi
, va
, data
);
825 case ASI_LSU_CONTROL_REG
:
827 tc
->setMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
, data
);
832 tc
->setMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
, data
);
835 tc
->setMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
, data
);
838 goto doMmuWriteError
;
842 assert(mbits(data
,13,6) == data
);
843 tc
->setMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
844 (va
>> 4) - 0x3c, data
);
846 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
848 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
, data
);
850 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
852 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
, data
);
854 case ASI_DMMU_CTXT_ZERO_CONFIG
:
856 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
, data
);
858 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
860 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
, data
);
862 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
864 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
, data
);
866 case ASI_IMMU_CTXT_ZERO_CONFIG
:
868 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
, data
);
870 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
872 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
, data
);
874 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
876 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
, data
);
878 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
880 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
, data
);
882 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
884 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
, data
);
886 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
888 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
, data
);
890 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
892 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
, data
);
894 case ASI_SPARC_ERROR_EN_REG
:
895 case ASI_SPARC_ERROR_STATUS_REG
:
896 warn("Ignoring write to SPARC ERROR regsiter\n");
898 case ASI_HYP_SCRATCHPAD
:
900 tc
->setMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3), data
);
905 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
, data
);
908 goto doMmuWriteError
;
911 case ASI_ITLB_DATA_ACCESS_REG
:
912 entry_insert
= bits(va
, 8,3);
913 case ASI_ITLB_DATA_IN_REG
:
914 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
915 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
916 va_insert
= mbits(ta_insert
, 63,13);
917 ct_insert
= mbits(ta_insert
, 12,0);
918 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
919 real_insert
= bits(va
, 9,9);
920 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
921 PageTableEntry::sun4u
);
922 tc
->getITBPtr()->insert(va_insert
, part_insert
, ct_insert
, real_insert
,
925 case ASI_DTLB_DATA_ACCESS_REG
:
926 entry_insert
= bits(va
, 8,3);
927 case ASI_DTLB_DATA_IN_REG
:
928 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
929 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
930 va_insert
= mbits(ta_insert
, 63,13);
931 ct_insert
= mbits(ta_insert
, 12,0);
932 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
933 real_insert
= bits(va
, 9,9);
934 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
935 PageTableEntry::sun4u
);
936 insert(va_insert
, part_insert
, ct_insert
, real_insert
, pte
, entry_insert
);
941 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
, data
);
944 tc
->setMiscRegWithEffect(MISCREG_MMU_PART_ID
, data
);
947 goto doMmuWriteError
;
952 panic("need to impl DTB::doMmuRegWrite() got asi=%#x, va=%#x d=%#x\n",
953 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr(), data
);
955 pkt
->result
= Packet::Success
;
956 return tc
->getCpuPtr()->cycles(1);
960 TLB::serialize(std::ostream
&os
)
962 panic("Need to implement serialize tlb for SPARC\n");
966 TLB::unserialize(Checkpoint
*cp
, const std::string
§ion
)
968 panic("Need to implement unserialize tlb for SPARC\n");
972 DEFINE_SIM_OBJECT_CLASS_NAME("SparcTLB", TLB
)
974 BEGIN_DECLARE_SIM_OBJECT_PARAMS(ITB
)
978 END_DECLARE_SIM_OBJECT_PARAMS(ITB
)
980 BEGIN_INIT_SIM_OBJECT_PARAMS(ITB
)
982 INIT_PARAM_DFLT(size
, "TLB size", 48)
984 END_INIT_SIM_OBJECT_PARAMS(ITB
)
987 CREATE_SIM_OBJECT(ITB
)
989 return new ITB(getInstanceName(), size
);
992 REGISTER_SIM_OBJECT("SparcITB", ITB
)
994 BEGIN_DECLARE_SIM_OBJECT_PARAMS(DTB
)
998 END_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1000 BEGIN_INIT_SIM_OBJECT_PARAMS(DTB
)
1002 INIT_PARAM_DFLT(size
, "TLB size", 64)
1004 END_INIT_SIM_OBJECT_PARAMS(DTB
)
1007 CREATE_SIM_OBJECT(DTB
)
1009 return new DTB(getInstanceName(), size
);
1012 REGISTER_SIM_OBJECT("SparcDTB", DTB
)