2 * Copyright (c) 2003-2006 The Regents of The University of Michigan
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.
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.
32 * Copyright (c) 2007 The Hewlett-Packard Development Company
33 * All rights reserved.
35 * Redistribution and use of this software in source and binary forms,
36 * with or without modification, are permitted provided that the
37 * following conditions are met:
39 * The software must be used only for Non-Commercial Use which means any
40 * use which is NOT directed to receiving any direct monetary
41 * compensation for, or commercial advantage from such use. Illustrative
42 * examples of non-commercial use are academic research, personal study,
43 * teaching, education and corporate research & development.
44 * Illustrative examples of commercial use are distributing products for
45 * commercial advantage and providing services using the software for
46 * commercial advantage.
48 * If you wish to use this software or functionality therein that may be
49 * covered by patents for commercial use, please contact:
50 * Director of Intellectual Property Licensing
51 * Office of Strategy and Technology
52 * Hewlett-Packard Company
54 * Palo Alto, California 94304
56 * Redistributions of source code must retain the above copyright notice,
57 * this list of conditions and the following disclaimer. Redistributions
58 * in binary form must reproduce the above copyright notice, this list of
59 * conditions and the following disclaimer in the documentation and/or
60 * other materials provided with the distribution. Neither the name of
61 * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
62 * contributors may be used to endorse or promote products derived from
63 * this software without specific prior written permission. No right of
64 * sublicense is granted herewith. Derivatives of the software and
65 * output created using the software may be prepared, but only for
66 * Non-Commercial Uses. Derivatives of the software may be shared with
67 * others provided: (i) the others agree to abide by the list of
68 * conditions herein which includes the Non-Commercial Use restrictions;
69 * and (ii) such Derivatives of the software include the above copyright
70 * notice to acknowledge the contribution from this software where
71 * applicable, this list of conditions and the disclaimer below.
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
74 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
75 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
76 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
77 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
78 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
79 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
83 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88 #include "arch/x86/miscregfile.hh"
89 #include "arch/x86/tlb.hh"
90 #include "cpu/thread_context.hh"
91 #include "sim/serialize.hh"
93 using namespace X86ISA
;
98 //These functions map register indices to names
99 string
X86ISA::getMiscRegName(RegIndex index
)
101 panic("No misc registers in x86 yet!\n");
104 void MiscRegFile::clear()
106 // Blank everything. 0 might not be an appropriate value for some things.
107 memset(regVal
, 0, NumMiscRegs
* sizeof(MiscReg
));
110 MiscReg
MiscRegFile::readRegNoEffect(int miscReg
)
112 // Make sure we're not dealing with an illegal control register.
113 // Instructions should filter out these indexes, and nothing else should
114 // attempt to read them directly.
115 assert( miscReg
!= MISCREG_CR1
&&
116 !(miscReg
> MISCREG_CR4
&&
117 miscReg
< MISCREG_CR8
) &&
118 !(miscReg
> MISCREG_CR8
&&
119 miscReg
<= MISCREG_CR15
));
121 return regVal
[miscReg
];
124 MiscReg
MiscRegFile::readReg(int miscReg
, ThreadContext
* tc
)
126 return readRegNoEffect(miscReg
);
129 void MiscRegFile::setRegNoEffect(int miscReg
, const MiscReg
&val
)
131 // Make sure we're not dealing with an illegal control register.
132 // Instructions should filter out these indexes, and nothing else should
133 // attempt to write to them directly.
134 assert( miscReg
!= MISCREG_CR1
&&
135 !(miscReg
> MISCREG_CR4
&&
136 miscReg
< MISCREG_CR8
) &&
137 !(miscReg
> MISCREG_CR8
&&
138 miscReg
<= MISCREG_CR15
));
139 regVal
[miscReg
] = val
;
142 void MiscRegFile::setReg(int miscReg
,
143 const MiscReg
&val
, ThreadContext
* tc
)
145 MiscReg newVal
= val
;
150 CR0 toggled
= regVal
[miscReg
] ^ val
;
152 Efer efer
= regVal
[MISCREG_EFER
];
153 if (toggled
.pg
&& efer
.lme
) {
155 //Turning on long mode
157 regVal
[MISCREG_EFER
] = efer
;
159 //Turning off long mode
161 regVal
[MISCREG_EFER
] = efer
;
165 tc
->getITBPtr()->invalidateAll();
166 tc
->getDTBPtr()->invalidateAll();
168 //This must always be 1.
176 tc
->getITBPtr()->invalidateNonGlobal();
177 tc
->getDTBPtr()->invalidateNonGlobal();
181 CR4 toggled
= regVal
[miscReg
] ^ val
;
182 if (toggled
.pae
|| toggled
.pse
|| toggled
.pge
) {
183 tc
->getITBPtr()->invalidateAll();
184 tc
->getDTBPtr()->invalidateAll();
190 case MISCREG_CS_ATTR
:
192 SegAttr toggled
= regVal
[miscReg
] ^ val
;
193 SegAttr newCSAttr
= val
;
194 if (toggled
.longMode
) {
195 SegAttr newCSAttr
= val
;
196 if (newCSAttr
.longMode
) {
197 regVal
[MISCREG_ES_EFF_BASE
] = 0;
198 regVal
[MISCREG_CS_EFF_BASE
] = 0;
199 regVal
[MISCREG_SS_EFF_BASE
] = 0;
200 regVal
[MISCREG_DS_EFF_BASE
] = 0;
202 regVal
[MISCREG_ES_EFF_BASE
] = regVal
[MISCREG_ES_BASE
];
203 regVal
[MISCREG_CS_EFF_BASE
] = regVal
[MISCREG_CS_BASE
];
204 regVal
[MISCREG_SS_EFF_BASE
] = regVal
[MISCREG_SS_BASE
];
205 regVal
[MISCREG_DS_EFF_BASE
] = regVal
[MISCREG_DS_BASE
];
209 // These segments always actually use their bases, or in other words
210 // their effective bases must stay equal to their actual bases.
218 regVal
[MISCREG_SEG_EFF_BASE(miscReg
- MISCREG_SEG_SEL_BASE
)] = val
;
220 // These segments ignore their bases in 64 bit mode.
221 // their effective bases must stay equal to their actual bases.
227 Efer efer
= regVal
[MISCREG_EFER
];
228 SegAttr csAttr
= regVal
[MISCREG_CS_ATTR
];
229 if (!efer
.lma
|| !csAttr
.longMode
) // Check for non 64 bit mode.
230 regVal
[MISCREG_SEG_EFF_BASE(miscReg
-
231 MISCREG_SEG_SEL_BASE
)] = val
;
235 setRegNoEffect(miscReg
, newVal
);
238 void MiscRegFile::serialize(std::ostream
& os
)
240 SERIALIZE_ARRAY(regVal
, NumMiscRegs
);
243 void MiscRegFile::unserialize(Checkpoint
* cp
, const std::string
& section
)
245 UNSERIALIZE_ARRAY(regVal
, NumMiscRegs
);