pagetable_walker.hh revision 5895:569e3b31a868
1/* 2 * Copyright (c) 2007 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#ifndef __ARCH_X86_PAGE_TABLE_WALKER_HH__ 59#define __ARCH_X86_PAGE_TABLE_WALKER_HH__ 60 61#include <vector> 62 63#include "arch/x86/pagetable.hh" 64#include "arch/x86/tlb.hh" 65#include "mem/mem_object.hh" 66#include "mem/packet.hh" 67#include "params/X86PagetableWalker.hh" 68#include "sim/host.hh" 69 70class ThreadContext; 71 72namespace X86ISA 73{ 74 class Walker : public MemObject 75 { 76 public: 77 enum State { 78 Ready, 79 Waiting, 80 // Long mode 81 LongPML4, LongPDP, LongPD, LongPTE, 82 // PAE legacy mode 83 PAEPDP, PAEPD, PAEPTE, 84 // Non PAE legacy mode with and without PSE 85 PSEPD, PD, PTE 86 }; 87 88 // Act on the current state and determine what to do next. read 89 // should be the packet that just came back from a read and write 90 // should be NULL. When the function returns, read is either NULL 91 // if the machine is finished, or points to a packet to initiate 92 // the next read. If any write is required to update an "accessed" 93 // bit, write will point to a packet to do the write. Otherwise it 94 // will be NULL. The return value is whatever fault was incurred 95 // during this stage of the lookup. 96 Fault doNext(PacketPtr &read, PacketPtr &write); 97 98 // Kick off the state machine. 99 Fault start(ThreadContext * _tc, BaseTLB::Translation *translation, 100 RequestPtr req, bool write, bool execute); 101 // Clean up after the state machine. 102 void 103 stop() 104 { 105 nextState = Ready; 106 delete read->req; 107 delete read; 108 read = NULL; 109 } 110 111 protected: 112 113 /* 114 * State having to do with sending packets. 115 */ 116 PacketPtr read; 117 std::vector<PacketPtr> writes; 118 119 // How many memory operations are in flight. 120 unsigned inflight; 121 122 bool retrying; 123 124 /* 125 * The fault, if any, that's waiting to be delivered in timing mode. 126 */ 127 Fault timingFault; 128 129 /* 130 * Functions for dealing with packets. 131 */ 132 bool recvTiming(PacketPtr pkt); 133 void recvRetry(); 134 135 void sendPackets(); 136 137 /* 138 * Port for accessing memory 139 */ 140 class WalkerPort : public Port 141 { 142 public: 143 WalkerPort(const std::string &_name, Walker * _walker) : 144 Port(_name, _walker), walker(_walker), 145 snoopRangeSent(false) 146 {} 147 148 protected: 149 Walker * walker; 150 151 bool snoopRangeSent; 152 153 bool recvTiming(PacketPtr pkt); 154 Tick recvAtomic(PacketPtr pkt); 155 void recvFunctional(PacketPtr pkt); 156 void recvStatusChange(Status status); 157 void recvRetry(); 158 void getDeviceAddressRanges(AddrRangeList &resp, 159 bool &snoop) 160 { 161 resp.clear(); 162 snoop = true; 163 } 164 }; 165 166 Port *getPort(const std::string &if_name, int idx = -1); 167 168 friend class WalkerPort; 169 170 WalkerPort port; 171 172 // The TLB we're supposed to load. 173 TLB * tlb; 174 System * sys; 175 BaseTLB::Translation * translation; 176 177 /* 178 * State machine state. 179 */ 180 ThreadContext * tc; 181 RequestPtr req; 182 State state; 183 State nextState; 184 int size; 185 bool enableNX; 186 bool write, execute, user; 187 TlbEntry entry; 188 189 Fault pageFault(bool present); 190 191 public: 192 193 void setTLB(TLB * _tlb) 194 { 195 tlb = _tlb; 196 } 197 198 typedef X86PagetableWalkerParams Params; 199 200 Walker(const Params *params) : 201 MemObject(params), 202 read(NULL), inflight(0), retrying(false), 203 port(name() + ".port", this), 204 tlb(NULL), sys(params->system), 205 tc(NULL), state(Ready), nextState(Ready) 206 { 207 } 208 }; 209} 210#endif // __ARCH_X86_PAGE_TABLE_WALKER_HH__ 211