VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstX86-FpuSaveRestore.cpp@ 100764

Last change on this file since 100764 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* $Id: tstX86-FpuSaveRestore.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * tstX86-FpuSaveRestore - Experimenting with saving and restoring FPU.
4 */
5
6/*
7 * Copyright (C) 2013-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <iprt/initterm.h>
33#include <iprt/message.h>
34#include <iprt/string.h>
35#include <iprt/test.h>
36#include <iprt/x86.h>
37
38DECLASM(void) MyFpuPrepXcpt(void);
39DECLASM(void) MyFpuSave(PX86FXSTATE pState);
40DECLASM(void) MyFpuStoreEnv(PX86FSTENV32P pEnv);
41DECLASM(void) MyFpuRestore(PX86FXSTATE pState);
42DECLASM(void) MyFpuLoadEnv(PX86FSTENV32P pEnv);
43
44int main()
45{
46 RTTEST hTest;
47 int rc = RTTestInitAndCreate("tstX86-FpuSaveRestore", &hTest);
48 if (RT_FAILURE(rc))
49 return RTEXITCODE_FAILURE;
50 RTTestBanner(hTest);
51
52 RTTestSub(hTest, "CS/DS Selector");
53
54 RTTestIPrintf(RTTESTLVL_ALWAYS, "Initial state (0x20 will be subtracted from IP):\n");
55 /* Trigger an exception to make sure we've got something to look at. */
56 MyFpuPrepXcpt();
57 static X86FXSTATE FxState;
58 MyFpuSave(&FxState);
59 static X86FSTENV32P FpuEnv;
60 MyFpuStoreEnv(&FpuEnv);
61#ifdef RT_ARCH_AMD64
62 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState IP=%#06x%04x%08x\n", FxState.Rsrvd1, FxState.CS, FxState.FPUIP);
63#else
64 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState CS:IP=%#06x:%#010x\n", FxState.CS, FxState.FPUIP);
65#endif
66 RTTestIPrintf(RTTESTLVL_ALWAYS, " FpuEnv CS:IP=%#06x:%#010x\n", FpuEnv.FPUCS, FpuEnv.FPUIP);
67
68 /* Modify the state a little so we can tell the difference. */
69 static X86FXSTATE FxState2;
70 FxState2 = FxState;
71 FxState2.FPUIP -= 0x20;
72 static X86FSTENV32P FpuEnv2;
73 FpuEnv2 = FpuEnv;
74 FpuEnv2.FPUIP -= 0x20;
75
76 /* Just do FXRSTOR. */
77 RTTestIPrintf(RTTESTLVL_ALWAYS, "Just FXRSTOR:\n");
78 MyFpuRestore(&FxState2);
79
80 static X86FXSTATE FxStateJustRestore;
81 MyFpuSave(&FxStateJustRestore);
82 static X86FSTENV32P FpuEnvJustRestore;
83 MyFpuStoreEnv(&FpuEnvJustRestore);
84#ifdef RT_ARCH_AMD64
85 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState IP=%#06x%04x%08x\n", FxStateJustRestore.Rsrvd1, FxStateJustRestore.CS, FxStateJustRestore.FPUIP);
86#else
87 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState CS:IP=%#06x:%#010x\n", FxStateJustRestore.CS, FxStateJustRestore.FPUIP);
88#endif
89 RTTestIPrintf(RTTESTLVL_ALWAYS, " FpuEnv CS:IP=%#06x:%#010x\n", FpuEnvJustRestore.FPUCS, FpuEnvJustRestore.FPUIP);
90
91
92 /* FXRSTORE + FLDENV */
93 RTTestIPrintf(RTTESTLVL_ALWAYS, "FXRSTOR first, then FLDENV:\n");
94 MyFpuRestore(&FxState2);
95 MyFpuLoadEnv(&FpuEnv2);
96
97 static X86FXSTATE FxStateRestoreLoad;
98 MyFpuSave(&FxStateRestoreLoad);
99 static X86FSTENV32P FpuEnvRestoreLoad;
100 MyFpuStoreEnv(&FpuEnvRestoreLoad);
101#ifdef RT_ARCH_AMD64
102 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState IP=%#06x%04x%08x\n", FxStateRestoreLoad.Rsrvd1, FxStateRestoreLoad.CS, FxStateRestoreLoad.FPUIP);
103#else
104 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState CS:IP=%#06x:%#010x\n", FxStateRestoreLoad.CS, FxStateRestoreLoad.FPUIP);
105#endif
106 RTTestIPrintf(RTTESTLVL_ALWAYS, " FpuEnv CS:IP=%#06x:%#010x\n", FpuEnvRestoreLoad.FPUCS, FpuEnvRestoreLoad.FPUIP);
107
108 /* Reverse the order (FLDENV + FXRSTORE). */
109 RTTestIPrintf(RTTESTLVL_ALWAYS, "FLDENV first, then FXRSTOR:\n");
110 MyFpuLoadEnv(&FpuEnv2);
111 MyFpuRestore(&FxState2);
112
113 static X86FXSTATE FxStateLoadRestore;
114 MyFpuSave(&FxStateLoadRestore);
115 static X86FSTENV32P FpuEnvLoadRestore;
116 MyFpuStoreEnv(&FpuEnvLoadRestore);
117#ifdef RT_ARCH_AMD64
118 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState IP=%#06x%04x%08x\n", FxStateLoadRestore.Rsrvd1, FxStateLoadRestore.CS, FxStateLoadRestore.FPUIP);
119#else
120 RTTestIPrintf(RTTESTLVL_ALWAYS, " FxState CS:IP=%#06x:%#010x\n", FxStateLoadRestore.CS, FxStateLoadRestore.FPUIP);
121#endif
122 RTTestIPrintf(RTTESTLVL_ALWAYS, " FpuEnv CS:IP=%#06x:%#010x\n", FpuEnvLoadRestore.FPUCS, FpuEnvLoadRestore.FPUIP);
123
124
125 return RTTestSummaryAndDestroy(hTest);
126}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette