VirtualBox

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

Last change on this file since 102163 was 102157, checked in by vboxsync, 16 months ago

ValKit/bs3kit,bs3-cpu-basic-3: Experimental support for loading a 2nd test image above 1MB (at 8MB by default). This should allow for larger testcases, esp. for 32-bit and 64-bit code. bugref:10371

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: bs3-rm-InitHighDlls.c 102157 2023-11-20 16:16:55Z vboxsync $ */
2/** @file
3 * BS3Kit - Initialize any high DLLs, 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 "bs3kit-linker.h"
44#include "bs3-cmn-memory.h"
45
46extern BS3HIGHDLLENTRY BS3_FAR_DATA BS3_DATA_NM(g_aBs3HighDllTable)[];
47extern BS3HIGHDLLENTRY BS3_FAR_DATA BS3_DATA_NM(g_Bs3HighDllTable_End);
48
49
50BS3_DECL_FAR(void) Bs3InitHighDlls_rm_far(void)
51{
52 unsigned const cHighDlls = (unsigned)(&g_Bs3HighDllTable_End - &g_aBs3HighDllTable[0]);
53 if ( cHighDlls > 0
54 && (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
55 {
56 unsigned i;
57
58 /*
59 * We need a buffer first of all. Using a 4K / PAGE_SIZE buffer let us
60 * share calculations and variables with the allocation code.
61 */
62 void BS3_FAR * const pvBuf = Bs3MemAlloc(BS3MEMKIND_REAL, _4K);
63 uint32_t const uFlatBuf = BS3_FP_REAL_TO_FLAT(pvBuf);
64 if (!pvBuf)
65 {
66 Bs3TestPrintf("Failed to allocate 4 KiB memory buffer for loading high DLL(s)!\n");
67 Bs3Shutdown();
68 }
69
70 /*
71 * Iterate the high DLL table and load it all into memory.
72 */
73 for (i = 0; i < cHighDlls; i++)
74 {
75 const char RT_FAR * const pszzStrings = (char RT_FAR *)&g_aBs3HighDllTable[i] + g_aBs3HighDllTable[i].offStrings;
76 const char RT_FAR * const pszFilename = &pszzStrings[g_aBs3HighDllTable[i].offFilename];
77 uint16_t cPagesToLoad = (uint16_t)(g_aBs3HighDllTable[i].cbLoaded / _4K);
78 uint16_t iPage;
79 Bs3Printf("Loading dll '%s' at %#RX32 ...", pszFilename, g_aBs3HighDllTable[i].uLoadAddr);
80
81 /* Allocate the memory taken by the DLL. */
82 iPage = Bs3SlabAllocFixed(&g_Bs3Mem4KUpperTiled.Core, g_aBs3HighDllTable[i].uLoadAddr, cPagesToLoad);
83 if (iPage == 0 || iPage == UINT16_MAX)
84 {
85 Bs3TestPrintf("Bs3SlabAllocFixed(,%#RX32, %#RX16) failed: %#RX16 (%s)\n",
86 g_aBs3HighDllTable[i].uLoadAddr, cPagesToLoad, iPage, pszFilename);
87 Bs3Shutdown();
88 }
89 /* We don't have any memory management above 16MB... */
90
91 /*
92 * Load the DLL. This is where we ASSUME real-mode as we need to
93 * use int13 for the actual reading. We temporarily restores the
94 * int13 entry in the interrupt table and loads the next chunk.
95 * Then we switch to 32-bit protected mode and copies the chunk
96 * from pvBuf and to the actual load address.
97 */
98 {
99 uint32_t uCurFlatLoadAddr;
100 uint32_t uCurSectorInImage;
101 uint16_t cSectorsPerCylinder;
102
103 /* Get the drive geometry. ASSUMES the bootsector hasn't been trashed yet! */
104 uint8_t const bDrive = ((BS3BOOTSECTOR RT_FAR *)BS3_FP_MAKE(0,0x7c00))->bBootDrv;
105 uint16_t uMaxCylinder = 0;
106 uint8_t uMaxHead = 0;
107 uint8_t uMaxSector = 0;
108 int rc;
109 rc = Bs3DiskQueryGeometry_rm(bDrive, &uMaxCylinder, &uMaxHead, &uMaxSector);
110 if (rc != 0)
111 {
112 Bs3TestPrintf("Bs3DiskQueryGeometry(%#x) failed: %#x\n", bDrive, rc);
113 Bs3Shutdown();
114 }
115 cSectorsPerCylinder = uMaxSector * ((uint16_t)uMaxHead + 1);
116 //Bs3TestPrintf("Bs3DiskQueryGeometry(%#x)-> C=%#x H=%#x S=%#x cSectorsPerCylinder=%#x\n",
117 // bDrive, uMaxCylinder, uMaxHead, uMaxSector, cSectorsPerCylinder);
118
119 /* Load the image. */
120 if (g_aBs3HighDllTable[i].cbInImage < g_aBs3HighDllTable[i].cbLoaded)
121 cPagesToLoad = (uint16_t)(g_aBs3HighDllTable[i].cbInImage / _4K);
122 uCurFlatLoadAddr = g_aBs3HighDllTable[i].uLoadAddr;
123 uCurSectorInImage = g_aBs3HighDllTable[i].offInImage / 512;
124 iPage = 0;
125 while (iPage < cPagesToLoad)
126 {
127 /* Read the next page. */
128 uint16_t const uCylinder = uCurSectorInImage / cSectorsPerCylinder;
129 uint16_t const uRemainder = uCurSectorInImage % cSectorsPerCylinder;
130 uint8_t const uHead = uRemainder / uMaxSector;
131 uint8_t const uSector = (uRemainder % uMaxSector) + 1;
132 //Bs3TestPrintf("Calling Bs3DiskRead(%#x,%#x,%#x,%#x,%#x,%p) [uCurSectorInImage=%RX32]\n",
133 // bDrive, uCylinder, uHead, uSector, (uint8_t)(_4K / 512), pvBuf, uCurSectorInImage);
134 rc = Bs3DiskRead_rm(bDrive, uCylinder, uHead, uSector, _4K / 512, pvBuf);
135 if (rc != 0)
136 {
137 Bs3TestPrintf("Bs3DiskRead(%#x,%#x,%#x,%#x,,) failed: %#x\n", bDrive, uCylinder, uHead, uSector, rc);
138 Bs3Shutdown();
139 }
140
141 /* Copy the page to where the DLL is being loaded. */
142 Bs3MemCopyFlat_rm_far(uCurFlatLoadAddr, uFlatBuf, _4K);
143 Bs3PrintChr('.');
144
145 /* Advance */
146 iPage += 1;
147 uCurFlatLoadAddr += _4K;
148 uCurSectorInImage += _4K / 512;
149 }
150 }
151 }
152
153 Bs3Printf("\n");
154 Bs3MemFree(pvBuf, _4K);
155 }
156}
157
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