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/miscregfile.hh"
35 #include "arch/sparc/tlb.hh"
36 #include "base/bitfield.hh"
37 #include "base/trace.hh"
38 #include "cpu/thread_context.hh"
39 #include "cpu/base.hh"
40 #include "mem/packet_access.hh"
41 #include "mem/request.hh"
42 #include "sim/builder.hh"
44 /* @todo remove some of the magic constants. -- ali
49 TLB::TLB(const std::string
&name
, int s
)
50 : SimObject(name
), size(s
), usedEntries(0), lastReplaced(0),
53 // To make this work you'll have to change the hypervisor and OS
55 fatal("SPARC T1 TLB registers don't support more than 64 TLB entries.");
57 tlb
= new TlbEntry
[size
];
58 std::memset(tlb
, 0, sizeof(TlbEntry
) * size
);
60 for (int x
= 0; x
< size
; x
++)
61 freeList
.push_back(&tlb
[x
]);
68 for (i
= lookupTable
.begin(); i
!= lookupTable
.end(); i
++) {
69 TlbEntry
*t
= i
->second
;
70 if (!t
->pte
.locked()) {
79 TLB::insert(Addr va
, int partition_id
, int context_id
, bool real
,
80 const PageTableEntry
& PTE
, int entry
)
85 TlbEntry
*new_entry
= NULL
;
90 va
&= ~(PTE
.size()-1);
92 tr.size = PTE.size() - 1;
93 tr.contextId = context_id;
94 tr.partitionId = partition_id;
98 DPRINTF(TLB
, "TLB: Inserting TLB Entry; va=%#x pa=%#x pid=%d cid=%d r=%d entryid=%d\n",
99 va
, PTE
.paddr(), partition_id
, context_id
, (int)real
, entry
);
101 // Demap any entry that conflicts
102 for (x
= 0; x
< size
; x
++) {
103 if (tlb
[x
].range
.real
== real
&&
104 tlb
[x
].range
.partitionId
== partition_id
&&
105 tlb
[x
].range
.va
< va
+ PTE
.size() - 1 &&
106 tlb
[x
].range
.va
+ tlb
[x
].range
.size
>= va
&&
107 (real
|| tlb
[x
].range
.contextId
== context_id
))
110 freeList
.push_front(&tlb
[x
]);
111 DPRINTF(TLB
, "TLB: Conflicting entry %#X , deleting it\n", x
);
113 tlb
[x
].valid
= false;
118 lookupTable
.erase(tlb
[x
].range
);
125 i = lookupTable.find(tr);
126 if (i != lookupTable.end()) {
127 i->second->valid = false;
128 if (i->second->used) {
129 i->second->used = false;
132 freeList.push_front(i->second);
133 DPRINTF(TLB, "TLB: Found conflicting entry %#X , deleting it\n",
135 lookupTable.erase(i);
140 assert(entry
< size
&& entry
>= 0);
141 new_entry
= &tlb
[entry
];
143 if (!freeList
.empty()) {
144 new_entry
= freeList
.front();
151 if (x
== lastReplaced
)
152 goto insertAllLocked
;
153 } while (tlb
[x
].pte
.locked());
158 for (x = 0; x < size; x++) {
159 if (!tlb[x].valid || !tlb[x].used) {
167 // Update the last ently if their all locked
169 new_entry
= &tlb
[size
-1];
172 freeList
.remove(new_entry
);
173 if (new_entry
->valid
&& new_entry
->used
)
175 if (new_entry
->valid
)
176 lookupTable
.erase(new_entry
->range
);
180 new_entry
->range
.va
= va
;
181 new_entry
->range
.size
= PTE
.size() - 1;
182 new_entry
->range
.partitionId
= partition_id
;
183 new_entry
->range
.contextId
= context_id
;
184 new_entry
->range
.real
= real
;
185 new_entry
->pte
= PTE
;
186 new_entry
->used
= true;;
187 new_entry
->valid
= true;
192 i
= lookupTable
.insert(new_entry
->range
, new_entry
);
193 assert(i
!= lookupTable
.end());
195 // If all entries have there used bit set, clear it on them all, but the
196 // one we just inserted
197 if (usedEntries
== size
) {
199 new_entry
->used
= true;
207 TLB::lookup(Addr va
, int partition_id
, bool real
, int context_id
, bool
214 DPRINTF(TLB
, "TLB: Looking up entry va=%#x pid=%d cid=%d r=%d\n",
215 va
, partition_id
, context_id
, real
);
216 // Assemble full address structure
218 tr
.size
= MachineBytes
;
219 tr
.contextId
= context_id
;
220 tr
.partitionId
= partition_id
;
223 // Try to find the entry
224 i
= lookupTable
.find(tr
);
225 if (i
== lookupTable
.end()) {
226 DPRINTF(TLB
, "TLB: No valid entry found\n");
230 // Mark the entries used bit and clear other used bits in needed
232 DPRINTF(TLB
, "TLB: Valid entry found pa: %#x size: %#x\n", t
->pte
.paddr(),
235 // Update the used bits only if this is a real access (not a fake one from
237 if (!t
->used
&& update_used
) {
240 if (usedEntries
== size
) {
254 for (int x
= 0; x
< size
; x
++) {
256 DPRINTFN("%4d: %#2x:%#2x %c %#4x %#8x %#8x %#16x\n",
257 x
, tlb
[x
].range
.partitionId
, tlb
[x
].range
.contextId
,
258 tlb
[x
].range
.real
? 'R' : ' ', tlb
[x
].range
.size
,
259 tlb
[x
].range
.va
, tlb
[x
].pte
.paddr(), tlb
[x
].pte());
265 TLB::demapPage(Addr va
, int partition_id
, bool real
, int context_id
)
270 DPRINTF(IPR
, "TLB: Demapping Page va=%#x pid=%#d cid=%d r=%d\n",
271 va
, partition_id
, context_id
, real
);
275 // Assemble full address structure
277 tr
.size
= MachineBytes
;
278 tr
.contextId
= context_id
;
279 tr
.partitionId
= partition_id
;
282 // Demap any entry that conflicts
283 i
= lookupTable
.find(tr
);
284 if (i
!= lookupTable
.end()) {
285 DPRINTF(IPR
, "TLB: Demapped page\n");
286 i
->second
->valid
= false;
287 if (i
->second
->used
) {
288 i
->second
->used
= false;
291 freeList
.push_front(i
->second
);
292 lookupTable
.erase(i
);
297 TLB::demapContext(int partition_id
, int context_id
)
300 DPRINTF(IPR
, "TLB: Demapping Context pid=%#d cid=%d\n",
301 partition_id
, context_id
);
303 for (x
= 0; x
< size
; x
++) {
304 if (tlb
[x
].range
.contextId
== context_id
&&
305 tlb
[x
].range
.partitionId
== partition_id
) {
306 if (tlb
[x
].valid
== true) {
307 freeList
.push_front(&tlb
[x
]);
309 tlb
[x
].valid
= false;
314 lookupTable
.erase(tlb
[x
].range
);
320 TLB::demapAll(int partition_id
)
323 DPRINTF(TLB
, "TLB: Demapping All pid=%#d\n", partition_id
);
325 for (x
= 0; x
< size
; x
++) {
326 if (!tlb
[x
].pte
.locked() && tlb
[x
].range
.partitionId
== partition_id
) {
327 if (tlb
[x
].valid
== true){
328 freeList
.push_front(&tlb
[x
]);
330 tlb
[x
].valid
= false;
335 lookupTable
.erase(tlb
[x
].range
);
348 for (x
= 0; x
< size
; x
++) {
349 if (tlb
[x
].valid
== true)
350 freeList
.push_back(&tlb
[x
]);
351 tlb
[x
].valid
= false;
358 TLB::TteRead(int entry
) {
360 panic("entry: %d\n", entry
);
362 assert(entry
< size
);
363 if (tlb
[entry
].valid
)
364 return tlb
[entry
].pte();
366 return (uint64_t)-1ll;
370 TLB::TagRead(int entry
) {
371 assert(entry
< size
);
373 if (!tlb
[entry
].valid
)
374 return (uint64_t)-1ll;
376 tag
= tlb
[entry
].range
.contextId
;
377 tag
|= tlb
[entry
].range
.va
;
378 tag
|= (uint64_t)tlb
[entry
].range
.partitionId
<< 61;
379 tag
|= tlb
[entry
].range
.real
? ULL(1) << 60 : 0;
380 tag
|= (uint64_t)~tlb
[entry
].pte
._size() << 56;
385 TLB::validVirtualAddress(Addr va
, bool am
)
389 if (va
>= StartVAddrHole
&& va
<= EndVAddrHole
)
395 TLB::writeSfsr(ThreadContext
*tc
, int reg
, bool write
, ContextType ct
,
396 bool se
, FaultTypes ft
, int asi
)
399 sfsr
= tc
->readMiscReg(reg
);
413 tc
->setMiscRegWithEffect(reg
, sfsr
);
417 TLB::writeTagAccess(ThreadContext
*tc
, int reg
, Addr va
, int context
)
419 DPRINTF(TLB
, "TLB: Writing Tag Access: va: %#X ctx: %#X value: %#X\n",
420 va
, context
, mbits(va
, 63,13) | mbits(context
,12,0));
422 tc
->setMiscRegWithEffect(reg
, mbits(va
, 63,13) | mbits(context
,12,0));
426 ITB::writeSfsr(ThreadContext
*tc
, bool write
, ContextType ct
,
427 bool se
, FaultTypes ft
, int asi
)
429 DPRINTF(TLB
, "TLB: ITB Fault: w=%d ct=%d ft=%d asi=%d\n",
430 (int)write
, ct
, ft
, asi
);
431 TLB::writeSfsr(tc
, MISCREG_MMU_ITLB_SFSR
, write
, ct
, se
, ft
, asi
);
435 ITB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
437 TLB::writeTagAccess(tc
, MISCREG_MMU_ITLB_TAG_ACCESS
, va
, context
);
441 DTB::writeSfr(ThreadContext
*tc
, Addr a
, bool write
, ContextType ct
,
442 bool se
, FaultTypes ft
, int asi
)
444 DPRINTF(TLB
, "TLB: DTB Fault: A=%#x w=%d ct=%d ft=%d asi=%d\n",
445 a
, (int)write
, ct
, ft
, asi
);
446 TLB::writeSfsr(tc
, MISCREG_MMU_DTLB_SFSR
, write
, ct
, se
, ft
, asi
);
447 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
, a
);
451 DTB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
453 TLB::writeTagAccess(tc
, MISCREG_MMU_DTLB_TAG_ACCESS
, va
, context
);
459 ITB::translate(RequestPtr
&req
, ThreadContext
*tc
)
461 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
463 Addr vaddr
= req
->getVaddr();
466 assert(req
->getAsi() == ASI_IMPLICIT
);
468 DPRINTF(TLB
, "TLB: ITB Request to translate va=%#x size=%d\n",
469 vaddr
, req
->getSize());
471 // Be fast if we can!
472 if (cacheValid
&& cacheState
== tlbdata
) {
474 if (cacheEntry
->range
.va
< vaddr
+ sizeof(MachInst
) &&
475 cacheEntry
->range
.va
+ cacheEntry
->range
.size
>= vaddr
) {
476 req
->setPaddr(cacheEntry
->pte
.paddr() & ~(cacheEntry
->pte
.size()-1) |
477 vaddr
& cacheEntry
->pte
.size()-1 );
481 req
->setPaddr(vaddr
& PAddrImplMask
);
486 bool hpriv
= bits(tlbdata
,0,0);
487 bool red
= bits(tlbdata
,1,1);
488 bool priv
= bits(tlbdata
,2,2);
489 bool addr_mask
= bits(tlbdata
,3,3);
490 bool lsu_im
= bits(tlbdata
,4,4);
492 int part_id
= bits(tlbdata
,15,8);
493 int tl
= bits(tlbdata
,18,16);
494 int pri_context
= bits(tlbdata
,47,32);
500 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsuim:%d part_id: %#X\n",
501 priv
, hpriv
, red
, lsu_im
, part_id
);
510 context
= pri_context
;
513 if ( hpriv
|| red
) {
515 cacheState
= tlbdata
;
517 req
->setPaddr(vaddr
& PAddrImplMask
);
521 // If the access is unaligned trap
523 writeSfsr(tc
, false, ct
, false, OtherFault
, asi
);
524 return new MemAddressNotAligned
;
528 vaddr
= vaddr
& VAddrAMask
;
530 if (!validVirtualAddress(vaddr
, addr_mask
)) {
531 writeSfsr(tc
, false, ct
, false, VaOutOfRange
, asi
);
532 return new InstructionAccessException
;
536 e
= lookup(vaddr
, part_id
, true);
540 e
= lookup(vaddr
, part_id
, false, context
);
543 if (e
== NULL
|| !e
->valid
) {
544 writeTagAccess(tc
, vaddr
, context
);
546 return new InstructionRealTranslationMiss
;
548 return new FastInstructionAccessMMUMiss
;
551 // were not priviledged accesing priv page
552 if (!priv
&& e
->pte
.priv()) {
553 writeTagAccess(tc
, vaddr
, context
);
554 writeSfsr(tc
, false, ct
, false, PrivViolation
, asi
);
555 return new InstructionAccessException
;
558 // cache translation date for next translation
560 cacheState
= tlbdata
;
563 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
564 vaddr
& e
->pte
.size()-1 );
565 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
572 DTB::translate(RequestPtr
&req
, ThreadContext
*tc
, bool write
)
574 /* @todo this could really use some profiling and fixing to make it faster! */
575 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
576 Addr vaddr
= req
->getVaddr();
577 Addr size
= req
->getSize();
579 asi
= (ASI
)req
->getAsi();
580 bool implicit
= false;
581 bool hpriv
= bits(tlbdata
,0,0);
583 DPRINTF(TLB
, "TLB: DTB Request to translate va=%#x size=%d asi=%#x\n",
586 if (lookupTable
.size() != 64 - freeList
.size())
587 panic("Lookup table size: %d tlb size: %d\n", lookupTable
.size(),
589 if (asi
== ASI_IMPLICIT
)
592 if (hpriv
&& implicit
) {
593 req
->setPaddr(vaddr
& PAddrImplMask
);
597 // Be fast if we can!
598 if (cacheValid
&& cacheState
== tlbdata
) {
599 if (cacheEntry
[0] && cacheAsi
[0] == asi
&& cacheEntry
[0]->range
.va
< vaddr
+ size
&&
600 cacheEntry
[0]->range
.va
+ cacheEntry
[0]->range
.size
> vaddr
&&
601 (!write
|| cacheEntry
[0]->pte
.writable())) {
602 req
->setPaddr(cacheEntry
[0]->pte
.paddr() & ~(cacheEntry
[0]->pte
.size()-1) |
603 vaddr
& cacheEntry
[0]->pte
.size()-1 );
606 if (cacheEntry
[1] && cacheAsi
[1] == asi
&& cacheEntry
[1]->range
.va
< vaddr
+ size
&&
607 cacheEntry
[1]->range
.va
+ cacheEntry
[1]->range
.size
> vaddr
&&
608 (!write
|| cacheEntry
[1]->pte
.writable())) {
609 req
->setPaddr(cacheEntry
[1]->pte
.paddr() & ~(cacheEntry
[1]->pte
.size()-1) |
610 vaddr
& cacheEntry
[1]->pte
.size()-1 );
615 bool red
= bits(tlbdata
,1,1);
616 bool priv
= bits(tlbdata
,2,2);
617 bool addr_mask
= bits(tlbdata
,3,3);
618 bool lsu_dm
= bits(tlbdata
,5,5);
620 int part_id
= bits(tlbdata
,15,8);
621 int tl
= bits(tlbdata
,18,16);
622 int pri_context
= bits(tlbdata
,47,32);
623 int sec_context
= bits(tlbdata
,63,48);
626 ContextType ct
= Primary
;
631 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsudm:%d part_id: %#X\n",
632 priv
, hpriv
, red
, lsu_dm
, part_id
);
642 context
= pri_context
;
645 // We need to check for priv level/asi priv
646 if (!priv
&& !hpriv
&& !AsiIsUnPriv(asi
)) {
647 // It appears that context should be Nucleus in these cases?
648 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
649 return new PrivilegedAction
;
652 if (!hpriv
&& AsiIsHPriv(asi
)) {
653 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
654 return new DataAccessException
;
657 if (AsiIsPrimary(asi
)) {
658 context
= pri_context
;
660 } else if (AsiIsSecondary(asi
)) {
661 context
= sec_context
;
663 } else if (AsiIsNucleus(asi
)) {
668 context
= pri_context
;
672 if (!implicit
&& asi
!= ASI_P
&& asi
!= ASI_S
) {
673 if (AsiIsLittle(asi
))
674 panic("Little Endian ASIs not supported\n");
675 if (AsiIsNoFault(asi
))
676 panic("No Fault ASIs not supported\n");
678 if (AsiIsPartialStore(asi
))
679 panic("Partial Store ASIs not supported\n");
680 if (AsiIsInterrupt(asi
))
681 panic("Interrupt ASIs not supported\n");
684 goto handleMmuRegAccess
;
685 if (AsiIsScratchPad(asi
))
686 goto handleScratchRegAccess
;
688 goto handleQueueRegAccess
;
689 if (AsiIsSparcError(asi
))
690 goto handleSparcErrorRegAccess
;
692 if (!AsiIsReal(asi
) && !AsiIsNucleus(asi
) && !AsiIsAsIfUser(asi
) &&
693 !AsiIsTwin(asi
) && !AsiIsBlock(asi
))
694 panic("Accessing ASI %#X. Should we?\n", asi
);
697 // If the asi is unaligned trap
698 if (vaddr
& size
-1) {
699 writeSfr(tc
, vaddr
, false, ct
, false, OtherFault
, asi
);
700 return new MemAddressNotAligned
;
704 vaddr
= vaddr
& VAddrAMask
;
706 if (!validVirtualAddress(vaddr
, addr_mask
)) {
707 writeSfr(tc
, vaddr
, false, ct
, true, VaOutOfRange
, asi
);
708 return new DataAccessException
;
712 if ((!lsu_dm
&& !hpriv
&& !red
) || AsiIsReal(asi
)) {
717 if (hpriv
&& (implicit
|| (!AsiIsAsIfUser(asi
) && !AsiIsReal(asi
)))) {
718 req
->setPaddr(vaddr
& PAddrImplMask
);
722 e
= lookup(vaddr
, part_id
, real
, context
);
724 if (e
== NULL
|| !e
->valid
) {
725 writeTagAccess(tc
, vaddr
, context
);
726 DPRINTF(TLB
, "TLB: DTB Failed to find matching TLB entry\n");
728 return new DataRealTranslationMiss
;
730 return new FastDataAccessMMUMiss
;
734 if (!priv
&& e
->pte
.priv()) {
735 writeTagAccess(tc
, vaddr
, context
);
736 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), PrivViolation
, asi
);
737 return new DataAccessException
;
740 if (write
&& !e
->pte
.writable()) {
741 writeTagAccess(tc
, vaddr
, context
);
742 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), OtherFault
, asi
);
743 return new FastDataAccessProtection
;
746 if (e
->pte
.nofault() && !AsiIsNoFault(asi
)) {
747 writeTagAccess(tc
, vaddr
, context
);
748 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), LoadFromNfo
, asi
);
749 return new DataAccessException
;
752 if (e
->pte
.sideffect() && AsiIsNoFault(asi
)) {
753 writeTagAccess(tc
, vaddr
, context
);
754 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), SideEffect
, asi
);
755 return new DataAccessException
;
759 if (e
->pte
.sideffect())
760 req
->setFlags(req
->getFlags() | UNCACHEABLE
);
762 // cache translation date for next translation
763 cacheState
= tlbdata
;
765 cacheEntry
[1] = NULL
;
766 cacheEntry
[0] = NULL
;
769 if (cacheEntry
[0] != e
&& cacheEntry
[1] != e
) {
770 cacheEntry
[1] = cacheEntry
[0];
772 cacheAsi
[1] = cacheAsi
[0];
775 cacheAsi
[0] = (ASI
)0;
778 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
779 vaddr
& e
->pte
.size()-1);
780 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
782 /** Normal flow ends here. */
784 handleScratchRegAccess
:
785 if (vaddr
> 0x38 || (vaddr
>= 0x20 && vaddr
< 0x30 && !hpriv
)) {
786 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
787 return new DataAccessException
;
791 handleQueueRegAccess
:
792 if (!priv
&& !hpriv
) {
793 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
794 return new PrivilegedAction
;
796 if (!hpriv
&& vaddr
& 0xF || vaddr
> 0x3f8 || vaddr
< 0x3c0) {
797 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
798 return new DataAccessException
;
802 handleSparcErrorRegAccess
:
804 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
806 return new DataAccessException
;
808 return new PrivilegedAction
;
815 DPRINTF(TLB
, "TLB: DTB Translating MM IPR access\n");
816 req
->setMmapedIpr(true);
817 req
->setPaddr(req
->getVaddr());
822 DTB::doMmuRegRead(ThreadContext
*tc
, Packet
*pkt
)
824 Addr va
= pkt
->getAddr();
825 ASI asi
= (ASI
)pkt
->req
->getAsi();
828 DPRINTF(IPR
, "Memory Mapped IPR Read: asi=%#X a=%#x\n",
829 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr());
832 case ASI_LSU_CONTROL_REG
:
834 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
));
839 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
));
842 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
));
849 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
852 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
854 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
));
856 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
858 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
));
860 case ASI_DMMU_CTXT_ZERO_CONFIG
:
862 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
));
864 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
866 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
));
868 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
870 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
));
872 case ASI_IMMU_CTXT_ZERO_CONFIG
:
874 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
));
876 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
878 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
));
880 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
882 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
));
884 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
886 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
888 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
890 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
));
892 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
894 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
));
896 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
898 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
900 case ASI_SPARC_ERROR_STATUS_REG
:
901 pkt
->set((uint64_t)0);
903 case ASI_HYP_SCRATCHPAD
:
905 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3)));
910 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
911 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
914 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
));
917 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
));
926 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
927 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
930 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
));
933 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
));
936 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
));
939 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
));
945 case ASI_DMMU_TSB_PS0_PTR_REG
:
946 pkt
->set(MakeTsbPtr(Ps0
,
947 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
),
948 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
),
949 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
950 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
),
951 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
)));
953 case ASI_DMMU_TSB_PS1_PTR_REG
:
954 pkt
->set(MakeTsbPtr(Ps1
,
955 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
),
956 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
),
957 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
958 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
),
959 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
)));
961 case ASI_IMMU_TSB_PS0_PTR_REG
:
962 pkt
->set(MakeTsbPtr(Ps0
,
963 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
),
964 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
),
965 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
966 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
),
967 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
)));
969 case ASI_IMMU_TSB_PS1_PTR_REG
:
970 pkt
->set(MakeTsbPtr(Ps1
,
971 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
),
972 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
),
973 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
974 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
),
975 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
)));
980 panic("need to impl DTB::doMmuRegRead() got asi=%#x, va=%#x\n",
983 pkt
->result
= Packet::Success
;
984 return tc
->getCpuPtr()->cycles(1);
988 DTB::doMmuRegWrite(ThreadContext
*tc
, Packet
*pkt
)
990 uint64_t data
= gtoh(pkt
->get
<uint64_t>());
991 Addr va
= pkt
->getAddr();
992 ASI asi
= (ASI
)pkt
->req
->getAsi();
998 int entry_insert
= -1;
1005 DPRINTF(IPR
, "Memory Mapped IPR Write: asi=%#X a=%#x d=%#X\n",
1006 (uint32_t)asi
, va
, data
);
1009 case ASI_LSU_CONTROL_REG
:
1011 tc
->setMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
, data
);
1016 tc
->setMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
, data
);
1019 tc
->setMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
, data
);
1022 goto doMmuWriteError
;
1026 assert(mbits(data
,13,6) == data
);
1027 tc
->setMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
1028 (va
>> 4) - 0x3c, data
);
1030 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
1032 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
, data
);
1034 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
1036 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
, data
);
1038 case ASI_DMMU_CTXT_ZERO_CONFIG
:
1040 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
, data
);
1042 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
1044 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
, data
);
1046 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
1048 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
, data
);
1050 case ASI_IMMU_CTXT_ZERO_CONFIG
:
1052 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
, data
);
1054 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1056 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
, data
);
1058 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1060 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
, data
);
1062 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
1064 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
, data
);
1066 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1068 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
, data
);
1070 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1072 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
, data
);
1074 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
1076 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
, data
);
1078 case ASI_SPARC_ERROR_EN_REG
:
1079 case ASI_SPARC_ERROR_STATUS_REG
:
1080 warn("Ignoring write to SPARC ERROR regsiter\n");
1082 case ASI_HYP_SCRATCHPAD
:
1083 case ASI_SCRATCHPAD
:
1084 tc
->setMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3), data
);
1089 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
, data
);
1092 sext
<59>(bits(data
, 59,0));
1093 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
, data
);
1096 goto doMmuWriteError
;
1099 case ASI_ITLB_DATA_ACCESS_REG
:
1100 entry_insert
= bits(va
, 8,3);
1101 case ASI_ITLB_DATA_IN_REG
:
1102 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1103 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
1104 va_insert
= mbits(ta_insert
, 63,13);
1105 ct_insert
= mbits(ta_insert
, 12,0);
1106 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1107 real_insert
= bits(va
, 9,9);
1108 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1109 PageTableEntry::sun4u
);
1110 tc
->getITBPtr()->insert(va_insert
, part_insert
, ct_insert
, real_insert
,
1113 case ASI_DTLB_DATA_ACCESS_REG
:
1114 entry_insert
= bits(va
, 8,3);
1115 case ASI_DTLB_DATA_IN_REG
:
1116 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1117 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
1118 va_insert
= mbits(ta_insert
, 63,13);
1119 ct_insert
= mbits(ta_insert
, 12,0);
1120 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1121 real_insert
= bits(va
, 9,9);
1122 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1123 PageTableEntry::sun4u
);
1124 insert(va_insert
, part_insert
, ct_insert
, real_insert
, pte
, entry_insert
);
1126 case ASI_IMMU_DEMAP
:
1129 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1130 switch (bits(va
,5,4)) {
1132 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1144 switch(bits(va
,7,6)) {
1145 case 0: // demap page
1147 tc
->getITBPtr()->demapPage(mbits(va
,63,13), part_id
,
1148 bits(va
,9,9), ctx_id
);
1150 case 1: //demap context
1152 tc
->getITBPtr()->demapContext(part_id
, ctx_id
);
1155 tc
->getITBPtr()->demapAll(part_id
);
1158 panic("Invalid type for IMMU demap\n");
1164 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
, data
);
1167 sext
<59>(bits(data
, 59,0));
1168 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
, data
);
1171 tc
->setMiscRegWithEffect(MISCREG_MMU_PART_ID
, data
);
1174 goto doMmuWriteError
;
1177 case ASI_DMMU_DEMAP
:
1180 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1181 switch (bits(va
,5,4)) {
1183 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1186 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
);
1195 switch(bits(va
,7,6)) {
1196 case 0: // demap page
1198 demapPage(mbits(va
,63,13), part_id
, bits(va
,9,9), ctx_id
);
1200 case 1: //demap context
1202 demapContext(part_id
, ctx_id
);
1208 panic("Invalid type for IMMU demap\n");
1213 panic("need to impl DTB::doMmuRegWrite() got asi=%#x, va=%#x d=%#x\n",
1214 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr(), data
);
1216 pkt
->result
= Packet::Success
;
1217 return tc
->getCpuPtr()->cycles(1);
1221 DTB::GetTsbPtr(ThreadContext
*tc
, Addr addr
, int ctx
, Addr
*ptrs
)
1223 uint64_t tag_access
= mbits(addr
,63,13) | mbits(ctx
,12,0);
1224 ptrs
[0] = MakeTsbPtr(Ps0
, tag_access
,
1225 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
),
1226 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
1227 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
),
1228 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
1229 ptrs
[1] = MakeTsbPtr(Ps1
, tag_access
,
1230 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
),
1231 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
1232 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
),
1233 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
1234 ptrs
[2] = MakeTsbPtr(Ps0
, tag_access
,
1235 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
),
1236 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
1237 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
),
1238 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
1239 ptrs
[3] = MakeTsbPtr(Ps1
, tag_access
,
1240 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
),
1241 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
1242 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
),
1243 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
1251 DTB::MakeTsbPtr(TsbPageSize ps
, uint64_t tag_access
, uint64_t c0_tsb
,
1252 uint64_t c0_config
, uint64_t cX_tsb
, uint64_t cX_config
)
1257 if (bits(tag_access
, 12,0) == 0) {
1265 uint64_t ptr
= mbits(tsb
,63,13);
1266 bool split
= bits(tsb
,12,12);
1267 int tsb_size
= bits(tsb
,3,0);
1268 int page_size
= (ps
== Ps0
) ? bits(config
, 2,0) : bits(config
,10,8);
1270 if (ps
== Ps1
&& split
)
1271 ptr
|= ULL(1) << (13 + tsb_size
);
1272 ptr
|= (tag_access
>> (9 + page_size
* 3)) & mask(12+tsb_size
, 4);
1279 TLB::serialize(std::ostream
&os
)
1281 SERIALIZE_SCALAR(size
);
1282 SERIALIZE_SCALAR(usedEntries
);
1283 SERIALIZE_SCALAR(lastReplaced
);
1285 // convert the pointer based free list into an index based one
1286 int *free_list
= (int*)malloc(sizeof(int) * size
);
1288 std::list
<TlbEntry
*>::iterator i
;
1289 i
= freeList
.begin();
1290 while (i
!= freeList
.end()) {
1291 free_list
[cntr
++] = ((size_t)*i
- (size_t)tlb
)/ sizeof(TlbEntry
);
1294 SERIALIZE_SCALAR(cntr
);
1295 SERIALIZE_ARRAY(free_list
, cntr
);
1297 for (int x
= 0; x
< size
; x
++) {
1298 nameOut(os
, csprintf("%s.PTE%d", name(), x
));
1299 tlb
[x
].serialize(os
);
1304 TLB::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1308 paramIn(cp
, section
, "size", oldSize
);
1309 if (oldSize
!= size
)
1310 panic("Don't support unserializing different sized TLBs\n");
1311 UNSERIALIZE_SCALAR(usedEntries
);
1312 UNSERIALIZE_SCALAR(lastReplaced
);
1315 UNSERIALIZE_SCALAR(cntr
);
1317 int *free_list
= (int*)malloc(sizeof(int) * cntr
);
1319 UNSERIALIZE_ARRAY(free_list
, cntr
);
1320 for (int x
= 0; x
< cntr
; x
++)
1321 freeList
.push_back(&tlb
[free_list
[x
]]);
1323 lookupTable
.clear();
1324 for (int x
= 0; x
< size
; x
++) {
1325 tlb
[x
].unserialize(cp
, csprintf("%s.PTE%d", section
, x
));
1327 lookupTable
.insert(tlb
[x
].range
, &tlb
[x
]);
1333 DEFINE_SIM_OBJECT_CLASS_NAME("SparcTLB", TLB
)
1335 BEGIN_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1339 END_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1341 BEGIN_INIT_SIM_OBJECT_PARAMS(ITB
)
1343 INIT_PARAM_DFLT(size
, "TLB size", 48)
1345 END_INIT_SIM_OBJECT_PARAMS(ITB
)
1348 CREATE_SIM_OBJECT(ITB
)
1350 return new ITB(getInstanceName(), size
);
1353 REGISTER_SIM_OBJECT("SparcITB", ITB
)
1355 BEGIN_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1359 END_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1361 BEGIN_INIT_SIM_OBJECT_PARAMS(DTB
)
1363 INIT_PARAM_DFLT(size
, "TLB size", 64)
1365 END_INIT_SIM_OBJECT_PARAMS(DTB
)
1368 CREATE_SIM_OBJECT(DTB
)
1370 return new DTB(getInstanceName(), size
);
1373 REGISTER_SIM_OBJECT("SparcDTB", DTB
)