VirtualBox

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

Last change on this file since 102270 was 102270, checked in by vboxsync, 12 months ago

bs3kit: Fixed some issues with loading of a fake 63.5 MB floppy. Added optional checksumming of the images we load (disabled by default, as it's slow in IEM). bugref:10371

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: bs3-rm-InitAll.c 102270 2023-11-23 00:40:38Z vboxsync $ */
2/** @file
3 * BS3Kit - Initialize all components, real mode.
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//#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();
103Bs3TestPrintf("#1\n");
104 Bs3InitMemory_rm_far();
105Bs3TestPrintf("#2\n");
106 Bs3InitGdt_rm_far();
107Bs3TestPrintf("#3\n");
108
109#ifdef BS3_INIT_ALL_WITH_HIGH_DLLS
110 /*
111 * Load the high DLLs (if any) now, before we bugger up the PIC and
112 * replace the IVT.
113 */
114 Bs3InitHighDlls_rm_far();
115#endif
116Bs3TestPrintf("#4\n");
117
118 /*
119 * Before we disable all interrupts, try convince the BIOS to stop the
120 * floppy motor, as it is kind of disturbing when the floppy light remains
121 * on for the whole testcase execution.
122 */
123 ASMIntDisable(); /* (probably already disabled, but no guarantees) */
124 pcTicksFlpyOff = (uint8_t volatile BS3_FAR *)BS3_FP_MAKE(0x40, 0x40);
125 if (*pcTicksFlpyOff)
126 {
127 uint32_t volatile BS3_FAR *pcTicks = (uint32_t volatile BS3_FAR *)BS3_FP_MAKE(0x40, 0x6c);
128 uint32_t cInitialTicks;
129
130 *pcTicksFlpyOff = 1; /* speed up the countdown, don't want to wait for two seconds here. */
131 cInitialTicks = *pcTicks;
132 ASMIntEnable();
133
134 while (*pcTicks == cInitialTicks)
135 ASMHalt();
136 }
137 ASMIntDisable();
138 Bs3PicSetup(false /*fForcedReInit*/);
139
140 /*
141 * Initialize IDTs and such.
142 */
143 if (g_uBs3CpuDetected & BS3CPU_F_LONG_MODE)
144 Bs3Trap64Init();
145 if ((g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
146 Bs3Trap32Init();
147 if ((g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80286)
148 Bs3Trap16Init();
149 Bs3TrapRmV86Init();
150
151 /*
152 * Perform a real-mode enter to make some final environment adjustments
153 * (like installing our syscall).
154 */
155 Bs3EnteredMode_rm();
156}
157
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