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
), usedEntries(0), lastReplaced(0),
51 // To make this work you'll have to change the hypervisor and OS
53 fatal("SPARC T1 TLB registers don't support more than 64 TLB entries.");
55 tlb
= new TlbEntry
[size
];
56 memset(tlb
, 0, sizeof(TlbEntry
) * size
);
58 for (int x
= 0; x
< size
; x
++)
59 freeList
.push_back(&tlb
[x
]);
66 for (i
= lookupTable
.begin(); i
!= lookupTable
.end(); i
++) {
67 TlbEntry
*t
= i
->second
;
68 if (!t
->pte
.locked()) {
77 TLB::insert(Addr va
, int partition_id
, int context_id
, bool real
,
78 const PageTableEntry
& PTE
, int entry
)
83 TlbEntry
*new_entry
= NULL
;
88 va
&= ~(PTE
.size()-1);
90 tr.size = PTE.size() - 1;
91 tr.contextId = context_id;
92 tr.partitionId = partition_id;
96 DPRINTF(TLB
, "TLB: Inserting TLB Entry; va=%#x pa=%#x pid=%d cid=%d r=%d entryid=%d\n",
97 va
, PTE
.paddr(), partition_id
, context_id
, (int)real
, entry
);
99 // Demap any entry that conflicts
100 for (x
= 0; x
< size
; x
++) {
101 if (tlb
[x
].range
.real
== real
&&
102 tlb
[x
].range
.partitionId
== partition_id
&&
103 tlb
[x
].range
.va
< va
+ PTE
.size() - 1 &&
104 tlb
[x
].range
.va
+ tlb
[x
].range
.size
>= va
&&
105 (real
|| tlb
[x
].range
.contextId
== context_id
))
108 freeList
.push_front(&tlb
[x
]);
109 DPRINTF(TLB
, "TLB: Conflicting entry %#X , deleting it\n", x
);
111 tlb
[x
].valid
= false;
116 lookupTable
.erase(tlb
[x
].range
);
123 i = lookupTable.find(tr);
124 if (i != lookupTable.end()) {
125 i->second->valid = false;
126 if (i->second->used) {
127 i->second->used = false;
130 freeList.push_front(i->second);
131 DPRINTF(TLB, "TLB: Found conflicting entry %#X , deleting it\n",
133 lookupTable.erase(i);
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());
156 for (x = 0; x < size; x++) {
157 if (!tlb[x].valid || !tlb[x].used) {
165 // Update the last ently if their all locked
167 new_entry
= &tlb
[size
-1];
170 freeList
.remove(new_entry
);
171 if (new_entry
->valid
&& new_entry
->used
)
174 lookupTable
.erase(new_entry
->range
);
177 DPRINTF(TLB
, "Using entry: %#X\n", new_entry
);
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
)
213 DPRINTF(TLB
, "TLB: Looking up entry va=%#x pid=%d cid=%d r=%d\n",
214 va
, partition_id
, context_id
, real
);
215 // Assemble full address structure
217 tr
.size
= MachineBytes
;
218 tr
.contextId
= context_id
;
219 tr
.partitionId
= partition_id
;
222 // Try to find the entry
223 i
= lookupTable
.find(tr
);
224 if (i
== lookupTable
.end()) {
225 DPRINTF(TLB
, "TLB: No valid entry found\n");
229 // Mark the entries used bit and clear other used bits in needed
231 DPRINTF(TLB
, "TLB: Valid entry found pa: %#x size: %#x\n", t
->pte
.paddr(),
236 if (usedEntries
== size
) {
250 for (int x
= 0; x
< size
; x
++) {
252 DPRINTFN("%4d: %#2x:%#2x %c %#4x %#8x %#8x %#16x\n",
253 x
, tlb
[x
].range
.partitionId
, tlb
[x
].range
.contextId
,
254 tlb
[x
].range
.real
? 'R' : ' ', tlb
[x
].range
.size
,
255 tlb
[x
].range
.va
, tlb
[x
].pte
.paddr(), tlb
[x
].pte());
261 TLB::demapPage(Addr va
, int partition_id
, bool real
, int context_id
)
266 DPRINTF(IPR
, "TLB: Demapping Page va=%#x pid=%#d cid=%d r=%d\n",
267 va
, partition_id
, context_id
, real
);
271 // Assemble full address structure
273 tr
.size
= MachineBytes
;
274 tr
.contextId
= context_id
;
275 tr
.partitionId
= partition_id
;
278 // Demap any entry that conflicts
279 i
= lookupTable
.find(tr
);
280 if (i
!= lookupTable
.end()) {
281 DPRINTF(IPR
, "TLB: Demapped page\n");
282 i
->second
->valid
= false;
283 if (i
->second
->used
) {
284 i
->second
->used
= false;
287 freeList
.push_front(i
->second
);
288 DPRINTF(TLB
, "Freeing TLB entry : %#X\n", i
->second
);
289 lookupTable
.erase(i
);
294 TLB::demapContext(int partition_id
, int context_id
)
297 DPRINTF(IPR
, "TLB: Demapping Context pid=%#d cid=%d\n",
298 partition_id
, context_id
);
300 for (x
= 0; x
< size
; x
++) {
301 if (tlb
[x
].range
.contextId
== context_id
&&
302 tlb
[x
].range
.partitionId
== partition_id
) {
303 if (tlb
[x
].valid
== true) {
304 freeList
.push_front(&tlb
[x
]);
305 DPRINTF(TLB
, "Freeing TLB entry : %#X\n", &tlb
[x
]);
307 tlb
[x
].valid
= false;
312 lookupTable
.erase(tlb
[x
].range
);
318 TLB::demapAll(int partition_id
)
321 DPRINTF(TLB
, "TLB: Demapping All pid=%#d\n", partition_id
);
323 for (x
= 0; x
< size
; x
++) {
324 if (!tlb
[x
].pte
.locked() && tlb
[x
].range
.partitionId
== partition_id
) {
325 if (tlb
[x
].valid
== true){
326 freeList
.push_front(&tlb
[x
]);
327 DPRINTF(TLB
, "Freeing TLB entry : %#X\n", &tlb
[x
]);
329 tlb
[x
].valid
= false;
334 lookupTable
.erase(tlb
[x
].range
);
347 for (x
= 0; x
< size
; x
++) {
348 if (tlb
[x
].valid
== true)
349 freeList
.push_back(&tlb
[x
]);
350 tlb
[x
].valid
= false;
357 TLB::TteRead(int entry
) {
359 panic("entry: %d\n", entry
);
361 assert(entry
< size
);
362 if (tlb
[entry
].valid
)
363 return tlb
[entry
].pte();
365 return (uint64_t)-1ll;
369 TLB::TagRead(int entry
) {
370 assert(entry
< size
);
372 if (!tlb
[entry
].valid
)
373 return (uint64_t)-1ll;
375 tag
= tlb
[entry
].range
.contextId
;
376 tag
|= tlb
[entry
].range
.va
;
377 tag
|= (uint64_t)tlb
[entry
].range
.partitionId
<< 61;
378 tag
|= tlb
[entry
].range
.real
? ULL(1) << 60 : 0;
379 tag
|= (uint64_t)~tlb
[entry
].pte
._size() << 56;
384 TLB::validVirtualAddress(Addr va
, bool am
)
388 if (va
>= StartVAddrHole
&& va
<= EndVAddrHole
)
394 TLB::writeSfsr(ThreadContext
*tc
, int reg
, bool write
, ContextType ct
,
395 bool se
, FaultTypes ft
, int asi
)
398 sfsr
= tc
->readMiscReg(reg
);
412 tc
->setMiscRegWithEffect(reg
, sfsr
);
416 TLB::writeTagAccess(ThreadContext
*tc
, int reg
, Addr va
, int context
)
418 DPRINTF(TLB
, "TLB: Writing Tag Access: va: %#X ctx: %#X value: %#X\n",
419 va
, context
, mbits(va
, 63,13) | mbits(context
,12,0));
421 tc
->setMiscRegWithEffect(reg
, mbits(va
, 63,13) | mbits(context
,12,0));
425 ITB::writeSfsr(ThreadContext
*tc
, bool write
, ContextType ct
,
426 bool se
, FaultTypes ft
, int asi
)
428 DPRINTF(TLB
, "TLB: ITB Fault: w=%d ct=%d ft=%d asi=%d\n",
429 (int)write
, ct
, ft
, asi
);
430 TLB::writeSfsr(tc
, MISCREG_MMU_ITLB_SFSR
, write
, ct
, se
, ft
, asi
);
434 ITB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
436 TLB::writeTagAccess(tc
, MISCREG_MMU_ITLB_TAG_ACCESS
, va
, context
);
440 DTB::writeSfr(ThreadContext
*tc
, Addr a
, bool write
, ContextType ct
,
441 bool se
, FaultTypes ft
, int asi
)
443 DPRINTF(TLB
, "TLB: DTB Fault: A=%#x w=%d ct=%d ft=%d asi=%d\n",
444 a
, (int)write
, ct
, ft
, asi
);
445 TLB::writeSfsr(tc
, MISCREG_MMU_DTLB_SFSR
, write
, ct
, se
, ft
, asi
);
446 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
, a
);
450 DTB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
452 TLB::writeTagAccess(tc
, MISCREG_MMU_DTLB_TAG_ACCESS
, va
, context
);
458 ITB::translate(RequestPtr
&req
, ThreadContext
*tc
)
460 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
462 Addr vaddr
= req
->getVaddr();
465 assert(req
->getAsi() == ASI_IMPLICIT
);
467 DPRINTF(TLB
, "TLB: ITB Request to translate va=%#x size=%d\n",
468 vaddr
, req
->getSize());
470 // Be fast if we can!
471 if (cacheValid
&& cacheState
== tlbdata
) {
473 if (cacheEntry
->range
.va
< vaddr
+ sizeof(MachInst
) &&
474 cacheEntry
->range
.va
+ cacheEntry
->range
.size
>= vaddr
) {
475 req
->setPaddr(cacheEntry
->pte
.paddr() & ~(cacheEntry
->pte
.size()-1) |
476 vaddr
& cacheEntry
->pte
.size()-1 );
480 req
->setPaddr(vaddr
& PAddrImplMask
);
485 bool hpriv
= bits(tlbdata
,0,0);
486 bool red
= bits(tlbdata
,1,1);
487 bool priv
= bits(tlbdata
,2,2);
488 bool addr_mask
= bits(tlbdata
,3,3);
489 bool lsu_im
= bits(tlbdata
,4,4);
491 int part_id
= bits(tlbdata
,15,8);
492 int tl
= bits(tlbdata
,18,16);
493 int pri_context
= bits(tlbdata
,47,32);
499 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsuim:%d part_id: %#X\n",
500 priv
, hpriv
, red
, lsu_im
, part_id
);
509 context
= pri_context
;
512 if ( hpriv
|| red
) {
514 cacheState
= tlbdata
;
516 req
->setPaddr(vaddr
& PAddrImplMask
);
520 // If the access is unaligned trap
522 writeSfsr(tc
, false, ct
, false, OtherFault
, asi
);
523 return new MemAddressNotAligned
;
527 vaddr
= vaddr
& VAddrAMask
;
529 if (!validVirtualAddress(vaddr
, addr_mask
)) {
530 writeSfsr(tc
, false, ct
, false, VaOutOfRange
, asi
);
531 return new InstructionAccessException
;
535 e
= lookup(vaddr
, part_id
, true);
539 e
= lookup(vaddr
, part_id
, false, context
);
542 if (e
== NULL
|| !e
->valid
) {
543 writeTagAccess(tc
, vaddr
, context
);
545 return new InstructionRealTranslationMiss
;
547 return new FastInstructionAccessMMUMiss
;
550 // were not priviledged accesing priv page
551 if (!priv
&& e
->pte
.priv()) {
552 writeSfsr(tc
, false, ct
, false, PrivViolation
, asi
);
553 return new InstructionAccessException
;
556 // cache translation date for next translation
558 cacheState
= tlbdata
;
561 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
562 vaddr
& e
->pte
.size()-1 );
563 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
570 DTB::translate(RequestPtr
&req
, ThreadContext
*tc
, bool write
)
572 /* @todo this could really use some profiling and fixing to make it faster! */
573 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
574 Addr vaddr
= req
->getVaddr();
575 Addr size
= req
->getSize();
577 asi
= (ASI
)req
->getAsi();
578 bool implicit
= false;
579 bool hpriv
= bits(tlbdata
,0,0);
581 DPRINTF(TLB
, "TLB: DTB Request to translate va=%#x size=%d asi=%#x\n",
584 if (asi
== ASI_IMPLICIT
)
587 if (hpriv
&& implicit
) {
588 req
->setPaddr(vaddr
& PAddrImplMask
);
592 // Be fast if we can!
593 if (cacheValid
&& cacheState
== tlbdata
) {
594 if (cacheEntry
[0] && cacheAsi
[0] == asi
&& cacheEntry
[0]->range
.va
< vaddr
+ size
&&
595 cacheEntry
[0]->range
.va
+ cacheEntry
[0]->range
.size
> vaddr
) {
596 req
->setPaddr(cacheEntry
[0]->pte
.paddr() & ~(cacheEntry
[0]->pte
.size()-1) |
597 vaddr
& cacheEntry
[0]->pte
.size()-1 );
600 if (cacheEntry
[1] && cacheAsi
[1] == asi
&& cacheEntry
[1]->range
.va
< vaddr
+ size
&&
601 cacheEntry
[1]->range
.va
+ cacheEntry
[1]->range
.size
> vaddr
) {
602 req
->setPaddr(cacheEntry
[1]->pte
.paddr() & ~(cacheEntry
[1]->pte
.size()-1) |
603 vaddr
& cacheEntry
[1]->pte
.size()-1 );
608 bool red
= bits(tlbdata
,1,1);
609 bool priv
= bits(tlbdata
,2,2);
610 bool addr_mask
= bits(tlbdata
,3,3);
611 bool lsu_dm
= bits(tlbdata
,5,5);
613 int part_id
= bits(tlbdata
,15,8);
614 int tl
= bits(tlbdata
,18,16);
615 int pri_context
= bits(tlbdata
,47,32);
616 int sec_context
= bits(tlbdata
,63,48);
619 ContextType ct
= Primary
;
624 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsudm:%d part_id: %#X\n",
625 priv
, hpriv
, red
, lsu_dm
, part_id
);
635 context
= pri_context
;
638 // We need to check for priv level/asi priv
639 if (!priv
&& !hpriv
&& !AsiIsUnPriv(asi
)) {
640 // It appears that context should be Nucleus in these cases?
641 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
642 return new PrivilegedAction
;
645 if (!hpriv
&& AsiIsHPriv(asi
)) {
646 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
647 return new DataAccessException
;
650 if (AsiIsPrimary(asi
)) {
651 context
= pri_context
;
653 } else if (AsiIsSecondary(asi
)) {
654 context
= sec_context
;
656 } else if (AsiIsNucleus(asi
)) {
661 context
= pri_context
;
665 if (!implicit
&& asi
!= ASI_P
&& asi
!= ASI_S
) {
666 if (AsiIsLittle(asi
))
667 panic("Little Endian ASIs not supported\n");
669 panic("Block ASIs not supported\n");
670 if (AsiIsNoFault(asi
))
671 panic("No Fault ASIs not supported\n");
673 if (AsiIsPartialStore(asi
))
674 panic("Partial Store ASIs not supported\n");
675 if (AsiIsInterrupt(asi
))
676 panic("Interrupt ASIs not supported\n");
679 goto handleMmuRegAccess
;
680 if (AsiIsScratchPad(asi
))
681 goto handleScratchRegAccess
;
683 goto handleQueueRegAccess
;
684 if (AsiIsSparcError(asi
))
685 goto handleSparcErrorRegAccess
;
687 if (!AsiIsReal(asi
) && !AsiIsNucleus(asi
) && !AsiIsAsIfUser(asi
) &&
689 panic("Accessing ASI %#X. Should we?\n", asi
);
692 // If the asi is unaligned trap
693 if (vaddr
& size
-1) {
694 writeSfr(tc
, vaddr
, false, ct
, false, OtherFault
, asi
);
695 return new MemAddressNotAligned
;
699 vaddr
= vaddr
& VAddrAMask
;
701 if (!validVirtualAddress(vaddr
, addr_mask
)) {
702 writeSfr(tc
, vaddr
, false, ct
, true, VaOutOfRange
, asi
);
703 return new DataAccessException
;
707 if ((!lsu_dm
&& !hpriv
&& !red
) || AsiIsReal(asi
)) {
712 if (hpriv
&& (implicit
|| (!AsiIsAsIfUser(asi
) && !AsiIsReal(asi
)))) {
713 req
->setPaddr(vaddr
& PAddrImplMask
);
717 e
= lookup(vaddr
, part_id
, real
, context
);
719 if (e
== NULL
|| !e
->valid
) {
720 writeTagAccess(tc
, vaddr
, context
);
721 DPRINTF(TLB
, "TLB: DTB Failed to find matching TLB entry\n");
723 return new DataRealTranslationMiss
;
725 return new FastDataAccessMMUMiss
;
730 if (write
&& !e
->pte
.writable()) {
731 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), OtherFault
, asi
);
732 return new FastDataAccessProtection
;
735 if (e
->pte
.nofault() && !AsiIsNoFault(asi
)) {
736 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), LoadFromNfo
, asi
);
737 return new DataAccessException
;
740 if (e
->pte
.sideffect())
741 req
->setFlags(req
->getFlags() | UNCACHEABLE
);
744 if (!priv
&& e
->pte
.priv()) {
745 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), PrivViolation
, asi
);
746 return new DataAccessException
;
749 // cache translation date for next translation
750 cacheState
= tlbdata
;
752 cacheEntry
[1] = NULL
;
753 cacheEntry
[0] = NULL
;
756 if (cacheEntry
[0] != e
&& cacheEntry
[1] != e
) {
757 cacheEntry
[1] = cacheEntry
[0];
759 cacheAsi
[1] = cacheAsi
[0];
762 cacheAsi
[0] = (ASI
)0;
765 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
766 vaddr
& e
->pte
.size()-1);
767 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
769 /** Normal flow ends here. */
771 handleScratchRegAccess
:
772 if (vaddr
> 0x38 || (vaddr
>= 0x20 && vaddr
< 0x30 && !hpriv
)) {
773 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
774 return new DataAccessException
;
778 handleQueueRegAccess
:
779 if (!priv
&& !hpriv
) {
780 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
781 return new PrivilegedAction
;
783 if (!hpriv
&& vaddr
& 0xF || vaddr
> 0x3f8 || vaddr
< 0x3c0) {
784 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
785 return new DataAccessException
;
789 handleSparcErrorRegAccess
:
792 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
793 return new DataAccessException
;
795 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
796 return new PrivilegedAction
;
804 DPRINTF(TLB
, "TLB: DTB Translating MM IPR access\n");
805 req
->setMmapedIpr(true);
806 req
->setPaddr(req
->getVaddr());
811 DTB::doMmuRegRead(ThreadContext
*tc
, Packet
*pkt
)
813 Addr va
= pkt
->getAddr();
814 ASI asi
= (ASI
)pkt
->req
->getAsi();
816 uint64_t tsbtemp
, cnftemp
;
818 DPRINTF(IPR
, "Memory Mapped IPR Read: asi=%#X a=%#x\n",
819 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr());
822 case ASI_LSU_CONTROL_REG
:
824 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
));
829 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
));
832 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
));
839 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
842 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
844 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
));
846 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
848 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
));
850 case ASI_DMMU_CTXT_ZERO_CONFIG
:
852 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
));
854 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
856 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
));
858 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
860 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
));
862 case ASI_IMMU_CTXT_ZERO_CONFIG
:
864 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
));
866 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
868 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
));
870 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
872 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
));
874 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
876 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
878 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
880 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
));
882 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
884 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
));
886 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
888 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
890 case ASI_SPARC_ERROR_STATUS_REG
:
891 warn("returning 0 for SPARC ERROR regsiter read\n");
892 pkt
->set((uint64_t)0);
894 case ASI_HYP_SCRATCHPAD
:
896 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3)));
901 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
902 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
905 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
));
908 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
));
917 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
918 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
921 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
));
924 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
));
927 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
));
930 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
));
936 case ASI_DMMU_TSB_PS0_PTR_REG
:
937 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
938 if (bits(temp
,12,0) == 0) {
939 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
);
940 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
);
942 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
);
943 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
);
945 data
= mbits(tsbtemp
,63,13);
946 data
|= temp
>> (9 + bits(cnftemp
,2,0) * 3) &
947 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
950 case ASI_DMMU_TSB_PS1_PTR_REG
:
951 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
952 if (bits(temp
,12,0) == 0) {
953 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
);
954 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
);
956 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
);
957 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
);
959 data
= mbits(tsbtemp
,63,13);
960 if (bits(tsbtemp
,12,12))
961 data
|= ULL(1) << (13+bits(tsbtemp
,3,0));
962 data
|= temp
>> (9 + bits(cnftemp
,10,8) * 3) &
963 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
966 case ASI_IMMU_TSB_PS0_PTR_REG
:
967 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
968 if (bits(temp
,12,0) == 0) {
969 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
);
970 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
);
972 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
);
973 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
);
975 data
= mbits(tsbtemp
,63,13);
976 data
|= temp
>> (9 + bits(cnftemp
,2,0) * 3) &
977 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
980 case ASI_IMMU_TSB_PS1_PTR_REG
:
981 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
982 if (bits(temp
,12,0) == 0) {
983 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
);
984 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
);
986 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
);
987 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
);
989 data
= mbits(tsbtemp
,63,13);
990 if (bits(tsbtemp
,12,12))
991 data
|= ULL(1) << (13+bits(tsbtemp
,3,0));
992 data
|= temp
>> (9 + bits(cnftemp
,10,8) * 3) &
993 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
999 panic("need to impl DTB::doMmuRegRead() got asi=%#x, va=%#x\n",
1002 pkt
->result
= Packet::Success
;
1003 return tc
->getCpuPtr()->cycles(1);
1007 DTB::doMmuRegWrite(ThreadContext
*tc
, Packet
*pkt
)
1009 uint64_t data
= gtoh(pkt
->get
<uint64_t>());
1010 Addr va
= pkt
->getAddr();
1011 ASI asi
= (ASI
)pkt
->req
->getAsi();
1017 int entry_insert
= -1;
1024 DPRINTF(IPR
, "Memory Mapped IPR Write: asi=%#X a=%#x d=%#X\n",
1025 (uint32_t)asi
, va
, data
);
1028 case ASI_LSU_CONTROL_REG
:
1030 tc
->setMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
, data
);
1035 tc
->setMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
, data
);
1038 tc
->setMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
, data
);
1041 goto doMmuWriteError
;
1045 assert(mbits(data
,13,6) == data
);
1046 tc
->setMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
1047 (va
>> 4) - 0x3c, data
);
1049 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
1051 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
, data
);
1053 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
1055 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
, data
);
1057 case ASI_DMMU_CTXT_ZERO_CONFIG
:
1059 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
, data
);
1061 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
1063 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
, data
);
1065 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
1067 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
, data
);
1069 case ASI_IMMU_CTXT_ZERO_CONFIG
:
1071 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
, data
);
1073 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1075 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
, data
);
1077 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1079 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
, data
);
1081 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
1083 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
, data
);
1085 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1087 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
, data
);
1089 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1091 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
, data
);
1093 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
1095 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
, data
);
1097 case ASI_SPARC_ERROR_EN_REG
:
1098 case ASI_SPARC_ERROR_STATUS_REG
:
1099 warn("Ignoring write to SPARC ERROR regsiter\n");
1101 case ASI_HYP_SCRATCHPAD
:
1102 case ASI_SCRATCHPAD
:
1103 tc
->setMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3), data
);
1108 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
, data
);
1111 sext
<59>(bits(data
, 59,0));
1112 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
, data
);
1115 goto doMmuWriteError
;
1118 case ASI_ITLB_DATA_ACCESS_REG
:
1119 entry_insert
= bits(va
, 8,3);
1120 case ASI_ITLB_DATA_IN_REG
:
1121 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1122 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
1123 va_insert
= mbits(ta_insert
, 63,13);
1124 ct_insert
= mbits(ta_insert
, 12,0);
1125 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1126 real_insert
= bits(va
, 9,9);
1127 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1128 PageTableEntry::sun4u
);
1129 tc
->getITBPtr()->insert(va_insert
, part_insert
, ct_insert
, real_insert
,
1132 case ASI_DTLB_DATA_ACCESS_REG
:
1133 entry_insert
= bits(va
, 8,3);
1134 case ASI_DTLB_DATA_IN_REG
:
1135 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1136 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
1137 va_insert
= mbits(ta_insert
, 63,13);
1138 ct_insert
= mbits(ta_insert
, 12,0);
1139 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1140 real_insert
= bits(va
, 9,9);
1141 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1142 PageTableEntry::sun4u
);
1143 insert(va_insert
, part_insert
, ct_insert
, real_insert
, pte
, entry_insert
);
1145 case ASI_IMMU_DEMAP
:
1148 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1149 switch (bits(va
,5,4)) {
1151 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1163 switch(bits(va
,7,6)) {
1164 case 0: // demap page
1166 tc
->getITBPtr()->demapPage(mbits(va
,63,13), part_id
,
1167 bits(va
,9,9), ctx_id
);
1169 case 1: //demap context
1171 tc
->getITBPtr()->demapContext(part_id
, ctx_id
);
1174 tc
->getITBPtr()->demapAll(part_id
);
1177 panic("Invalid type for IMMU demap\n");
1183 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
, data
);
1186 sext
<59>(bits(data
, 59,0));
1187 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
, data
);
1190 tc
->setMiscRegWithEffect(MISCREG_MMU_PART_ID
, data
);
1193 goto doMmuWriteError
;
1196 case ASI_DMMU_DEMAP
:
1199 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1200 switch (bits(va
,5,4)) {
1202 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1205 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
);
1214 switch(bits(va
,7,6)) {
1215 case 0: // demap page
1217 demapPage(mbits(va
,63,13), part_id
, bits(va
,9,9), ctx_id
);
1219 case 1: //demap context
1221 demapContext(part_id
, ctx_id
);
1227 panic("Invalid type for IMMU demap\n");
1232 panic("need to impl DTB::doMmuRegWrite() got asi=%#x, va=%#x d=%#x\n",
1233 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr(), data
);
1235 pkt
->result
= Packet::Success
;
1236 return tc
->getCpuPtr()->cycles(1);
1240 TLB::serialize(std::ostream
&os
)
1242 panic("Need to implement serialize tlb for SPARC\n");
1246 TLB::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1248 panic("Need to implement unserialize tlb for SPARC\n");
1252 DEFINE_SIM_OBJECT_CLASS_NAME("SparcTLB", TLB
)
1254 BEGIN_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1258 END_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1260 BEGIN_INIT_SIM_OBJECT_PARAMS(ITB
)
1262 INIT_PARAM_DFLT(size
, "TLB size", 48)
1264 END_INIT_SIM_OBJECT_PARAMS(ITB
)
1267 CREATE_SIM_OBJECT(ITB
)
1269 return new ITB(getInstanceName(), size
);
1272 REGISTER_SIM_OBJECT("SparcITB", ITB
)
1274 BEGIN_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1278 END_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1280 BEGIN_INIT_SIM_OBJECT_PARAMS(DTB
)
1282 INIT_PARAM_DFLT(size
, "TLB size", 64)
1284 END_INIT_SIM_OBJECT_PARAMS(DTB
)
1287 CREATE_SIM_OBJECT(DTB
)
1289 return new DTB(getInstanceName(), size
);
1292 REGISTER_SIM_OBJECT("SparcDTB", DTB
)