VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-state64-1.c64

Last change on this file was 106061, checked in by vboxsync, 8 weeks ago

Copyright year updates by scm.

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