VirtualBox

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

Last change on this file since 62890 was 62776, checked in by vboxsync, 8 years ago

VMM: warnings.

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