tlb.cc revision 5245
14997Sgblack@eecs.umich.edu/*
24997Sgblack@eecs.umich.edu * Copyright (c) 2007 The Hewlett-Packard Development Company
34997Sgblack@eecs.umich.edu * All rights reserved.
44997Sgblack@eecs.umich.edu *
54997Sgblack@eecs.umich.edu * Redistribution and use of this software in source and binary forms,
64997Sgblack@eecs.umich.edu * with or without modification, are permitted provided that the
74997Sgblack@eecs.umich.edu * following conditions are met:
84997Sgblack@eecs.umich.edu *
94997Sgblack@eecs.umich.edu * The software must be used only for Non-Commercial Use which means any
104997Sgblack@eecs.umich.edu * use which is NOT directed to receiving any direct monetary
114997Sgblack@eecs.umich.edu * compensation for, or commercial advantage from such use.  Illustrative
124997Sgblack@eecs.umich.edu * examples of non-commercial use are academic research, personal study,
134997Sgblack@eecs.umich.edu * teaching, education and corporate research & development.
144997Sgblack@eecs.umich.edu * Illustrative examples of commercial use are distributing products for
154997Sgblack@eecs.umich.edu * commercial advantage and providing services using the software for
164997Sgblack@eecs.umich.edu * commercial advantage.
174997Sgblack@eecs.umich.edu *
184997Sgblack@eecs.umich.edu * If you wish to use this software or functionality therein that may be
194997Sgblack@eecs.umich.edu * covered by patents for commercial use, please contact:
204997Sgblack@eecs.umich.edu *     Director of Intellectual Property Licensing
214997Sgblack@eecs.umich.edu *     Office of Strategy and Technology
224997Sgblack@eecs.umich.edu *     Hewlett-Packard Company
234997Sgblack@eecs.umich.edu *     1501 Page Mill Road
244997Sgblack@eecs.umich.edu *     Palo Alto, California  94304
254997Sgblack@eecs.umich.edu *
264997Sgblack@eecs.umich.edu * Redistributions of source code must retain the above copyright notice,
274997Sgblack@eecs.umich.edu * this list of conditions and the following disclaimer.  Redistributions
284997Sgblack@eecs.umich.edu * in binary form must reproduce the above copyright notice, this list of
294997Sgblack@eecs.umich.edu * conditions and the following disclaimer in the documentation and/or
304997Sgblack@eecs.umich.edu * other materials provided with the distribution.  Neither the name of
314997Sgblack@eecs.umich.edu * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
324997Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
334997Sgblack@eecs.umich.edu * this software without specific prior written permission.  No right of
344997Sgblack@eecs.umich.edu * sublicense is granted herewith.  Derivatives of the software and
354997Sgblack@eecs.umich.edu * output created using the software may be prepared, but only for
364997Sgblack@eecs.umich.edu * Non-Commercial Uses.  Derivatives of the software may be shared with
374997Sgblack@eecs.umich.edu * others provided: (i) the others agree to abide by the list of
384997Sgblack@eecs.umich.edu * conditions herein which includes the Non-Commercial Use restrictions;
394997Sgblack@eecs.umich.edu * and (ii) such Derivatives of the software include the above copyright
404997Sgblack@eecs.umich.edu * notice to acknowledge the contribution from this software where
414997Sgblack@eecs.umich.edu * applicable, this list of conditions and the disclaimer below.
424997Sgblack@eecs.umich.edu *
434997Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
444997Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
454997Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
464997Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
474997Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
484997Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
494997Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
504997Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
514997Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
524997Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
534997Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
544997Sgblack@eecs.umich.edu *
554997Sgblack@eecs.umich.edu * Authors: Gabe Black
564997Sgblack@eecs.umich.edu */
574997Sgblack@eecs.umich.edu
584997Sgblack@eecs.umich.edu#include <cstring>
594997Sgblack@eecs.umich.edu
605086Sgblack@eecs.umich.edu#include "config/full_system.hh"
615086Sgblack@eecs.umich.edu
625124Sgblack@eecs.umich.edu#include "arch/x86/pagetable.hh"
635086Sgblack@eecs.umich.edu#include "arch/x86/tlb.hh"
645149Sgblack@eecs.umich.edu#include "arch/x86/x86_traits.hh"
655086Sgblack@eecs.umich.edu#include "base/bitfield.hh"
665086Sgblack@eecs.umich.edu#include "base/trace.hh"
675237Sgblack@eecs.umich.edu#include "config/full_system.hh"
685086Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
695086Sgblack@eecs.umich.edu#include "cpu/base.hh"
705086Sgblack@eecs.umich.edu#include "mem/packet_access.hh"
715086Sgblack@eecs.umich.edu#include "mem/request.hh"
725245Sgblack@eecs.umich.edu
735245Sgblack@eecs.umich.edu#if FULL_SYSTEM
745245Sgblack@eecs.umich.edu#include "arch/x86/pagetable_walker.hh"
755245Sgblack@eecs.umich.edu#endif
765086Sgblack@eecs.umich.edu
775086Sgblack@eecs.umich.edunamespace X86ISA {
785086Sgblack@eecs.umich.edu
795245Sgblack@eecs.umich.eduTLB::TLB(const Params *p) : SimObject(p), size(p->size)
805124Sgblack@eecs.umich.edu{
815124Sgblack@eecs.umich.edu    tlb = new TlbEntry[size];
825124Sgblack@eecs.umich.edu    std::memset(tlb, 0, sizeof(TlbEntry) * size);
835124Sgblack@eecs.umich.edu
845124Sgblack@eecs.umich.edu    for (int x = 0; x < size; x++)
855124Sgblack@eecs.umich.edu        freeList.push_back(&tlb[x]);
865124Sgblack@eecs.umich.edu
875237Sgblack@eecs.umich.edu#if FULL_SYSTEM
885245Sgblack@eecs.umich.edu    walker = p->walker;
895245Sgblack@eecs.umich.edu    walker->setTLB(this);
905245Sgblack@eecs.umich.edu#endif
915236Sgblack@eecs.umich.edu}
925236Sgblack@eecs.umich.edu
935236Sgblack@eecs.umich.eduvoid
945124Sgblack@eecs.umich.eduTLB::insert(Addr vpn, TlbEntry &entry)
955124Sgblack@eecs.umich.edu{
965124Sgblack@eecs.umich.edu    //TODO Deal with conflicting entries
975124Sgblack@eecs.umich.edu
985124Sgblack@eecs.umich.edu    TlbEntry *newEntry = NULL;
995124Sgblack@eecs.umich.edu    if (!freeList.empty()) {
1005124Sgblack@eecs.umich.edu        newEntry = freeList.front();
1015124Sgblack@eecs.umich.edu        freeList.pop_front();
1025124Sgblack@eecs.umich.edu    } else {
1035124Sgblack@eecs.umich.edu        newEntry = entryList.back();
1045124Sgblack@eecs.umich.edu        entryList.pop_back();
1055124Sgblack@eecs.umich.edu    }
1065124Sgblack@eecs.umich.edu    *newEntry = entry;
1075124Sgblack@eecs.umich.edu    newEntry->vaddr = vpn;
1085124Sgblack@eecs.umich.edu    entryList.push_front(newEntry);
1095124Sgblack@eecs.umich.edu}
1105124Sgblack@eecs.umich.edu
1115124Sgblack@eecs.umich.eduTlbEntry *
1125124Sgblack@eecs.umich.eduTLB::lookup(Addr va, bool update_lru)
1135124Sgblack@eecs.umich.edu{
1145124Sgblack@eecs.umich.edu    //TODO make this smarter at some point
1155124Sgblack@eecs.umich.edu    EntryList::iterator entry;
1165124Sgblack@eecs.umich.edu    for (entry = entryList.begin(); entry != entryList.end(); entry++) {
1175124Sgblack@eecs.umich.edu        if ((*entry)->vaddr <= va && (*entry)->vaddr + (*entry)->size > va) {
1185124Sgblack@eecs.umich.edu            DPRINTF(TLB, "Matched vaddr %#x to entry starting at %#x "
1195124Sgblack@eecs.umich.edu                    "with size %#x.\n", va, (*entry)->vaddr, (*entry)->size);
1205124Sgblack@eecs.umich.edu            TlbEntry *e = *entry;
1215124Sgblack@eecs.umich.edu            if (update_lru) {
1225124Sgblack@eecs.umich.edu                entryList.erase(entry);
1235124Sgblack@eecs.umich.edu                entryList.push_front(e);
1245124Sgblack@eecs.umich.edu            }
1255124Sgblack@eecs.umich.edu            return e;
1265124Sgblack@eecs.umich.edu        }
1275124Sgblack@eecs.umich.edu    }
1285124Sgblack@eecs.umich.edu    return NULL;
1295124Sgblack@eecs.umich.edu}
1305124Sgblack@eecs.umich.edu
1315245Sgblack@eecs.umich.edu#if FULL_SYSTEM
1325245Sgblack@eecs.umich.eduvoid
1335245Sgblack@eecs.umich.eduTLB::walk(ThreadContext * _tc, Addr vaddr)
1345245Sgblack@eecs.umich.edu{
1355245Sgblack@eecs.umich.edu    walker->start(_tc, vaddr);
1365245Sgblack@eecs.umich.edu}
1375245Sgblack@eecs.umich.edu#endif
1385245Sgblack@eecs.umich.edu
1395124Sgblack@eecs.umich.eduvoid
1405124Sgblack@eecs.umich.eduTLB::invalidateAll()
1415124Sgblack@eecs.umich.edu{
1425242Sgblack@eecs.umich.edu    DPRINTF(TLB, "Invalidating all entries.\n");
1435242Sgblack@eecs.umich.edu    while (!entryList.empty()) {
1445242Sgblack@eecs.umich.edu        TlbEntry *entry = entryList.front();
1455242Sgblack@eecs.umich.edu        entryList.pop_front();
1465242Sgblack@eecs.umich.edu        freeList.push_back(entry);
1475242Sgblack@eecs.umich.edu    }
1485124Sgblack@eecs.umich.edu}
1495124Sgblack@eecs.umich.edu
1505124Sgblack@eecs.umich.eduvoid
1515124Sgblack@eecs.umich.eduTLB::invalidateNonGlobal()
1525124Sgblack@eecs.umich.edu{
1535242Sgblack@eecs.umich.edu    DPRINTF(TLB, "Invalidating all non global entries.\n");
1545242Sgblack@eecs.umich.edu    EntryList::iterator entryIt;
1555242Sgblack@eecs.umich.edu    for (entryIt = entryList.begin(); entryIt != entryList.end();) {
1565242Sgblack@eecs.umich.edu        if (!(*entryIt)->global) {
1575242Sgblack@eecs.umich.edu            freeList.push_back(*entryIt);
1585242Sgblack@eecs.umich.edu            entryList.erase(entryIt++);
1595242Sgblack@eecs.umich.edu        } else {
1605242Sgblack@eecs.umich.edu            entryIt++;
1615242Sgblack@eecs.umich.edu        }
1625242Sgblack@eecs.umich.edu    }
1635124Sgblack@eecs.umich.edu}
1645124Sgblack@eecs.umich.edu
1655124Sgblack@eecs.umich.eduvoid
1665124Sgblack@eecs.umich.eduTLB::demapPage(Addr va)
1675086Sgblack@eecs.umich.edu{
1685086Sgblack@eecs.umich.edu}
1695086Sgblack@eecs.umich.edu
1705140Sgblack@eecs.umich.edutemplate<class TlbFault>
1715086Sgblack@eecs.umich.eduFault
1725140Sgblack@eecs.umich.eduTLB::translate(RequestPtr &req, ThreadContext *tc, bool write, bool execute)
1735086Sgblack@eecs.umich.edu{
1745124Sgblack@eecs.umich.edu    Addr vaddr = req->getVaddr();
1755140Sgblack@eecs.umich.edu    DPRINTF(TLB, "Translating vaddr %#x.\n", vaddr);
1765124Sgblack@eecs.umich.edu    uint32_t flags = req->getFlags();
1775124Sgblack@eecs.umich.edu    bool storeCheck = flags & StoreCheck;
1785140Sgblack@eecs.umich.edu
1795149Sgblack@eecs.umich.edu    int seg = flags & mask(3);
1805124Sgblack@eecs.umich.edu
1815124Sgblack@eecs.umich.edu    //XXX Junk code to surpress the warning
1825149Sgblack@eecs.umich.edu    if (storeCheck);
1835149Sgblack@eecs.umich.edu
1845149Sgblack@eecs.umich.edu    // If this is true, we're dealing with a request to read an internal
1855149Sgblack@eecs.umich.edu    // value.
1865232Sgblack@eecs.umich.edu    if (seg == SEGMENT_REG_INT) {
1875243Sgblack@eecs.umich.edu        DPRINTF(TLB, "Addresses references internal memory.\n");
1885149Sgblack@eecs.umich.edu        Addr prefix = vaddr & IntAddrPrefixMask;
1895149Sgblack@eecs.umich.edu        if (prefix == IntAddrPrefixCPUID) {
1905149Sgblack@eecs.umich.edu            panic("CPUID memory space not yet implemented!\n");
1915149Sgblack@eecs.umich.edu        } else if (prefix == IntAddrPrefixMSR) {
1925149Sgblack@eecs.umich.edu            req->setMmapedIpr(true);
1935149Sgblack@eecs.umich.edu            Addr regNum = 0;
1945149Sgblack@eecs.umich.edu            switch (vaddr & ~IntAddrPrefixMask) {
1955149Sgblack@eecs.umich.edu              case 0x10:
1965149Sgblack@eecs.umich.edu                regNum = MISCREG_TSC;
1975149Sgblack@eecs.umich.edu                break;
1985149Sgblack@eecs.umich.edu              case 0xFE:
1995149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRRCAP;
2005149Sgblack@eecs.umich.edu                break;
2015149Sgblack@eecs.umich.edu              case 0x174:
2025149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSENTER_CS;
2035149Sgblack@eecs.umich.edu                break;
2045149Sgblack@eecs.umich.edu              case 0x175:
2055149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSENTER_ESP;
2065149Sgblack@eecs.umich.edu                break;
2075149Sgblack@eecs.umich.edu              case 0x176:
2085149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSENTER_EIP;
2095149Sgblack@eecs.umich.edu                break;
2105149Sgblack@eecs.umich.edu              case 0x179:
2115149Sgblack@eecs.umich.edu                regNum = MISCREG_MCG_CAP;
2125149Sgblack@eecs.umich.edu                break;
2135149Sgblack@eecs.umich.edu              case 0x17A:
2145149Sgblack@eecs.umich.edu                regNum = MISCREG_MCG_STATUS;
2155149Sgblack@eecs.umich.edu                break;
2165149Sgblack@eecs.umich.edu              case 0x17B:
2175149Sgblack@eecs.umich.edu                regNum = MISCREG_MCG_CTL;
2185149Sgblack@eecs.umich.edu                break;
2195149Sgblack@eecs.umich.edu              case 0x1D9:
2205149Sgblack@eecs.umich.edu                regNum = MISCREG_DEBUG_CTL_MSR;
2215149Sgblack@eecs.umich.edu                break;
2225149Sgblack@eecs.umich.edu              case 0x1DB:
2235149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_BRANCH_FROM_IP;
2245149Sgblack@eecs.umich.edu                break;
2255149Sgblack@eecs.umich.edu              case 0x1DC:
2265149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_BRANCH_TO_IP;
2275149Sgblack@eecs.umich.edu                break;
2285149Sgblack@eecs.umich.edu              case 0x1DD:
2295149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_EXCEPTION_FROM_IP;
2305149Sgblack@eecs.umich.edu                break;
2315149Sgblack@eecs.umich.edu              case 0x1DE:
2325149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_EXCEPTION_TO_IP;
2335149Sgblack@eecs.umich.edu                break;
2345149Sgblack@eecs.umich.edu              case 0x200:
2355149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_0;
2365149Sgblack@eecs.umich.edu                break;
2375149Sgblack@eecs.umich.edu              case 0x201:
2385149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_0;
2395149Sgblack@eecs.umich.edu                break;
2405149Sgblack@eecs.umich.edu              case 0x202:
2415149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_1;
2425149Sgblack@eecs.umich.edu                break;
2435149Sgblack@eecs.umich.edu              case 0x203:
2445149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_1;
2455149Sgblack@eecs.umich.edu                break;
2465149Sgblack@eecs.umich.edu              case 0x204:
2475149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_2;
2485149Sgblack@eecs.umich.edu                break;
2495149Sgblack@eecs.umich.edu              case 0x205:
2505149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_2;
2515149Sgblack@eecs.umich.edu                break;
2525149Sgblack@eecs.umich.edu              case 0x206:
2535149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_3;
2545149Sgblack@eecs.umich.edu                break;
2555149Sgblack@eecs.umich.edu              case 0x207:
2565149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_3;
2575149Sgblack@eecs.umich.edu                break;
2585149Sgblack@eecs.umich.edu              case 0x208:
2595149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_4;
2605149Sgblack@eecs.umich.edu                break;
2615149Sgblack@eecs.umich.edu              case 0x209:
2625149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_4;
2635149Sgblack@eecs.umich.edu                break;
2645149Sgblack@eecs.umich.edu              case 0x20A:
2655149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_5;
2665149Sgblack@eecs.umich.edu                break;
2675149Sgblack@eecs.umich.edu              case 0x20B:
2685149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_5;
2695149Sgblack@eecs.umich.edu                break;
2705149Sgblack@eecs.umich.edu              case 0x20C:
2715149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_6;
2725149Sgblack@eecs.umich.edu                break;
2735149Sgblack@eecs.umich.edu              case 0x20D:
2745149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_6;
2755149Sgblack@eecs.umich.edu                break;
2765149Sgblack@eecs.umich.edu              case 0x20E:
2775149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_7;
2785149Sgblack@eecs.umich.edu                break;
2795149Sgblack@eecs.umich.edu              case 0x20F:
2805149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_7;
2815149Sgblack@eecs.umich.edu                break;
2825149Sgblack@eecs.umich.edu              case 0x250:
2835149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_64K_00000;
2845149Sgblack@eecs.umich.edu                break;
2855149Sgblack@eecs.umich.edu              case 0x258:
2865149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_16K_80000;
2875149Sgblack@eecs.umich.edu                break;
2885149Sgblack@eecs.umich.edu              case 0x259:
2895149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_16K_A0000;
2905149Sgblack@eecs.umich.edu                break;
2915149Sgblack@eecs.umich.edu              case 0x268:
2925149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_C0000;
2935149Sgblack@eecs.umich.edu                break;
2945149Sgblack@eecs.umich.edu              case 0x269:
2955149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_C8000;
2965149Sgblack@eecs.umich.edu                break;
2975149Sgblack@eecs.umich.edu              case 0x26A:
2985149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_D0000;
2995149Sgblack@eecs.umich.edu                break;
3005149Sgblack@eecs.umich.edu              case 0x26B:
3015149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_D8000;
3025149Sgblack@eecs.umich.edu                break;
3035149Sgblack@eecs.umich.edu              case 0x26C:
3045149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_E0000;
3055149Sgblack@eecs.umich.edu                break;
3065149Sgblack@eecs.umich.edu              case 0x26D:
3075149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_E8000;
3085149Sgblack@eecs.umich.edu                break;
3095149Sgblack@eecs.umich.edu              case 0x26E:
3105149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_F0000;
3115149Sgblack@eecs.umich.edu                break;
3125149Sgblack@eecs.umich.edu              case 0x26F:
3135149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_F8000;
3145149Sgblack@eecs.umich.edu                break;
3155149Sgblack@eecs.umich.edu              case 0x277:
3165149Sgblack@eecs.umich.edu                regNum = MISCREG_PAT;
3175149Sgblack@eecs.umich.edu                break;
3185149Sgblack@eecs.umich.edu              case 0x2FF:
3195149Sgblack@eecs.umich.edu                regNum = MISCREG_DEF_TYPE;
3205149Sgblack@eecs.umich.edu                break;
3215149Sgblack@eecs.umich.edu              case 0x400:
3225149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_CTL;
3235149Sgblack@eecs.umich.edu                break;
3245149Sgblack@eecs.umich.edu              case 0x404:
3255149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_CTL;
3265149Sgblack@eecs.umich.edu                break;
3275149Sgblack@eecs.umich.edu              case 0x408:
3285149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_CTL;
3295149Sgblack@eecs.umich.edu                break;
3305149Sgblack@eecs.umich.edu              case 0x40C:
3315149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_CTL;
3325149Sgblack@eecs.umich.edu                break;
3335149Sgblack@eecs.umich.edu              case 0x410:
3345149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_CTL;
3355149Sgblack@eecs.umich.edu                break;
3365149Sgblack@eecs.umich.edu              case 0x401:
3375149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_STATUS;
3385149Sgblack@eecs.umich.edu                break;
3395149Sgblack@eecs.umich.edu              case 0x405:
3405149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_STATUS;
3415149Sgblack@eecs.umich.edu                break;
3425149Sgblack@eecs.umich.edu              case 0x409:
3435149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_STATUS;
3445149Sgblack@eecs.umich.edu                break;
3455149Sgblack@eecs.umich.edu              case 0x40D:
3465149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_STATUS;
3475149Sgblack@eecs.umich.edu                break;
3485149Sgblack@eecs.umich.edu              case 0x411:
3495149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_STATUS;
3505149Sgblack@eecs.umich.edu                break;
3515149Sgblack@eecs.umich.edu              case 0x402:
3525149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_ADDR;
3535149Sgblack@eecs.umich.edu                break;
3545149Sgblack@eecs.umich.edu              case 0x406:
3555149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_ADDR;
3565149Sgblack@eecs.umich.edu                break;
3575149Sgblack@eecs.umich.edu              case 0x40A:
3585149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_ADDR;
3595149Sgblack@eecs.umich.edu                break;
3605149Sgblack@eecs.umich.edu              case 0x40E:
3615149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_ADDR;
3625149Sgblack@eecs.umich.edu                break;
3635149Sgblack@eecs.umich.edu              case 0x412:
3645149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_ADDR;
3655149Sgblack@eecs.umich.edu                break;
3665149Sgblack@eecs.umich.edu              case 0x403:
3675149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_MISC;
3685149Sgblack@eecs.umich.edu                break;
3695149Sgblack@eecs.umich.edu              case 0x407:
3705149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_MISC;
3715149Sgblack@eecs.umich.edu                break;
3725149Sgblack@eecs.umich.edu              case 0x40B:
3735149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_MISC;
3745149Sgblack@eecs.umich.edu                break;
3755149Sgblack@eecs.umich.edu              case 0x40F:
3765149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_MISC;
3775149Sgblack@eecs.umich.edu                break;
3785149Sgblack@eecs.umich.edu              case 0x413:
3795149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_MISC;
3805149Sgblack@eecs.umich.edu                break;
3815149Sgblack@eecs.umich.edu              case 0xC0000080:
3825149Sgblack@eecs.umich.edu                regNum = MISCREG_EFER;
3835149Sgblack@eecs.umich.edu                break;
3845149Sgblack@eecs.umich.edu              case 0xC0000081:
3855149Sgblack@eecs.umich.edu                regNum = MISCREG_STAR;
3865149Sgblack@eecs.umich.edu                break;
3875149Sgblack@eecs.umich.edu              case 0xC0000082:
3885149Sgblack@eecs.umich.edu                regNum = MISCREG_LSTAR;
3895149Sgblack@eecs.umich.edu                break;
3905149Sgblack@eecs.umich.edu              case 0xC0000083:
3915149Sgblack@eecs.umich.edu                regNum = MISCREG_CSTAR;
3925149Sgblack@eecs.umich.edu                break;
3935149Sgblack@eecs.umich.edu              case 0xC0000084:
3945149Sgblack@eecs.umich.edu                regNum = MISCREG_SF_MASK;
3955149Sgblack@eecs.umich.edu                break;
3965149Sgblack@eecs.umich.edu              case 0xC0000100:
3975149Sgblack@eecs.umich.edu                regNum = MISCREG_FS_BASE;
3985149Sgblack@eecs.umich.edu                break;
3995149Sgblack@eecs.umich.edu              case 0xC0000101:
4005149Sgblack@eecs.umich.edu                regNum = MISCREG_GS_BASE;
4015149Sgblack@eecs.umich.edu                break;
4025149Sgblack@eecs.umich.edu              case 0xC0000102:
4035149Sgblack@eecs.umich.edu                regNum = MISCREG_KERNEL_GS_BASE;
4045149Sgblack@eecs.umich.edu                break;
4055149Sgblack@eecs.umich.edu              case 0xC0000103:
4065149Sgblack@eecs.umich.edu                regNum = MISCREG_TSC_AUX;
4075149Sgblack@eecs.umich.edu                break;
4085149Sgblack@eecs.umich.edu              case 0xC0010000:
4095149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL0;
4105149Sgblack@eecs.umich.edu                break;
4115149Sgblack@eecs.umich.edu              case 0xC0010001:
4125149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL1;
4135149Sgblack@eecs.umich.edu                break;
4145149Sgblack@eecs.umich.edu              case 0xC0010002:
4155149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL2;
4165149Sgblack@eecs.umich.edu                break;
4175149Sgblack@eecs.umich.edu              case 0xC0010003:
4185149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL3;
4195149Sgblack@eecs.umich.edu                break;
4205149Sgblack@eecs.umich.edu              case 0xC0010004:
4215149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR0;
4225149Sgblack@eecs.umich.edu                break;
4235149Sgblack@eecs.umich.edu              case 0xC0010005:
4245149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR1;
4255149Sgblack@eecs.umich.edu                break;
4265149Sgblack@eecs.umich.edu              case 0xC0010006:
4275149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR2;
4285149Sgblack@eecs.umich.edu                break;
4295149Sgblack@eecs.umich.edu              case 0xC0010007:
4305149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR3;
4315149Sgblack@eecs.umich.edu                break;
4325149Sgblack@eecs.umich.edu              case 0xC0010010:
4335149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSCFG;
4345149Sgblack@eecs.umich.edu                break;
4355149Sgblack@eecs.umich.edu              case 0xC0010016:
4365149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_BASE0;
4375149Sgblack@eecs.umich.edu                break;
4385149Sgblack@eecs.umich.edu              case 0xC0010017:
4395149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_BASE1;
4405149Sgblack@eecs.umich.edu                break;
4415149Sgblack@eecs.umich.edu              case 0xC0010018:
4425149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_MASK0;
4435149Sgblack@eecs.umich.edu                break;
4445149Sgblack@eecs.umich.edu              case 0xC0010019:
4455149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_MASK1;
4465149Sgblack@eecs.umich.edu                break;
4475149Sgblack@eecs.umich.edu              case 0xC001001A:
4485149Sgblack@eecs.umich.edu                regNum = MISCREG_TOP_MEM;
4495149Sgblack@eecs.umich.edu                break;
4505149Sgblack@eecs.umich.edu              case 0xC001001D:
4515149Sgblack@eecs.umich.edu                regNum = MISCREG_TOP_MEM2;
4525149Sgblack@eecs.umich.edu                break;
4535149Sgblack@eecs.umich.edu              case 0xC0010114:
4545149Sgblack@eecs.umich.edu                regNum = MISCREG_VM_CR;
4555149Sgblack@eecs.umich.edu                break;
4565149Sgblack@eecs.umich.edu              case 0xC0010115:
4575149Sgblack@eecs.umich.edu                regNum = MISCREG_IGNNE;
4585149Sgblack@eecs.umich.edu                break;
4595149Sgblack@eecs.umich.edu              case 0xC0010116:
4605149Sgblack@eecs.umich.edu                regNum = MISCREG_SMM_CTL;
4615149Sgblack@eecs.umich.edu                break;
4625149Sgblack@eecs.umich.edu              case 0xC0010117:
4635149Sgblack@eecs.umich.edu                regNum = MISCREG_VM_HSAVE_PA;
4645149Sgblack@eecs.umich.edu                break;
4655149Sgblack@eecs.umich.edu              default:
4665149Sgblack@eecs.umich.edu                return new GeneralProtection(0);
4675149Sgblack@eecs.umich.edu            }
4685149Sgblack@eecs.umich.edu            //The index is multiplied by the size of a MiscReg so that
4695149Sgblack@eecs.umich.edu            //any memory dependence calculations will not see these as
4705149Sgblack@eecs.umich.edu            //overlapping.
4715149Sgblack@eecs.umich.edu            req->setPaddr(regNum * sizeof(MiscReg));
4725149Sgblack@eecs.umich.edu            return NoFault;
4735149Sgblack@eecs.umich.edu        } else {
4745149Sgblack@eecs.umich.edu            panic("Access to unrecognized internal address space %#x.\n",
4755149Sgblack@eecs.umich.edu                    prefix);
4765149Sgblack@eecs.umich.edu        }
4775149Sgblack@eecs.umich.edu    }
4785124Sgblack@eecs.umich.edu
4795140Sgblack@eecs.umich.edu    // Get cr0. This will tell us how to do translation. We'll assume it was
4805140Sgblack@eecs.umich.edu    // verified to be correct and consistent when set.
4815140Sgblack@eecs.umich.edu    CR0 cr0 = tc->readMiscRegNoEffect(MISCREG_CR0);
4825140Sgblack@eecs.umich.edu
4835140Sgblack@eecs.umich.edu    // If protected mode has been enabled...
4845140Sgblack@eecs.umich.edu    if (cr0.pe) {
4855237Sgblack@eecs.umich.edu        DPRINTF(TLB, "In protected mode.\n");
4865140Sgblack@eecs.umich.edu        Efer efer = tc->readMiscRegNoEffect(MISCREG_EFER);
4875140Sgblack@eecs.umich.edu        SegAttr csAttr = tc->readMiscRegNoEffect(MISCREG_CS_ATTR);
4885140Sgblack@eecs.umich.edu        // If we're not in 64-bit mode, do protection/limit checks
4895140Sgblack@eecs.umich.edu        if (!efer.lma || !csAttr.longMode) {
4905237Sgblack@eecs.umich.edu            DPRINTF(TLB, "Not in long mode. Checking segment protection.\n");
4915140Sgblack@eecs.umich.edu            SegAttr attr = tc->readMiscRegNoEffect(MISCREG_SEG_ATTR(seg));
4925140Sgblack@eecs.umich.edu            if (!attr.writable && write)
4935140Sgblack@eecs.umich.edu                return new GeneralProtection(0);
4945140Sgblack@eecs.umich.edu            if (!attr.readable && !write && !execute)
4955140Sgblack@eecs.umich.edu                return new GeneralProtection(0);
4965140Sgblack@eecs.umich.edu            Addr base = tc->readMiscRegNoEffect(MISCREG_SEG_BASE(seg));
4975140Sgblack@eecs.umich.edu            Addr limit = tc->readMiscRegNoEffect(MISCREG_SEG_LIMIT(seg));
4985140Sgblack@eecs.umich.edu            if (!attr.expandDown) {
4995237Sgblack@eecs.umich.edu                DPRINTF(TLB, "Checking an expand down segment.\n");
5005140Sgblack@eecs.umich.edu                // We don't have to worry about the access going around the
5015140Sgblack@eecs.umich.edu                // end of memory because accesses will be broken up into
5025140Sgblack@eecs.umich.edu                // pieces at boundaries aligned on sizes smaller than an
5035140Sgblack@eecs.umich.edu                // entire address space. We do have to worry about the limit
5045140Sgblack@eecs.umich.edu                // being less than the base.
5055140Sgblack@eecs.umich.edu                if (limit < base) {
5065140Sgblack@eecs.umich.edu                    if (limit < vaddr + req->getSize() && vaddr < base)
5075140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
5085140Sgblack@eecs.umich.edu                } else {
5095140Sgblack@eecs.umich.edu                    if (limit < vaddr + req->getSize())
5105140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
5115140Sgblack@eecs.umich.edu                }
5125140Sgblack@eecs.umich.edu            } else {
5135140Sgblack@eecs.umich.edu                if (limit < base) {
5145140Sgblack@eecs.umich.edu                    if (vaddr <= limit || vaddr + req->getSize() >= base)
5155140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
5165140Sgblack@eecs.umich.edu                } else {
5175140Sgblack@eecs.umich.edu                    if (vaddr <= limit && vaddr + req->getSize() >= base)
5185140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
5195140Sgblack@eecs.umich.edu                }
5205140Sgblack@eecs.umich.edu            }
5215140Sgblack@eecs.umich.edu        }
5225140Sgblack@eecs.umich.edu        // If paging is enabled, do the translation.
5235140Sgblack@eecs.umich.edu        if (cr0.pg) {
5245237Sgblack@eecs.umich.edu            DPRINTF(TLB, "Paging enabled.\n");
5255140Sgblack@eecs.umich.edu            // The vaddr already has the segment base applied.
5265140Sgblack@eecs.umich.edu            TlbEntry *entry = lookup(vaddr);
5275140Sgblack@eecs.umich.edu            if (!entry) {
5285140Sgblack@eecs.umich.edu                return new TlbFault(vaddr);
5295140Sgblack@eecs.umich.edu            } else {
5305140Sgblack@eecs.umich.edu                // Do paging protection checks.
5315237Sgblack@eecs.umich.edu                DPRINTF(TLB, "Entry found with paddr %#x, doing protection checks.\n", entry->paddr);
5325237Sgblack@eecs.umich.edu                Addr paddr = entry->paddr | (vaddr & (entry->size-1));
5335237Sgblack@eecs.umich.edu                DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, paddr);
5345140Sgblack@eecs.umich.edu                req->setPaddr(paddr);
5355140Sgblack@eecs.umich.edu            }
5365140Sgblack@eecs.umich.edu        } else {
5375140Sgblack@eecs.umich.edu            //Use the address which already has segmentation applied.
5385237Sgblack@eecs.umich.edu            DPRINTF(TLB, "Paging disabled.\n");
5395237Sgblack@eecs.umich.edu            DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, vaddr);
5405140Sgblack@eecs.umich.edu            req->setPaddr(vaddr);
5415140Sgblack@eecs.umich.edu        }
5425124Sgblack@eecs.umich.edu    } else {
5435140Sgblack@eecs.umich.edu        // Real mode
5445237Sgblack@eecs.umich.edu        DPRINTF(TLB, "In real mode.\n");
5455237Sgblack@eecs.umich.edu        DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, vaddr);
5465140Sgblack@eecs.umich.edu        req->setPaddr(vaddr);
5475124Sgblack@eecs.umich.edu    }
5485086Sgblack@eecs.umich.edu    return NoFault;
5495086Sgblack@eecs.umich.edu};
5505086Sgblack@eecs.umich.edu
5515140Sgblack@eecs.umich.eduFault
5525140Sgblack@eecs.umich.eduDTB::translate(RequestPtr &req, ThreadContext *tc, bool write)
5535140Sgblack@eecs.umich.edu{
5545140Sgblack@eecs.umich.edu    return TLB::translate<FakeDTLBFault>(req, tc, write, false);
5555140Sgblack@eecs.umich.edu}
5565140Sgblack@eecs.umich.edu
5575140Sgblack@eecs.umich.eduFault
5585140Sgblack@eecs.umich.eduITB::translate(RequestPtr &req, ThreadContext *tc)
5595140Sgblack@eecs.umich.edu{
5605140Sgblack@eecs.umich.edu    return TLB::translate<FakeITLBFault>(req, tc, false, true);
5615140Sgblack@eecs.umich.edu}
5625140Sgblack@eecs.umich.edu
5635086Sgblack@eecs.umich.edu#if FULL_SYSTEM
5645086Sgblack@eecs.umich.edu
5655086Sgblack@eecs.umich.eduTick
5665086Sgblack@eecs.umich.eduDTB::doMmuRegRead(ThreadContext *tc, Packet *pkt)
5675086Sgblack@eecs.umich.edu{
5685100Ssaidi@eecs.umich.edu    return tc->getCpuPtr()->ticks(1);
5695086Sgblack@eecs.umich.edu}
5705086Sgblack@eecs.umich.edu
5715086Sgblack@eecs.umich.eduTick
5725086Sgblack@eecs.umich.eduDTB::doMmuRegWrite(ThreadContext *tc, Packet *pkt)
5735086Sgblack@eecs.umich.edu{
5745100Ssaidi@eecs.umich.edu    return tc->getCpuPtr()->ticks(1);
5755086Sgblack@eecs.umich.edu}
5765086Sgblack@eecs.umich.edu
5775086Sgblack@eecs.umich.edu#endif
5785086Sgblack@eecs.umich.edu
5795086Sgblack@eecs.umich.eduvoid
5805086Sgblack@eecs.umich.eduTLB::serialize(std::ostream &os)
5815086Sgblack@eecs.umich.edu{
5825086Sgblack@eecs.umich.edu}
5835086Sgblack@eecs.umich.edu
5845086Sgblack@eecs.umich.eduvoid
5855086Sgblack@eecs.umich.eduTLB::unserialize(Checkpoint *cp, const std::string &section)
5865086Sgblack@eecs.umich.edu{
5875086Sgblack@eecs.umich.edu}
5885086Sgblack@eecs.umich.edu
5895086Sgblack@eecs.umich.eduvoid
5905086Sgblack@eecs.umich.eduDTB::serialize(std::ostream &os)
5915086Sgblack@eecs.umich.edu{
5925086Sgblack@eecs.umich.edu    TLB::serialize(os);
5935086Sgblack@eecs.umich.edu}
5945086Sgblack@eecs.umich.edu
5955086Sgblack@eecs.umich.eduvoid
5965086Sgblack@eecs.umich.eduDTB::unserialize(Checkpoint *cp, const std::string &section)
5975086Sgblack@eecs.umich.edu{
5985086Sgblack@eecs.umich.edu    TLB::unserialize(cp, section);
5995086Sgblack@eecs.umich.edu}
6005086Sgblack@eecs.umich.edu
6015086Sgblack@eecs.umich.edu/* end namespace X86ISA */ }
6025086Sgblack@eecs.umich.edu
6034997Sgblack@eecs.umich.eduX86ISA::ITB *
6044997Sgblack@eecs.umich.eduX86ITBParams::create()
6054997Sgblack@eecs.umich.edu{
6065038Sgblack@eecs.umich.edu    return new X86ISA::ITB(this);
6074997Sgblack@eecs.umich.edu}
6084997Sgblack@eecs.umich.edu
6094997Sgblack@eecs.umich.eduX86ISA::DTB *
6104997Sgblack@eecs.umich.eduX86DTBParams::create()
6114997Sgblack@eecs.umich.edu{
6125038Sgblack@eecs.umich.edu    return new X86ISA::DTB(this);
6134997Sgblack@eecs.umich.edu}
614