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.
33 #include "arch/sparc/asi.hh"
34 #include "arch/sparc/faults.hh"
35 #include "arch/sparc/registers.hh"
36 #include "arch/sparc/tlb.hh"
37 #include "base/bitfield.hh"
38 #include "base/trace.hh"
39 #include "cpu/base.hh"
40 #include "cpu/thread_context.hh"
41 #include "debug/IPR.hh"
42 #include "debug/TLB.hh"
43 #include "mem/packet_access.hh"
44 #include "mem/request.hh"
45 #include "sim/full_system.hh"
46 #include "sim/system.hh"
48 /* @todo remove some of the magic constants. -- ali
52 TLB::TLB(const Params
*p
)
53 : BaseTLB(p
), size(p
->size
), usedEntries(0), lastReplaced(0),
54 cacheState(0), cacheValid(false)
56 // To make this work you'll have to change the hypervisor and OS
58 fatal("SPARC T1 TLB registers don't support more than 64 TLB entries");
60 tlb
= new TlbEntry
[size
];
61 std::memset(tlb
, 0, sizeof(TlbEntry
) * size
);
63 for (int x
= 0; x
< size
; x
++)
64 freeList
.push_back(&tlb
[x
]);
83 for (i
= lookupTable
.begin(); i
!= lookupTable
.end(); i
++) {
84 TlbEntry
*t
= i
->second
;
85 if (!t
->pte
.locked()) {
94 TLB::insert(Addr va
, int partition_id
, int context_id
, bool real
,
95 const PageTableEntry
& PTE
, int entry
)
98 TlbEntry
*new_entry
= NULL
;
103 va
&= ~(PTE
.size()-1);
105 tr.size = PTE.size() - 1;
106 tr.contextId = context_id;
107 tr.partitionId = partition_id;
112 "TLB: Inserting Entry; va=%#x pa=%#x pid=%d cid=%d r=%d entryid=%d\n",
113 va
, PTE
.paddr(), partition_id
, context_id
, (int)real
, entry
);
115 // Demap any entry that conflicts
116 for (x
= 0; x
< size
; x
++) {
117 if (tlb
[x
].range
.real
== real
&&
118 tlb
[x
].range
.partitionId
== partition_id
&&
119 tlb
[x
].range
.va
< va
+ PTE
.size() - 1 &&
120 tlb
[x
].range
.va
+ tlb
[x
].range
.size
>= va
&&
121 (real
|| tlb
[x
].range
.contextId
== context_id
))
124 freeList
.push_front(&tlb
[x
]);
125 DPRINTF(TLB
, "TLB: Conflicting entry %#X , deleting it\n", x
);
127 tlb
[x
].valid
= false;
132 lookupTable
.erase(tlb
[x
].range
);
138 assert(entry
< size
&& entry
>= 0);
139 new_entry
= &tlb
[entry
];
141 if (!freeList
.empty()) {
142 new_entry
= freeList
.front();
149 if (x
== lastReplaced
)
150 goto insertAllLocked
;
151 } while (tlb
[x
].pte
.locked());
158 // Update the last ently if their all locked
160 new_entry
= &tlb
[size
-1];
163 freeList
.remove(new_entry
);
164 if (new_entry
->valid
&& new_entry
->used
)
166 if (new_entry
->valid
)
167 lookupTable
.erase(new_entry
->range
);
171 new_entry
->range
.va
= va
;
172 new_entry
->range
.size
= PTE
.size() - 1;
173 new_entry
->range
.partitionId
= partition_id
;
174 new_entry
->range
.contextId
= context_id
;
175 new_entry
->range
.real
= real
;
176 new_entry
->pte
= PTE
;
177 new_entry
->used
= true;;
178 new_entry
->valid
= true;
181 i
= lookupTable
.insert(new_entry
->range
, new_entry
);
182 assert(i
!= lookupTable
.end());
184 // If all entries have their used bit set, clear it on them all,
185 // but the one we just inserted
186 if (usedEntries
== size
) {
188 new_entry
->used
= true;
195 TLB::lookup(Addr va
, int partition_id
, bool real
, int context_id
,
202 DPRINTF(TLB
, "TLB: Looking up entry va=%#x pid=%d cid=%d r=%d\n",
203 va
, partition_id
, context_id
, real
);
204 // Assemble full address structure
207 tr
.contextId
= context_id
;
208 tr
.partitionId
= partition_id
;
211 // Try to find the entry
212 i
= lookupTable
.find(tr
);
213 if (i
== lookupTable
.end()) {
214 DPRINTF(TLB
, "TLB: No valid entry found\n");
218 // Mark the entries used bit and clear other used bits in needed
220 DPRINTF(TLB
, "TLB: Valid entry found pa: %#x size: %#x\n", t
->pte
.paddr(),
223 // Update the used bits only if this is a real access (not a fake
224 // one from virttophys()
225 if (!t
->used
&& update_used
) {
228 if (usedEntries
== size
) {
242 for (int x
= 0; x
< size
; x
++) {
244 DPRINTFN("%4d: %#2x:%#2x %c %#4x %#8x %#8x %#16x\n",
245 x
, tlb
[x
].range
.partitionId
, tlb
[x
].range
.contextId
,
246 tlb
[x
].range
.real
? 'R' : ' ', tlb
[x
].range
.size
,
247 tlb
[x
].range
.va
, tlb
[x
].pte
.paddr(), tlb
[x
].pte());
253 TLB::demapPage(Addr va
, int partition_id
, bool real
, int context_id
)
258 DPRINTF(IPR
, "TLB: Demapping Page va=%#x pid=%#d cid=%d r=%d\n",
259 va
, partition_id
, context_id
, real
);
263 // Assemble full address structure
266 tr
.contextId
= context_id
;
267 tr
.partitionId
= partition_id
;
270 // Demap any entry that conflicts
271 i
= lookupTable
.find(tr
);
272 if (i
!= lookupTable
.end()) {
273 DPRINTF(IPR
, "TLB: Demapped page\n");
274 i
->second
->valid
= false;
275 if (i
->second
->used
) {
276 i
->second
->used
= false;
279 freeList
.push_front(i
->second
);
280 lookupTable
.erase(i
);
285 TLB::demapContext(int partition_id
, int context_id
)
287 DPRINTF(IPR
, "TLB: Demapping Context pid=%#d cid=%d\n",
288 partition_id
, context_id
);
290 for (int x
= 0; x
< size
; x
++) {
291 if (tlb
[x
].range
.contextId
== context_id
&&
292 tlb
[x
].range
.partitionId
== partition_id
) {
294 freeList
.push_front(&tlb
[x
]);
296 tlb
[x
].valid
= false;
301 lookupTable
.erase(tlb
[x
].range
);
307 TLB::demapAll(int partition_id
)
309 DPRINTF(TLB
, "TLB: Demapping All pid=%#d\n", partition_id
);
311 for (int x
= 0; x
< size
; x
++) {
312 if (tlb
[x
].valid
&& !tlb
[x
].pte
.locked() &&
313 tlb
[x
].range
.partitionId
== partition_id
) {
314 freeList
.push_front(&tlb
[x
]);
315 tlb
[x
].valid
= false;
320 lookupTable
.erase(tlb
[x
].range
);
331 for (int x
= 0; x
< size
; x
++) {
333 freeList
.push_back(&tlb
[x
]);
334 tlb
[x
].valid
= false;
341 TLB::TteRead(int entry
)
344 panic("entry: %d\n", entry
);
346 assert(entry
< size
);
347 if (tlb
[entry
].valid
)
348 return tlb
[entry
].pte();
350 return (uint64_t)-1ll;
354 TLB::TagRead(int entry
)
356 assert(entry
< size
);
358 if (!tlb
[entry
].valid
)
359 return (uint64_t)-1ll;
361 tag
= tlb
[entry
].range
.contextId
;
362 tag
|= tlb
[entry
].range
.va
;
363 tag
|= (uint64_t)tlb
[entry
].range
.partitionId
<< 61;
364 tag
|= tlb
[entry
].range
.real
? ULL(1) << 60 : 0;
365 tag
|= (uint64_t)~tlb
[entry
].pte
._size() << 56;
370 TLB::validVirtualAddress(Addr va
, bool am
)
374 if (va
>= StartVAddrHole
&& va
<= EndVAddrHole
)
380 TLB::writeSfsr(bool write
, ContextType ct
, bool se
, FaultTypes ft
, int asi
)
397 TLB::writeTagAccess(Addr va
, int context
)
399 DPRINTF(TLB
, "TLB: Writing Tag Access: va: %#X ctx: %#X value: %#X\n",
400 va
, context
, mbits(va
, 63,13) | mbits(context
,12,0));
402 tag_access
= mbits(va
, 63,13) | mbits(context
,12,0);
406 TLB::writeSfsr(Addr a
, bool write
, ContextType ct
,
407 bool se
, FaultTypes ft
, int asi
)
409 DPRINTF(TLB
, "TLB: Fault: A=%#x w=%d ct=%d ft=%d asi=%d\n",
410 a
, (int)write
, ct
, ft
, asi
);
411 TLB::writeSfsr(write
, ct
, se
, ft
, asi
);
416 TLB::translateInst(RequestPtr req
, ThreadContext
*tc
)
418 uint64_t tlbdata
= tc
->readMiscRegNoEffect(MISCREG_TLB_DATA
);
420 Addr vaddr
= req
->getVaddr();
423 assert(req
->getArchFlags() == ASI_IMPLICIT
);
425 DPRINTF(TLB
, "TLB: ITB Request to translate va=%#x size=%d\n",
426 vaddr
, req
->getSize());
428 // Be fast if we can!
429 if (cacheValid
&& cacheState
== tlbdata
) {
431 if (cacheEntry
[0]->range
.va
< vaddr
+ sizeof(MachInst
) &&
432 cacheEntry
[0]->range
.va
+ cacheEntry
[0]->range
.size
>= vaddr
) {
433 req
->setPaddr(cacheEntry
[0]->pte
.translate(vaddr
));
437 req
->setPaddr(vaddr
& PAddrImplMask
);
442 bool hpriv
= bits(tlbdata
,0,0);
443 bool red
= bits(tlbdata
,1,1);
444 bool priv
= bits(tlbdata
,2,2);
445 bool addr_mask
= bits(tlbdata
,3,3);
446 bool lsu_im
= bits(tlbdata
,4,4);
448 int part_id
= bits(tlbdata
,15,8);
449 int tl
= bits(tlbdata
,18,16);
450 int pri_context
= bits(tlbdata
,47,32);
456 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsuim:%d part_id: %#X\n",
457 priv
, hpriv
, red
, lsu_im
, part_id
);
466 context
= pri_context
;
469 if ( hpriv
|| red
) {
471 cacheState
= tlbdata
;
472 cacheEntry
[0] = NULL
;
473 req
->setPaddr(vaddr
& PAddrImplMask
);
477 // If the access is unaligned trap
479 writeSfsr(false, ct
, false, OtherFault
, asi
);
480 return new MemAddressNotAligned
;
484 vaddr
= vaddr
& VAddrAMask
;
486 if (!validVirtualAddress(vaddr
, addr_mask
)) {
487 writeSfsr(false, ct
, false, VaOutOfRange
, asi
);
488 return new InstructionAccessException
;
492 e
= lookup(vaddr
, part_id
, true);
496 e
= lookup(vaddr
, part_id
, false, context
);
499 if (e
== NULL
|| !e
->valid
) {
500 writeTagAccess(vaddr
, context
);
502 return new InstructionRealTranslationMiss
;
505 return new FastInstructionAccessMMUMiss
;
507 return new FastInstructionAccessMMUMiss(req
->getVaddr());
511 // were not priviledged accesing priv page
512 if (!priv
&& e
->pte
.priv()) {
513 writeTagAccess(vaddr
, context
);
514 writeSfsr(false, ct
, false, PrivViolation
, asi
);
515 return new InstructionAccessException
;
518 // cache translation date for next translation
520 cacheState
= tlbdata
;
523 req
->setPaddr(e
->pte
.translate(vaddr
));
524 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
529 TLB::translateData(RequestPtr req
, ThreadContext
*tc
, bool write
)
532 * @todo this could really use some profiling and fixing to make
535 uint64_t tlbdata
= tc
->readMiscRegNoEffect(MISCREG_TLB_DATA
);
536 Addr vaddr
= req
->getVaddr();
537 Addr size
= req
->getSize();
539 asi
= (ASI
)req
->getArchFlags();
540 bool implicit
= false;
541 bool hpriv
= bits(tlbdata
,0,0);
542 bool unaligned
= vaddr
& (size
- 1);
544 DPRINTF(TLB
, "TLB: DTB Request to translate va=%#x size=%d asi=%#x\n",
547 if (lookupTable
.size() != 64 - freeList
.size())
548 panic("Lookup table size: %d tlb size: %d\n", lookupTable
.size(),
550 if (asi
== ASI_IMPLICIT
)
553 // Only use the fast path here if there doesn't need to be an unaligned
556 if (hpriv
&& implicit
) {
557 req
->setPaddr(vaddr
& PAddrImplMask
);
561 // Be fast if we can!
562 if (cacheValid
&& cacheState
== tlbdata
) {
567 TlbEntry
*ce
= cacheEntry
[0];
568 Addr ce_va
= ce
->range
.va
;
569 if (cacheAsi
[0] == asi
&&
570 ce_va
< vaddr
+ size
&& ce_va
+ ce
->range
.size
> vaddr
&&
571 (!write
|| ce
->pte
.writable())) {
572 req
->setPaddr(ce
->pte
.translate(vaddr
));
573 if (ce
->pte
.sideffect() || (ce
->pte
.paddr() >> 39) & 1)
574 req
->setFlags(Request::UNCACHEABLE
);
575 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
578 } // if cache entry valid
580 TlbEntry
*ce
= cacheEntry
[1];
581 Addr ce_va
= ce
->range
.va
;
582 if (cacheAsi
[1] == asi
&&
583 ce_va
< vaddr
+ size
&& ce_va
+ ce
->range
.size
> vaddr
&&
584 (!write
|| ce
->pte
.writable())) {
585 req
->setPaddr(ce
->pte
.translate(vaddr
));
586 if (ce
->pte
.sideffect() || (ce
->pte
.paddr() >> 39) & 1)
587 req
->setFlags(Request::UNCACHEABLE
);
588 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
591 } // if cache entry valid
595 bool red
= bits(tlbdata
,1,1);
596 bool priv
= bits(tlbdata
,2,2);
597 bool addr_mask
= bits(tlbdata
,3,3);
598 bool lsu_dm
= bits(tlbdata
,5,5);
600 int part_id
= bits(tlbdata
,15,8);
601 int tl
= bits(tlbdata
,18,16);
602 int pri_context
= bits(tlbdata
,47,32);
603 int sec_context
= bits(tlbdata
,63,48);
606 ContextType ct
= Primary
;
611 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsudm:%d part_id: %#X\n",
612 priv
, hpriv
, red
, lsu_dm
, part_id
);
622 context
= pri_context
;
625 // We need to check for priv level/asi priv
626 if (!priv
&& !hpriv
&& !asiIsUnPriv(asi
)) {
627 // It appears that context should be Nucleus in these cases?
628 writeSfsr(vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
629 return new PrivilegedAction
;
632 if (!hpriv
&& asiIsHPriv(asi
)) {
633 writeSfsr(vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
634 return new DataAccessException
;
637 if (asiIsPrimary(asi
)) {
638 context
= pri_context
;
640 } else if (asiIsSecondary(asi
)) {
641 context
= sec_context
;
643 } else if (asiIsNucleus(asi
)) {
648 context
= pri_context
;
652 if (!implicit
&& asi
!= ASI_P
&& asi
!= ASI_S
) {
653 if (asiIsLittle(asi
))
654 panic("Little Endian ASIs not supported\n");
656 //XXX It's unclear from looking at the documentation how a no fault
657 // load differs from a regular one, other than what happens concerning
658 // nfo and e bits in the TTE
659 // if (asiIsNoFault(asi))
660 // panic("No Fault ASIs not supported\n");
662 if (asiIsPartialStore(asi
))
663 panic("Partial Store ASIs not supported\n");
666 panic("Cmt ASI registers not implmented\n");
668 if (asiIsInterrupt(asi
))
669 goto handleIntRegAccess
;
671 goto handleMmuRegAccess
;
672 if (asiIsScratchPad(asi
))
673 goto handleScratchRegAccess
;
675 goto handleQueueRegAccess
;
676 if (asiIsSparcError(asi
))
677 goto handleSparcErrorRegAccess
;
679 if (!asiIsReal(asi
) && !asiIsNucleus(asi
) && !asiIsAsIfUser(asi
) &&
680 !asiIsTwin(asi
) && !asiIsBlock(asi
) && !asiIsNoFault(asi
))
681 panic("Accessing ASI %#X. Should we?\n", asi
);
684 // If the asi is unaligned trap
686 writeSfsr(vaddr
, false, ct
, false, OtherFault
, asi
);
687 return new MemAddressNotAligned
;
691 vaddr
= vaddr
& VAddrAMask
;
693 if (!validVirtualAddress(vaddr
, addr_mask
)) {
694 writeSfsr(vaddr
, false, ct
, true, VaOutOfRange
, asi
);
695 return new DataAccessException
;
698 if ((!lsu_dm
&& !hpriv
&& !red
) || asiIsReal(asi
)) {
703 if (hpriv
&& (implicit
|| (!asiIsAsIfUser(asi
) && !asiIsReal(asi
)))) {
704 req
->setPaddr(vaddr
& PAddrImplMask
);
708 e
= lookup(vaddr
, part_id
, real
, context
);
710 if (e
== NULL
|| !e
->valid
) {
711 writeTagAccess(vaddr
, context
);
712 DPRINTF(TLB
, "TLB: DTB Failed to find matching TLB entry\n");
714 return new DataRealTranslationMiss
;
717 return new FastDataAccessMMUMiss
;
719 return new FastDataAccessMMUMiss(req
->getVaddr());
724 if (!priv
&& e
->pte
.priv()) {
725 writeTagAccess(vaddr
, context
);
726 writeSfsr(vaddr
, write
, ct
, e
->pte
.sideffect(), PrivViolation
, asi
);
727 return new DataAccessException
;
730 if (write
&& !e
->pte
.writable()) {
731 writeTagAccess(vaddr
, context
);
732 writeSfsr(vaddr
, write
, ct
, e
->pte
.sideffect(), OtherFault
, asi
);
733 return new FastDataAccessProtection
;
736 if (e
->pte
.nofault() && !asiIsNoFault(asi
)) {
737 writeTagAccess(vaddr
, context
);
738 writeSfsr(vaddr
, write
, ct
, e
->pte
.sideffect(), LoadFromNfo
, asi
);
739 return new DataAccessException
;
742 if (e
->pte
.sideffect() && asiIsNoFault(asi
)) {
743 writeTagAccess(vaddr
, context
);
744 writeSfsr(vaddr
, write
, ct
, e
->pte
.sideffect(), SideEffect
, asi
);
745 return new DataAccessException
;
748 if (e
->pte
.sideffect() || (e
->pte
.paddr() >> 39) & 1)
749 req
->setFlags(Request::UNCACHEABLE
);
751 // cache translation date for next translation
752 cacheState
= tlbdata
;
754 cacheEntry
[1] = NULL
;
755 cacheEntry
[0] = NULL
;
758 if (cacheEntry
[0] != e
&& cacheEntry
[1] != e
) {
759 cacheEntry
[1] = cacheEntry
[0];
761 cacheAsi
[1] = cacheAsi
[0];
764 cacheAsi
[0] = (ASI
)0;
767 req
->setPaddr(e
->pte
.translate(vaddr
));
768 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
771 /** Normal flow ends here. */
774 writeSfsr(vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
776 return new DataAccessException
;
778 return new PrivilegedAction
;
781 if ((asi
== ASI_SWVR_UDB_INTR_W
&& !write
) ||
782 (asi
== ASI_SWVR_UDB_INTR_R
&& write
)) {
783 writeSfsr(vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
784 return new DataAccessException
;
790 handleScratchRegAccess
:
791 if (vaddr
> 0x38 || (vaddr
>= 0x20 && vaddr
< 0x30 && !hpriv
)) {
792 writeSfsr(vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
793 return new DataAccessException
;
797 handleQueueRegAccess
:
798 if (!priv
&& !hpriv
) {
799 writeSfsr(vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
800 return new PrivilegedAction
;
802 if ((!hpriv
&& vaddr
& 0xF) || vaddr
> 0x3f8 || vaddr
< 0x3c0) {
803 writeSfsr(vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
804 return new DataAccessException
;
808 handleSparcErrorRegAccess
:
810 writeSfsr(vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
812 return new DataAccessException
;
814 return new PrivilegedAction
;
821 DPRINTF(TLB
, "TLB: DTB Translating MM IPR access\n");
822 req
->setFlags(Request::MMAPPED_IPR
);
823 req
->setPaddr(req
->getVaddr());
828 TLB::translateAtomic(RequestPtr req
, ThreadContext
*tc
, Mode mode
)
831 return translateInst(req
, tc
);
833 return translateData(req
, tc
, mode
== Write
);
837 TLB::translateTiming(RequestPtr req
, ThreadContext
*tc
,
838 Translation
*translation
, Mode mode
)
841 translation
->finish(translateAtomic(req
, tc
, mode
), req
, tc
, mode
);
845 TLB::translateFunctional(RequestPtr req
, ThreadContext
*tc
, Mode mode
)
847 panic("Not implemented\n");
852 TLB::finalizePhysical(RequestPtr req
, ThreadContext
*tc
, Mode mode
) const
858 TLB::doMmuRegRead(ThreadContext
*tc
, Packet
*pkt
)
860 Addr va
= pkt
->getAddr();
861 ASI asi
= (ASI
)pkt
->req
->getArchFlags();
864 DPRINTF(IPR
, "Memory Mapped IPR Read: asi=%#X a=%#x\n",
865 (uint32_t)pkt
->req
->getArchFlags(), pkt
->getAddr());
867 TLB
*itb
= tc
->getITBPtr();
870 case ASI_LSU_CONTROL_REG
:
872 pkt
->set(tc
->readMiscReg(MISCREG_MMU_LSU_CTRL
));
877 pkt
->set(tc
->readMiscReg(MISCREG_MMU_P_CONTEXT
));
880 pkt
->set(tc
->readMiscReg(MISCREG_MMU_S_CONTEXT
));
887 pkt
->set(tc
->readMiscReg(MISCREG_QUEUE_CPU_MONDO_HEAD
+
890 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
892 pkt
->set(c0_tsb_ps0
);
894 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
896 pkt
->set(c0_tsb_ps1
);
898 case ASI_DMMU_CTXT_ZERO_CONFIG
:
902 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
904 pkt
->set(itb
->c0_tsb_ps0
);
906 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
908 pkt
->set(itb
->c0_tsb_ps1
);
910 case ASI_IMMU_CTXT_ZERO_CONFIG
:
912 pkt
->set(itb
->c0_config
);
914 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
916 pkt
->set(cx_tsb_ps0
);
918 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
920 pkt
->set(cx_tsb_ps1
);
922 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
926 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
928 pkt
->set(itb
->cx_tsb_ps0
);
930 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
932 pkt
->set(itb
->cx_tsb_ps1
);
934 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
936 pkt
->set(itb
->cx_config
);
938 case ASI_SPARC_ERROR_STATUS_REG
:
939 pkt
->set((uint64_t)0);
941 case ASI_HYP_SCRATCHPAD
:
943 pkt
->set(tc
->readMiscReg(MISCREG_SCRATCHPAD_R0
+ (va
>> 3)));
948 temp
= itb
->tag_access
;
949 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
955 pkt
->set(itb
->tag_access
);
965 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
974 pkt
->set(tag_access
);
977 pkt
->set(tc
->readMiscReg(MISCREG_MMU_PART_ID
));
983 case ASI_DMMU_TSB_PS0_PTR_REG
:
984 pkt
->set(MakeTsbPtr(Ps0
,
991 case ASI_DMMU_TSB_PS1_PTR_REG
:
992 pkt
->set(MakeTsbPtr(Ps1
,
999 case ASI_IMMU_TSB_PS0_PTR_REG
:
1000 pkt
->set(MakeTsbPtr(Ps0
,
1007 case ASI_IMMU_TSB_PS1_PTR_REG
:
1008 pkt
->set(MakeTsbPtr(Ps1
,
1015 case ASI_SWVR_INTR_RECEIVE
:
1017 SparcISA::Interrupts
* interrupts
=
1018 dynamic_cast<SparcISA::Interrupts
*>(
1019 tc
->getCpuPtr()->getInterruptController());
1020 pkt
->set(interrupts
->get_vec(IT_INT_VEC
));
1023 case ASI_SWVR_UDB_INTR_R
:
1025 SparcISA::Interrupts
* interrupts
=
1026 dynamic_cast<SparcISA::Interrupts
*>(
1027 tc
->getCpuPtr()->getInterruptController());
1028 temp
= findMsbSet(interrupts
->get_vec(IT_INT_VEC
));
1029 tc
->getCpuPtr()->clearInterrupt(IT_INT_VEC
, temp
);
1035 panic("need to impl DTB::doMmuRegRead() got asi=%#x, va=%#x\n",
1038 pkt
->makeAtomicResponse();
1043 TLB::doMmuRegWrite(ThreadContext
*tc
, Packet
*pkt
)
1045 uint64_t data
= pkt
->get
<uint64_t>();
1046 Addr va
= pkt
->getAddr();
1047 ASI asi
= (ASI
)pkt
->req
->getArchFlags();
1053 int entry_insert
= -1;
1060 DPRINTF(IPR
, "Memory Mapped IPR Write: asi=%#X a=%#x d=%#X\n",
1061 (uint32_t)asi
, va
, data
);
1063 TLB
*itb
= tc
->getITBPtr();
1066 case ASI_LSU_CONTROL_REG
:
1068 tc
->setMiscReg(MISCREG_MMU_LSU_CTRL
, data
);
1073 tc
->setMiscReg(MISCREG_MMU_P_CONTEXT
, data
);
1076 tc
->setMiscReg(MISCREG_MMU_S_CONTEXT
, data
);
1079 goto doMmuWriteError
;
1083 assert(mbits(data
,13,6) == data
);
1084 tc
->setMiscReg(MISCREG_QUEUE_CPU_MONDO_HEAD
+
1085 (va
>> 4) - 0x3c, data
);
1087 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
1091 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
1095 case ASI_DMMU_CTXT_ZERO_CONFIG
:
1099 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
1101 itb
->c0_tsb_ps0
= data
;
1103 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
1105 itb
->c0_tsb_ps1
= data
;
1107 case ASI_IMMU_CTXT_ZERO_CONFIG
:
1109 itb
->c0_config
= data
;
1111 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1115 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1119 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
1123 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1125 itb
->cx_tsb_ps0
= data
;
1127 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1129 itb
->cx_tsb_ps1
= data
;
1131 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
1133 itb
->cx_config
= data
;
1135 case ASI_SPARC_ERROR_EN_REG
:
1136 case ASI_SPARC_ERROR_STATUS_REG
:
1137 inform("Ignoring write to SPARC ERROR regsiter\n");
1139 case ASI_HYP_SCRATCHPAD
:
1140 case ASI_SCRATCHPAD
:
1141 tc
->setMiscReg(MISCREG_SCRATCHPAD_R0
+ (va
>> 3), data
);
1149 sext
<59>(bits(data
, 59,0));
1150 itb
->tag_access
= data
;
1153 goto doMmuWriteError
;
1156 case ASI_ITLB_DATA_ACCESS_REG
:
1157 entry_insert
= bits(va
, 8,3);
1158 case ASI_ITLB_DATA_IN_REG
:
1159 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1160 ta_insert
= itb
->tag_access
;
1161 va_insert
= mbits(ta_insert
, 63,13);
1162 ct_insert
= mbits(ta_insert
, 12,0);
1163 part_insert
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1164 real_insert
= bits(va
, 9,9);
1165 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1166 PageTableEntry::sun4u
);
1167 tc
->getITBPtr()->insert(va_insert
, part_insert
, ct_insert
, real_insert
,
1170 case ASI_DTLB_DATA_ACCESS_REG
:
1171 entry_insert
= bits(va
, 8,3);
1172 case ASI_DTLB_DATA_IN_REG
:
1173 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1174 ta_insert
= tag_access
;
1175 va_insert
= mbits(ta_insert
, 63,13);
1176 ct_insert
= mbits(ta_insert
, 12,0);
1177 part_insert
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1178 real_insert
= bits(va
, 9,9);
1179 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1180 PageTableEntry::sun4u
);
1181 insert(va_insert
, part_insert
, ct_insert
, real_insert
, pte
,
1184 case ASI_IMMU_DEMAP
:
1187 part_id
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1188 switch (bits(va
,5,4)) {
1190 ctx_id
= tc
->readMiscReg(MISCREG_MMU_P_CONTEXT
);
1202 switch (bits(va
,7,6)) {
1203 case 0: // demap page
1205 tc
->getITBPtr()->demapPage(mbits(va
,63,13), part_id
,
1206 bits(va
,9,9), ctx_id
);
1208 case 1: // demap context
1210 tc
->getITBPtr()->demapContext(part_id
, ctx_id
);
1213 tc
->getITBPtr()->demapAll(part_id
);
1216 panic("Invalid type for IMMU demap\n");
1225 sext
<59>(bits(data
, 59,0));
1229 tc
->setMiscReg(MISCREG_MMU_PART_ID
, data
);
1232 goto doMmuWriteError
;
1235 case ASI_DMMU_DEMAP
:
1238 part_id
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1239 switch (bits(va
,5,4)) {
1241 ctx_id
= tc
->readMiscReg(MISCREG_MMU_P_CONTEXT
);
1244 ctx_id
= tc
->readMiscReg(MISCREG_MMU_S_CONTEXT
);
1253 switch (bits(va
,7,6)) {
1254 case 0: // demap page
1256 demapPage(mbits(va
,63,13), part_id
, bits(va
,9,9), ctx_id
);
1258 case 1: // demap context
1260 demapContext(part_id
, ctx_id
);
1266 panic("Invalid type for IMMU demap\n");
1269 case ASI_SWVR_INTR_RECEIVE
:
1272 // clear all the interrupts that aren't set in the write
1273 SparcISA::Interrupts
* interrupts
=
1274 dynamic_cast<SparcISA::Interrupts
*>(
1275 tc
->getCpuPtr()->getInterruptController());
1276 while (interrupts
->get_vec(IT_INT_VEC
) & data
) {
1277 msb
= findMsbSet(interrupts
->get_vec(IT_INT_VEC
) & data
);
1278 tc
->getCpuPtr()->clearInterrupt(IT_INT_VEC
, msb
);
1282 case ASI_SWVR_UDB_INTR_W
:
1283 tc
->getSystemPtr()->threadContexts
[bits(data
,12,8)]->getCpuPtr()->
1284 postInterrupt(bits(data
, 5, 0), 0);
1288 panic("need to impl DTB::doMmuRegWrite() got asi=%#x, va=%#x d=%#x\n",
1289 (uint32_t)pkt
->req
->getArchFlags(), pkt
->getAddr(), data
);
1291 pkt
->makeAtomicResponse();
1296 TLB::GetTsbPtr(ThreadContext
*tc
, Addr addr
, int ctx
, Addr
*ptrs
)
1298 uint64_t tag_access
= mbits(addr
,63,13) | mbits(ctx
,12,0);
1299 TLB
* itb
= tc
->getITBPtr();
1300 ptrs
[0] = MakeTsbPtr(Ps0
, tag_access
,
1305 ptrs
[1] = MakeTsbPtr(Ps1
, tag_access
,
1310 ptrs
[2] = MakeTsbPtr(Ps0
, tag_access
,
1315 ptrs
[3] = MakeTsbPtr(Ps1
, tag_access
,
1323 TLB::MakeTsbPtr(TsbPageSize ps
, uint64_t tag_access
, uint64_t c0_tsb
,
1324 uint64_t c0_config
, uint64_t cX_tsb
, uint64_t cX_config
)
1329 if (bits(tag_access
, 12,0) == 0) {
1337 uint64_t ptr
= mbits(tsb
,63,13);
1338 bool split
= bits(tsb
,12,12);
1339 int tsb_size
= bits(tsb
,3,0);
1340 int page_size
= (ps
== Ps0
) ? bits(config
, 2,0) : bits(config
,10,8);
1342 if (ps
== Ps1
&& split
)
1343 ptr
|= ULL(1) << (13 + tsb_size
);
1344 ptr
|= (tag_access
>> (9 + page_size
* 3)) & mask(12+tsb_size
, 4);
1350 TLB::serialize(std::ostream
&os
)
1352 SERIALIZE_SCALAR(size
);
1353 SERIALIZE_SCALAR(usedEntries
);
1354 SERIALIZE_SCALAR(lastReplaced
);
1356 // convert the pointer based free list into an index based one
1357 int *free_list
= (int*)malloc(sizeof(int) * size
);
1359 std::list
<TlbEntry
*>::iterator i
;
1360 i
= freeList
.begin();
1361 while (i
!= freeList
.end()) {
1362 free_list
[cntr
++] = ((size_t)*i
- (size_t)tlb
)/ sizeof(TlbEntry
);
1365 SERIALIZE_SCALAR(cntr
);
1366 SERIALIZE_ARRAY(free_list
, cntr
);
1368 SERIALIZE_SCALAR(c0_tsb_ps0
);
1369 SERIALIZE_SCALAR(c0_tsb_ps1
);
1370 SERIALIZE_SCALAR(c0_config
);
1371 SERIALIZE_SCALAR(cx_tsb_ps0
);
1372 SERIALIZE_SCALAR(cx_tsb_ps1
);
1373 SERIALIZE_SCALAR(cx_config
);
1374 SERIALIZE_SCALAR(sfsr
);
1375 SERIALIZE_SCALAR(tag_access
);
1377 for (int x
= 0; x
< size
; x
++) {
1378 nameOut(os
, csprintf("%s.PTE%d", name(), x
));
1379 tlb
[x
].serialize(os
);
1381 SERIALIZE_SCALAR(sfar
);
1385 TLB::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1389 paramIn(cp
, section
, "size", oldSize
);
1390 if (oldSize
!= size
)
1391 panic("Don't support unserializing different sized TLBs\n");
1392 UNSERIALIZE_SCALAR(usedEntries
);
1393 UNSERIALIZE_SCALAR(lastReplaced
);
1396 UNSERIALIZE_SCALAR(cntr
);
1398 int *free_list
= (int*)malloc(sizeof(int) * cntr
);
1400 UNSERIALIZE_ARRAY(free_list
, cntr
);
1401 for (int x
= 0; x
< cntr
; x
++)
1402 freeList
.push_back(&tlb
[free_list
[x
]]);
1404 UNSERIALIZE_SCALAR(c0_tsb_ps0
);
1405 UNSERIALIZE_SCALAR(c0_tsb_ps1
);
1406 UNSERIALIZE_SCALAR(c0_config
);
1407 UNSERIALIZE_SCALAR(cx_tsb_ps0
);
1408 UNSERIALIZE_SCALAR(cx_tsb_ps1
);
1409 UNSERIALIZE_SCALAR(cx_config
);
1410 UNSERIALIZE_SCALAR(sfsr
);
1411 UNSERIALIZE_SCALAR(tag_access
);
1413 lookupTable
.clear();
1414 for (int x
= 0; x
< size
; x
++) {
1415 tlb
[x
].unserialize(cp
, csprintf("%s.PTE%d", section
, x
));
1417 lookupTable
.insert(tlb
[x
].range
, &tlb
[x
]);
1420 UNSERIALIZE_SCALAR(sfar
);
1423 } // namespace SparcISA
1426 SparcTLBParams::create()
1428 return new SparcISA::TLB(this);