VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: bs3-rm-InitAll.c 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * BS3Kit - Initialize all components, real mode.
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//#define BS3_USE_RM_TEXT_SEG 1
42#include "bs3kit-template-header.h"
43#include "bs3-cmn-test.h"
44#include "bs3kit-linker.h"
45#include <iprt/asm-amd64-x86.h>
46
47
48BS3_MODE_PROTO_NOSB(void, Bs3EnteredMode,(void));
49
50
51#ifdef BS3_WITH_LOAD_CHECKSUMS
52/**
53 * Verifies the base image checksum.
54 */
55static void bs3InitVerifyChecksum(void)
56{
57 BS3BOOTSECTOR const RT_FAR *pBootSector = (BS3BOOTSECTOR const RT_FAR *)BS3_FP_MAKE(0, 0x7c00);
58 uint32_t cSectors = pBootSector->cTotalSectors;
59 uint32_t const cSectorsSaved = cSectors;
60 uint16_t uCurSeg = (BS3_ADDR_LOAD >> 4); /* ASSUMES 16 byte aligned load address! */
61 uint32_t uChecksum = BS3_CALC_CHECKSUM_INITIAL_VALUE;
62 while (cSectors > 0)
63 {
64 uint8_t const *pbSrc = BS3_FP_MAKE(uCurSeg, 0);
65 if (cSectors >= _32K / 512)
66 {
67 uChecksum = Bs3CalcChecksum(uChecksum, pbSrc, _32K);
68 cSectors -= _32K / 512;
69 uCurSeg += 0x800;
70 }
71 else
72 {
73 uChecksum = Bs3CalcChecksum(uChecksum, pbSrc, (uint16_t)cSectors * 512);
74 break;
75 }
76 }
77 Bs3TestPrintf("base image checksum: %#RX32, expected %#RX32 over (%#RX32 sectors, uCurSeg=%#x) sizeof(size_t)=%d\n",
78 uChecksum, pBootSector->dwSerialNumber, cSectorsSaved, uCurSeg, sizeof(size_t));
79 if (uChecksum != pBootSector->dwSerialNumber)
80 {
81 Bs3TestPrintf("base image checksum mismatch: %#RX32, expected %#RX32 over %#RX32 sectors\n",
82 uChecksum, pBootSector->dwSerialNumber, cSectorsSaved);
83 Bs3Panic();
84 }
85}
86#endif /* BS3_WITH_LOAD_CHECKSUMS */
87
88
89BS3_DECL(void) Bs3InitAll_rm(void)
90{
91 uint8_t volatile BS3_FAR *pcTicksFlpyOff;
92
93#ifdef BS3_WITH_LOAD_CHECKSUMS
94 /* This must be done before we modify anything in the loaded image. */
95 bs3InitVerifyChecksum();
96#endif
97
98 /*
99 * Detect CPU first as the memory init code will otherwise use 386
100 * instrunctions and cause trouble on older CPUs.
101 */
102 Bs3CpuDetect_rm_far();
103 Bs3InitMemory_rm_far();
104 Bs3InitGdt_rm_far();
105
106#ifdef BS3_INIT_ALL_WITH_HIGH_DLLS
107 /*
108 * Load the high DLLs (if any) now, before we bugger up the PIC and
109 * replace the IVT.
110 */
111 Bs3InitHighDlls_rm_far();
112#endif
113
114 /*
115 * Before we disable all interrupts, try convince the BIOS to stop the
116 * floppy motor, as it is kind of disturbing when the floppy light remains
117 * on for the whole testcase execution.
118 */
119 ASMIntDisable(); /* (probably already disabled, but no guarantees) */
120 pcTicksFlpyOff = (uint8_t volatile BS3_FAR *)BS3_FP_MAKE(0x40, 0x40);
121 if (*pcTicksFlpyOff)
122 {
123 uint32_t volatile BS3_FAR *pcTicks = (uint32_t volatile BS3_FAR *)BS3_FP_MAKE(0x40, 0x6c);
124 uint32_t cInitialTicks;
125
126 *pcTicksFlpyOff = 1; /* speed up the countdown, don't want to wait for two seconds here. */
127 cInitialTicks = *pcTicks;
128 ASMIntEnable();
129
130 while (*pcTicks == cInitialTicks)
131 ASMHalt();
132 }
133 ASMIntDisable();
134 Bs3PicSetup(false /*fForcedReInit*/);
135
136 /*
137 * Initialize IDTs and such.
138 */
139 if (g_uBs3CpuDetected & BS3CPU_F_LONG_MODE)
140 Bs3Trap64Init();
141 if ((g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
142 Bs3Trap32Init();
143 if ((g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80286)
144 Bs3Trap16Init();
145 Bs3TrapRmV86Init();
146
147 /*
148 * Perform a real-mode enter to make some final environment adjustments
149 * (like installing our syscall).
150 */
151 Bs3EnteredMode_rm();
152}
153
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