1 | /* $Id: bs3-shutdown.c 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - Shutdown VM from PE16 - proof of concept (BS3Kit).
|
---|
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/assert.h>
|
---|
33 | #include <iprt/asm-amd64-x86.h>
|
---|
34 |
|
---|
35 | AssertCompileSize(uint16_t, 2);
|
---|
36 | AssertCompileSize(uint32_t, 4);
|
---|
37 | AssertCompileSize(uint64_t, 8);
|
---|
38 |
|
---|
39 | extern uint16_t ASMGetMsw();
|
---|
40 | #pragma aux ASMGetMsw = \
|
---|
41 | ".286" \
|
---|
42 | "smsw ax" \
|
---|
43 | value [ax] \
|
---|
44 | modify exact;
|
---|
45 |
|
---|
46 | extern void ASMSetMsw(uint16_t uMsw);
|
---|
47 | #pragma aux ASMSetMsw = \
|
---|
48 | ".286p" \
|
---|
49 | "lmsw ax" \
|
---|
50 | parm [ax] \
|
---|
51 | modify exact;
|
---|
52 |
|
---|
53 | /* Just a sample. */
|
---|
54 | BS3_DECL(void) Main_pe16(void)
|
---|
55 | {
|
---|
56 | uint16_t uMsw = ASMGetMsw();
|
---|
57 | Bs3Printf("msw=%#x cr0=%RX32 g_uBs3CpuDetected=%#x\n", uMsw, ASMGetCR0(), g_uBs3CpuDetected);
|
---|
58 | Bs3Printf("cr2=%RX32 cr3=%RX32\n", ASMGetCR2(), ASMGetCR3());
|
---|
59 | ASMSetMsw(X86_CR0_PE);
|
---|
60 | Bs3Printf("lmsw(PE) => msw=%#x cr0=%RX32\n", ASMGetMsw(), ASMGetCR0());
|
---|
61 | ASMSetMsw(UINT16_MAX);
|
---|
62 | Bs3Printf("lmsw(0xffff) => msw=%#x cr0=%RX32\n", ASMGetMsw(), ASMGetCR0());
|
---|
63 | ASMSetCR0(X86_CR0_PE);
|
---|
64 | Bs3Printf("ASMSetCR0(X86_CR0_PE) => msw=%#x cr0=%RX32\n", ASMGetMsw(), ASMGetCR0());
|
---|
65 | ASMSetCR0(UINT32_C(0x7fffffff));
|
---|
66 | Bs3Printf("ASMSetCR0(0x7fffffff) => msw=%#x cr0=%RX32\n", ASMGetMsw(), ASMGetCR0());
|
---|
67 |
|
---|
68 | Bs3TestInit("bs3-shutdown");
|
---|
69 | Bs3TestPrintf("detected cpu: %#x\n", g_uBs3CpuDetected);
|
---|
70 | #if 1
|
---|
71 | ASMHalt();
|
---|
72 | #else
|
---|
73 | Bs3Shutdown();
|
---|
74 | #endif
|
---|
75 | return;
|
---|
76 | }
|
---|
77 |
|
---|