tlb.cc revision 5418
1/*
2 * Copyright (c) 2007-2008 The Hewlett-Packard Development Company
3 * All rights reserved.
4 *
5 * Redistribution and use of this software in source and binary forms,
6 * with or without modification, are permitted provided that the
7 * following conditions are met:
8 *
9 * The software must be used only for Non-Commercial Use which means any
10 * use which is NOT directed to receiving any direct monetary
11 * compensation for, or commercial advantage from such use.  Illustrative
12 * examples of non-commercial use are academic research, personal study,
13 * teaching, education and corporate research & development.
14 * Illustrative examples of commercial use are distributing products for
15 * commercial advantage and providing services using the software for
16 * commercial advantage.
17 *
18 * If you wish to use this software or functionality therein that may be
19 * covered by patents for commercial use, please contact:
20 *     Director of Intellectual Property Licensing
21 *     Office of Strategy and Technology
22 *     Hewlett-Packard Company
23 *     1501 Page Mill Road
24 *     Palo Alto, California  94304
25 *
26 * Redistributions of source code must retain the above copyright notice,
27 * this list of conditions and the following disclaimer.  Redistributions
28 * in binary form must reproduce the above copyright notice, this list of
29 * conditions and the following disclaimer in the documentation and/or
30 * other materials provided with the distribution.  Neither the name of
31 * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
32 * contributors may be used to endorse or promote products derived from
33 * this software without specific prior written permission.  No right of
34 * sublicense is granted herewith.  Derivatives of the software and
35 * output created using the software may be prepared, but only for
36 * Non-Commercial Uses.  Derivatives of the software may be shared with
37 * others provided: (i) the others agree to abide by the list of
38 * conditions herein which includes the Non-Commercial Use restrictions;
39 * and (ii) such Derivatives of the software include the above copyright
40 * notice to acknowledge the contribution from this software where
41 * applicable, this list of conditions and the disclaimer below.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 *
55 * Authors: Gabe Black
56 */
57
58#include <cstring>
59
60#include "config/full_system.hh"
61
62#include "arch/x86/pagetable.hh"
63#include "arch/x86/tlb.hh"
64#include "arch/x86/x86_traits.hh"
65#include "base/bitfield.hh"
66#include "base/trace.hh"
67#include "config/full_system.hh"
68#include "cpu/thread_context.hh"
69#include "cpu/base.hh"
70#include "mem/packet_access.hh"
71#include "mem/request.hh"
72
73#if FULL_SYSTEM
74#include "arch/x86/pagetable_walker.hh"
75#endif
76
77namespace X86ISA {
78
79TLB::TLB(const Params *p) : BaseTLB(p), configAddress(0), size(p->size)
80{
81    tlb = new TlbEntry[size];
82    std::memset(tlb, 0, sizeof(TlbEntry) * size);
83
84    for (int x = 0; x < size; x++)
85        freeList.push_back(&tlb[x]);
86
87#if FULL_SYSTEM
88    walker = p->walker;
89    walker->setTLB(this);
90#endif
91}
92
93void
94TLB::insert(Addr vpn, TlbEntry &entry)
95{
96    //TODO Deal with conflicting entries
97
98    TlbEntry *newEntry = NULL;
99    if (!freeList.empty()) {
100        newEntry = freeList.front();
101        freeList.pop_front();
102    } else {
103        newEntry = entryList.back();
104        entryList.pop_back();
105    }
106    *newEntry = entry;
107    newEntry->vaddr = vpn;
108    entryList.push_front(newEntry);
109}
110
111TLB::EntryList::iterator
112TLB::lookupIt(Addr va, bool update_lru)
113{
114    //TODO make this smarter at some point
115    EntryList::iterator entry;
116    for (entry = entryList.begin(); entry != entryList.end(); entry++) {
117        if ((*entry)->vaddr <= va && (*entry)->vaddr + (*entry)->size > va) {
118            DPRINTF(TLB, "Matched vaddr %#x to entry starting at %#x "
119                    "with size %#x.\n", va, (*entry)->vaddr, (*entry)->size);
120            if (update_lru) {
121                entryList.push_front(*entry);
122                entryList.erase(entry);
123                entry = entryList.begin();
124            }
125            break;
126        }
127    }
128    return entry;
129}
130
131TlbEntry *
132TLB::lookup(Addr va, bool update_lru)
133{
134    EntryList::iterator entry = lookupIt(va, update_lru);
135    if (entry == entryList.end())
136        return NULL;
137    else
138        return *entry;
139}
140
141#if FULL_SYSTEM
142void
143TLB::walk(ThreadContext * _tc, Addr vaddr)
144{
145    walker->start(_tc, vaddr);
146}
147#endif
148
149void
150TLB::invalidateAll()
151{
152    DPRINTF(TLB, "Invalidating all entries.\n");
153    while (!entryList.empty()) {
154        TlbEntry *entry = entryList.front();
155        entryList.pop_front();
156        freeList.push_back(entry);
157    }
158}
159
160void
161TLB::setConfigAddress(uint32_t addr)
162{
163    configAddress = addr;
164}
165
166void
167TLB::invalidateNonGlobal()
168{
169    DPRINTF(TLB, "Invalidating all non global entries.\n");
170    EntryList::iterator entryIt;
171    for (entryIt = entryList.begin(); entryIt != entryList.end();) {
172        if (!(*entryIt)->global) {
173            freeList.push_back(*entryIt);
174            entryList.erase(entryIt++);
175        } else {
176            entryIt++;
177        }
178    }
179}
180
181void
182TLB::demapPage(Addr va, uint64_t asn)
183{
184    EntryList::iterator entry = lookupIt(va, false);
185    if (entry != entryList.end()) {
186        freeList.push_back(*entry);
187        entryList.erase(entry);
188    }
189}
190
191template<class TlbFault>
192Fault
193TLB::translate(RequestPtr &req, ThreadContext *tc, bool write, bool execute)
194{
195    Addr vaddr = req->getVaddr();
196    DPRINTF(TLB, "Translating vaddr %#x.\n", vaddr);
197    uint32_t flags = req->getFlags();
198    bool storeCheck = flags & StoreCheck;
199
200    int seg = flags & mask(4);
201
202    //XXX Junk code to surpress the warning
203    if (storeCheck);
204
205    // If this is true, we're dealing with a request to read an internal
206    // value.
207    if (seg == SEGMENT_REG_MS) {
208        DPRINTF(TLB, "Addresses references internal memory.\n");
209        Addr prefix = (vaddr >> 3) & IntAddrPrefixMask;
210        if (prefix == IntAddrPrefixCPUID) {
211            panic("CPUID memory space not yet implemented!\n");
212        } else if (prefix == IntAddrPrefixMSR) {
213            vaddr = vaddr >> 3;
214            req->setMmapedIpr(true);
215            Addr regNum = 0;
216            switch (vaddr & ~IntAddrPrefixMask) {
217              case 0x10:
218                regNum = MISCREG_TSC;
219                break;
220              case 0x1B:
221                regNum = MISCREG_APIC_BASE;
222                break;
223              case 0xFE:
224                regNum = MISCREG_MTRRCAP;
225                break;
226              case 0x174:
227                regNum = MISCREG_SYSENTER_CS;
228                break;
229              case 0x175:
230                regNum = MISCREG_SYSENTER_ESP;
231                break;
232              case 0x176:
233                regNum = MISCREG_SYSENTER_EIP;
234                break;
235              case 0x179:
236                regNum = MISCREG_MCG_CAP;
237                break;
238              case 0x17A:
239                regNum = MISCREG_MCG_STATUS;
240                break;
241              case 0x17B:
242                regNum = MISCREG_MCG_CTL;
243                break;
244              case 0x1D9:
245                regNum = MISCREG_DEBUG_CTL_MSR;
246                break;
247              case 0x1DB:
248                regNum = MISCREG_LAST_BRANCH_FROM_IP;
249                break;
250              case 0x1DC:
251                regNum = MISCREG_LAST_BRANCH_TO_IP;
252                break;
253              case 0x1DD:
254                regNum = MISCREG_LAST_EXCEPTION_FROM_IP;
255                break;
256              case 0x1DE:
257                regNum = MISCREG_LAST_EXCEPTION_TO_IP;
258                break;
259              case 0x200:
260                regNum = MISCREG_MTRR_PHYS_BASE_0;
261                break;
262              case 0x201:
263                regNum = MISCREG_MTRR_PHYS_MASK_0;
264                break;
265              case 0x202:
266                regNum = MISCREG_MTRR_PHYS_BASE_1;
267                break;
268              case 0x203:
269                regNum = MISCREG_MTRR_PHYS_MASK_1;
270                break;
271              case 0x204:
272                regNum = MISCREG_MTRR_PHYS_BASE_2;
273                break;
274              case 0x205:
275                regNum = MISCREG_MTRR_PHYS_MASK_2;
276                break;
277              case 0x206:
278                regNum = MISCREG_MTRR_PHYS_BASE_3;
279                break;
280              case 0x207:
281                regNum = MISCREG_MTRR_PHYS_MASK_3;
282                break;
283              case 0x208:
284                regNum = MISCREG_MTRR_PHYS_BASE_4;
285                break;
286              case 0x209:
287                regNum = MISCREG_MTRR_PHYS_MASK_4;
288                break;
289              case 0x20A:
290                regNum = MISCREG_MTRR_PHYS_BASE_5;
291                break;
292              case 0x20B:
293                regNum = MISCREG_MTRR_PHYS_MASK_5;
294                break;
295              case 0x20C:
296                regNum = MISCREG_MTRR_PHYS_BASE_6;
297                break;
298              case 0x20D:
299                regNum = MISCREG_MTRR_PHYS_MASK_6;
300                break;
301              case 0x20E:
302                regNum = MISCREG_MTRR_PHYS_BASE_7;
303                break;
304              case 0x20F:
305                regNum = MISCREG_MTRR_PHYS_MASK_7;
306                break;
307              case 0x250:
308                regNum = MISCREG_MTRR_FIX_64K_00000;
309                break;
310              case 0x258:
311                regNum = MISCREG_MTRR_FIX_16K_80000;
312                break;
313              case 0x259:
314                regNum = MISCREG_MTRR_FIX_16K_A0000;
315                break;
316              case 0x268:
317                regNum = MISCREG_MTRR_FIX_4K_C0000;
318                break;
319              case 0x269:
320                regNum = MISCREG_MTRR_FIX_4K_C8000;
321                break;
322              case 0x26A:
323                regNum = MISCREG_MTRR_FIX_4K_D0000;
324                break;
325              case 0x26B:
326                regNum = MISCREG_MTRR_FIX_4K_D8000;
327                break;
328              case 0x26C:
329                regNum = MISCREG_MTRR_FIX_4K_E0000;
330                break;
331              case 0x26D:
332                regNum = MISCREG_MTRR_FIX_4K_E8000;
333                break;
334              case 0x26E:
335                regNum = MISCREG_MTRR_FIX_4K_F0000;
336                break;
337              case 0x26F:
338                regNum = MISCREG_MTRR_FIX_4K_F8000;
339                break;
340              case 0x277:
341                regNum = MISCREG_PAT;
342                break;
343              case 0x2FF:
344                regNum = MISCREG_DEF_TYPE;
345                break;
346              case 0x400:
347                regNum = MISCREG_MC0_CTL;
348                break;
349              case 0x404:
350                regNum = MISCREG_MC1_CTL;
351                break;
352              case 0x408:
353                regNum = MISCREG_MC2_CTL;
354                break;
355              case 0x40C:
356                regNum = MISCREG_MC3_CTL;
357                break;
358              case 0x410:
359                regNum = MISCREG_MC4_CTL;
360                break;
361              case 0x401:
362                regNum = MISCREG_MC0_STATUS;
363                break;
364              case 0x405:
365                regNum = MISCREG_MC1_STATUS;
366                break;
367              case 0x409:
368                regNum = MISCREG_MC2_STATUS;
369                break;
370              case 0x40D:
371                regNum = MISCREG_MC3_STATUS;
372                break;
373              case 0x411:
374                regNum = MISCREG_MC4_STATUS;
375                break;
376              case 0x402:
377                regNum = MISCREG_MC0_ADDR;
378                break;
379              case 0x406:
380                regNum = MISCREG_MC1_ADDR;
381                break;
382              case 0x40A:
383                regNum = MISCREG_MC2_ADDR;
384                break;
385              case 0x40E:
386                regNum = MISCREG_MC3_ADDR;
387                break;
388              case 0x412:
389                regNum = MISCREG_MC4_ADDR;
390                break;
391              case 0x403:
392                regNum = MISCREG_MC0_MISC;
393                break;
394              case 0x407:
395                regNum = MISCREG_MC1_MISC;
396                break;
397              case 0x40B:
398                regNum = MISCREG_MC2_MISC;
399                break;
400              case 0x40F:
401                regNum = MISCREG_MC3_MISC;
402                break;
403              case 0x413:
404                regNum = MISCREG_MC4_MISC;
405                break;
406              case 0xC0000080:
407                regNum = MISCREG_EFER;
408                break;
409              case 0xC0000081:
410                regNum = MISCREG_STAR;
411                break;
412              case 0xC0000082:
413                regNum = MISCREG_LSTAR;
414                break;
415              case 0xC0000083:
416                regNum = MISCREG_CSTAR;
417                break;
418              case 0xC0000084:
419                regNum = MISCREG_SF_MASK;
420                break;
421              case 0xC0000100:
422                regNum = MISCREG_FS_BASE;
423                break;
424              case 0xC0000101:
425                regNum = MISCREG_GS_BASE;
426                break;
427              case 0xC0000102:
428                regNum = MISCREG_KERNEL_GS_BASE;
429                break;
430              case 0xC0000103:
431                regNum = MISCREG_TSC_AUX;
432                break;
433              case 0xC0010000:
434                regNum = MISCREG_PERF_EVT_SEL0;
435                break;
436              case 0xC0010001:
437                regNum = MISCREG_PERF_EVT_SEL1;
438                break;
439              case 0xC0010002:
440                regNum = MISCREG_PERF_EVT_SEL2;
441                break;
442              case 0xC0010003:
443                regNum = MISCREG_PERF_EVT_SEL3;
444                break;
445              case 0xC0010004:
446                regNum = MISCREG_PERF_EVT_CTR0;
447                break;
448              case 0xC0010005:
449                regNum = MISCREG_PERF_EVT_CTR1;
450                break;
451              case 0xC0010006:
452                regNum = MISCREG_PERF_EVT_CTR2;
453                break;
454              case 0xC0010007:
455                regNum = MISCREG_PERF_EVT_CTR3;
456                break;
457              case 0xC0010010:
458                regNum = MISCREG_SYSCFG;
459                break;
460              case 0xC0010016:
461                regNum = MISCREG_IORR_BASE0;
462                break;
463              case 0xC0010017:
464                regNum = MISCREG_IORR_BASE1;
465                break;
466              case 0xC0010018:
467                regNum = MISCREG_IORR_MASK0;
468                break;
469              case 0xC0010019:
470                regNum = MISCREG_IORR_MASK1;
471                break;
472              case 0xC001001A:
473                regNum = MISCREG_TOP_MEM;
474                break;
475              case 0xC001001D:
476                regNum = MISCREG_TOP_MEM2;
477                break;
478              case 0xC0010114:
479                regNum = MISCREG_VM_CR;
480                break;
481              case 0xC0010115:
482                regNum = MISCREG_IGNNE;
483                break;
484              case 0xC0010116:
485                regNum = MISCREG_SMM_CTL;
486                break;
487              case 0xC0010117:
488                regNum = MISCREG_VM_HSAVE_PA;
489                break;
490              default:
491                return new GeneralProtection(0);
492            }
493            //The index is multiplied by the size of a MiscReg so that
494            //any memory dependence calculations will not see these as
495            //overlapping.
496            req->setPaddr(regNum * sizeof(MiscReg));
497            return NoFault;
498        } else if (prefix == IntAddrPrefixIO) {
499            // TODO If CPL > IOPL or in virtual mode, check the I/O permission
500            // bitmap in the TSS.
501
502            Addr IOPort = vaddr & ~IntAddrPrefixMask;
503            // Make sure the address fits in the expected 16 bit IO address
504            // space.
505            assert(!(IOPort & ~0xFFFF));
506            if (IOPort == 0xCF8 && req->getSize() == 4) {
507                req->setMmapedIpr(true);
508                req->setPaddr(MISCREG_PCI_CONFIG_ADDRESS * sizeof(MiscReg));
509            } else if ((IOPort & ~mask(2)) == 0xCFC) {
510                Addr configAddress =
511                    tc->readMiscRegNoEffect(MISCREG_PCI_CONFIG_ADDRESS);
512                if (bits(configAddress, 31, 31)) {
513                    req->setPaddr(PhysAddrPrefixPciConfig |
514                            bits(configAddress, 30, 0));
515                }
516            } else {
517                req->setPaddr(PhysAddrPrefixIO | IOPort);
518            }
519            return NoFault;
520        } else {
521            panic("Access to unrecognized internal address space %#x.\n",
522                    prefix);
523        }
524    }
525
526    // Get cr0. This will tell us how to do translation. We'll assume it was
527    // verified to be correct and consistent when set.
528    CR0 cr0 = tc->readMiscRegNoEffect(MISCREG_CR0);
529
530    // If protected mode has been enabled...
531    if (cr0.pe) {
532        DPRINTF(TLB, "In protected mode.\n");
533        Efer efer = tc->readMiscRegNoEffect(MISCREG_EFER);
534        SegAttr csAttr = tc->readMiscRegNoEffect(MISCREG_CS_ATTR);
535        // If we're not in 64-bit mode, do protection/limit checks
536        if (!efer.lma || !csAttr.longMode) {
537            DPRINTF(TLB, "Not in long mode. Checking segment protection.\n");
538            SegAttr attr = tc->readMiscRegNoEffect(MISCREG_SEG_ATTR(seg));
539            if (!attr.writable && write)
540                return new GeneralProtection(0);
541            if (!attr.readable && !write && !execute)
542                return new GeneralProtection(0);
543            Addr base = tc->readMiscRegNoEffect(MISCREG_SEG_BASE(seg));
544            Addr limit = tc->readMiscRegNoEffect(MISCREG_SEG_LIMIT(seg));
545            if (!attr.expandDown) {
546                DPRINTF(TLB, "Checking an expand down segment.\n");
547                // We don't have to worry about the access going around the
548                // end of memory because accesses will be broken up into
549                // pieces at boundaries aligned on sizes smaller than an
550                // entire address space. We do have to worry about the limit
551                // being less than the base.
552                if (limit < base) {
553                    if (limit < vaddr + req->getSize() && vaddr < base)
554                        return new GeneralProtection(0);
555                } else {
556                    if (limit < vaddr + req->getSize())
557                        return new GeneralProtection(0);
558                }
559            } else {
560                if (limit < base) {
561                    if (vaddr <= limit || vaddr + req->getSize() >= base)
562                        return new GeneralProtection(0);
563                } else {
564                    if (vaddr <= limit && vaddr + req->getSize() >= base)
565                        return new GeneralProtection(0);
566                }
567            }
568        }
569        // If paging is enabled, do the translation.
570        if (cr0.pg) {
571            DPRINTF(TLB, "Paging enabled.\n");
572            // The vaddr already has the segment base applied.
573            TlbEntry *entry = lookup(vaddr);
574            if (!entry) {
575                return new TlbFault(vaddr);
576            } else {
577                // Do paging protection checks.
578                DPRINTF(TLB, "Entry found with paddr %#x, doing protection checks.\n", entry->paddr);
579                Addr paddr = entry->paddr | (vaddr & (entry->size-1));
580                DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, paddr);
581                req->setPaddr(paddr);
582            }
583        } else {
584            //Use the address which already has segmentation applied.
585            DPRINTF(TLB, "Paging disabled.\n");
586            DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, vaddr);
587            req->setPaddr(vaddr);
588        }
589    } else {
590        // Real mode
591        DPRINTF(TLB, "In real mode.\n");
592        DPRINTF(TLB, "Translated %#x -> %#x.\n", vaddr, vaddr);
593        req->setPaddr(vaddr);
594    }
595    // Check for an access to the local APIC
596#if FULL_SYSTEM
597    LocalApicBase localApicBase = tc->readMiscRegNoEffect(MISCREG_APIC_BASE);
598    Addr baseAddr = localApicBase.base << 12;
599    Addr paddr = req->getPaddr();
600    if (baseAddr <= paddr && baseAddr + (1 << 12) > paddr) {
601        req->setMmapedIpr(true);
602        // The Intel developer's manuals say the below restrictions apply,
603        // but the linux kernel, because of a compiler optimization, breaks
604        // them.
605        /*
606        // Check alignment
607        if (paddr & ((32/8) - 1))
608            return new GeneralProtection(0);
609        // Check access size
610        if (req->getSize() != (32/8))
611            return new GeneralProtection(0);
612        */
613
614        //Make sure we're at least only accessing one register.
615        if ((paddr & ~mask(3)) != ((paddr + req->getSize()) & ~mask(3)))
616            panic("Accessed more than one register at a time in the APIC!\n");
617        MiscReg regNum;
618        Addr offset = paddr & mask(3);
619        paddr &= ~mask(3);
620        switch (paddr - baseAddr)
621        {
622          case 0x20:
623            regNum = MISCREG_APIC_ID;
624            break;
625          case 0x30:
626            regNum = MISCREG_APIC_VERSION;
627            break;
628          case 0x80:
629            regNum = MISCREG_APIC_TASK_PRIORITY;
630            break;
631          case 0x90:
632            regNum = MISCREG_APIC_ARBITRATION_PRIORITY;
633            break;
634          case 0xA0:
635            regNum = MISCREG_APIC_PROCESSOR_PRIORITY;
636            break;
637          case 0xB0:
638            regNum = MISCREG_APIC_EOI;
639            break;
640          case 0xD0:
641            regNum = MISCREG_APIC_LOGICAL_DESTINATION;
642            break;
643          case 0xE0:
644            regNum = MISCREG_APIC_DESTINATION_FORMAT;
645            break;
646          case 0xF0:
647            regNum = MISCREG_APIC_SPURIOUS_INTERRUPT_VECTOR;
648            break;
649          case 0x100:
650          case 0x108:
651          case 0x110:
652          case 0x118:
653          case 0x120:
654          case 0x128:
655          case 0x130:
656          case 0x138:
657          case 0x140:
658          case 0x148:
659          case 0x150:
660          case 0x158:
661          case 0x160:
662          case 0x168:
663          case 0x170:
664          case 0x178:
665            regNum = MISCREG_APIC_IN_SERVICE(
666                    (paddr - baseAddr - 0x100) / 0x8);
667            break;
668          case 0x180:
669          case 0x188:
670          case 0x190:
671          case 0x198:
672          case 0x1A0:
673          case 0x1A8:
674          case 0x1B0:
675          case 0x1B8:
676          case 0x1C0:
677          case 0x1C8:
678          case 0x1D0:
679          case 0x1D8:
680          case 0x1E0:
681          case 0x1E8:
682          case 0x1F0:
683          case 0x1F8:
684            regNum = MISCREG_APIC_TRIGGER_MODE(
685                    (paddr - baseAddr - 0x180) / 0x8);
686            break;
687          case 0x200:
688          case 0x208:
689          case 0x210:
690          case 0x218:
691          case 0x220:
692          case 0x228:
693          case 0x230:
694          case 0x238:
695          case 0x240:
696          case 0x248:
697          case 0x250:
698          case 0x258:
699          case 0x260:
700          case 0x268:
701          case 0x270:
702          case 0x278:
703            regNum = MISCREG_APIC_INTERRUPT_REQUEST(
704                    (paddr - baseAddr - 0x200) / 0x8);
705            break;
706          case 0x280:
707            regNum = MISCREG_APIC_ERROR_STATUS;
708            break;
709          case 0x300:
710            regNum = MISCREG_APIC_INTERRUPT_COMMAND_LOW;
711            break;
712          case 0x310:
713            regNum = MISCREG_APIC_INTERRUPT_COMMAND_HIGH;
714            break;
715          case 0x320:
716            regNum = MISCREG_APIC_LVT_TIMER;
717            break;
718          case 0x330:
719            regNum = MISCREG_APIC_LVT_THERMAL_SENSOR;
720            break;
721          case 0x340:
722            regNum = MISCREG_APIC_LVT_PERFORMANCE_MONITORING_COUNTERS;
723            break;
724          case 0x350:
725            regNum = MISCREG_APIC_LVT_LINT0;
726            break;
727          case 0x360:
728            regNum = MISCREG_APIC_LVT_LINT1;
729            break;
730          case 0x370:
731            regNum = MISCREG_APIC_LVT_ERROR;
732            break;
733          case 0x380:
734            regNum = MISCREG_APIC_INITIAL_COUNT;
735            break;
736          case 0x390:
737            regNum = MISCREG_APIC_CURRENT_COUNT;
738            break;
739          case 0x3E0:
740            regNum = MISCREG_APIC_DIVIDE_COUNT;
741            break;
742          default:
743            // A reserved register field.
744            return new GeneralProtection(0);
745            break;
746        }
747        req->setPaddr(regNum * sizeof(MiscReg) + offset);
748    }
749#endif
750    return NoFault;
751};
752
753Fault
754DTB::translate(RequestPtr &req, ThreadContext *tc, bool write)
755{
756    return TLB::translate<FakeDTLBFault>(req, tc, write, false);
757}
758
759Fault
760ITB::translate(RequestPtr &req, ThreadContext *tc)
761{
762    return TLB::translate<FakeITLBFault>(req, tc, false, true);
763}
764
765#if FULL_SYSTEM
766
767Tick
768DTB::doMmuRegRead(ThreadContext *tc, Packet *pkt)
769{
770    return tc->getCpuPtr()->ticks(1);
771}
772
773Tick
774DTB::doMmuRegWrite(ThreadContext *tc, Packet *pkt)
775{
776    return tc->getCpuPtr()->ticks(1);
777}
778
779#endif
780
781void
782TLB::serialize(std::ostream &os)
783{
784}
785
786void
787TLB::unserialize(Checkpoint *cp, const std::string &section)
788{
789}
790
791void
792DTB::serialize(std::ostream &os)
793{
794    TLB::serialize(os);
795}
796
797void
798DTB::unserialize(Checkpoint *cp, const std::string &section)
799{
800    TLB::unserialize(cp, section);
801}
802
803/* end namespace X86ISA */ }
804
805X86ISA::ITB *
806X86ITBParams::create()
807{
808    return new X86ISA::ITB(this);
809}
810
811X86ISA::DTB *
812X86DTBParams::create()
813{
814    return new X86ISA::DTB(this);
815}
816