pagetable_walker.hh revision 5245
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. 95 void doNext(PacketPtr &read, PacketPtr &write); 96 97 // Kick off the state machine. 98 void start(ThreadContext * _tc, Addr vaddr); 99 100 protected: 101 102 /* 103 * State having to do with sending packets. 104 */ 105 PacketPtr read; 106 std::vector<PacketPtr> writes; 107 108 // How many memory operations are in flight. 109 unsigned inflight; 110 111 bool retrying; 112 113 /* 114 * Functions for dealing with packets. 115 */ 116 bool recvTiming(PacketPtr pkt); 117 void recvRetry(); 118 119 void sendPackets(); 120 121 /* 122 * Port for accessing memory 123 */ 124 class WalkerPort : public Port 125 { 126 public: 127 WalkerPort(const std::string &_name, Walker * _walker) : 128 Port(_name, _walker), walker(_walker), 129 snoopRangeSent(false) 130 {} 131 132 protected: 133 Walker * walker; 134 135 bool snoopRangeSent; 136 137 bool recvTiming(PacketPtr pkt); 138 Tick recvAtomic(PacketPtr pkt); 139 void recvFunctional(PacketPtr pkt); 140 void recvStatusChange(Status status); 141 void recvRetry(); 142 void getDeviceAddressRanges(AddrRangeList &resp, 143 bool &snoop) 144 { 145 resp.clear(); 146 snoop = true; 147 } 148 }; 149 150 Port *getPort(const std::string &if_name, int idx = -1); 151 152 friend class WalkerPort; 153 154 WalkerPort port; 155 156 // The TLB we're supposed to load. 157 TLB * tlb; 158 System * sys; 159 160 /* 161 * State machine state. 162 */ 163 ThreadContext * tc; 164 State state; 165 State nextState; 166 int size; 167 bool enableNX; 168 TlbEntry entry; 169 170 public: 171 172 void setTLB(TLB * _tlb) 173 { 174 tlb = _tlb; 175 } 176 177 typedef X86PagetableWalkerParams Params; 178 179 Walker(const Params *params) : 180 MemObject(params), 181 read(NULL), inflight(0), retrying(false), 182 port(name() + ".port", this), 183 tlb(NULL), sys(params->system), 184 tc(NULL), state(Ready), nextState(Ready) 185 { 186 } 187 }; 188} 189#endif // __ARCH_X86_PAGE_TABLE_WALKER_HH__ 190