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
;
89 tr.size = PTE.size() - 1;
90 tr.contextId = context_id;
91 tr.partitionId = partition_id;
95 DPRINTF(TLB
, "TLB: Inserting TLB Entry; va=%#x pa=%#x pid=%d cid=%d r=%d entryid=%d\n",
96 va
, PTE
.paddr(), partition_id
, context_id
, (int)real
, entry
);
98 // Demap any entry that conflicts
99 for (x
= 0; x
< size
; x
++) {
100 if (tlb
[x
].range
.real
== real
&&
101 tlb
[x
].range
.partitionId
== partition_id
&&
102 tlb
[x
].range
.va
< va
+ PTE
.size() - 1 &&
103 tlb
[x
].range
.va
+ tlb
[x
].range
.size
>= va
&&
104 (real
|| tlb
[x
].range
.contextId
== context_id
))
107 freeList
.push_front(&tlb
[x
]);
108 DPRINTF(TLB
, "TLB: Conflicting entry %#X , deleting it\n", x
);
110 tlb
[x
].valid
= false;
115 lookupTable
.erase(tlb
[x
].range
);
122 i = lookupTable.find(tr);
123 if (i != lookupTable.end()) {
124 i->second->valid = false;
125 if (i->second->used) {
126 i->second->used = false;
129 freeList.push_front(i->second);
130 DPRINTF(TLB, "TLB: Found conflicting entry %#X , deleting it\n",
132 lookupTable.erase(i);
137 assert(entry
< size
&& entry
>= 0);
138 new_entry
= &tlb
[entry
];
140 if (!freeList
.empty()) {
141 new_entry
= freeList
.front();
148 if (x
== lastReplaced
)
149 goto insertAllLocked
;
150 } while (tlb
[x
].pte
.locked());
155 for (x = 0; x < size; x++) {
156 if (!tlb[x].valid || !tlb[x].used) {
164 // Update the last ently if their all locked
166 new_entry
= &tlb
[size
-1];
169 freeList
.remove(new_entry
);
170 if (new_entry
->valid
&& new_entry
->used
)
173 lookupTable
.erase(new_entry
->range
);
176 DPRINTF(TLB
, "Using entry: %#X\n", new_entry
);
179 new_entry
->range
.va
= va
;
180 new_entry
->range
.size
= PTE
.size() - 1;
181 new_entry
->range
.partitionId
= partition_id
;
182 new_entry
->range
.contextId
= context_id
;
183 new_entry
->range
.real
= real
;
184 new_entry
->pte
= PTE
;
185 new_entry
->used
= true;;
186 new_entry
->valid
= true;
191 i
= lookupTable
.insert(new_entry
->range
, new_entry
);
192 assert(i
!= lookupTable
.end());
194 // If all entries have there used bit set, clear it on them all, but the
195 // one we just inserted
196 if (usedEntries
== size
) {
198 new_entry
->used
= true;
206 TLB::lookup(Addr va
, int partition_id
, bool real
, int context_id
)
212 DPRINTF(TLB
, "TLB: Looking up entry va=%#x pid=%d cid=%d r=%d\n",
213 va
, partition_id
, context_id
, real
);
214 // Assemble full address structure
216 tr
.size
= MachineBytes
;
217 tr
.contextId
= context_id
;
218 tr
.partitionId
= partition_id
;
221 // Try to find the entry
222 i
= lookupTable
.find(tr
);
223 if (i
== lookupTable
.end()) {
224 DPRINTF(TLB
, "TLB: No valid entry found\n");
228 // Mark the entries used bit and clear other used bits in needed
230 DPRINTF(TLB
, "TLB: Valid entry found pa: %#x size: %#x\n", t
->pte
.paddr(),
235 if (usedEntries
== size
) {
249 for (int x
= 0; x
< size
; x
++) {
251 DPRINTFN("%4d: %#2x:%#2x %c %#4x %#8x %#8x %#16x\n",
252 x
, tlb
[x
].range
.partitionId
, tlb
[x
].range
.contextId
,
253 tlb
[x
].range
.real
? 'R' : ' ', tlb
[x
].range
.size
,
254 tlb
[x
].range
.va
, tlb
[x
].pte
.paddr(), tlb
[x
].pte());
260 TLB::demapPage(Addr va
, int partition_id
, bool real
, int context_id
)
265 DPRINTF(IPR
, "TLB: Demapping Page va=%#x pid=%#d cid=%d r=%d\n",
266 va
, partition_id
, context_id
, real
);
270 // Assemble full address structure
272 tr
.size
= MachineBytes
;
273 tr
.contextId
= context_id
;
274 tr
.partitionId
= partition_id
;
277 // Demap any entry that conflicts
278 i
= lookupTable
.find(tr
);
279 if (i
!= lookupTable
.end()) {
280 DPRINTF(IPR
, "TLB: Demapped page\n");
281 i
->second
->valid
= false;
282 if (i
->second
->used
) {
283 i
->second
->used
= false;
286 freeList
.push_front(i
->second
);
287 DPRINTF(TLB
, "Freeing TLB entry : %#X\n", i
->second
);
288 lookupTable
.erase(i
);
293 TLB::demapContext(int partition_id
, int context_id
)
296 DPRINTF(IPR
, "TLB: Demapping Context pid=%#d cid=%d\n",
297 partition_id
, context_id
);
299 for (x
= 0; x
< size
; x
++) {
300 if (tlb
[x
].range
.contextId
== context_id
&&
301 tlb
[x
].range
.partitionId
== partition_id
) {
302 if (tlb
[x
].valid
== true) {
303 freeList
.push_front(&tlb
[x
]);
304 DPRINTF(TLB
, "Freeing TLB entry : %#X\n", &tlb
[x
]);
306 tlb
[x
].valid
= false;
311 lookupTable
.erase(tlb
[x
].range
);
317 TLB::demapAll(int partition_id
)
320 DPRINTF(TLB
, "TLB: Demapping All pid=%#d\n", partition_id
);
322 for (x
= 0; x
< size
; x
++) {
323 if (!tlb
[x
].pte
.locked() && tlb
[x
].range
.partitionId
== partition_id
) {
324 if (tlb
[x
].valid
== true){
325 freeList
.push_front(&tlb
[x
]);
326 DPRINTF(TLB
, "Freeing TLB entry : %#X\n", &tlb
[x
]);
328 tlb
[x
].valid
= false;
333 lookupTable
.erase(tlb
[x
].range
);
346 for (x
= 0; x
< size
; x
++) {
347 if (tlb
[x
].valid
== true)
348 freeList
.push_back(&tlb
[x
]);
349 tlb
[x
].valid
= false;
356 TLB::TteRead(int entry
) {
358 panic("entry: %d\n", entry
);
360 assert(entry
< size
);
361 if (tlb
[entry
].valid
)
362 return tlb
[entry
].pte();
364 return (uint64_t)-1ll;
368 TLB::TagRead(int entry
) {
369 assert(entry
< size
);
371 if (!tlb
[entry
].valid
)
372 return (uint64_t)-1ll;
374 tag
= tlb
[entry
].range
.contextId
;
375 tag
|= tlb
[entry
].range
.va
;
376 tag
|= (uint64_t)tlb
[entry
].range
.partitionId
<< 61;
377 tag
|= tlb
[entry
].range
.real
? ULL(1) << 60 : 0;
378 tag
|= (uint64_t)~tlb
[entry
].pte
._size() << 56;
383 TLB::validVirtualAddress(Addr va
, bool am
)
387 if (va
>= StartVAddrHole
&& va
<= EndVAddrHole
)
393 TLB::writeSfsr(ThreadContext
*tc
, int reg
, bool write
, ContextType ct
,
394 bool se
, FaultTypes ft
, int asi
)
397 sfsr
= tc
->readMiscReg(reg
);
411 tc
->setMiscRegWithEffect(reg
, sfsr
);
415 TLB::writeTagAccess(ThreadContext
*tc
, int reg
, Addr va
, int context
)
417 tc
->setMiscRegWithEffect(reg
, mbits(va
, 63,13) | mbits(context
,12,0));
421 ITB::writeSfsr(ThreadContext
*tc
, bool write
, ContextType ct
,
422 bool se
, FaultTypes ft
, int asi
)
424 DPRINTF(TLB
, "TLB: ITB Fault: w=%d ct=%d ft=%d asi=%d\n",
425 (int)write
, ct
, ft
, asi
);
426 TLB::writeSfsr(tc
, MISCREG_MMU_ITLB_SFSR
, write
, ct
, se
, ft
, asi
);
430 ITB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
432 TLB::writeTagAccess(tc
, MISCREG_MMU_ITLB_TAG_ACCESS
, va
, context
);
436 DTB::writeSfr(ThreadContext
*tc
, Addr a
, bool write
, ContextType ct
,
437 bool se
, FaultTypes ft
, int asi
)
439 DPRINTF(TLB
, "TLB: DTB Fault: A=%#x w=%d ct=%d ft=%d asi=%d\n",
440 a
, (int)write
, ct
, ft
, asi
);
441 TLB::writeSfsr(tc
, MISCREG_MMU_DTLB_SFSR
, write
, ct
, se
, ft
, asi
);
442 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
, a
);
446 DTB::writeTagAccess(ThreadContext
*tc
, Addr va
, int context
)
448 TLB::writeTagAccess(tc
, MISCREG_MMU_DTLB_TAG_ACCESS
, va
, context
);
454 ITB::translate(RequestPtr
&req
, ThreadContext
*tc
)
456 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
458 Addr vaddr
= req
->getVaddr();
461 assert(req
->getAsi() == ASI_IMPLICIT
);
463 DPRINTF(TLB
, "TLB: ITB Request to translate va=%#x size=%d\n",
464 vaddr
, req
->getSize());
466 // Be fast if we can!
467 if (cacheValid
&& cacheState
== tlbdata
) {
469 if (cacheEntry
->range
.va
< vaddr
+ sizeof(MachInst
) &&
470 cacheEntry
->range
.va
+ cacheEntry
->range
.size
>= vaddr
) {
471 req
->setPaddr(cacheEntry
->pte
.paddr() & ~(cacheEntry
->pte
.size()-1) |
472 vaddr
& cacheEntry
->pte
.size()-1 );
476 req
->setPaddr(vaddr
& PAddrImplMask
);
481 bool hpriv
= bits(tlbdata
,0,0);
482 bool red
= bits(tlbdata
,1,1);
483 bool priv
= bits(tlbdata
,2,2);
484 bool addr_mask
= bits(tlbdata
,3,3);
485 bool lsu_im
= bits(tlbdata
,4,4);
487 int part_id
= bits(tlbdata
,15,8);
488 int tl
= bits(tlbdata
,18,16);
489 int pri_context
= bits(tlbdata
,47,32);
495 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsuim:%d part_id: %#X\n",
496 priv
, hpriv
, red
, lsu_im
, part_id
);
505 context
= pri_context
;
508 if ( hpriv
|| red
) {
510 cacheState
= tlbdata
;
512 req
->setPaddr(vaddr
& PAddrImplMask
);
516 // If the access is unaligned trap
518 writeSfsr(tc
, false, ct
, false, OtherFault
, asi
);
519 return new MemAddressNotAligned
;
523 vaddr
= vaddr
& VAddrAMask
;
525 if (!validVirtualAddress(vaddr
, addr_mask
)) {
526 writeSfsr(tc
, false, ct
, false, VaOutOfRange
, asi
);
527 return new InstructionAccessException
;
531 e
= lookup(vaddr
, part_id
, true);
535 e
= lookup(vaddr
, part_id
, false, context
);
538 if (e
== NULL
|| !e
->valid
) {
539 tc
->setMiscReg(MISCREG_MMU_ITLB_TAG_ACCESS
,
540 vaddr
& ~BytesInPageMask
| context
);
542 return new InstructionRealTranslationMiss
;
544 return new FastInstructionAccessMMUMiss
;
547 // were not priviledged accesing priv page
548 if (!priv
&& e
->pte
.priv()) {
549 writeSfsr(tc
, false, ct
, false, PrivViolation
, asi
);
550 return new InstructionAccessException
;
553 // cache translation date for next translation
555 cacheState
= tlbdata
;
558 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
559 vaddr
& e
->pte
.size()-1 );
560 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
567 DTB::translate(RequestPtr
&req
, ThreadContext
*tc
, bool write
)
569 /* @todo this could really use some profiling and fixing to make it faster! */
570 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
571 Addr vaddr
= req
->getVaddr();
572 Addr size
= req
->getSize();
574 asi
= (ASI
)req
->getAsi();
575 bool implicit
= false;
576 bool hpriv
= bits(tlbdata
,0,0);
578 DPRINTF(TLB
, "TLB: DTB Request to translate va=%#x size=%d asi=%#x\n",
581 if (asi
== ASI_IMPLICIT
)
584 if (hpriv
&& implicit
) {
585 req
->setPaddr(vaddr
& PAddrImplMask
);
589 // Be fast if we can!
590 if (cacheValid
&& cacheState
== tlbdata
) {
591 if (cacheEntry
[0] && cacheAsi
[0] == asi
&& cacheEntry
[0]->range
.va
< vaddr
+ size
&&
592 cacheEntry
[0]->range
.va
+ cacheEntry
[0]->range
.size
> vaddr
) {
593 req
->setPaddr(cacheEntry
[0]->pte
.paddr() & ~(cacheEntry
[0]->pte
.size()-1) |
594 vaddr
& cacheEntry
[0]->pte
.size()-1 );
597 if (cacheEntry
[1] && cacheAsi
[1] == asi
&& cacheEntry
[1]->range
.va
< vaddr
+ size
&&
598 cacheEntry
[1]->range
.va
+ cacheEntry
[1]->range
.size
> vaddr
) {
599 req
->setPaddr(cacheEntry
[1]->pte
.paddr() & ~(cacheEntry
[1]->pte
.size()-1) |
600 vaddr
& cacheEntry
[1]->pte
.size()-1 );
605 bool red
= bits(tlbdata
,1,1);
606 bool priv
= bits(tlbdata
,2,2);
607 bool addr_mask
= bits(tlbdata
,3,3);
608 bool lsu_dm
= bits(tlbdata
,5,5);
610 int part_id
= bits(tlbdata
,15,8);
611 int tl
= bits(tlbdata
,18,16);
612 int pri_context
= bits(tlbdata
,47,32);
613 int sec_context
= bits(tlbdata
,47,32);
616 ContextType ct
= Primary
;
621 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsudm:%d part_id: %#X\n",
622 priv
, hpriv
, red
, lsu_dm
, part_id
);
632 context
= pri_context
;
635 // We need to check for priv level/asi priv
636 if (!priv
&& !hpriv
&& !AsiIsUnPriv(asi
)) {
637 // It appears that context should be Nucleus in these cases?
638 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
639 return new PrivilegedAction
;
642 if (!hpriv
&& AsiIsHPriv(asi
)) {
643 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
644 return new DataAccessException
;
647 if (AsiIsPrimary(asi
)) {
648 context
= pri_context
;
650 } else if (AsiIsSecondary(asi
)) {
651 context
= sec_context
;
653 } else if (AsiIsNucleus(asi
)) {
658 context
= pri_context
;
663 if (AsiIsLittle(asi
))
664 panic("Little Endian ASIs not supported\n");
666 panic("Block ASIs not supported\n");
667 if (AsiIsNoFault(asi
))
668 panic("No Fault ASIs not supported\n");
670 // These twin ASIs are OK
671 if (asi
== ASI_P
|| asi
== ASI_LDTX_P
)
672 goto continueDtbFlow
;
673 if (!write
&& (asi
== ASI_QUAD_LDD
|| asi
== ASI_LDTX_REAL
))
674 goto continueDtbFlow
;
677 panic("Twin 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 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 tc
->setMiscReg(MISCREG_MMU_DTLB_TAG_ACCESS
,
726 vaddr
& ~BytesInPageMask
| context
);
727 DPRINTF(TLB
, "TLB: DTB Failed to find matching TLB entry\n");
729 return new DataRealTranslationMiss
;
731 return new FastDataAccessMMUMiss
;
736 if (write
&& !e
->pte
.writable()) {
737 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), OtherFault
, asi
);
738 return new FastDataAccessProtection
;
741 if (e
->pte
.nofault() && !AsiIsNoFault(asi
)) {
742 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), LoadFromNfo
, asi
);
743 return new DataAccessException
;
746 if (e
->pte
.sideffect())
747 req
->setFlags(req
->getFlags() | UNCACHEABLE
);
750 if (!priv
&& e
->pte
.priv()) {
751 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), PrivViolation
, asi
);
752 return new DataAccessException
;
755 // cache translation date for next translation
756 cacheState
= tlbdata
;
758 cacheEntry
[1] = NULL
;
759 cacheEntry
[0] = NULL
;
762 if (cacheEntry
[0] != e
&& cacheEntry
[1] != e
) {
763 cacheEntry
[1] = cacheEntry
[0];
765 cacheAsi
[1] = cacheAsi
[0];
768 cacheAsi
[0] = (ASI
)0;
771 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
772 vaddr
& e
->pte
.size()-1);
773 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
775 /** Normal flow ends here. */
777 handleScratchRegAccess
:
778 if (vaddr
> 0x38 || (vaddr
>= 0x20 && vaddr
< 0x30 && !hpriv
)) {
779 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
780 return new DataAccessException
;
784 handleQueueRegAccess
:
785 if (!priv
&& !hpriv
) {
786 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
787 return new PrivilegedAction
;
789 if (!hpriv
&& vaddr
& 0xF || vaddr
> 0x3f8 || vaddr
< 0x3c0) {
790 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
791 return new DataAccessException
;
795 handleSparcErrorRegAccess
:
798 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
799 return new DataAccessException
;
801 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
802 return new PrivilegedAction
;
810 DPRINTF(TLB
, "TLB: DTB Translating MM IPR access\n");
811 req
->setMmapedIpr(true);
812 req
->setPaddr(req
->getVaddr());
817 DTB::doMmuRegRead(ThreadContext
*tc
, Packet
*pkt
)
819 Addr va
= pkt
->getAddr();
820 ASI asi
= (ASI
)pkt
->req
->getAsi();
822 uint64_t tsbtemp
, cnftemp
;
824 DPRINTF(IPR
, "Memory Mapped IPR Read: asi=%#X a=%#x\n",
825 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr());
828 case ASI_LSU_CONTROL_REG
:
830 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
));
835 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
));
838 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
));
845 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
848 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
850 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
));
852 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
854 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
));
856 case ASI_DMMU_CTXT_ZERO_CONFIG
:
858 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
));
860 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
862 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
));
864 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
866 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
));
868 case ASI_IMMU_CTXT_ZERO_CONFIG
:
870 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
));
872 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
874 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
));
876 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
878 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
));
880 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
882 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
884 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
886 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
));
888 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
890 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
));
892 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
894 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
896 case ASI_SPARC_ERROR_STATUS_REG
:
897 warn("returning 0 for SPARC ERROR regsiter read\n");
898 pkt
->set((uint64_t)0);
900 case ASI_HYP_SCRATCHPAD
:
902 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3)));
907 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
908 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
911 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
));
914 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
));
923 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
924 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
927 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
));
930 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
));
933 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
));
936 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
));
942 case ASI_DMMU_TSB_PS0_PTR_REG
:
943 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
944 if (bits(temp
,12,0) == 0) {
945 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
);
946 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
);
948 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
);
949 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
);
951 data
= mbits(tsbtemp
,63,13);
952 data
|= temp
>> (9 + bits(cnftemp
,2,0) * 3) &
953 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
956 case ASI_DMMU_TSB_PS1_PTR_REG
:
957 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
958 if (bits(temp
,12,0) == 0) {
959 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
);
960 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
);
962 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
);
963 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
);
965 data
= mbits(tsbtemp
,63,13);
966 if (bits(tsbtemp
,12,12))
967 data
|= ULL(1) << (13+bits(tsbtemp
,3,0));
968 data
|= temp
>> (9 + bits(cnftemp
,10,8) * 3) &
969 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
972 case ASI_IMMU_TSB_PS0_PTR_REG
:
973 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
974 if (bits(temp
,12,0) == 0) {
975 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
);
976 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
);
978 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
);
979 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
);
981 data
= mbits(tsbtemp
,63,13);
982 data
|= temp
>> (9 + bits(cnftemp
,2,0) * 3) &
983 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
986 case ASI_IMMU_TSB_PS1_PTR_REG
:
987 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
988 if (bits(temp
,12,0) == 0) {
989 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
);
990 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
);
992 tsbtemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
);
993 cnftemp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
);
995 data
= mbits(tsbtemp
,63,13);
996 if (bits(tsbtemp
,12,12))
997 data
|= ULL(1) << (13+bits(tsbtemp
,3,0));
998 data
|= temp
>> (9 + bits(cnftemp
,10,8) * 3) &
999 mbits((uint64_t)-1ll,12+bits(tsbtemp
,3,0), 4);
1005 panic("need to impl DTB::doMmuRegRead() got asi=%#x, va=%#x\n",
1008 pkt
->result
= Packet::Success
;
1009 return tc
->getCpuPtr()->cycles(1);
1013 DTB::doMmuRegWrite(ThreadContext
*tc
, Packet
*pkt
)
1015 uint64_t data
= gtoh(pkt
->get
<uint64_t>());
1016 Addr va
= pkt
->getAddr();
1017 ASI asi
= (ASI
)pkt
->req
->getAsi();
1023 int entry_insert
= -1;
1030 DPRINTF(IPR
, "Memory Mapped IPR Write: asi=%#X a=%#x d=%#X\n",
1031 (uint32_t)asi
, va
, data
);
1034 case ASI_LSU_CONTROL_REG
:
1036 tc
->setMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
, data
);
1041 tc
->setMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
, data
);
1044 tc
->setMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
, data
);
1047 goto doMmuWriteError
;
1051 assert(mbits(data
,13,6) == data
);
1052 tc
->setMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
1053 (va
>> 4) - 0x3c, data
);
1055 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
1057 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
, data
);
1059 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
1061 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
, data
);
1063 case ASI_DMMU_CTXT_ZERO_CONFIG
:
1065 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
, data
);
1067 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
1069 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
, data
);
1071 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
1073 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
, data
);
1075 case ASI_IMMU_CTXT_ZERO_CONFIG
:
1077 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
, data
);
1079 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1081 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
, data
);
1083 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1085 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
, data
);
1087 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
1089 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
, data
);
1091 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1093 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
, data
);
1095 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1097 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
, data
);
1099 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
1101 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
, data
);
1103 case ASI_SPARC_ERROR_EN_REG
:
1104 case ASI_SPARC_ERROR_STATUS_REG
:
1105 warn("Ignoring write to SPARC ERROR regsiter\n");
1107 case ASI_HYP_SCRATCHPAD
:
1108 case ASI_SCRATCHPAD
:
1109 tc
->setMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3), data
);
1114 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
, data
);
1117 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
, data
);
1120 goto doMmuWriteError
;
1123 case ASI_ITLB_DATA_ACCESS_REG
:
1124 entry_insert
= bits(va
, 8,3);
1125 case ASI_ITLB_DATA_IN_REG
:
1126 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1127 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
1128 va_insert
= mbits(ta_insert
, 63,13);
1129 ct_insert
= mbits(ta_insert
, 12,0);
1130 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1131 real_insert
= bits(va
, 9,9);
1132 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1133 PageTableEntry::sun4u
);
1134 tc
->getITBPtr()->insert(va_insert
, part_insert
, ct_insert
, real_insert
,
1137 case ASI_DTLB_DATA_ACCESS_REG
:
1138 entry_insert
= bits(va
, 8,3);
1139 case ASI_DTLB_DATA_IN_REG
:
1140 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1141 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
1142 va_insert
= mbits(ta_insert
, 63,13);
1143 ct_insert
= mbits(ta_insert
, 12,0);
1144 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1145 real_insert
= bits(va
, 9,9);
1146 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1147 PageTableEntry::sun4u
);
1148 insert(va_insert
, part_insert
, ct_insert
, real_insert
, pte
, entry_insert
);
1150 case ASI_IMMU_DEMAP
:
1153 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1154 switch (bits(va
,5,4)) {
1156 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1168 switch(bits(va
,7,6)) {
1169 case 0: // demap page
1171 tc
->getITBPtr()->demapPage(mbits(va
,63,13), part_id
,
1172 bits(va
,9,9), ctx_id
);
1174 case 1: //demap context
1176 tc
->getITBPtr()->demapContext(part_id
, ctx_id
);
1179 tc
->getITBPtr()->demapAll(part_id
);
1182 panic("Invalid type for IMMU demap\n");
1188 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
, data
);
1191 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
, data
);
1194 tc
->setMiscRegWithEffect(MISCREG_MMU_PART_ID
, data
);
1197 goto doMmuWriteError
;
1200 case ASI_DMMU_DEMAP
:
1203 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1204 switch (bits(va
,5,4)) {
1206 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1209 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
);
1218 switch(bits(va
,7,6)) {
1219 case 0: // demap page
1221 demapPage(mbits(va
,63,13), part_id
, bits(va
,9,9), ctx_id
);
1223 case 1: //demap context
1225 demapContext(part_id
, ctx_id
);
1231 panic("Invalid type for IMMU demap\n");
1236 panic("need to impl DTB::doMmuRegWrite() got asi=%#x, va=%#x d=%#x\n",
1237 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr(), data
);
1239 pkt
->result
= Packet::Success
;
1240 return tc
->getCpuPtr()->cycles(1);
1244 TLB::serialize(std::ostream
&os
)
1246 panic("Need to implement serialize tlb for SPARC\n");
1250 TLB::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1252 panic("Need to implement unserialize tlb for SPARC\n");
1256 DEFINE_SIM_OBJECT_CLASS_NAME("SparcTLB", TLB
)
1258 BEGIN_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1262 END_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1264 BEGIN_INIT_SIM_OBJECT_PARAMS(ITB
)
1266 INIT_PARAM_DFLT(size
, "TLB size", 48)
1268 END_INIT_SIM_OBJECT_PARAMS(ITB
)
1271 CREATE_SIM_OBJECT(ITB
)
1273 return new ITB(getInstanceName(), size
);
1276 REGISTER_SIM_OBJECT("SparcITB", ITB
)
1278 BEGIN_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1282 END_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1284 BEGIN_INIT_SIM_OBJECT_PARAMS(DTB
)
1286 INIT_PARAM_DFLT(size
, "TLB size", 64)
1288 END_INIT_SIM_OBJECT_PARAMS(DTB
)
1291 CREATE_SIM_OBJECT(DTB
)
1293 return new DTB(getInstanceName(), size
);
1296 REGISTER_SIM_OBJECT("SparcDTB", DTB
)