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
) {
293 if (tlb
[x
].valid
== true) {
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
++) {
332 if (tlb
[x
].valid
== true)
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
->getAsi() == 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
->getAsi();
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::doMmuRegRead(ThreadContext
*tc
, Packet
*pkt
)
854 Addr va
= pkt
->getAddr();
855 ASI asi
= (ASI
)pkt
->req
->getAsi();
858 DPRINTF(IPR
, "Memory Mapped IPR Read: asi=%#X a=%#x\n",
859 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr());
861 TLB
*itb
= tc
->getITBPtr();
864 case ASI_LSU_CONTROL_REG
:
866 pkt
->set(tc
->readMiscReg(MISCREG_MMU_LSU_CTRL
));
871 pkt
->set(tc
->readMiscReg(MISCREG_MMU_P_CONTEXT
));
874 pkt
->set(tc
->readMiscReg(MISCREG_MMU_S_CONTEXT
));
881 pkt
->set(tc
->readMiscReg(MISCREG_QUEUE_CPU_MONDO_HEAD
+
884 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
886 pkt
->set(c0_tsb_ps0
);
888 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
890 pkt
->set(c0_tsb_ps1
);
892 case ASI_DMMU_CTXT_ZERO_CONFIG
:
896 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
898 pkt
->set(itb
->c0_tsb_ps0
);
900 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
902 pkt
->set(itb
->c0_tsb_ps1
);
904 case ASI_IMMU_CTXT_ZERO_CONFIG
:
906 pkt
->set(itb
->c0_config
);
908 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
910 pkt
->set(cx_tsb_ps0
);
912 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
914 pkt
->set(cx_tsb_ps1
);
916 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
920 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
922 pkt
->set(itb
->cx_tsb_ps0
);
924 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
926 pkt
->set(itb
->cx_tsb_ps1
);
928 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
930 pkt
->set(itb
->cx_config
);
932 case ASI_SPARC_ERROR_STATUS_REG
:
933 pkt
->set((uint64_t)0);
935 case ASI_HYP_SCRATCHPAD
:
937 pkt
->set(tc
->readMiscReg(MISCREG_SCRATCHPAD_R0
+ (va
>> 3)));
942 temp
= itb
->tag_access
;
943 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
949 pkt
->set(itb
->tag_access
);
959 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
968 pkt
->set(tag_access
);
971 pkt
->set(tc
->readMiscReg(MISCREG_MMU_PART_ID
));
977 case ASI_DMMU_TSB_PS0_PTR_REG
:
978 pkt
->set(MakeTsbPtr(Ps0
,
985 case ASI_DMMU_TSB_PS1_PTR_REG
:
986 pkt
->set(MakeTsbPtr(Ps1
,
993 case ASI_IMMU_TSB_PS0_PTR_REG
:
994 pkt
->set(MakeTsbPtr(Ps0
,
1001 case ASI_IMMU_TSB_PS1_PTR_REG
:
1002 pkt
->set(MakeTsbPtr(Ps1
,
1009 case ASI_SWVR_INTR_RECEIVE
:
1011 SparcISA::Interrupts
* interrupts
=
1012 dynamic_cast<SparcISA::Interrupts
*>(
1013 tc
->getCpuPtr()->getInterruptController());
1014 pkt
->set(interrupts
->get_vec(IT_INT_VEC
));
1017 case ASI_SWVR_UDB_INTR_R
:
1019 SparcISA::Interrupts
* interrupts
=
1020 dynamic_cast<SparcISA::Interrupts
*>(
1021 tc
->getCpuPtr()->getInterruptController());
1022 temp
= findMsbSet(interrupts
->get_vec(IT_INT_VEC
));
1023 tc
->getCpuPtr()->clearInterrupt(IT_INT_VEC
, temp
);
1029 panic("need to impl DTB::doMmuRegRead() got asi=%#x, va=%#x\n",
1032 pkt
->makeAtomicResponse();
1033 return tc
->getCpuPtr()->ticks(1);
1037 TLB::doMmuRegWrite(ThreadContext
*tc
, Packet
*pkt
)
1039 uint64_t data
= pkt
->get
<uint64_t>();
1040 Addr va
= pkt
->getAddr();
1041 ASI asi
= (ASI
)pkt
->req
->getAsi();
1047 int entry_insert
= -1;
1054 DPRINTF(IPR
, "Memory Mapped IPR Write: asi=%#X a=%#x d=%#X\n",
1055 (uint32_t)asi
, va
, data
);
1057 TLB
*itb
= tc
->getITBPtr();
1060 case ASI_LSU_CONTROL_REG
:
1062 tc
->setMiscReg(MISCREG_MMU_LSU_CTRL
, data
);
1067 tc
->setMiscReg(MISCREG_MMU_P_CONTEXT
, data
);
1070 tc
->setMiscReg(MISCREG_MMU_S_CONTEXT
, data
);
1073 goto doMmuWriteError
;
1077 assert(mbits(data
,13,6) == data
);
1078 tc
->setMiscReg(MISCREG_QUEUE_CPU_MONDO_HEAD
+
1079 (va
>> 4) - 0x3c, data
);
1081 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
1085 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
1089 case ASI_DMMU_CTXT_ZERO_CONFIG
:
1093 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
1095 itb
->c0_tsb_ps0
= data
;
1097 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
1099 itb
->c0_tsb_ps1
= data
;
1101 case ASI_IMMU_CTXT_ZERO_CONFIG
:
1103 itb
->c0_config
= data
;
1105 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1109 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1113 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
1117 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1119 itb
->cx_tsb_ps0
= data
;
1121 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1123 itb
->cx_tsb_ps1
= data
;
1125 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
1127 itb
->cx_config
= data
;
1129 case ASI_SPARC_ERROR_EN_REG
:
1130 case ASI_SPARC_ERROR_STATUS_REG
:
1131 inform("Ignoring write to SPARC ERROR regsiter\n");
1133 case ASI_HYP_SCRATCHPAD
:
1134 case ASI_SCRATCHPAD
:
1135 tc
->setMiscReg(MISCREG_SCRATCHPAD_R0
+ (va
>> 3), data
);
1143 sext
<59>(bits(data
, 59,0));
1144 itb
->tag_access
= data
;
1147 goto doMmuWriteError
;
1150 case ASI_ITLB_DATA_ACCESS_REG
:
1151 entry_insert
= bits(va
, 8,3);
1152 case ASI_ITLB_DATA_IN_REG
:
1153 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1154 ta_insert
= itb
->tag_access
;
1155 va_insert
= mbits(ta_insert
, 63,13);
1156 ct_insert
= mbits(ta_insert
, 12,0);
1157 part_insert
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1158 real_insert
= bits(va
, 9,9);
1159 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1160 PageTableEntry::sun4u
);
1161 tc
->getITBPtr()->insert(va_insert
, part_insert
, ct_insert
, real_insert
,
1164 case ASI_DTLB_DATA_ACCESS_REG
:
1165 entry_insert
= bits(va
, 8,3);
1166 case ASI_DTLB_DATA_IN_REG
:
1167 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1168 ta_insert
= tag_access
;
1169 va_insert
= mbits(ta_insert
, 63,13);
1170 ct_insert
= mbits(ta_insert
, 12,0);
1171 part_insert
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1172 real_insert
= bits(va
, 9,9);
1173 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1174 PageTableEntry::sun4u
);
1175 insert(va_insert
, part_insert
, ct_insert
, real_insert
, pte
,
1178 case ASI_IMMU_DEMAP
:
1181 part_id
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1182 switch (bits(va
,5,4)) {
1184 ctx_id
= tc
->readMiscReg(MISCREG_MMU_P_CONTEXT
);
1196 switch (bits(va
,7,6)) {
1197 case 0: // demap page
1199 tc
->getITBPtr()->demapPage(mbits(va
,63,13), part_id
,
1200 bits(va
,9,9), ctx_id
);
1202 case 1: // demap context
1204 tc
->getITBPtr()->demapContext(part_id
, ctx_id
);
1207 tc
->getITBPtr()->demapAll(part_id
);
1210 panic("Invalid type for IMMU demap\n");
1219 sext
<59>(bits(data
, 59,0));
1223 tc
->setMiscReg(MISCREG_MMU_PART_ID
, data
);
1226 goto doMmuWriteError
;
1229 case ASI_DMMU_DEMAP
:
1232 part_id
= tc
->readMiscReg(MISCREG_MMU_PART_ID
);
1233 switch (bits(va
,5,4)) {
1235 ctx_id
= tc
->readMiscReg(MISCREG_MMU_P_CONTEXT
);
1238 ctx_id
= tc
->readMiscReg(MISCREG_MMU_S_CONTEXT
);
1247 switch (bits(va
,7,6)) {
1248 case 0: // demap page
1250 demapPage(mbits(va
,63,13), part_id
, bits(va
,9,9), ctx_id
);
1252 case 1: // demap context
1254 demapContext(part_id
, ctx_id
);
1260 panic("Invalid type for IMMU demap\n");
1263 case ASI_SWVR_INTR_RECEIVE
:
1266 // clear all the interrupts that aren't set in the write
1267 SparcISA::Interrupts
* interrupts
=
1268 dynamic_cast<SparcISA::Interrupts
*>(
1269 tc
->getCpuPtr()->getInterruptController());
1270 while (interrupts
->get_vec(IT_INT_VEC
) & data
) {
1271 msb
= findMsbSet(interrupts
->get_vec(IT_INT_VEC
) & data
);
1272 tc
->getCpuPtr()->clearInterrupt(IT_INT_VEC
, msb
);
1276 case ASI_SWVR_UDB_INTR_W
:
1277 tc
->getSystemPtr()->threadContexts
[bits(data
,12,8)]->getCpuPtr()->
1278 postInterrupt(bits(data
, 5, 0), 0);
1282 panic("need to impl DTB::doMmuRegWrite() got asi=%#x, va=%#x d=%#x\n",
1283 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr(), data
);
1285 pkt
->makeAtomicResponse();
1286 return tc
->getCpuPtr()->ticks(1);
1290 TLB::GetTsbPtr(ThreadContext
*tc
, Addr addr
, int ctx
, Addr
*ptrs
)
1292 uint64_t tag_access
= mbits(addr
,63,13) | mbits(ctx
,12,0);
1293 TLB
* itb
= tc
->getITBPtr();
1294 ptrs
[0] = MakeTsbPtr(Ps0
, tag_access
,
1299 ptrs
[1] = MakeTsbPtr(Ps1
, tag_access
,
1304 ptrs
[2] = MakeTsbPtr(Ps0
, tag_access
,
1309 ptrs
[3] = MakeTsbPtr(Ps1
, tag_access
,
1317 TLB::MakeTsbPtr(TsbPageSize ps
, uint64_t tag_access
, uint64_t c0_tsb
,
1318 uint64_t c0_config
, uint64_t cX_tsb
, uint64_t cX_config
)
1323 if (bits(tag_access
, 12,0) == 0) {
1331 uint64_t ptr
= mbits(tsb
,63,13);
1332 bool split
= bits(tsb
,12,12);
1333 int tsb_size
= bits(tsb
,3,0);
1334 int page_size
= (ps
== Ps0
) ? bits(config
, 2,0) : bits(config
,10,8);
1336 if (ps
== Ps1
&& split
)
1337 ptr
|= ULL(1) << (13 + tsb_size
);
1338 ptr
|= (tag_access
>> (9 + page_size
* 3)) & mask(12+tsb_size
, 4);
1344 TLB::serialize(std::ostream
&os
)
1346 SERIALIZE_SCALAR(size
);
1347 SERIALIZE_SCALAR(usedEntries
);
1348 SERIALIZE_SCALAR(lastReplaced
);
1350 // convert the pointer based free list into an index based one
1351 int *free_list
= (int*)malloc(sizeof(int) * size
);
1353 std::list
<TlbEntry
*>::iterator i
;
1354 i
= freeList
.begin();
1355 while (i
!= freeList
.end()) {
1356 free_list
[cntr
++] = ((size_t)*i
- (size_t)tlb
)/ sizeof(TlbEntry
);
1359 SERIALIZE_SCALAR(cntr
);
1360 SERIALIZE_ARRAY(free_list
, cntr
);
1362 SERIALIZE_SCALAR(c0_tsb_ps0
);
1363 SERIALIZE_SCALAR(c0_tsb_ps1
);
1364 SERIALIZE_SCALAR(c0_config
);
1365 SERIALIZE_SCALAR(cx_tsb_ps0
);
1366 SERIALIZE_SCALAR(cx_tsb_ps1
);
1367 SERIALIZE_SCALAR(cx_config
);
1368 SERIALIZE_SCALAR(sfsr
);
1369 SERIALIZE_SCALAR(tag_access
);
1371 for (int x
= 0; x
< size
; x
++) {
1372 nameOut(os
, csprintf("%s.PTE%d", name(), x
));
1373 tlb
[x
].serialize(os
);
1375 SERIALIZE_SCALAR(sfar
);
1379 TLB::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1383 paramIn(cp
, section
, "size", oldSize
);
1384 if (oldSize
!= size
)
1385 panic("Don't support unserializing different sized TLBs\n");
1386 UNSERIALIZE_SCALAR(usedEntries
);
1387 UNSERIALIZE_SCALAR(lastReplaced
);
1390 UNSERIALIZE_SCALAR(cntr
);
1392 int *free_list
= (int*)malloc(sizeof(int) * cntr
);
1394 UNSERIALIZE_ARRAY(free_list
, cntr
);
1395 for (int x
= 0; x
< cntr
; x
++)
1396 freeList
.push_back(&tlb
[free_list
[x
]]);
1398 UNSERIALIZE_SCALAR(c0_tsb_ps0
);
1399 UNSERIALIZE_SCALAR(c0_tsb_ps1
);
1400 UNSERIALIZE_SCALAR(c0_config
);
1401 UNSERIALIZE_SCALAR(cx_tsb_ps0
);
1402 UNSERIALIZE_SCALAR(cx_tsb_ps1
);
1403 UNSERIALIZE_SCALAR(cx_config
);
1404 UNSERIALIZE_SCALAR(sfsr
);
1405 UNSERIALIZE_SCALAR(tag_access
);
1407 lookupTable
.clear();
1408 for (int x
= 0; x
< size
; x
++) {
1409 tlb
[x
].unserialize(cp
, csprintf("%s.PTE%d", section
, x
));
1411 lookupTable
.insert(tlb
[x
].range
, &tlb
[x
]);
1414 UNSERIALIZE_SCALAR(sfar
);
1417 } // namespace SparcISA
1420 SparcTLBParams::create()
1422 return new SparcISA::TLB(this);