VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3-apic-1.c@ 92580

Last change on this file since 92580 was 92580, checked in by vboxsync, 3 years ago

ValKit/bs3-apic-1: Just some extremely basic APIC checking. bugref:9044

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: bs3-apic-1.c 92580 2021-11-24 03:06:41Z vboxsync $ */
2/** @file
3 * BS3Kit - bs3-apic-1, 16-bit C code.
4 */
5
6/*
7 * Copyright (C) 2007-2021 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#include <iprt/x86.h>
34
35
36BS3_DECL(void) Main_rm()
37{
38 Bs3InitAll_rm();
39 Bs3TestInit("bs3-apic-1");
40 Bs3TestPrintf("g_uBs3CpuDetected=%#x\n", g_uBs3CpuDetected);
41
42 /*
43 * Check that there is an APIC
44 */
45 if (!(g_uBs3CpuDetected & BS3CPU_F_CPUID))
46 Bs3TestFailed("CPUID not supported");
47 else if (!(ASMCpuId_EDX(1) & X86_CPUID_FEATURE_EDX_MSR))
48 Bs3TestFailed("No APIC: RDMSR/WRMSR not supported!");
49 else if (!(ASMCpuId_EDX(1) & X86_CPUID_FEATURE_EDX_APIC))
50 Bs3TestFailed("No APIC: CPUID(1) does not have EDX_APIC set!\n");
51 else
52 {
53 uint64_t uApicBase2;
54 uint64_t uApicBase = ASMRdMsr(MSR_IA32_APICBASE);
55 Bs3TestPrintf("MSR_IA32_APICBASE=%#RX64 %s, %s cpu%s\n",
56 uApicBase,
57 uApicBase & MSR_IA32_APICBASE_EN ? "enabled" : "disabled",
58 uApicBase & MSR_IA32_APICBASE_EXTD ? "bootstrap" : "slave",
59 uApicBase & MSR_IA32_APICBASE_EXTD ? ", x2apic" : "",
60 (uApicBase & X86_PAGE_4K_BASE_MASK) == MSR_IA32_APICBASE_ADDR ? ", !non-default address!" : "");
61
62 /* Disable the APIC (according to wiki.osdev.org/APIC, disabling the
63 APIC could require a CPU reset to re-enable it, but it works for us): */
64 ASMWrMsr(MSR_IA32_APICBASE, uApicBase & ~(uint64_t)MSR_IA32_APICBASE_EN);
65 uApicBase2 = ASMRdMsr(MSR_IA32_APICBASE);
66 if (uApicBase2 == (uApicBase & ~(uint64_t)MSR_IA32_APICBASE_EN))
67 Bs3TestPrintf("Disabling worked.\n");
68 else
69 Bs3TestFailedF("Disabling the APIC did not work (%#RX64)", uApicBase2);
70
71 /* Enabling the APIC: */
72 ASMWrMsr(MSR_IA32_APICBASE, uApicBase | MSR_IA32_APICBASE_EN);
73 uApicBase2 = ASMRdMsr(MSR_IA32_APICBASE);
74 if (uApicBase2 == (uApicBase | MSR_IA32_APICBASE_EN))
75 Bs3TestPrintf("Enabling worked.\n");
76 else
77 Bs3TestFailedF("Enabling the APIC did not work (%#RX64)", uApicBase2);
78 }
79
80 Bs3TestTerm();
81 Bs3Shutdown();
82}
83
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