tlb.hh revision 555
1/* 2 * Copyright (c) 2003 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef __ALPHA_MEMORY_HH__ 30#define __ALPHA_MEMORY_HH__ 31 32#include <map> 33 34#include "mem/mem_req.hh" 35#include "sim/sim_object.hh" 36#include "base/statistics.hh" 37 38class ExecContext; 39 40class AlphaTlb : public SimObject 41{ 42 protected: 43 typedef std::multimap<Addr, int> PageTable; 44 PageTable lookupTable; // Quick lookup into page table 45 46 AlphaISA::PTE *table; // the Page Table 47 int size; // TLB Size 48 int nlu; // not last used entry (for replacement) 49 50 void nextnlu() { if (++nlu >= size) nlu = 0; } 51 AlphaISA::PTE *lookup(Addr vpn, uint8_t asn) const; 52 53 public: 54 AlphaTlb(const std::string &name, int size); 55 virtual ~AlphaTlb(); 56 57 int getsize() const { return size; } 58 59 AlphaISA::PTE &index(bool advance = true); 60 void insert(Addr vaddr, AlphaISA::PTE &pte); 61 62 void flushAll(); 63 void flushProcesses(); 64 void flushAddr(Addr addr, uint8_t asn); 65 66 // static helper functions... really EV5 VM traits 67 static bool validVirtualAddress(Addr vaddr) { 68 // unimplemented bits must be all 0 or all 1 69 Addr unimplBits = vaddr & VA_UNIMPL_MASK; 70 return (unimplBits == 0) || (unimplBits == VA_UNIMPL_MASK); 71 } 72 73 static void checkCacheability(MemReqPtr &req); 74 75 // Checkpointing 76 virtual void serialize(std::ostream &os); 77 virtual void unserialize(Checkpoint *cp, const std::string §ion); 78}; 79 80class AlphaItb : public AlphaTlb 81{ 82 protected: 83 mutable Statistics::Scalar<> hits; 84 mutable Statistics::Scalar<> misses; 85 mutable Statistics::Scalar<> acv; 86 mutable Statistics::Formula accesses; 87 88 protected: 89 void fault(Addr pc, ExecContext *xc) const; 90 91 public: 92 AlphaItb(const std::string &name, int size); 93 virtual void regStats(); 94 95 Fault translate(MemReqPtr &req) const; 96}; 97 98class AlphaDtb : public AlphaTlb 99{ 100 protected: 101 mutable Statistics::Scalar<> read_hits; 102 mutable Statistics::Scalar<> read_misses; 103 mutable Statistics::Scalar<> read_acv; 104 mutable Statistics::Scalar<> read_accesses; 105 mutable Statistics::Scalar<> write_hits; 106 mutable Statistics::Scalar<> write_misses; 107 mutable Statistics::Scalar<> write_acv; 108 mutable Statistics::Scalar<> write_accesses; 109 Statistics::Formula hits; 110 Statistics::Formula misses; 111 Statistics::Formula acv; 112 Statistics::Formula accesses; 113 114 protected: 115 void fault(Addr pc, uint64_t flags, ExecContext *xc) const; 116 117 public: 118 AlphaDtb(const std::string &name, int size); 119 virtual void regStats(); 120 121 Fault translate(MemReqPtr &req, bool write) const; 122}; 123 124#endif // __ALPHA_MEMORY_HH__ 125