gem5  v22.1.0.0
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/regs/ccr.hh"
44 #include "arch/x86/regs/float.hh"
45 #include "arch/x86/regs/int.hh"
46 #include "arch/x86/regs/misc.hh"
47 #include "arch/x86/x86_traits.hh"
48 #include "cpu/base.hh"
49 #include "fputils/fp80.h"
50 
51 namespace gem5
52 {
53 
54 namespace X86ISA
55 {
56 
57 uint64_t
59 {
60  const uint64_t ncc_flags(tc->readMiscRegNoEffect(misc_reg::Rflags));
61  const uint64_t cc_flags(tc->getReg(X86ISA::cc_reg::Zaps));
62  const uint64_t cfof_bits(tc->getReg(X86ISA::cc_reg::Cfof));
63  const uint64_t df_bit(tc->getReg(X86ISA::cc_reg::Df));
64  // ecf (PSEUDO(3)) & ezf (PSEUDO(4)) are only visible to
65  // microcode, so we can safely ignore them.
66 
67  // Reconstruct the real rflags state, mask out internal flags, and
68  // make sure reserved bits have the expected values.
69  return ((ncc_flags | cc_flags | cfof_bits | df_bit) & 0x3F7FD5)
70  | 0x2;
71 }
72 
73 void
74 setRFlags(ThreadContext *tc, uint64_t val)
75 {
79 
80  // Internal microcode registers (ECF & EZF)
83 
84  // Update the RFLAGS misc reg with whatever didn't go into the
85  // magic registers.
87 }
88 
89 uint8_t
90 convX87TagsToXTags(uint16_t ftw)
91 {
92  uint8_t ftwx(0);
93  for (int i = 0; i < 8; ++i) {
94  // Extract the tag for the current element on the FP stack
95  const unsigned tag((ftw >> (2 * i)) & 0x3);
96 
97  /*
98  * Check the type of the current FP element. Valid values are:
99  * 0 == Valid
100  * 1 == Zero
101  * 2 == Special (Nan, unsupported, infinity, denormal)
102  * 3 == Empty
103  */
104  // The xsave version of the tag word only keeps track of
105  // whether the element is empty or not. Set the corresponding
106  // bit in the ftwx if it's not empty,
107  if (tag != 0x3)
108  ftwx |= 1 << i;
109  }
110 
111  return ftwx;
112 }
113 
114 uint16_t
115 convX87XTagsToTags(uint8_t ftwx)
116 {
117  uint16_t ftw(0);
118  for (int i = 0; i < 8; ++i) {
119  const unsigned xtag(((ftwx >> i) & 0x1));
120 
121  // The xtag for an x87 stack position is 0 for empty stack positions.
122  if (!xtag) {
123  // Set the tag word to 3 (empty) for the current element.
124  ftw |= 0x3 << (2 * i);
125  } else {
126  // TODO: We currently assume that non-empty elements are
127  // valid (0x0), but we should ideally reconstruct the full
128  // state (valid/zero/special).
129  }
130  }
131 
132  return ftw;
133 }
134 
135 uint16_t
136 genX87Tags(uint16_t ftw, uint8_t top, int8_t spm)
137 {
138  const uint8_t new_top((top + spm + 8) % 8);
139 
140  if (spm > 0) {
141  // Removing elements from the stack. Flag the elements as empty.
142  for (int i = top; i != new_top; i = (i + 1 + 8) % 8)
143  ftw |= 0x3 << (2 * i);
144  } else if (spm < 0) {
145  // Adding elements to the stack. Flag the new elements as
146  // valid. We should ideally decode them and "do the right
147  // thing".
148  for (int i = new_top; i != top; i = (i + 1 + 8) % 8)
149  ftw &= ~(0x3 << (2 * i));
150  }
151 
152  return ftw;
153 }
154 
155 double
156 loadFloat80(const void *_mem)
157 {
158  fp80_t fp80;
159  memcpy(fp80.bits, _mem, 10);
160 
161  return fp80_cvtd(fp80);
162 }
163 
164 void
165 storeFloat80(void *_mem, double value)
166 {
167  fp80_t fp80 = fp80_cvfd(value);
168  memcpy(_mem, fp80.bits, 10);
169 }
170 
171 } // namespace X86_ISA
172 } // namespace gem5
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
virtual RegVal getReg(const RegId &reg) const
virtual void setReg(const RegId &reg, RegVal val)
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
Definition: test.h:63
Bitfield< 7 > i
Definition: misc_types.hh:67
constexpr RegId Cfof
Definition: ccr.hh:72
constexpr RegId Ecf
Definition: ccr.hh:74
constexpr RegId Df
Definition: ccr.hh:73
constexpr RegId Ezf
Definition: ccr.hh:75
constexpr RegId Zaps
Definition: ccr.hh:71
double loadFloat80(const void *_mem)
Load an 80-bit float from memory and convert it to double.
Definition: utility.cc:156
Bitfield< 63 > val
Definition: misc.hh:776
void storeFloat80(void *_mem, double value)
Convert and store a double as an 80-bit float.
Definition: utility.cc:165
constexpr uint32_t CcFlagMask
Definition: misc.hh:73
uint8_t convX87TagsToXTags(uint16_t ftw)
Convert an x87 tag word to abridged tag format.
Definition: utility.cc:90
void setRFlags(ThreadContext *tc, uint64_t val)
Set update the rflags register and internal gem5 state.
Definition: utility.cc:74
uint16_t convX87XTagsToTags(uint8_t ftwx)
Convert an x87 xtag word to normal tags format.
Definition: utility.cc:115
uint64_t getRFlags(ThreadContext *tc)
Reconstruct the rflags register from the internal gem5 register state.
Definition: utility.cc:58
constexpr uint32_t CfofMask
Definition: misc.hh:72
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:136
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t RegVal
Definition: types.hh:173

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1