VirtualBox

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

Last change on this file since 49731 was 49731, checked in by vboxsync, 11 years ago

FPU save/restore experiment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: tstX86-FpuSaveRestore.cpp 49731 2013-11-29 18:19:02Z vboxsync $ */
2/** @file
3 * tstX86-FpuSaveRestore - Experimenting with saving and restoring FPU.
4 */
5
6/*
7 * Copyright (C) 2013 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 RTTestBanner(hTest);
39
40
41 RTTestSub(hTest, "CS/DS Selector");
42
43 /* Trigger an exception to make sure we've got something to look at. */
44 MyFpuPrepXcpt();
45
46 /* Initial state.*/
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 MyFpuRestore(&FxState2);
68
69 static X86FXSTATE FxStateJustRestore;
70 MyFpuSave(&FxStateJustRestore);
71 static X86FSTENV32P FpuEnvJustRestore;
72 MyFpuStoreEnv(&FpuEnvJustRestore);
73#ifdef RT_ARCH_AMD64
74 RTTestIPrintf(RTTESTLVL_ALWAYS, "FxState IP=%#06x%04x%08x\n", FxStateJustRestore.Rsrvd1, FxStateJustRestore.CS, FxStateJustRestore.FPUIP);
75#else
76 RTTestIPrintf(RTTESTLVL_ALWAYS, "FxState CS:IP=%#06x:%#010x\n", FxStateJustRestore.CS, FxStateJustRestore.FPUIP);
77#endif
78 RTTestIPrintf(RTTESTLVL_ALWAYS, "FpuEnv CS:IP=%#06x:%#010x\n", FpuEnvJustRestore.FPUCS, FpuEnvJustRestore.FPUIP);
79
80
81 /* FXRSTORE + FLDENV */
82 MyFpuRestore(&FxState2);
83 MyFpuLoadEnv(&FpuEnv2);
84
85 static X86FXSTATE FxStateRestoreLoad;
86 MyFpuSave(&FxStateRestoreLoad);
87 static X86FSTENV32P FpuEnvRestoreLoad;
88 MyFpuStoreEnv(&FpuEnvRestoreLoad);
89#ifdef RT_ARCH_AMD64
90 RTTestIPrintf(RTTESTLVL_ALWAYS, "FxState IP=%#06x%04x%08x\n", FxStateRestoreLoad.Rsrvd1, FxStateRestoreLoad.CS, FxStateRestoreLoad.FPUIP);
91#else
92 RTTestIPrintf(RTTESTLVL_ALWAYS, "FxState CS:IP=%#06x:%#010x\n", FxStateRestoreLoad.CS, FxStateRestoreLoad.FPUIP);
93#endif
94 RTTestIPrintf(RTTESTLVL_ALWAYS, "FpuEnv CS:IP=%#06x:%#010x\n", FpuEnvRestoreLoad.FPUCS, FpuEnvRestoreLoad.FPUIP);
95
96 /* Reverse the order (FLDENV + FXRSTORE). */
97 MyFpuLoadEnv(&FpuEnv2);
98 MyFpuRestore(&FxState2);
99
100 static X86FXSTATE FxStateLoadRestore;
101 MyFpuSave(&FxStateLoadRestore);
102 static X86FSTENV32P FpuEnvLoadRestore;
103 MyFpuStoreEnv(&FpuEnvLoadRestore);
104#ifdef RT_ARCH_AMD64
105 RTTestIPrintf(RTTESTLVL_ALWAYS, "FxState IP=%#06x%04x%08x\n", FxStateLoadRestore.Rsrvd1, FxStateLoadRestore.CS, FxStateLoadRestore.FPUIP);
106#else
107 RTTestIPrintf(RTTESTLVL_ALWAYS, "FxState CS:IP=%#06x:%#010x\n", FxStateLoadRestore.CS, FxStateLoadRestore.FPUIP);
108#endif
109 RTTestIPrintf(RTTESTLVL_ALWAYS, "FpuEnv CS:IP=%#06x:%#010x\n", FpuEnvLoadRestore.FPUCS, FpuEnvLoadRestore.FPUIP);
110
111
112 return RTTestSummaryAndDestroy(hTest);
113}
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