pagetable.hh revision 5013:d789d5458d81
1/* 2 * Copyright (c) 2006 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 * Authors: Ali Saidi 29 */ 30 31#ifndef __ARCH_SPARC_PAGETABLE_HH__ 32#define __ARCH_SPARC_PAGETABLE_HH__ 33 34#include "arch/sparc/isa_traits.hh" 35#include "base/bitfield.hh" 36#include "base/misc.hh" 37#include "config/full_system.hh" 38 39class Checkpoint; 40 41namespace SparcISA 42{ 43struct VAddr 44{ 45 VAddr(Addr a) { panic("not implemented yet."); } 46}; 47 48class TteTag 49{ 50 private: 51 uint64_t entry; 52 bool populated; 53 54 public: 55 TteTag() : entry(0), populated(false) {} 56 TteTag(uint64_t e) : entry(e), populated(true) {} 57 const TteTag &operator=(uint64_t e) { populated = true; 58 entry = e; return *this; } 59 bool valid() const {assert(populated); return !bits(entry,62,62); } 60 Addr va() const {assert(populated); return bits(entry,41,0); } 61}; 62 63 64class PageTableEntry 65{ 66 public: 67 enum EntryType { 68 sun4v, 69 sun4u, 70 invalid 71 }; 72 73 private: 74 uint64_t entry; 75 EntryType type; 76 uint64_t entry4u; 77 bool populated; 78 79 80 public: 81 PageTableEntry() : entry(0), type(invalid), populated(false) {} 82 83 PageTableEntry(uint64_t e, EntryType t = sun4u) 84 : entry(e), type(t), populated(true) 85 86 { 87 populate(entry, type); 88 } 89 90 void populate(uint64_t e, EntryType t = sun4u) 91 { 92 entry = e; 93 type = t; 94 populated = true; 95 96 // If we get a sun4v format TTE, turn it into a sun4u 97 if (type == sun4u) 98 entry4u = entry; 99 else { 100 entry4u = 0; 101 entry4u |= mbits(entry,63,63); //valid 102 entry4u |= bits(entry,1,0) << 61; //size[1:0] 103 entry4u |= bits(entry,62,62) << 60; //nfo 104 entry4u |= bits(entry,12,12) << 59; //ie 105 entry4u |= bits(entry,2,2) << 48; //size[2] 106 entry4u |= mbits(entry,39,13); //paddr 107 entry4u |= bits(entry,61,61) << 6;; // locked 108 entry4u |= bits(entry,10,10) << 5; //cp 109 entry4u |= bits(entry,9,9) << 4; //cv 110 entry4u |= bits(entry,11,11) << 3; //e 111 entry4u |= bits(entry,8,8) << 2; //p 112 entry4u |= bits(entry,6,6) << 1; //w 113 } 114 } 115 116 void clear() 117 { 118 populated = false; 119 } 120 121 static int pageSizes[6]; 122 123 124 uint64_t operator()() const { assert(populated); return entry4u; } 125 const PageTableEntry &operator=(uint64_t e) { populated = true; 126 entry4u = e; return *this; } 127 128 const PageTableEntry &operator=(const PageTableEntry &e) 129 { populated = true; entry4u = e.entry4u; type = e.type; return *this; } 130 131 bool valid() const { return bits(entry4u,63,63) && populated; } 132 uint8_t _size() const { assert(populated); 133 return bits(entry4u, 62,61) | 134 bits(entry4u, 48,48) << 2; } 135 Addr size() const { assert(_size() < 6); return pageSizes[_size()]; } 136 Addr sizeMask() const { assert(_size() < 6); return pageSizes[_size()]-1;} 137 bool ie() const { return bits(entry4u, 59,59); } 138 Addr pfn() const { assert(populated); return bits(entry4u,39,13); } 139 Addr paddr() const { assert(populated); return mbits(entry4u, 39,13);} 140 bool locked() const { assert(populated); return bits(entry4u,6,6); } 141 bool cv() const { assert(populated); return bits(entry4u,4,4); } 142 bool cp() const { assert(populated); return bits(entry4u,5,5); } 143 bool priv() const { assert(populated); return bits(entry4u,2,2); } 144 bool writable() const { assert(populated); return bits(entry4u,1,1); } 145 bool nofault() const { assert(populated); return bits(entry4u,60,60); } 146 bool sideffect() const { assert(populated); return bits(entry4u,3,3); } 147 Addr paddrMask() const { assert(populated); 148 return mbits(entry4u, 39,13) & ~sizeMask(); } 149}; 150 151struct TlbRange { 152 Addr va; 153 Addr size; 154 int contextId; 155 int partitionId; 156 bool real; 157 158 inline bool operator<(const TlbRange &r2) const 159 { 160 if (real && !r2.real) 161 return true; 162 if (!real && r2.real) 163 return false; 164 165 if (!real && !r2.real) { 166 if (contextId < r2.contextId) 167 return true; 168 else if (contextId > r2.contextId) 169 return false; 170 } 171 172 if (partitionId < r2.partitionId) 173 return true; 174 else if (partitionId > r2.partitionId) 175 return false; 176 177 if (va < r2.va) 178 return true; 179 return false; 180 } 181 inline bool operator==(const TlbRange &r2) const 182 { 183 return va == r2.va && 184 size == r2.size && 185 contextId == r2.contextId && 186 partitionId == r2.partitionId && 187 real == r2.real; 188 } 189}; 190 191 192struct TlbEntry { 193 Addr pageStart; 194 TlbEntry() 195 {} 196 TlbEntry(Addr addr) : pageStart(addr) 197 {} 198 TlbRange range; 199 PageTableEntry pte; 200 bool used; 201 bool valid; 202 203 void serialize(std::ostream &os); 204 void unserialize(Checkpoint *cp, const std::string §ion); 205 206}; 207 208 209}; // namespace SparcISA 210 211#endif // __ARCH_SPARC_PAGE_TABLE_HH__ 212 213