1 | /* $Id: bs3-cpu-state64-1.c64 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - bs3-cpu-state64-1, 64-bit C code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2022 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 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include <bs3kit.h>
|
---|
32 | #include <iprt/asm-amd64-x86.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*********************************************************************************************************************************
|
---|
36 | * Internal Functions *
|
---|
37 | *********************************************************************************************************************************/
|
---|
38 | BS3_DECL(void) bs3CpuState64Worker_Nop(void);
|
---|
39 | BS3_DECL(void) bs3CpuState64Worker_ModAll32BitGrps(void);
|
---|
40 | BS3_DECL(void) bs3CpuState64Worker_ModAll16BitGrps(void);
|
---|
41 | BS3_DECL(void) bs3CpuState64Worker_ModAll8BitGrps(void);
|
---|
42 | BS3_DECL(void) bs3CpuState64Worker_ModCr2(void);
|
---|
43 | BS3_DECL(void) bs3CpuState64Worker(PFNBS3NEAR pfnWorker);
|
---|
44 |
|
---|
45 |
|
---|
46 | /*********************************************************************************************************************************
|
---|
47 | * Global Variables *
|
---|
48 | *********************************************************************************************************************************/
|
---|
49 | extern BS3REGCTX g_bs3CpuState64CtxToLoad;
|
---|
50 | extern BS3REGCTX const g_bs3CpuState64CtxSaved;
|
---|
51 |
|
---|
52 |
|
---|
53 | static void bs3CpuState64InitCtx(uint64_t uTweak)
|
---|
54 | {
|
---|
55 | Bs3RegCtxSave(&g_bs3CpuState64CtxToLoad);
|
---|
56 | g_bs3CpuState64CtxToLoad.rax.u = UINT64_C(0x8877f055443322e0) ^ uTweak;
|
---|
57 | g_bs3CpuState64CtxToLoad.rcx.u = UINT64_C(0x8877f155443322e1) ^ uTweak;
|
---|
58 | g_bs3CpuState64CtxToLoad.rdx.u = UINT64_C(0x8877f255443322e2) ^ uTweak;
|
---|
59 | g_bs3CpuState64CtxToLoad.rbx.u = UINT64_C(0x8877f355443322e3) ^ uTweak;
|
---|
60 | g_bs3CpuState64CtxToLoad.rsp.u = UINT64_C(0x8877f455443322e4) ^ uTweak;
|
---|
61 | g_bs3CpuState64CtxToLoad.rbp.u = UINT64_C(0x8877f555443322e5) ^ uTweak;
|
---|
62 | g_bs3CpuState64CtxToLoad.rsi.u = UINT64_C(0x8877f655443322e6) ^ uTweak;
|
---|
63 | g_bs3CpuState64CtxToLoad.rdi.u = UINT64_C(0x8877f755443322e7) ^ uTweak;
|
---|
64 | g_bs3CpuState64CtxToLoad.r8.u = UINT64_C(0x8877f855443322e8) ^ uTweak;
|
---|
65 | g_bs3CpuState64CtxToLoad.r9.u = UINT64_C(0x8877f955443322e9) ^ uTweak;
|
---|
66 | g_bs3CpuState64CtxToLoad.r10.u = UINT64_C(0x8877fa55443322ea) ^ uTweak;
|
---|
67 | g_bs3CpuState64CtxToLoad.r11.u = UINT64_C(0x8877fb55443322eb) ^ uTweak;
|
---|
68 | g_bs3CpuState64CtxToLoad.r12.u = UINT64_C(0x8877fc55443322ec) ^ uTweak;
|
---|
69 | g_bs3CpuState64CtxToLoad.r13.u = UINT64_C(0x8877fd55443322ed) ^ uTweak;
|
---|
70 | g_bs3CpuState64CtxToLoad.r14.u = UINT64_C(0x8877fe55443322ee) ^ uTweak;
|
---|
71 | g_bs3CpuState64CtxToLoad.r15.u = UINT64_C(0x8877ff55443322ef) ^ uTweak;
|
---|
72 | g_bs3CpuState64CtxToLoad.cr2.u = UINT64_C(0x89abcdef76543210) ^ uTweak;
|
---|
73 | //Bs3TestPrintf("** Input:\n");
|
---|
74 | //Bs3RegCtxPrint(&g_bs3CpuState64CtxToLoad);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | static void bs3CpuState64Comp(bool fModRbx)
|
---|
79 | {
|
---|
80 | //Bs3TestPrintf("** Result:\n");
|
---|
81 | //Bs3RegCtxPrint(&g_bs3CpuState64CtxSaved);
|
---|
82 | g_bs3CpuState64CtxToLoad.rax = g_bs3CpuState64CtxSaved.rax;
|
---|
83 | g_bs3CpuState64CtxToLoad.rip = g_bs3CpuState64CtxSaved.rip;
|
---|
84 | g_bs3CpuState64CtxToLoad.rflags = g_bs3CpuState64CtxSaved.rflags;
|
---|
85 | g_bs3CpuState64CtxToLoad.rsp = g_bs3CpuState64CtxSaved.rsp;
|
---|
86 | if (!fModRbx)
|
---|
87 | g_bs3CpuState64CtxToLoad.rbx.au16[0] = g_bs3CpuState64CtxSaved.rbx.au16[0];
|
---|
88 | if (1)
|
---|
89 | g_bs3CpuState64CtxToLoad.ds = g_bs3CpuState64CtxSaved.ds;
|
---|
90 |
|
---|
91 | Bs3TestCheckRegCtxEx(&g_bs3CpuState64CtxSaved, &g_bs3CpuState64CtxToLoad, 0 /*cbPcAdjust*/, 0 /*cbSpAdjust*/,
|
---|
92 | 0 /*fExtraEfl*/, "lm64", 0 /*idTestStep*/);
|
---|
93 | }
|
---|
94 |
|
---|
95 | BS3_DECL(void) Main_lm64()
|
---|
96 | {
|
---|
97 | Bs3TestInit("bs3-cpu-state64-1");
|
---|
98 | /*
|
---|
99 | * Switch to 64-bit mode and back to rm.
|
---|
100 | */
|
---|
101 | Bs3TestSub("noop");
|
---|
102 | bs3CpuState64InitCtx(0);
|
---|
103 | bs3CpuState64Worker(bs3CpuState64Worker_Nop);
|
---|
104 | bs3CpuState64Comp(false /*fModRbx*/);
|
---|
105 |
|
---|
106 | Bs3TestSub("Modify all 32-bit GPRs");
|
---|
107 | bs3CpuState64InitCtx(0);
|
---|
108 | bs3CpuState64Worker(bs3CpuState64Worker_ModAll32BitGrps);
|
---|
109 | g_bs3CpuState64CtxToLoad.rax.u = UINT64_C(0xc0ffee0d);
|
---|
110 | g_bs3CpuState64CtxToLoad.rcx.u = UINT64_C(0xc0ffee1d);
|
---|
111 | g_bs3CpuState64CtxToLoad.rdx.u = UINT64_C(0xc0ffee2d);
|
---|
112 | g_bs3CpuState64CtxToLoad.rbx.u = UINT64_C(0xc0ffee3d);
|
---|
113 | g_bs3CpuState64CtxToLoad.rsp.u = UINT64_C(0xc0ffee4d);
|
---|
114 | g_bs3CpuState64CtxToLoad.rbp.u = UINT64_C(0xc0ffee5d);
|
---|
115 | g_bs3CpuState64CtxToLoad.rsi.u = UINT64_C(0xc0ffee6d);
|
---|
116 | g_bs3CpuState64CtxToLoad.rdi.u = UINT64_C(0xc0ffee7d);
|
---|
117 | bs3CpuState64Comp(true /*fModRbx*/);
|
---|
118 |
|
---|
119 | Bs3TestSub("Modify all 16-bit GPRs");
|
---|
120 | bs3CpuState64InitCtx(0);
|
---|
121 | bs3CpuState64Worker(bs3CpuState64Worker_ModAll16BitGrps);
|
---|
122 | g_bs3CpuState64CtxToLoad.rax.au16[0] = UINT16_C(0xfad0);
|
---|
123 | g_bs3CpuState64CtxToLoad.rcx.au16[0] = UINT16_C(0xfad1);
|
---|
124 | g_bs3CpuState64CtxToLoad.rdx.au16[0] = UINT16_C(0xfad2);
|
---|
125 | g_bs3CpuState64CtxToLoad.rbx.au16[0] = UINT16_C(0xfad3);
|
---|
126 | g_bs3CpuState64CtxToLoad.rsp.au16[0] = UINT16_C(0xfad4);
|
---|
127 | g_bs3CpuState64CtxToLoad.rbp.au16[0] = UINT16_C(0xfad5);
|
---|
128 | g_bs3CpuState64CtxToLoad.rsi.au16[0] = UINT16_C(0xfad6);
|
---|
129 | g_bs3CpuState64CtxToLoad.rdi.au16[0] = UINT16_C(0xfad7);
|
---|
130 | bs3CpuState64Comp(true /*fModRbx*/);
|
---|
131 |
|
---|
132 | Bs3TestSub("Modify all 8-bit GPRs");
|
---|
133 | bs3CpuState64InitCtx(0);
|
---|
134 | bs3CpuState64Worker(bs3CpuState64Worker_ModAll8BitGrps);
|
---|
135 | g_bs3CpuState64CtxToLoad.rax.au8[0] = 0x10;
|
---|
136 | g_bs3CpuState64CtxToLoad.rax.au8[1] = 0x11;
|
---|
137 | g_bs3CpuState64CtxToLoad.rcx.au8[0] = 0x20;
|
---|
138 | g_bs3CpuState64CtxToLoad.rcx.au8[1] = 0x21;
|
---|
139 | g_bs3CpuState64CtxToLoad.rdx.au8[0] = 0x30;
|
---|
140 | g_bs3CpuState64CtxToLoad.rdx.au8[1] = 0x31;
|
---|
141 | g_bs3CpuState64CtxToLoad.rbx.au8[0] = 0x40;
|
---|
142 | g_bs3CpuState64CtxToLoad.rbx.au8[1] = 0x41;
|
---|
143 | bs3CpuState64Comp(true /*fModRbx*/);
|
---|
144 |
|
---|
145 | Bs3TestSub("Modify CR2");
|
---|
146 | bs3CpuState64InitCtx(0);
|
---|
147 | bs3CpuState64Worker(bs3CpuState64Worker_ModCr2);
|
---|
148 | g_bs3CpuState64CtxToLoad.cr2.u = 0xf00dface;
|
---|
149 | bs3CpuState64Comp(true /*fModRbx*/);
|
---|
150 |
|
---|
151 | /** @todo DRx */
|
---|
152 | Bs3TestTerm();
|
---|
153 | for (;;)
|
---|
154 | ASMHalt();
|
---|
155 | }
|
---|
156 |
|
---|