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
48 TLB::TLB(const std::string
&name
, int s
)
49 : SimObject(name
), size(s
), usedEntries(0), lastReplaced(0),
52 // To make this work you'll have to change the hypervisor and OS
54 fatal("SPARC T1 TLB registers don't support more than 64 TLB entries.");
56 tlb
= new TlbEntry
[size
];
57 std::memset(tlb
, 0, sizeof(TlbEntry
) * size
);
59 for (int x
= 0; x
< size
; x
++)
60 freeList
.push_back(&tlb
[x
]);
67 for (i
= lookupTable
.begin(); i
!= lookupTable
.end(); i
++) {
68 TlbEntry
*t
= i
->second
;
69 if (!t
->pte
.locked()) {
78 TLB::insert(Addr va
, int partition_id
, int context_id
, bool real
,
79 const PageTableEntry
& PTE
, int entry
)
84 TlbEntry
*new_entry
= NULL
;
89 va
&= ~(PTE
.size()-1);
91 tr.size = PTE.size() - 1;
92 tr.contextId = context_id;
93 tr.partitionId = partition_id;
97 DPRINTF(TLB
, "TLB: Inserting TLB Entry; va=%#x pa=%#x pid=%d cid=%d r=%d entryid=%d\n",
98 va
, PTE
.paddr(), partition_id
, context_id
, (int)real
, entry
);
100 // Demap any entry that conflicts
101 for (x
= 0; x
< size
; x
++) {
102 if (tlb
[x
].range
.real
== real
&&
103 tlb
[x
].range
.partitionId
== partition_id
&&
104 tlb
[x
].range
.va
< va
+ PTE
.size() - 1 &&
105 tlb
[x
].range
.va
+ tlb
[x
].range
.size
>= va
&&
106 (real
|| tlb
[x
].range
.contextId
== context_id
))
109 freeList
.push_front(&tlb
[x
]);
110 DPRINTF(TLB
, "TLB: Conflicting entry %#X , deleting it\n", x
);
112 tlb
[x
].valid
= false;
117 lookupTable
.erase(tlb
[x
].range
);
124 i = lookupTable.find(tr);
125 if (i != lookupTable.end()) {
126 i->second->valid = false;
127 if (i->second->used) {
128 i->second->used = false;
131 freeList.push_front(i->second);
132 DPRINTF(TLB, "TLB: Found conflicting entry %#X , deleting it\n",
134 lookupTable.erase(i);
139 assert(entry
< size
&& entry
>= 0);
140 new_entry
= &tlb
[entry
];
142 if (!freeList
.empty()) {
143 new_entry
= freeList
.front();
150 if (x
== lastReplaced
)
151 goto insertAllLocked
;
152 } while (tlb
[x
].pte
.locked());
157 for (x = 0; x < size; x++) {
158 if (!tlb[x].valid || !tlb[x].used) {
166 // Update the last ently if their all locked
168 new_entry
= &tlb
[size
-1];
171 freeList
.remove(new_entry
);
172 if (new_entry
->valid
&& new_entry
->used
)
174 if (new_entry
->valid
)
175 lookupTable
.erase(new_entry
->range
);
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
, bool
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(),
234 // Update the used bits only if this is a real access (not a fake one from
236 if (!t
->used
&& update_used
) {
239 if (usedEntries
== size
) {
253 for (int x
= 0; x
< size
; x
++) {
255 DPRINTFN("%4d: %#2x:%#2x %c %#4x %#8x %#8x %#16x\n",
256 x
, tlb
[x
].range
.partitionId
, tlb
[x
].range
.contextId
,
257 tlb
[x
].range
.real
? 'R' : ' ', tlb
[x
].range
.size
,
258 tlb
[x
].range
.va
, tlb
[x
].pte
.paddr(), tlb
[x
].pte());
264 TLB::demapPage(Addr va
, int partition_id
, bool real
, int context_id
)
269 DPRINTF(IPR
, "TLB: Demapping Page va=%#x pid=%#d cid=%d r=%d\n",
270 va
, partition_id
, context_id
, real
);
274 // Assemble full address structure
276 tr
.size
= MachineBytes
;
277 tr
.contextId
= context_id
;
278 tr
.partitionId
= partition_id
;
281 // Demap any entry that conflicts
282 i
= lookupTable
.find(tr
);
283 if (i
!= lookupTable
.end()) {
284 DPRINTF(IPR
, "TLB: Demapped page\n");
285 i
->second
->valid
= false;
286 if (i
->second
->used
) {
287 i
->second
->used
= false;
290 freeList
.push_front(i
->second
);
291 lookupTable
.erase(i
);
296 TLB::demapContext(int partition_id
, int context_id
)
299 DPRINTF(IPR
, "TLB: Demapping Context pid=%#d cid=%d\n",
300 partition_id
, context_id
);
302 for (x
= 0; x
< size
; x
++) {
303 if (tlb
[x
].range
.contextId
== context_id
&&
304 tlb
[x
].range
.partitionId
== partition_id
) {
305 if (tlb
[x
].valid
== true) {
306 freeList
.push_front(&tlb
[x
]);
308 tlb
[x
].valid
= false;
313 lookupTable
.erase(tlb
[x
].range
);
319 TLB::demapAll(int partition_id
)
322 DPRINTF(TLB
, "TLB: Demapping All pid=%#d\n", partition_id
);
324 for (x
= 0; x
< size
; x
++) {
325 if (!tlb
[x
].pte
.locked() && tlb
[x
].range
.partitionId
== partition_id
) {
326 if (tlb
[x
].valid
== true){
327 freeList
.push_front(&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 writeTagAccess(tc
, vaddr
, context
);
553 writeSfsr(tc
, false, ct
, false, PrivViolation
, asi
);
554 return new InstructionAccessException
;
557 // cache translation date for next translation
559 cacheState
= tlbdata
;
562 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
563 vaddr
& e
->pte
.size()-1 );
564 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
571 DTB::translate(RequestPtr
&req
, ThreadContext
*tc
, bool write
)
573 /* @todo this could really use some profiling and fixing to make it faster! */
574 uint64_t tlbdata
= tc
->readMiscReg(MISCREG_TLB_DATA
);
575 Addr vaddr
= req
->getVaddr();
576 Addr size
= req
->getSize();
578 asi
= (ASI
)req
->getAsi();
579 bool implicit
= false;
580 bool hpriv
= bits(tlbdata
,0,0);
582 DPRINTF(TLB
, "TLB: DTB Request to translate va=%#x size=%d asi=%#x\n",
585 if (lookupTable
.size() != 64 - freeList
.size())
586 panic("Lookup table size: %d tlb size: %d\n", lookupTable
.size(),
588 if (asi
== ASI_IMPLICIT
)
591 if (hpriv
&& implicit
) {
592 req
->setPaddr(vaddr
& PAddrImplMask
);
596 // Be fast if we can!
597 if (cacheValid
&& cacheState
== tlbdata
) {
602 TlbEntry
*ce
= cacheEntry
[0];
603 Addr ce_va
= ce
->range
.va
;
604 if (cacheAsi
[0] == asi
&&
605 ce_va
< vaddr
+ size
&& ce_va
+ ce
->range
.size
> vaddr
&&
606 (!write
|| ce
->pte
.writable())) {
607 req
->setPaddr(ce
->pte
.paddrMask() | vaddr
& ce
->pte
.sizeMask());
608 if (ce
->pte
.sideffect() || (ce
->pte
.paddr() >> 39) & 1)
609 req
->setFlags(req
->getFlags() | UNCACHEABLE
);
610 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
613 } // if cache entry valid
615 TlbEntry
*ce
= cacheEntry
[1];
616 Addr ce_va
= ce
->range
.va
;
617 if (cacheAsi
[1] == asi
&&
618 ce_va
< vaddr
+ size
&& ce_va
+ ce
->range
.size
> vaddr
&&
619 (!write
|| ce
->pte
.writable())) {
620 req
->setPaddr(ce
->pte
.paddrMask() | vaddr
& ce
->pte
.sizeMask());
621 if (ce
->pte
.sideffect() || (ce
->pte
.paddr() >> 39) & 1)
622 req
->setFlags(req
->getFlags() | UNCACHEABLE
);
623 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
626 } // if cache entry valid
629 bool red
= bits(tlbdata
,1,1);
630 bool priv
= bits(tlbdata
,2,2);
631 bool addr_mask
= bits(tlbdata
,3,3);
632 bool lsu_dm
= bits(tlbdata
,5,5);
634 int part_id
= bits(tlbdata
,15,8);
635 int tl
= bits(tlbdata
,18,16);
636 int pri_context
= bits(tlbdata
,47,32);
637 int sec_context
= bits(tlbdata
,63,48);
640 ContextType ct
= Primary
;
645 DPRINTF(TLB
, "TLB: priv:%d hpriv:%d red:%d lsudm:%d part_id: %#X\n",
646 priv
, hpriv
, red
, lsu_dm
, part_id
);
656 context
= pri_context
;
659 // We need to check for priv level/asi priv
660 if (!priv
&& !hpriv
&& !AsiIsUnPriv(asi
)) {
661 // It appears that context should be Nucleus in these cases?
662 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
663 return new PrivilegedAction
;
666 if (!hpriv
&& AsiIsHPriv(asi
)) {
667 writeSfr(tc
, vaddr
, write
, Nucleus
, false, IllegalAsi
, asi
);
668 return new DataAccessException
;
671 if (AsiIsPrimary(asi
)) {
672 context
= pri_context
;
674 } else if (AsiIsSecondary(asi
)) {
675 context
= sec_context
;
677 } else if (AsiIsNucleus(asi
)) {
682 context
= pri_context
;
686 if (!implicit
&& asi
!= ASI_P
&& asi
!= ASI_S
) {
687 if (AsiIsLittle(asi
))
688 panic("Little Endian ASIs not supported\n");
689 if (AsiIsNoFault(asi
))
690 panic("No Fault ASIs not supported\n");
692 if (AsiIsPartialStore(asi
))
693 panic("Partial Store ASIs not supported\n");
694 if (AsiIsInterrupt(asi
))
695 panic("Interrupt ASIs not supported\n");
698 goto handleMmuRegAccess
;
699 if (AsiIsScratchPad(asi
))
700 goto handleScratchRegAccess
;
702 goto handleQueueRegAccess
;
703 if (AsiIsSparcError(asi
))
704 goto handleSparcErrorRegAccess
;
706 if (!AsiIsReal(asi
) && !AsiIsNucleus(asi
) && !AsiIsAsIfUser(asi
) &&
707 !AsiIsTwin(asi
) && !AsiIsBlock(asi
))
708 panic("Accessing ASI %#X. Should we?\n", asi
);
711 // If the asi is unaligned trap
712 if (vaddr
& size
-1) {
713 writeSfr(tc
, vaddr
, false, ct
, false, OtherFault
, asi
);
714 return new MemAddressNotAligned
;
718 vaddr
= vaddr
& VAddrAMask
;
720 if (!validVirtualAddress(vaddr
, addr_mask
)) {
721 writeSfr(tc
, vaddr
, false, ct
, true, VaOutOfRange
, asi
);
722 return new DataAccessException
;
726 if ((!lsu_dm
&& !hpriv
&& !red
) || AsiIsReal(asi
)) {
731 if (hpriv
&& (implicit
|| (!AsiIsAsIfUser(asi
) && !AsiIsReal(asi
)))) {
732 req
->setPaddr(vaddr
& PAddrImplMask
);
736 e
= lookup(vaddr
, part_id
, real
, context
);
738 if (e
== NULL
|| !e
->valid
) {
739 writeTagAccess(tc
, vaddr
, context
);
740 DPRINTF(TLB
, "TLB: DTB Failed to find matching TLB entry\n");
742 return new DataRealTranslationMiss
;
744 return new FastDataAccessMMUMiss
;
748 if (!priv
&& e
->pte
.priv()) {
749 writeTagAccess(tc
, vaddr
, context
);
750 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), PrivViolation
, asi
);
751 return new DataAccessException
;
754 if (write
&& !e
->pte
.writable()) {
755 writeTagAccess(tc
, vaddr
, context
);
756 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), OtherFault
, asi
);
757 return new FastDataAccessProtection
;
760 if (e
->pte
.nofault() && !AsiIsNoFault(asi
)) {
761 writeTagAccess(tc
, vaddr
, context
);
762 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), LoadFromNfo
, asi
);
763 return new DataAccessException
;
766 if (e
->pte
.sideffect() && AsiIsNoFault(asi
)) {
767 writeTagAccess(tc
, vaddr
, context
);
768 writeSfr(tc
, vaddr
, write
, ct
, e
->pte
.sideffect(), SideEffect
, asi
);
769 return new DataAccessException
;
773 if (e
->pte
.sideffect() || (e
->pte
.paddr() >> 39) & 1)
774 req
->setFlags(req
->getFlags() | UNCACHEABLE
);
776 // cache translation date for next translation
777 cacheState
= tlbdata
;
779 cacheEntry
[1] = NULL
;
780 cacheEntry
[0] = NULL
;
783 if (cacheEntry
[0] != e
&& cacheEntry
[1] != e
) {
784 cacheEntry
[1] = cacheEntry
[0];
786 cacheAsi
[1] = cacheAsi
[0];
789 cacheAsi
[0] = (ASI
)0;
792 req
->setPaddr(e
->pte
.paddr() & ~(e
->pte
.size()-1) |
793 vaddr
& e
->pte
.size()-1);
794 DPRINTF(TLB
, "TLB: %#X -> %#X\n", vaddr
, req
->getPaddr());
796 /** Normal flow ends here. */
798 handleScratchRegAccess
:
799 if (vaddr
> 0x38 || (vaddr
>= 0x20 && vaddr
< 0x30 && !hpriv
)) {
800 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
801 return new DataAccessException
;
805 handleQueueRegAccess
:
806 if (!priv
&& !hpriv
) {
807 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
808 return new PrivilegedAction
;
810 if (!hpriv
&& vaddr
& 0xF || vaddr
> 0x3f8 || vaddr
< 0x3c0) {
811 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
812 return new DataAccessException
;
816 handleSparcErrorRegAccess
:
818 writeSfr(tc
, vaddr
, write
, Primary
, true, IllegalAsi
, asi
);
820 return new DataAccessException
;
822 return new PrivilegedAction
;
829 DPRINTF(TLB
, "TLB: DTB Translating MM IPR access\n");
830 req
->setMmapedIpr(true);
831 req
->setPaddr(req
->getVaddr());
836 DTB::doMmuRegRead(ThreadContext
*tc
, Packet
*pkt
)
838 Addr va
= pkt
->getAddr();
839 ASI asi
= (ASI
)pkt
->req
->getAsi();
842 DPRINTF(IPR
, "Memory Mapped IPR Read: asi=%#X a=%#x\n",
843 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr());
846 case ASI_LSU_CONTROL_REG
:
848 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
));
853 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
));
856 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
));
863 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
866 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
868 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
));
870 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
872 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
));
874 case ASI_DMMU_CTXT_ZERO_CONFIG
:
876 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
));
878 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
880 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
));
882 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
884 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
));
886 case ASI_IMMU_CTXT_ZERO_CONFIG
:
888 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
));
890 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
892 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
));
894 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
896 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
));
898 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
900 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
902 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
904 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
));
906 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
908 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
));
910 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
912 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
914 case ASI_SPARC_ERROR_STATUS_REG
:
915 pkt
->set((uint64_t)0);
917 case ASI_HYP_SCRATCHPAD
:
919 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3)));
924 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
);
925 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
928 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
));
931 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
));
940 temp
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
941 pkt
->set(bits(temp
,63,22) | bits(temp
,12,0) << 48);
944 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
));
947 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_SFAR
));
950 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
));
953 pkt
->set(tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
));
959 case ASI_DMMU_TSB_PS0_PTR_REG
:
960 pkt
->set(MakeTsbPtr(Ps0
,
961 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
),
962 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
),
963 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
964 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
),
965 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
)));
967 case ASI_DMMU_TSB_PS1_PTR_REG
:
968 pkt
->set(MakeTsbPtr(Ps1
,
969 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
),
970 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
),
971 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
972 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
),
973 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
)));
975 case ASI_IMMU_TSB_PS0_PTR_REG
:
976 pkt
->set(MakeTsbPtr(Ps0
,
977 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
),
978 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
),
979 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
980 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
),
981 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
)));
983 case ASI_IMMU_TSB_PS1_PTR_REG
:
984 pkt
->set(MakeTsbPtr(Ps1
,
985 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
),
986 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
),
987 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
988 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
),
989 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
)));
994 panic("need to impl DTB::doMmuRegRead() got asi=%#x, va=%#x\n",
997 pkt
->result
= Packet::Success
;
998 return tc
->getCpuPtr()->cycles(1);
1002 DTB::doMmuRegWrite(ThreadContext
*tc
, Packet
*pkt
)
1004 uint64_t data
= gtoh(pkt
->get
<uint64_t>());
1005 Addr va
= pkt
->getAddr();
1006 ASI asi
= (ASI
)pkt
->req
->getAsi();
1012 int entry_insert
= -1;
1019 DPRINTF(IPR
, "Memory Mapped IPR Write: asi=%#X a=%#x d=%#X\n",
1020 (uint32_t)asi
, va
, data
);
1023 case ASI_LSU_CONTROL_REG
:
1025 tc
->setMiscRegWithEffect(MISCREG_MMU_LSU_CTRL
, data
);
1030 tc
->setMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
, data
);
1033 tc
->setMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
, data
);
1036 goto doMmuWriteError
;
1040 assert(mbits(data
,13,6) == data
);
1041 tc
->setMiscRegWithEffect(MISCREG_QUEUE_CPU_MONDO_HEAD
+
1042 (va
>> 4) - 0x3c, data
);
1044 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS0
:
1046 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
, data
);
1048 case ASI_DMMU_CTXT_ZERO_TSB_BASE_PS1
:
1050 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
, data
);
1052 case ASI_DMMU_CTXT_ZERO_CONFIG
:
1054 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
, data
);
1056 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS0
:
1058 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
, data
);
1060 case ASI_IMMU_CTXT_ZERO_TSB_BASE_PS1
:
1062 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
, data
);
1064 case ASI_IMMU_CTXT_ZERO_CONFIG
:
1066 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
, data
);
1068 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1070 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
, data
);
1072 case ASI_DMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1074 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
, data
);
1076 case ASI_DMMU_CTXT_NONZERO_CONFIG
:
1078 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
, data
);
1080 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS0
:
1082 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
, data
);
1084 case ASI_IMMU_CTXT_NONZERO_TSB_BASE_PS1
:
1086 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
, data
);
1088 case ASI_IMMU_CTXT_NONZERO_CONFIG
:
1090 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
, data
);
1092 case ASI_SPARC_ERROR_EN_REG
:
1093 case ASI_SPARC_ERROR_STATUS_REG
:
1094 warn("Ignoring write to SPARC ERROR regsiter\n");
1096 case ASI_HYP_SCRATCHPAD
:
1097 case ASI_SCRATCHPAD
:
1098 tc
->setMiscRegWithEffect(MISCREG_SCRATCHPAD_R0
+ (va
>> 3), data
);
1103 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_SFSR
, data
);
1106 sext
<59>(bits(data
, 59,0));
1107 tc
->setMiscRegWithEffect(MISCREG_MMU_ITLB_TAG_ACCESS
, data
);
1110 goto doMmuWriteError
;
1113 case ASI_ITLB_DATA_ACCESS_REG
:
1114 entry_insert
= bits(va
, 8,3);
1115 case ASI_ITLB_DATA_IN_REG
:
1116 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1117 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_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 tc
->getITBPtr()->insert(va_insert
, part_insert
, ct_insert
, real_insert
,
1127 case ASI_DTLB_DATA_ACCESS_REG
:
1128 entry_insert
= bits(va
, 8,3);
1129 case ASI_DTLB_DATA_IN_REG
:
1130 assert(entry_insert
!= -1 || mbits(va
,10,9) == va
);
1131 ta_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
);
1132 va_insert
= mbits(ta_insert
, 63,13);
1133 ct_insert
= mbits(ta_insert
, 12,0);
1134 part_insert
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1135 real_insert
= bits(va
, 9,9);
1136 pte
.populate(data
, bits(va
,10,10) ? PageTableEntry::sun4v
:
1137 PageTableEntry::sun4u
);
1138 insert(va_insert
, part_insert
, ct_insert
, real_insert
, pte
, entry_insert
);
1140 case ASI_IMMU_DEMAP
:
1143 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1144 switch (bits(va
,5,4)) {
1146 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1158 switch(bits(va
,7,6)) {
1159 case 0: // demap page
1161 tc
->getITBPtr()->demapPage(mbits(va
,63,13), part_id
,
1162 bits(va
,9,9), ctx_id
);
1164 case 1: //demap context
1166 tc
->getITBPtr()->demapContext(part_id
, ctx_id
);
1169 tc
->getITBPtr()->demapAll(part_id
);
1172 panic("Invalid type for IMMU demap\n");
1178 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_SFSR
, data
);
1181 sext
<59>(bits(data
, 59,0));
1182 tc
->setMiscRegWithEffect(MISCREG_MMU_DTLB_TAG_ACCESS
, data
);
1185 tc
->setMiscRegWithEffect(MISCREG_MMU_PART_ID
, data
);
1188 goto doMmuWriteError
;
1191 case ASI_DMMU_DEMAP
:
1194 part_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_PART_ID
);
1195 switch (bits(va
,5,4)) {
1197 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_P_CONTEXT
);
1200 ctx_id
= tc
->readMiscRegWithEffect(MISCREG_MMU_S_CONTEXT
);
1209 switch(bits(va
,7,6)) {
1210 case 0: // demap page
1212 demapPage(mbits(va
,63,13), part_id
, bits(va
,9,9), ctx_id
);
1214 case 1: //demap context
1216 demapContext(part_id
, ctx_id
);
1222 panic("Invalid type for IMMU demap\n");
1227 panic("need to impl DTB::doMmuRegWrite() got asi=%#x, va=%#x d=%#x\n",
1228 (uint32_t)pkt
->req
->getAsi(), pkt
->getAddr(), data
);
1230 pkt
->result
= Packet::Success
;
1231 return tc
->getCpuPtr()->cycles(1);
1235 DTB::GetTsbPtr(ThreadContext
*tc
, Addr addr
, int ctx
, Addr
*ptrs
)
1237 uint64_t tag_access
= mbits(addr
,63,13) | mbits(ctx
,12,0);
1238 ptrs
[0] = MakeTsbPtr(Ps0
, tag_access
,
1239 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS0
),
1240 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
1241 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS0
),
1242 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
1243 ptrs
[1] = MakeTsbPtr(Ps1
, tag_access
,
1244 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_TSB_PS1
),
1245 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_C0_CONFIG
),
1246 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_TSB_PS1
),
1247 tc
->readMiscRegWithEffect(MISCREG_MMU_DTLB_CX_CONFIG
));
1248 ptrs
[2] = MakeTsbPtr(Ps0
, tag_access
,
1249 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS0
),
1250 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
1251 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS0
),
1252 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
1253 ptrs
[3] = MakeTsbPtr(Ps1
, tag_access
,
1254 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_TSB_PS1
),
1255 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_C0_CONFIG
),
1256 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_TSB_PS1
),
1257 tc
->readMiscRegWithEffect(MISCREG_MMU_ITLB_CX_CONFIG
));
1265 DTB::MakeTsbPtr(TsbPageSize ps
, uint64_t tag_access
, uint64_t c0_tsb
,
1266 uint64_t c0_config
, uint64_t cX_tsb
, uint64_t cX_config
)
1271 if (bits(tag_access
, 12,0) == 0) {
1279 uint64_t ptr
= mbits(tsb
,63,13);
1280 bool split
= bits(tsb
,12,12);
1281 int tsb_size
= bits(tsb
,3,0);
1282 int page_size
= (ps
== Ps0
) ? bits(config
, 2,0) : bits(config
,10,8);
1284 if (ps
== Ps1
&& split
)
1285 ptr
|= ULL(1) << (13 + tsb_size
);
1286 ptr
|= (tag_access
>> (9 + page_size
* 3)) & mask(12+tsb_size
, 4);
1293 TLB::serialize(std::ostream
&os
)
1295 SERIALIZE_SCALAR(size
);
1296 SERIALIZE_SCALAR(usedEntries
);
1297 SERIALIZE_SCALAR(lastReplaced
);
1299 // convert the pointer based free list into an index based one
1300 int *free_list
= (int*)malloc(sizeof(int) * size
);
1302 std::list
<TlbEntry
*>::iterator i
;
1303 i
= freeList
.begin();
1304 while (i
!= freeList
.end()) {
1305 free_list
[cntr
++] = ((size_t)*i
- (size_t)tlb
)/ sizeof(TlbEntry
);
1308 SERIALIZE_SCALAR(cntr
);
1309 SERIALIZE_ARRAY(free_list
, cntr
);
1311 for (int x
= 0; x
< size
; x
++) {
1312 nameOut(os
, csprintf("%s.PTE%d", name(), x
));
1313 tlb
[x
].serialize(os
);
1318 TLB::unserialize(Checkpoint
*cp
, const std::string
§ion
)
1322 paramIn(cp
, section
, "size", oldSize
);
1323 if (oldSize
!= size
)
1324 panic("Don't support unserializing different sized TLBs\n");
1325 UNSERIALIZE_SCALAR(usedEntries
);
1326 UNSERIALIZE_SCALAR(lastReplaced
);
1329 UNSERIALIZE_SCALAR(cntr
);
1331 int *free_list
= (int*)malloc(sizeof(int) * cntr
);
1333 UNSERIALIZE_ARRAY(free_list
, cntr
);
1334 for (int x
= 0; x
< cntr
; x
++)
1335 freeList
.push_back(&tlb
[free_list
[x
]]);
1337 lookupTable
.clear();
1338 for (int x
= 0; x
< size
; x
++) {
1339 tlb
[x
].unserialize(cp
, csprintf("%s.PTE%d", section
, x
));
1341 lookupTable
.insert(tlb
[x
].range
, &tlb
[x
]);
1346 /* end namespace SparcISA */ }
1348 using namespace SparcISA
;
1350 DEFINE_SIM_OBJECT_CLASS_NAME("SparcTLB", TLB
)
1352 BEGIN_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1356 END_DECLARE_SIM_OBJECT_PARAMS(ITB
)
1358 BEGIN_INIT_SIM_OBJECT_PARAMS(ITB
)
1360 INIT_PARAM_DFLT(size
, "TLB size", 48)
1362 END_INIT_SIM_OBJECT_PARAMS(ITB
)
1365 CREATE_SIM_OBJECT(ITB
)
1367 return new ITB(getInstanceName(), size
);
1370 REGISTER_SIM_OBJECT("SparcITB", ITB
)
1372 BEGIN_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1376 END_DECLARE_SIM_OBJECT_PARAMS(DTB
)
1378 BEGIN_INIT_SIM_OBJECT_PARAMS(DTB
)
1380 INIT_PARAM_DFLT(size
, "TLB size", 64)
1382 END_INIT_SIM_OBJECT_PARAMS(DTB
)
1385 CREATE_SIM_OBJECT(DTB
)
1387 return new DTB(getInstanceName(), size
);
1390 REGISTER_SIM_OBJECT("SparcDTB", DTB
)