VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c@ 60088

Last change on this file since 60088 was 60088, checked in by vboxsync, 9 years ago

bs3kit: updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: bs3-cpu-basic-2-template.c 60088 2016-03-18 00:07:33Z vboxsync $ */
2/** @file
3 * BS3Kit - bs3-cpu-basic-2, C code template.
4 */
5
6/*
7 * Copyright (C) 2007-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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#ifdef BS3_INSTANTIATING_MODE
29
30extern BS3_DECL(void) TMPL_NM(bs3CpuBasic2_TssGateEsp_IntXx)(void);
31
32# if TMPL_MODE == BS3_MODE_PE16 \
33 || TMPL_MODE == BS3_MODE_PE16_32
34
35static void bs3CpuBasic2_CompareTrapCtx1(PCBS3TRAPFRAME pTrapCtx, PCBS3REGCTX pStartCtx, uint16_t cbIpAdjust, uint8_t bXcpt,
36 unsigned uStep)
37{
38 const char *pszMode = BS3_DATA_NM(TMPL_NM(g_szBs3ModeName));
39 uint16_t cErrorsBefore = Bs3TestSubErrorCount();
40
41#define CHECK_MEMBER(a_szName, a_szFmt, a_Actual, a_Expected) \
42 do { \
43 if ((a_Actual) == (a_Expected)) { /* likely */ } \
44 else Bs3TestFailedF("%u - %s: " a_szName "=" a_szFmt " expected " a_szFmt, uStep, pszMode, (a_Actual), (a_Expected)); \
45 } while (0)
46
47 CHECK_MEMBER("bXcpt", "%#04x", pTrapCtx->bXcpt, bXcpt);
48 CHECK_MEMBER("rax", "%08RX64", pTrapCtx->Ctx.rax.u, pStartCtx->rax.u);
49 CHECK_MEMBER("rcx", "%08RX64", pTrapCtx->Ctx.rcx.u, pStartCtx->rcx.u);
50 CHECK_MEMBER("rdx", "%08RX64", pTrapCtx->Ctx.rdx.u, pStartCtx->rdx.u);
51 CHECK_MEMBER("rbx", "%08RX64", pTrapCtx->Ctx.rbx.u, pStartCtx->rbx.u);
52 CHECK_MEMBER("rsp", "%08RX64", pTrapCtx->Ctx.rsp.u, pStartCtx->rsp.u);
53 CHECK_MEMBER("rbp", "%08RX64", pTrapCtx->Ctx.rbp.u, pStartCtx->rbp.u);
54 CHECK_MEMBER("rsi", "%08RX64", pTrapCtx->Ctx.rsi.u, pStartCtx->rsi.u);
55 CHECK_MEMBER("rdi", "%08RX64", pTrapCtx->Ctx.rdi.u, pStartCtx->rdi.u);
56 CHECK_MEMBER("r8", "%08RX64", pTrapCtx->Ctx.r8.u, pStartCtx->r8.u);
57 CHECK_MEMBER("r9", "%08RX64", pTrapCtx->Ctx.r9.u, pStartCtx->r9.u);
58 CHECK_MEMBER("r10", "%08RX64", pTrapCtx->Ctx.r10.u, pStartCtx->r10.u);
59 CHECK_MEMBER("r11", "%08RX64", pTrapCtx->Ctx.r11.u, pStartCtx->r11.u);
60 CHECK_MEMBER("r12", "%08RX64", pTrapCtx->Ctx.r12.u, pStartCtx->r12.u);
61 CHECK_MEMBER("r13", "%08RX64", pTrapCtx->Ctx.r13.u, pStartCtx->r13.u);
62 CHECK_MEMBER("r14", "%08RX64", pTrapCtx->Ctx.r14.u, pStartCtx->r14.u);
63 CHECK_MEMBER("r15", "%08RX64", pTrapCtx->Ctx.r15.u, pStartCtx->r15.u);
64 CHECK_MEMBER("rflags", "%08RX64", pTrapCtx->Ctx.rflags.u, pStartCtx->rflags.u);
65 CHECK_MEMBER("rip", "%08RX64", pTrapCtx->Ctx.rip.u, pStartCtx->rip.u + cbIpAdjust);
66 CHECK_MEMBER("cs", "%04RX16", pTrapCtx->Ctx.cs, pStartCtx->cs);
67 CHECK_MEMBER("ds", "%04RX16", pTrapCtx->Ctx.ds, pStartCtx->ds);
68 CHECK_MEMBER("es", "%04RX16", pTrapCtx->Ctx.es, pStartCtx->es);
69 CHECK_MEMBER("fs", "%04RX16", pTrapCtx->Ctx.fs, pStartCtx->fs);
70 CHECK_MEMBER("gs", "%04RX16", pTrapCtx->Ctx.gs, pStartCtx->gs);
71 CHECK_MEMBER("tr", "%04RX16", pTrapCtx->Ctx.tr, pStartCtx->tr);
72 CHECK_MEMBER("ldtr", "%04RX16", pTrapCtx->Ctx.ldtr, pStartCtx->ldtr);
73 CHECK_MEMBER("bMode", "%#04x", pTrapCtx->Ctx.bMode, pStartCtx->bMode);
74 CHECK_MEMBER("bCpl", "%u", pTrapCtx->Ctx.bCpl, pStartCtx->bCpl);
75 CHECK_MEMBER("cr0", "%08RX32", pTrapCtx->Ctx.cr0.u, pStartCtx->cr0.u);
76 CHECK_MEMBER("cr2", "%08RX32", pTrapCtx->Ctx.cr2.u, pStartCtx->cr2.u);
77 CHECK_MEMBER("cr3", "%08RX32", pTrapCtx->Ctx.cr3.u, pStartCtx->cr3.u);
78 CHECK_MEMBER("cr4", "%08RX32", pTrapCtx->Ctx.cr4.u, pStartCtx->cr4.u);
79 if (Bs3TestSubErrorCount() != cErrorsBefore)
80 Bs3TrapPrintFrame(pTrapCtx);
81}
82#endif
83
84AssertCompileMemberOffset(BS3REGCTX, ss, 0x9a);
85
86BS3_DECL(uint8_t) TMPL_NM(bs3CpuBasic2_TssGateEsp)(uint8_t bMode)
87{
88 uint8_t bRet = 0;
89 BS3TRAPFRAME TrapCtx;
90 BS3REGCTX Ctx;
91
92 /* make sure they're allocated */
93 Bs3MemZero(&Ctx, sizeof(Ctx));
94 Bs3MemZero(&TrapCtx, sizeof(TrapCtx));
95
96# if TMPL_MODE == BS3_MODE_PE16 \
97 || TMPL_MODE == BS3_MODE_PE16_32
98
99 Bs3RegCtxSave(&Ctx);
100 Ctx.rsp.u -= 0x80;
101 Ctx.rip.u = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_TssGateEsp_IntXx));
102# if TMPL_BITS == 32
103 BS3_DATA_NM(g_uBs3TrapEipHint) = Ctx.rip.u32;
104# endif
105 Bs3Printf("esp=%#llx\n", Ctx.rsp.u);
106
107 /*
108 * Check that the stuff works first.
109 */
110 if (Bs3TrapSetJmp(&TrapCtx))
111 {
112 Bs3RegCtxRestore(&Ctx, 0); /* (does not return) */
113 }
114 /* trapped. */
115 bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx, 2 /*int 80h*/, 0x80 /*bXcpt*/, 1/*bStep*/);
116 Bs3Printf("esp=%#llx\n", Ctx.rsp.u);
117
118Bs3Printf("trapped\n");
119
120
121# else
122 bRet = BS3TESTDOMODE_SKIPPED;
123# endif
124
125 /*
126 * Re-initialize the IDT.
127 */
128# if BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
129 Bs3Trap16Init();
130# elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
131 Bs3Trap32Init();
132# elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
133 Bs3Trap64Init();
134# endif
135
136 return bRet;
137}
138
139
140#endif /* BS3_INSTANTIATING_MODE */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette