gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utility.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 The Hewlett-Packard Development Company
3  * Copyright (c) 2011 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include "arch/x86/utility.hh"
40 
41 #include "arch/x86/interrupts.hh"
42 #include "arch/x86/mmu.hh"
43 #include "arch/x86/registers.hh"
44 #include "arch/x86/x86_traits.hh"
45 #include "cpu/base.hh"
46 #include "fputils/fp80.h"
47 #include "sim/full_system.hh"
48 
49 namespace X86ISA
50 {
51 
52 void
54 {
55  // This function assumes no side effects other than TLB invalidation
56  // need to be considered while copying state. That will likely not be
57  // true in the future.
58  for (int i = 0; i < NUM_MISCREGS; ++i) {
59  if (!isValidMiscReg(i))
60  continue;
61 
63  }
64 
65  // The TSC has to be updated with side-effects if the CPUs in a
66  // CPU switch have different frequencies.
68 
69  dest->getMMUPtr()->flushAll();
70 }
71 
72 void
74 {
75  //copy int regs
76  for (int i = 0; i < NumIntRegs; ++i)
77  dest->setIntRegFlat(i, src->readIntRegFlat(i));
78  //copy float regs
79  for (int i = 0; i < NumFloatRegs; ++i)
80  dest->setFloatRegFlat(i, src->readFloatRegFlat(i));
81  //copy condition-code regs
82  for (int i = 0; i < NumCCRegs; ++i)
83  dest->setCCRegFlat(i, src->readCCRegFlat(i));
84  copyMiscRegs(src, dest);
85  dest->pcState(src->pcState());
86 }
87 
88 uint64_t
90 {
91  const uint64_t ncc_flags(tc->readMiscRegNoEffect(MISCREG_RFLAGS));
92  const uint64_t cc_flags(tc->readCCReg(X86ISA::CCREG_ZAPS));
93  const uint64_t cfof_bits(tc->readCCReg(X86ISA::CCREG_CFOF));
94  const uint64_t df_bit(tc->readCCReg(X86ISA::CCREG_DF));
95  // ecf (PSEUDO(3)) & ezf (PSEUDO(4)) are only visible to
96  // microcode, so we can safely ignore them.
97 
98  // Reconstruct the real rflags state, mask out internal flags, and
99  // make sure reserved bits have the expected values.
100  return ((ncc_flags | cc_flags | cfof_bits | df_bit) & 0x3F7FD5)
101  | 0x2;
102 }
103 
104 void
106 {
110 
111  // Internal microcode registers (ECF & EZF)
112  tc->setCCReg(X86ISA::CCREG_ECF, 0);
113  tc->setCCReg(X86ISA::CCREG_EZF, 0);
114 
115  // Update the RFLAGS misc reg with whatever didn't go into the
116  // magic registers.
118 }
119 
120 uint8_t
121 convX87TagsToXTags(uint16_t ftw)
122 {
123  uint8_t ftwx(0);
124  for (int i = 0; i < 8; ++i) {
125  // Extract the tag for the current element on the FP stack
126  const unsigned tag((ftw >> (2 * i)) & 0x3);
127 
128  /*
129  * Check the type of the current FP element. Valid values are:
130  * 0 == Valid
131  * 1 == Zero
132  * 2 == Special (Nan, unsupported, infinity, denormal)
133  * 3 == Empty
134  */
135  // The xsave version of the tag word only keeps track of
136  // whether the element is empty or not. Set the corresponding
137  // bit in the ftwx if it's not empty,
138  if (tag != 0x3)
139  ftwx |= 1 << i;
140  }
141 
142  return ftwx;
143 }
144 
145 uint16_t
146 convX87XTagsToTags(uint8_t ftwx)
147 {
148  uint16_t ftw(0);
149  for (int i = 0; i < 8; ++i) {
150  const unsigned xtag(((ftwx >> i) & 0x1));
151 
152  // The xtag for an x87 stack position is 0 for empty stack positions.
153  if (!xtag) {
154  // Set the tag word to 3 (empty) for the current element.
155  ftw |= 0x3 << (2 * i);
156  } else {
157  // TODO: We currently assume that non-empty elements are
158  // valid (0x0), but we should ideally reconstruct the full
159  // state (valid/zero/special).
160  }
161  }
162 
163  return ftw;
164 }
165 
166 uint16_t
167 genX87Tags(uint16_t ftw, uint8_t top, int8_t spm)
168 {
169  const uint8_t new_top((top + spm + 8) % 8);
170 
171  if (spm > 0) {
172  // Removing elements from the stack. Flag the elements as empty.
173  for (int i = top; i != new_top; i = (i + 1 + 8) % 8)
174  ftw |= 0x3 << (2 * i);
175  } else if (spm < 0) {
176  // Adding elements to the stack. Flag the new elements as
177  // valid. We should ideally decode them and "do the right
178  // thing".
179  for (int i = new_top; i != top; i = (i + 1 + 8) % 8)
180  ftw &= ~(0x3 << (2 * i));
181  }
182 
183  return ftw;
184 }
185 
186 double
187 loadFloat80(const void *_mem)
188 {
189  fp80_t fp80;
190  memcpy(fp80.bits, _mem, 10);
191 
192  return fp80_cvtd(fp80);
193 }
194 
195 void
196 storeFloat80(void *_mem, double value)
197 {
198  fp80_t fp80 = fp80_cvfd(value);
199  memcpy(_mem, fp80.bits, 10);
200 }
201 
202 } // namespace X86_ISA
X86ISA::CCREG_ZAPS
@ CCREG_ZAPS
Definition: ccr.hh:47
ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
X86ISA::convX87TagsToXTags
uint8_t convX87TagsToXTags(uint16_t ftw)
Convert an x87 tag word to abridged tag format.
Definition: utility.cc:121
ThreadContext::readIntRegFlat
virtual RegVal readIntRegFlat(RegIndex idx) const =0
Flat register interfaces.
X86ISA::genX87Tags
uint16_t genX87Tags(uint16_t ftw, uint8_t top, int8_t spm)
Generate and updated x87 tag register after a push/pop operation.
Definition: utility.cc:167
x86_traits.hh
X86ISA::NumIntRegs
const int NumIntRegs
Definition: registers.hh:55
mmu.hh
registers.hh
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ThreadContext::getMMUPtr
virtual BaseMMU * getMMUPtr()=0
interrupts.hh
X86ISA::loadFloat80
double loadFloat80(const void *_mem)
Load an 80-bit float from memory and convert it to double.
Definition: utility.cc:187
top
Definition: test.h:61
X86ISA::copyRegs
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:73
X86ISA::convX87XTagsToTags
uint16_t convX87XTagsToTags(uint8_t ftwx)
Convert an x87 xtag word to normal tags format.
Definition: utility.cc:146
X86ISA::CCREG_DF
@ CCREG_DF
Definition: ccr.hh:49
ThreadContext::setFloatRegFlat
virtual void setFloatRegFlat(RegIndex idx, RegVal val)=0
BaseMMU::flushAll
void flushAll()
Definition: mmu.hh:65
X86ISA::CCREG_CFOF
@ CCREG_CFOF
Definition: ccr.hh:48
X86ISA::storeFloat80
void storeFloat80(void *_mem, double value)
Convert and store a double as an 80-bit float.
Definition: utility.cc:196
ThreadContext::readCCRegFlat
virtual RegVal readCCRegFlat(RegIndex idx) const =0
X86ISA::NUM_MISCREGS
@ NUM_MISCREGS
Definition: misc.hh:398
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
X86ISA::MISCREG_RFLAGS
@ MISCREG_RFLAGS
Definition: misc.hh:134
ThreadContext::setIntRegFlat
virtual void setIntRegFlat(RegIndex idx, RegVal val)=0
X86ISA::ccFlagMask
const uint32_t ccFlagMask
Definition: misc.hh:67
X86ISA::isValidMiscReg
static bool isValidMiscReg(int index)
Definition: misc.hh:402
X86ISA::NumFloatRegs
const int NumFloatRegs
Definition: registers.hh:60
utility.hh
X86ISA::setRFlags
void setRFlags(ThreadContext *tc, uint64_t val)
Set update the rflags register and internal gem5 state.
Definition: utility.cc:105
ThreadContext::readFloatRegFlat
virtual RegVal readFloatRegFlat(RegIndex idx) const =0
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
X86ISA
This is exposed globally, independent of the ISA.
Definition: acpi.hh:55
X86ISA::DFBit
@ DFBit
Definition: misc.hh:62
full_system.hh
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
X86ISA::getRFlags
uint64_t getRFlags(ThreadContext *tc)
Reconstruct the rflags register from the internal gem5 register state.
Definition: utility.cc:89
ThreadContext::readCCReg
virtual RegVal readCCReg(RegIndex reg_idx) const =0
ThreadContext::setCCReg
virtual void setCCReg(RegIndex reg_idx, RegVal val)=0
ThreadContext::setCCRegFlat
virtual void setCCRegFlat(RegIndex idx, RegVal val)=0
base.hh
ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
ThreadContext::setMiscReg
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
X86ISA::CCREG_EZF
@ CCREG_EZF
Definition: ccr.hh:51
ThreadContext::setMiscRegNoEffect
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
X86ISA::cfofMask
const uint32_t cfofMask
Definition: misc.hh:66
X86ISA::copyMiscRegs
void copyMiscRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:53
X86ISA::MISCREG_TSC
@ MISCREG_TSC
Definition: misc.hh:143
X86ISA::NumCCRegs
const int NumCCRegs
Definition: registers.hh:56
X86ISA::CCREG_ECF
@ CCREG_ECF
Definition: ccr.hh:50

Generated on Tue Mar 23 2021 19:41:20 for gem5 by doxygen 1.8.17