summaryrefslogtreecommitdiff
path: root/src/arch/x86/utility.cc
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas@sandberg.pp.se>2013-06-18 16:36:08 +0200
committerAndreas Sandberg <andreas@sandberg.pp.se>2013-06-18 16:36:08 +0200
commitd06064c38613662dfbf68a701052278b4018de8c (patch)
treecc7870da633caf1c52abbd624c37754fe5a99b52 /src/arch/x86/utility.cc
parenta8e8c4f433fb3cce354950ba72136b84abb78015 (diff)
downloadgem5-d06064c38613662dfbf68a701052278b4018de8c.tar.xz
x86: Add support for maintaining the x87 tag word
The current implementation of the x87 never updates the x87 tag word. This is currently not a big issue since the simulated x87 never checks for stack overflows, however this becomes an issue when switching between a virtualized CPU and a simulated CPU. This changeset adds support, which is enabled by default, for updating the tag register to every floating point microop that updates the stack top using the spm mechanism. The new tag words is generated by the helper function X86ISA::genX87Tags(). This function is currently limited to flagging a stack position as valid or invalid and does not try to distinguish between the valid, zero, and special states.
Diffstat (limited to 'src/arch/x86/utility.cc')
-rw-r--r--src/arch/x86/utility.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/arch/x86/utility.cc b/src/arch/x86/utility.cc
index 2398ca073..3df948986 100644
--- a/src/arch/x86/utility.cc
+++ b/src/arch/x86/utility.cc
@@ -268,4 +268,24 @@ setRFlags(ThreadContext *tc, uint64_t val)
tc->setMiscReg(MISCREG_RFLAGS, val & ~(ccFlagMask | cfofMask | DFBit));
}
+uint16_t
+genX87Tags(uint16_t ftw, uint8_t top, int8_t spm)
+{
+ const uint8_t new_top((top + spm + 8) % 8);
+
+ if (spm > 0) {
+ // Removing elements from the stack. Flag the elements as empty.
+ for (int i = top; i != new_top; i = (i + 1 + 8) % 8)
+ ftw |= 0x3 << (2 * i);
+ } else if (spm < 0) {
+ // Adding elements to the stack. Flag the new elements as
+ // valid. We should ideally decode them and "do the right
+ // thing".
+ for (int i = new_top; i != top; i = (i + 1 + 8) % 8)
+ ftw &= ~(0x3 << (2 * i));
+ }
+
+ return ftw;
+}
+
} // namespace X86_ISA