X86: Implement the instructions that compare fp values and write to rflags.
[gem5.git] / src / arch / x86 / pagetable_walker.hh
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 "base/types.hh"
66 #include "mem/mem_object.hh"
67 #include "mem/packet.hh"
68 #include "params/X86PagetableWalker.hh"
69
70 class ThreadContext;
71
72 namespace 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. The global
89 // read 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 &write);
97
98 // Kick off the state machine.
99 Fault start(ThreadContext * _tc, BaseTLB::Translation *translation,
100 RequestPtr req, BaseTLB::Mode mode);
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 BaseTLB::Mode mode;
187 bool user;
188 TlbEntry entry;
189
190 Fault pageFault(bool present);
191
192 public:
193
194 void setTLB(TLB * _tlb)
195 {
196 tlb = _tlb;
197 }
198
199 typedef X86PagetableWalkerParams Params;
200
201 Walker(const Params *params) :
202 MemObject(params),
203 read(NULL), inflight(0), retrying(false),
204 port(name() + ".port", this),
205 tlb(NULL), sys(params->system),
206 tc(NULL), state(Ready), nextState(Ready)
207 {
208 }
209 };
210 }
211 #endif // __ARCH_X86_PAGE_TABLE_WALKER_HH__