tlb.cc revision 5149
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"
675086Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
685086Sgblack@eecs.umich.edu#include "cpu/base.hh"
695086Sgblack@eecs.umich.edu#include "mem/packet_access.hh"
705086Sgblack@eecs.umich.edu#include "mem/request.hh"
715086Sgblack@eecs.umich.edu#include "sim/system.hh"
725086Sgblack@eecs.umich.edu
735086Sgblack@eecs.umich.edunamespace X86ISA {
745086Sgblack@eecs.umich.edu
755124Sgblack@eecs.umich.eduTLB::TLB(const Params *p) : SimObject(p), size(p->size)
765124Sgblack@eecs.umich.edu{
775124Sgblack@eecs.umich.edu    tlb = new TlbEntry[size];
785124Sgblack@eecs.umich.edu    std::memset(tlb, 0, sizeof(TlbEntry) * size);
795124Sgblack@eecs.umich.edu
805124Sgblack@eecs.umich.edu    for (int x = 0; x < size; x++)
815124Sgblack@eecs.umich.edu        freeList.push_back(&tlb[x]);
825124Sgblack@eecs.umich.edu}
835124Sgblack@eecs.umich.edu
845124Sgblack@eecs.umich.eduvoid
855124Sgblack@eecs.umich.eduTLB::insert(Addr vpn, TlbEntry &entry)
865124Sgblack@eecs.umich.edu{
875124Sgblack@eecs.umich.edu    //TODO Deal with conflicting entries
885124Sgblack@eecs.umich.edu
895124Sgblack@eecs.umich.edu    TlbEntry *newEntry = NULL;
905124Sgblack@eecs.umich.edu    if (!freeList.empty()) {
915124Sgblack@eecs.umich.edu        newEntry = freeList.front();
925124Sgblack@eecs.umich.edu        freeList.pop_front();
935124Sgblack@eecs.umich.edu    } else {
945124Sgblack@eecs.umich.edu        newEntry = entryList.back();
955124Sgblack@eecs.umich.edu        entryList.pop_back();
965124Sgblack@eecs.umich.edu    }
975124Sgblack@eecs.umich.edu    *newEntry = entry;
985124Sgblack@eecs.umich.edu    newEntry->vaddr = vpn;
995124Sgblack@eecs.umich.edu    entryList.push_front(newEntry);
1005124Sgblack@eecs.umich.edu}
1015124Sgblack@eecs.umich.edu
1025124Sgblack@eecs.umich.eduTlbEntry *
1035124Sgblack@eecs.umich.eduTLB::lookup(Addr va, bool update_lru)
1045124Sgblack@eecs.umich.edu{
1055124Sgblack@eecs.umich.edu    //TODO make this smarter at some point
1065124Sgblack@eecs.umich.edu    EntryList::iterator entry;
1075124Sgblack@eecs.umich.edu    for (entry = entryList.begin(); entry != entryList.end(); entry++) {
1085124Sgblack@eecs.umich.edu        if ((*entry)->vaddr <= va && (*entry)->vaddr + (*entry)->size > va) {
1095124Sgblack@eecs.umich.edu            DPRINTF(TLB, "Matched vaddr %#x to entry starting at %#x "
1105124Sgblack@eecs.umich.edu                    "with size %#x.\n", va, (*entry)->vaddr, (*entry)->size);
1115124Sgblack@eecs.umich.edu            TlbEntry *e = *entry;
1125124Sgblack@eecs.umich.edu            if (update_lru) {
1135124Sgblack@eecs.umich.edu                entryList.erase(entry);
1145124Sgblack@eecs.umich.edu                entryList.push_front(e);
1155124Sgblack@eecs.umich.edu            }
1165124Sgblack@eecs.umich.edu            return e;
1175124Sgblack@eecs.umich.edu        }
1185124Sgblack@eecs.umich.edu    }
1195124Sgblack@eecs.umich.edu    return NULL;
1205124Sgblack@eecs.umich.edu}
1215124Sgblack@eecs.umich.edu
1225124Sgblack@eecs.umich.eduvoid
1235124Sgblack@eecs.umich.eduTLB::invalidateAll()
1245124Sgblack@eecs.umich.edu{
1255124Sgblack@eecs.umich.edu}
1265124Sgblack@eecs.umich.edu
1275124Sgblack@eecs.umich.eduvoid
1285124Sgblack@eecs.umich.eduTLB::invalidateNonGlobal()
1295124Sgblack@eecs.umich.edu{
1305124Sgblack@eecs.umich.edu}
1315124Sgblack@eecs.umich.edu
1325124Sgblack@eecs.umich.eduvoid
1335124Sgblack@eecs.umich.eduTLB::demapPage(Addr va)
1345086Sgblack@eecs.umich.edu{
1355086Sgblack@eecs.umich.edu}
1365086Sgblack@eecs.umich.edu
1375140Sgblack@eecs.umich.edutemplate<class TlbFault>
1385086Sgblack@eecs.umich.eduFault
1395140Sgblack@eecs.umich.eduTLB::translate(RequestPtr &req, ThreadContext *tc, bool write, bool execute)
1405086Sgblack@eecs.umich.edu{
1415124Sgblack@eecs.umich.edu    Addr vaddr = req->getVaddr();
1425140Sgblack@eecs.umich.edu    DPRINTF(TLB, "Translating vaddr %#x.\n", vaddr);
1435124Sgblack@eecs.umich.edu    uint32_t flags = req->getFlags();
1445124Sgblack@eecs.umich.edu    bool storeCheck = flags & StoreCheck;
1455140Sgblack@eecs.umich.edu
1465149Sgblack@eecs.umich.edu    int seg = flags & mask(3);
1475124Sgblack@eecs.umich.edu
1485124Sgblack@eecs.umich.edu    //XXX Junk code to surpress the warning
1495149Sgblack@eecs.umich.edu    if (storeCheck);
1505149Sgblack@eecs.umich.edu
1515149Sgblack@eecs.umich.edu    // If this is true, we're dealing with a request to read an internal
1525149Sgblack@eecs.umich.edu    // value.
1535149Sgblack@eecs.umich.edu    if (seg == NUM_SEGMENTREGS) {
1545149Sgblack@eecs.umich.edu        Addr prefix = vaddr & IntAddrPrefixMask;
1555149Sgblack@eecs.umich.edu        if (prefix == IntAddrPrefixCPUID) {
1565149Sgblack@eecs.umich.edu            panic("CPUID memory space not yet implemented!\n");
1575149Sgblack@eecs.umich.edu        } else if (prefix == IntAddrPrefixMSR) {
1585149Sgblack@eecs.umich.edu            req->setMmapedIpr(true);
1595149Sgblack@eecs.umich.edu            Addr regNum = 0;
1605149Sgblack@eecs.umich.edu            switch (vaddr & ~IntAddrPrefixMask) {
1615149Sgblack@eecs.umich.edu              case 0x10:
1625149Sgblack@eecs.umich.edu                regNum = MISCREG_TSC;
1635149Sgblack@eecs.umich.edu                break;
1645149Sgblack@eecs.umich.edu              case 0xFE:
1655149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRRCAP;
1665149Sgblack@eecs.umich.edu                break;
1675149Sgblack@eecs.umich.edu              case 0x174:
1685149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSENTER_CS;
1695149Sgblack@eecs.umich.edu                break;
1705149Sgblack@eecs.umich.edu              case 0x175:
1715149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSENTER_ESP;
1725149Sgblack@eecs.umich.edu                break;
1735149Sgblack@eecs.umich.edu              case 0x176:
1745149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSENTER_EIP;
1755149Sgblack@eecs.umich.edu                break;
1765149Sgblack@eecs.umich.edu              case 0x179:
1775149Sgblack@eecs.umich.edu                regNum = MISCREG_MCG_CAP;
1785149Sgblack@eecs.umich.edu                break;
1795149Sgblack@eecs.umich.edu              case 0x17A:
1805149Sgblack@eecs.umich.edu                regNum = MISCREG_MCG_STATUS;
1815149Sgblack@eecs.umich.edu                break;
1825149Sgblack@eecs.umich.edu              case 0x17B:
1835149Sgblack@eecs.umich.edu                regNum = MISCREG_MCG_CTL;
1845149Sgblack@eecs.umich.edu                break;
1855149Sgblack@eecs.umich.edu              case 0x1D9:
1865149Sgblack@eecs.umich.edu                regNum = MISCREG_DEBUG_CTL_MSR;
1875149Sgblack@eecs.umich.edu                break;
1885149Sgblack@eecs.umich.edu              case 0x1DB:
1895149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_BRANCH_FROM_IP;
1905149Sgblack@eecs.umich.edu                break;
1915149Sgblack@eecs.umich.edu              case 0x1DC:
1925149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_BRANCH_TO_IP;
1935149Sgblack@eecs.umich.edu                break;
1945149Sgblack@eecs.umich.edu              case 0x1DD:
1955149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_EXCEPTION_FROM_IP;
1965149Sgblack@eecs.umich.edu                break;
1975149Sgblack@eecs.umich.edu              case 0x1DE:
1985149Sgblack@eecs.umich.edu                regNum = MISCREG_LAST_EXCEPTION_TO_IP;
1995149Sgblack@eecs.umich.edu                break;
2005149Sgblack@eecs.umich.edu              case 0x200:
2015149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_0;
2025149Sgblack@eecs.umich.edu                break;
2035149Sgblack@eecs.umich.edu              case 0x201:
2045149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_0;
2055149Sgblack@eecs.umich.edu                break;
2065149Sgblack@eecs.umich.edu              case 0x202:
2075149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_1;
2085149Sgblack@eecs.umich.edu                break;
2095149Sgblack@eecs.umich.edu              case 0x203:
2105149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_1;
2115149Sgblack@eecs.umich.edu                break;
2125149Sgblack@eecs.umich.edu              case 0x204:
2135149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_2;
2145149Sgblack@eecs.umich.edu                break;
2155149Sgblack@eecs.umich.edu              case 0x205:
2165149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_2;
2175149Sgblack@eecs.umich.edu                break;
2185149Sgblack@eecs.umich.edu              case 0x206:
2195149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_3;
2205149Sgblack@eecs.umich.edu                break;
2215149Sgblack@eecs.umich.edu              case 0x207:
2225149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_3;
2235149Sgblack@eecs.umich.edu                break;
2245149Sgblack@eecs.umich.edu              case 0x208:
2255149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_4;
2265149Sgblack@eecs.umich.edu                break;
2275149Sgblack@eecs.umich.edu              case 0x209:
2285149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_4;
2295149Sgblack@eecs.umich.edu                break;
2305149Sgblack@eecs.umich.edu              case 0x20A:
2315149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_5;
2325149Sgblack@eecs.umich.edu                break;
2335149Sgblack@eecs.umich.edu              case 0x20B:
2345149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_5;
2355149Sgblack@eecs.umich.edu                break;
2365149Sgblack@eecs.umich.edu              case 0x20C:
2375149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_6;
2385149Sgblack@eecs.umich.edu                break;
2395149Sgblack@eecs.umich.edu              case 0x20D:
2405149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_6;
2415149Sgblack@eecs.umich.edu                break;
2425149Sgblack@eecs.umich.edu              case 0x20E:
2435149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_BASE_7;
2445149Sgblack@eecs.umich.edu                break;
2455149Sgblack@eecs.umich.edu              case 0x20F:
2465149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_PHYS_MASK_7;
2475149Sgblack@eecs.umich.edu                break;
2485149Sgblack@eecs.umich.edu              case 0x250:
2495149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_64K_00000;
2505149Sgblack@eecs.umich.edu                break;
2515149Sgblack@eecs.umich.edu              case 0x258:
2525149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_16K_80000;
2535149Sgblack@eecs.umich.edu                break;
2545149Sgblack@eecs.umich.edu              case 0x259:
2555149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_16K_A0000;
2565149Sgblack@eecs.umich.edu                break;
2575149Sgblack@eecs.umich.edu              case 0x268:
2585149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_C0000;
2595149Sgblack@eecs.umich.edu                break;
2605149Sgblack@eecs.umich.edu              case 0x269:
2615149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_C8000;
2625149Sgblack@eecs.umich.edu                break;
2635149Sgblack@eecs.umich.edu              case 0x26A:
2645149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_D0000;
2655149Sgblack@eecs.umich.edu                break;
2665149Sgblack@eecs.umich.edu              case 0x26B:
2675149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_D8000;
2685149Sgblack@eecs.umich.edu                break;
2695149Sgblack@eecs.umich.edu              case 0x26C:
2705149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_E0000;
2715149Sgblack@eecs.umich.edu                break;
2725149Sgblack@eecs.umich.edu              case 0x26D:
2735149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_E8000;
2745149Sgblack@eecs.umich.edu                break;
2755149Sgblack@eecs.umich.edu              case 0x26E:
2765149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_F0000;
2775149Sgblack@eecs.umich.edu                break;
2785149Sgblack@eecs.umich.edu              case 0x26F:
2795149Sgblack@eecs.umich.edu                regNum = MISCREG_MTRR_FIX_4K_F8000;
2805149Sgblack@eecs.umich.edu                break;
2815149Sgblack@eecs.umich.edu              case 0x277:
2825149Sgblack@eecs.umich.edu                regNum = MISCREG_PAT;
2835149Sgblack@eecs.umich.edu                break;
2845149Sgblack@eecs.umich.edu              case 0x2FF:
2855149Sgblack@eecs.umich.edu                regNum = MISCREG_DEF_TYPE;
2865149Sgblack@eecs.umich.edu                break;
2875149Sgblack@eecs.umich.edu              case 0x400:
2885149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_CTL;
2895149Sgblack@eecs.umich.edu                break;
2905149Sgblack@eecs.umich.edu              case 0x404:
2915149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_CTL;
2925149Sgblack@eecs.umich.edu                break;
2935149Sgblack@eecs.umich.edu              case 0x408:
2945149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_CTL;
2955149Sgblack@eecs.umich.edu                break;
2965149Sgblack@eecs.umich.edu              case 0x40C:
2975149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_CTL;
2985149Sgblack@eecs.umich.edu                break;
2995149Sgblack@eecs.umich.edu              case 0x410:
3005149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_CTL;
3015149Sgblack@eecs.umich.edu                break;
3025149Sgblack@eecs.umich.edu              case 0x401:
3035149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_STATUS;
3045149Sgblack@eecs.umich.edu                break;
3055149Sgblack@eecs.umich.edu              case 0x405:
3065149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_STATUS;
3075149Sgblack@eecs.umich.edu                break;
3085149Sgblack@eecs.umich.edu              case 0x409:
3095149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_STATUS;
3105149Sgblack@eecs.umich.edu                break;
3115149Sgblack@eecs.umich.edu              case 0x40D:
3125149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_STATUS;
3135149Sgblack@eecs.umich.edu                break;
3145149Sgblack@eecs.umich.edu              case 0x411:
3155149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_STATUS;
3165149Sgblack@eecs.umich.edu                break;
3175149Sgblack@eecs.umich.edu              case 0x402:
3185149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_ADDR;
3195149Sgblack@eecs.umich.edu                break;
3205149Sgblack@eecs.umich.edu              case 0x406:
3215149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_ADDR;
3225149Sgblack@eecs.umich.edu                break;
3235149Sgblack@eecs.umich.edu              case 0x40A:
3245149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_ADDR;
3255149Sgblack@eecs.umich.edu                break;
3265149Sgblack@eecs.umich.edu              case 0x40E:
3275149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_ADDR;
3285149Sgblack@eecs.umich.edu                break;
3295149Sgblack@eecs.umich.edu              case 0x412:
3305149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_ADDR;
3315149Sgblack@eecs.umich.edu                break;
3325149Sgblack@eecs.umich.edu              case 0x403:
3335149Sgblack@eecs.umich.edu                regNum = MISCREG_MC0_MISC;
3345149Sgblack@eecs.umich.edu                break;
3355149Sgblack@eecs.umich.edu              case 0x407:
3365149Sgblack@eecs.umich.edu                regNum = MISCREG_MC1_MISC;
3375149Sgblack@eecs.umich.edu                break;
3385149Sgblack@eecs.umich.edu              case 0x40B:
3395149Sgblack@eecs.umich.edu                regNum = MISCREG_MC2_MISC;
3405149Sgblack@eecs.umich.edu                break;
3415149Sgblack@eecs.umich.edu              case 0x40F:
3425149Sgblack@eecs.umich.edu                regNum = MISCREG_MC3_MISC;
3435149Sgblack@eecs.umich.edu                break;
3445149Sgblack@eecs.umich.edu              case 0x413:
3455149Sgblack@eecs.umich.edu                regNum = MISCREG_MC4_MISC;
3465149Sgblack@eecs.umich.edu                break;
3475149Sgblack@eecs.umich.edu              case 0xC0000080:
3485149Sgblack@eecs.umich.edu                regNum = MISCREG_EFER;
3495149Sgblack@eecs.umich.edu                break;
3505149Sgblack@eecs.umich.edu              case 0xC0000081:
3515149Sgblack@eecs.umich.edu                regNum = MISCREG_STAR;
3525149Sgblack@eecs.umich.edu                break;
3535149Sgblack@eecs.umich.edu              case 0xC0000082:
3545149Sgblack@eecs.umich.edu                regNum = MISCREG_LSTAR;
3555149Sgblack@eecs.umich.edu                break;
3565149Sgblack@eecs.umich.edu              case 0xC0000083:
3575149Sgblack@eecs.umich.edu                regNum = MISCREG_CSTAR;
3585149Sgblack@eecs.umich.edu                break;
3595149Sgblack@eecs.umich.edu              case 0xC0000084:
3605149Sgblack@eecs.umich.edu                regNum = MISCREG_SF_MASK;
3615149Sgblack@eecs.umich.edu                break;
3625149Sgblack@eecs.umich.edu              case 0xC0000100:
3635149Sgblack@eecs.umich.edu                regNum = MISCREG_FS_BASE;
3645149Sgblack@eecs.umich.edu                break;
3655149Sgblack@eecs.umich.edu              case 0xC0000101:
3665149Sgblack@eecs.umich.edu                regNum = MISCREG_GS_BASE;
3675149Sgblack@eecs.umich.edu                break;
3685149Sgblack@eecs.umich.edu              case 0xC0000102:
3695149Sgblack@eecs.umich.edu                regNum = MISCREG_KERNEL_GS_BASE;
3705149Sgblack@eecs.umich.edu                break;
3715149Sgblack@eecs.umich.edu              case 0xC0000103:
3725149Sgblack@eecs.umich.edu                regNum = MISCREG_TSC_AUX;
3735149Sgblack@eecs.umich.edu                break;
3745149Sgblack@eecs.umich.edu              case 0xC0010000:
3755149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL0;
3765149Sgblack@eecs.umich.edu                break;
3775149Sgblack@eecs.umich.edu              case 0xC0010001:
3785149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL1;
3795149Sgblack@eecs.umich.edu                break;
3805149Sgblack@eecs.umich.edu              case 0xC0010002:
3815149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL2;
3825149Sgblack@eecs.umich.edu                break;
3835149Sgblack@eecs.umich.edu              case 0xC0010003:
3845149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_SEL3;
3855149Sgblack@eecs.umich.edu                break;
3865149Sgblack@eecs.umich.edu              case 0xC0010004:
3875149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR0;
3885149Sgblack@eecs.umich.edu                break;
3895149Sgblack@eecs.umich.edu              case 0xC0010005:
3905149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR1;
3915149Sgblack@eecs.umich.edu                break;
3925149Sgblack@eecs.umich.edu              case 0xC0010006:
3935149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR2;
3945149Sgblack@eecs.umich.edu                break;
3955149Sgblack@eecs.umich.edu              case 0xC0010007:
3965149Sgblack@eecs.umich.edu                regNum = MISCREG_PERF_EVT_CTR3;
3975149Sgblack@eecs.umich.edu                break;
3985149Sgblack@eecs.umich.edu              case 0xC0010010:
3995149Sgblack@eecs.umich.edu                regNum = MISCREG_SYSCFG;
4005149Sgblack@eecs.umich.edu                break;
4015149Sgblack@eecs.umich.edu              case 0xC0010016:
4025149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_BASE0;
4035149Sgblack@eecs.umich.edu                break;
4045149Sgblack@eecs.umich.edu              case 0xC0010017:
4055149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_BASE1;
4065149Sgblack@eecs.umich.edu                break;
4075149Sgblack@eecs.umich.edu              case 0xC0010018:
4085149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_MASK0;
4095149Sgblack@eecs.umich.edu                break;
4105149Sgblack@eecs.umich.edu              case 0xC0010019:
4115149Sgblack@eecs.umich.edu                regNum = MISCREG_IORR_MASK1;
4125149Sgblack@eecs.umich.edu                break;
4135149Sgblack@eecs.umich.edu              case 0xC001001A:
4145149Sgblack@eecs.umich.edu                regNum = MISCREG_TOP_MEM;
4155149Sgblack@eecs.umich.edu                break;
4165149Sgblack@eecs.umich.edu              case 0xC001001D:
4175149Sgblack@eecs.umich.edu                regNum = MISCREG_TOP_MEM2;
4185149Sgblack@eecs.umich.edu                break;
4195149Sgblack@eecs.umich.edu              case 0xC0010114:
4205149Sgblack@eecs.umich.edu                regNum = MISCREG_VM_CR;
4215149Sgblack@eecs.umich.edu                break;
4225149Sgblack@eecs.umich.edu              case 0xC0010115:
4235149Sgblack@eecs.umich.edu                regNum = MISCREG_IGNNE;
4245149Sgblack@eecs.umich.edu                break;
4255149Sgblack@eecs.umich.edu              case 0xC0010116:
4265149Sgblack@eecs.umich.edu                regNum = MISCREG_SMM_CTL;
4275149Sgblack@eecs.umich.edu                break;
4285149Sgblack@eecs.umich.edu              case 0xC0010117:
4295149Sgblack@eecs.umich.edu                regNum = MISCREG_VM_HSAVE_PA;
4305149Sgblack@eecs.umich.edu                break;
4315149Sgblack@eecs.umich.edu              default:
4325149Sgblack@eecs.umich.edu                return new GeneralProtection(0);
4335149Sgblack@eecs.umich.edu            }
4345149Sgblack@eecs.umich.edu            //The index is multiplied by the size of a MiscReg so that
4355149Sgblack@eecs.umich.edu            //any memory dependence calculations will not see these as
4365149Sgblack@eecs.umich.edu            //overlapping.
4375149Sgblack@eecs.umich.edu            req->setPaddr(regNum * sizeof(MiscReg));
4385149Sgblack@eecs.umich.edu            return NoFault;
4395149Sgblack@eecs.umich.edu        } else {
4405149Sgblack@eecs.umich.edu            panic("Access to unrecognized internal address space %#x.\n",
4415149Sgblack@eecs.umich.edu                    prefix);
4425149Sgblack@eecs.umich.edu        }
4435149Sgblack@eecs.umich.edu    }
4445124Sgblack@eecs.umich.edu
4455140Sgblack@eecs.umich.edu    // Get cr0. This will tell us how to do translation. We'll assume it was
4465140Sgblack@eecs.umich.edu    // verified to be correct and consistent when set.
4475140Sgblack@eecs.umich.edu    CR0 cr0 = tc->readMiscRegNoEffect(MISCREG_CR0);
4485140Sgblack@eecs.umich.edu
4495140Sgblack@eecs.umich.edu    // If protected mode has been enabled...
4505140Sgblack@eecs.umich.edu    if (cr0.pe) {
4515140Sgblack@eecs.umich.edu        Efer efer = tc->readMiscRegNoEffect(MISCREG_EFER);
4525140Sgblack@eecs.umich.edu        SegAttr csAttr = tc->readMiscRegNoEffect(MISCREG_CS_ATTR);
4535140Sgblack@eecs.umich.edu        // If we're not in 64-bit mode, do protection/limit checks
4545140Sgblack@eecs.umich.edu        if (!efer.lma || !csAttr.longMode) {
4555140Sgblack@eecs.umich.edu            SegAttr attr = tc->readMiscRegNoEffect(MISCREG_SEG_ATTR(seg));
4565140Sgblack@eecs.umich.edu            if (!attr.writable && write)
4575140Sgblack@eecs.umich.edu                return new GeneralProtection(0);
4585140Sgblack@eecs.umich.edu            if (!attr.readable && !write && !execute)
4595140Sgblack@eecs.umich.edu                return new GeneralProtection(0);
4605140Sgblack@eecs.umich.edu            Addr base = tc->readMiscRegNoEffect(MISCREG_SEG_BASE(seg));
4615140Sgblack@eecs.umich.edu            Addr limit = tc->readMiscRegNoEffect(MISCREG_SEG_LIMIT(seg));
4625140Sgblack@eecs.umich.edu            if (!attr.expandDown) {
4635140Sgblack@eecs.umich.edu                // We don't have to worry about the access going around the
4645140Sgblack@eecs.umich.edu                // end of memory because accesses will be broken up into
4655140Sgblack@eecs.umich.edu                // pieces at boundaries aligned on sizes smaller than an
4665140Sgblack@eecs.umich.edu                // entire address space. We do have to worry about the limit
4675140Sgblack@eecs.umich.edu                // being less than the base.
4685140Sgblack@eecs.umich.edu                if (limit < base) {
4695140Sgblack@eecs.umich.edu                    if (limit < vaddr + req->getSize() && vaddr < base)
4705140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
4715140Sgblack@eecs.umich.edu                } else {
4725140Sgblack@eecs.umich.edu                    if (limit < vaddr + req->getSize())
4735140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
4745140Sgblack@eecs.umich.edu                }
4755140Sgblack@eecs.umich.edu            } else {
4765140Sgblack@eecs.umich.edu                if (limit < base) {
4775140Sgblack@eecs.umich.edu                    if (vaddr <= limit || vaddr + req->getSize() >= base)
4785140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
4795140Sgblack@eecs.umich.edu                } else {
4805140Sgblack@eecs.umich.edu                    if (vaddr <= limit && vaddr + req->getSize() >= base)
4815140Sgblack@eecs.umich.edu                        return new GeneralProtection(0);
4825140Sgblack@eecs.umich.edu                }
4835140Sgblack@eecs.umich.edu            }
4845140Sgblack@eecs.umich.edu        }
4855140Sgblack@eecs.umich.edu        // If paging is enabled, do the translation.
4865140Sgblack@eecs.umich.edu        if (cr0.pg) {
4875140Sgblack@eecs.umich.edu            // The vaddr already has the segment base applied.
4885140Sgblack@eecs.umich.edu            TlbEntry *entry = lookup(vaddr);
4895140Sgblack@eecs.umich.edu            if (!entry) {
4905124Sgblack@eecs.umich.edu#if FULL_SYSTEM
4915140Sgblack@eecs.umich.edu                return new TlbFault();
4925124Sgblack@eecs.umich.edu#else
4935140Sgblack@eecs.umich.edu                return new TlbFault(vaddr);
4945124Sgblack@eecs.umich.edu#endif
4955140Sgblack@eecs.umich.edu            } else {
4965140Sgblack@eecs.umich.edu                // Do paging protection checks.
4975140Sgblack@eecs.umich.edu                Addr paddr = entry->pageStart | (vaddr & mask(12));
4985140Sgblack@eecs.umich.edu                req->setPaddr(paddr);
4995140Sgblack@eecs.umich.edu            }
5005140Sgblack@eecs.umich.edu        } else {
5015140Sgblack@eecs.umich.edu            //Use the address which already has segmentation applied.
5025140Sgblack@eecs.umich.edu            req->setPaddr(vaddr);
5035140Sgblack@eecs.umich.edu        }
5045124Sgblack@eecs.umich.edu    } else {
5055140Sgblack@eecs.umich.edu        // Real mode
5065140Sgblack@eecs.umich.edu        req->setPaddr(vaddr);
5075124Sgblack@eecs.umich.edu    }
5085086Sgblack@eecs.umich.edu    return NoFault;
5095086Sgblack@eecs.umich.edu};
5105086Sgblack@eecs.umich.edu
5115140Sgblack@eecs.umich.eduFault
5125140Sgblack@eecs.umich.eduDTB::translate(RequestPtr &req, ThreadContext *tc, bool write)
5135140Sgblack@eecs.umich.edu{
5145140Sgblack@eecs.umich.edu    return TLB::translate<FakeDTLBFault>(req, tc, write, false);
5155140Sgblack@eecs.umich.edu}
5165140Sgblack@eecs.umich.edu
5175140Sgblack@eecs.umich.eduFault
5185140Sgblack@eecs.umich.eduITB::translate(RequestPtr &req, ThreadContext *tc)
5195140Sgblack@eecs.umich.edu{
5205140Sgblack@eecs.umich.edu    return TLB::translate<FakeITLBFault>(req, tc, false, true);
5215140Sgblack@eecs.umich.edu}
5225140Sgblack@eecs.umich.edu
5235086Sgblack@eecs.umich.edu#if FULL_SYSTEM
5245086Sgblack@eecs.umich.edu
5255086Sgblack@eecs.umich.eduTick
5265086Sgblack@eecs.umich.eduDTB::doMmuRegRead(ThreadContext *tc, Packet *pkt)
5275086Sgblack@eecs.umich.edu{
5285100Ssaidi@eecs.umich.edu    return tc->getCpuPtr()->ticks(1);
5295086Sgblack@eecs.umich.edu}
5305086Sgblack@eecs.umich.edu
5315086Sgblack@eecs.umich.eduTick
5325086Sgblack@eecs.umich.eduDTB::doMmuRegWrite(ThreadContext *tc, Packet *pkt)
5335086Sgblack@eecs.umich.edu{
5345100Ssaidi@eecs.umich.edu    return tc->getCpuPtr()->ticks(1);
5355086Sgblack@eecs.umich.edu}
5365086Sgblack@eecs.umich.edu
5375086Sgblack@eecs.umich.edu#endif
5385086Sgblack@eecs.umich.edu
5395086Sgblack@eecs.umich.eduvoid
5405086Sgblack@eecs.umich.eduTLB::serialize(std::ostream &os)
5415086Sgblack@eecs.umich.edu{
5425086Sgblack@eecs.umich.edu}
5435086Sgblack@eecs.umich.edu
5445086Sgblack@eecs.umich.eduvoid
5455086Sgblack@eecs.umich.eduTLB::unserialize(Checkpoint *cp, const std::string &section)
5465086Sgblack@eecs.umich.edu{
5475086Sgblack@eecs.umich.edu}
5485086Sgblack@eecs.umich.edu
5495086Sgblack@eecs.umich.eduvoid
5505086Sgblack@eecs.umich.eduDTB::serialize(std::ostream &os)
5515086Sgblack@eecs.umich.edu{
5525086Sgblack@eecs.umich.edu    TLB::serialize(os);
5535086Sgblack@eecs.umich.edu}
5545086Sgblack@eecs.umich.edu
5555086Sgblack@eecs.umich.eduvoid
5565086Sgblack@eecs.umich.eduDTB::unserialize(Checkpoint *cp, const std::string &section)
5575086Sgblack@eecs.umich.edu{
5585086Sgblack@eecs.umich.edu    TLB::unserialize(cp, section);
5595086Sgblack@eecs.umich.edu}
5605086Sgblack@eecs.umich.edu
5615086Sgblack@eecs.umich.edu/* end namespace X86ISA */ }
5625086Sgblack@eecs.umich.edu
5634997Sgblack@eecs.umich.eduX86ISA::ITB *
5644997Sgblack@eecs.umich.eduX86ITBParams::create()
5654997Sgblack@eecs.umich.edu{
5665038Sgblack@eecs.umich.edu    return new X86ISA::ITB(this);
5674997Sgblack@eecs.umich.edu}
5684997Sgblack@eecs.umich.edu
5694997Sgblack@eecs.umich.eduX86ISA::DTB *
5704997Sgblack@eecs.umich.eduX86DTBParams::create()
5714997Sgblack@eecs.umich.edu{
5725038Sgblack@eecs.umich.edu    return new X86ISA::DTB(this);
5734997Sgblack@eecs.umich.edu}
574