1 | /* $Id: bs3-cmn-TestCheckRegCtxEx.c 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - TestCheckRegCtxEx
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-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 | * 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-template-header.h"
|
---|
42 |
|
---|
43 |
|
---|
44 | #undef Bs3TestCheckRegCtxEx
|
---|
45 | BS3_CMN_DEF(bool, Bs3TestCheckRegCtxEx,(PCBS3REGCTX pActualCtx, PCBS3REGCTX pExpectedCtx, uint16_t cbPcAdjust, int16_t cbSpAcjust,
|
---|
46 | uint32_t fExtraEfl, const char BS3_FAR *pszMode, uint16_t idTestStep))
|
---|
47 | {
|
---|
48 | uint16_t const cErrorsBefore = Bs3TestSubErrorCount();
|
---|
49 | uint8_t const fbFlags = pActualCtx->fbFlags | pExpectedCtx->fbFlags;
|
---|
50 |
|
---|
51 | #define CHECK_MEMBER(a_szName, a_szFmt, a_Actual, a_Expected) \
|
---|
52 | do { \
|
---|
53 | if ((a_Actual) == (a_Expected)) { /* likely */ } \
|
---|
54 | else Bs3TestFailedF("%u - %s: " a_szName "=" a_szFmt " expected " a_szFmt, idTestStep, pszMode, (a_Actual), (a_Expected)); \
|
---|
55 | } while (0)
|
---|
56 |
|
---|
57 | CHECK_MEMBER("rax", "%08RX64", pActualCtx->rax.u, pExpectedCtx->rax.u);
|
---|
58 | CHECK_MEMBER("rcx", "%08RX64", pActualCtx->rcx.u, pExpectedCtx->rcx.u);
|
---|
59 | CHECK_MEMBER("rdx", "%08RX64", pActualCtx->rdx.u, pExpectedCtx->rdx.u);
|
---|
60 | CHECK_MEMBER("rbx", "%08RX64", pActualCtx->rbx.u, pExpectedCtx->rbx.u);
|
---|
61 | CHECK_MEMBER("rsp", "%08RX64", pActualCtx->rsp.u, pExpectedCtx->rsp.u + cbSpAcjust);
|
---|
62 | CHECK_MEMBER("rbp", "%08RX64", pActualCtx->rbp.u, pExpectedCtx->rbp.u);
|
---|
63 | CHECK_MEMBER("rsi", "%08RX64", pActualCtx->rsi.u, pExpectedCtx->rsi.u);
|
---|
64 | CHECK_MEMBER("rdi", "%08RX64", pActualCtx->rdi.u, pExpectedCtx->rdi.u);
|
---|
65 | if (!(fbFlags & BS3REG_CTX_F_NO_AMD64))
|
---|
66 | {
|
---|
67 | CHECK_MEMBER("r8", "%08RX64", pActualCtx->r8.u, pExpectedCtx->r8.u);
|
---|
68 | CHECK_MEMBER("r9", "%08RX64", pActualCtx->r9.u, pExpectedCtx->r9.u);
|
---|
69 | CHECK_MEMBER("r10", "%08RX64", pActualCtx->r10.u, pExpectedCtx->r10.u);
|
---|
70 | CHECK_MEMBER("r11", "%08RX64", pActualCtx->r11.u, pExpectedCtx->r11.u);
|
---|
71 | CHECK_MEMBER("r12", "%08RX64", pActualCtx->r12.u, pExpectedCtx->r12.u);
|
---|
72 | CHECK_MEMBER("r13", "%08RX64", pActualCtx->r13.u, pExpectedCtx->r13.u);
|
---|
73 | CHECK_MEMBER("r14", "%08RX64", pActualCtx->r14.u, pExpectedCtx->r14.u);
|
---|
74 | CHECK_MEMBER("r15", "%08RX64", pActualCtx->r15.u, pExpectedCtx->r15.u);
|
---|
75 | }
|
---|
76 | CHECK_MEMBER("rflags", "%08RX64", pActualCtx->rflags.u, pExpectedCtx->rflags.u | fExtraEfl);
|
---|
77 | CHECK_MEMBER("rip", "%08RX64", pActualCtx->rip.u, pExpectedCtx->rip.u + cbPcAdjust);
|
---|
78 | CHECK_MEMBER("cs", "%04RX16", pActualCtx->cs, pExpectedCtx->cs);
|
---|
79 | CHECK_MEMBER("ds", "%04RX16", pActualCtx->ds, pExpectedCtx->ds);
|
---|
80 | CHECK_MEMBER("es", "%04RX16", pActualCtx->es, pExpectedCtx->es);
|
---|
81 | CHECK_MEMBER("fs", "%04RX16", pActualCtx->fs, pExpectedCtx->fs);
|
---|
82 | CHECK_MEMBER("gs", "%04RX16", pActualCtx->gs, pExpectedCtx->gs);
|
---|
83 |
|
---|
84 | if (!(fbFlags & BS3REG_CTX_F_NO_TR_LDTR))
|
---|
85 | {
|
---|
86 | CHECK_MEMBER("tr", "%04RX16", pActualCtx->tr, pExpectedCtx->tr);
|
---|
87 | CHECK_MEMBER("ldtr", "%04RX16", pActualCtx->ldtr, pExpectedCtx->ldtr);
|
---|
88 | }
|
---|
89 | CHECK_MEMBER("bMode", "%#04x", pActualCtx->bMode, pExpectedCtx->bMode);
|
---|
90 | CHECK_MEMBER("bCpl", "%u", pActualCtx->bCpl, pExpectedCtx->bCpl);
|
---|
91 |
|
---|
92 | if (!(fbFlags & BS3REG_CTX_F_NO_CR0_IS_MSW))
|
---|
93 | CHECK_MEMBER("cr0", "%08RX64", pActualCtx->cr0.u, pExpectedCtx->cr0.u);
|
---|
94 | else
|
---|
95 | CHECK_MEMBER("msw", "%08RX16", pActualCtx->cr0.u16, pExpectedCtx->cr0.u16);
|
---|
96 | if (!(fbFlags & BS3REG_CTX_F_NO_CR2_CR3))
|
---|
97 | {
|
---|
98 | CHECK_MEMBER("cr2", "%08RX64", pActualCtx->cr2.u, pExpectedCtx->cr2.u);
|
---|
99 | CHECK_MEMBER("cr3", "%08RX64", pActualCtx->cr3.u, pExpectedCtx->cr3.u);
|
---|
100 | }
|
---|
101 | if (!(fbFlags & BS3REG_CTX_F_NO_CR4))
|
---|
102 | CHECK_MEMBER("cr4", "%08RX64", pActualCtx->cr4.u, pExpectedCtx->cr4.u);
|
---|
103 | #undef CHECK_MEMBER
|
---|
104 |
|
---|
105 | return Bs3TestSubErrorCount() == cErrorsBefore;
|
---|
106 | }
|
---|
107 |
|
---|