VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/DevPcArch.cpp@ 92192

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

VMM/MM,DevPcArch: Split the base RAM allocation into conventional (< 640KB) and extended (>= 1MB) ranges, leaving the UMA w/o RAM range backing. This will fit better with NEM, esp. on linux. bugref:10122

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 11.4 KB
Line 
1/* $Id: DevPcArch.cpp 92192 2021-11-03 14:44:45Z vboxsync $ */
2/** @file
3 * DevPcArch - PC Architecture Device.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEV_PC_ARCH
23#include <VBox/vmm/pdmdev.h>
24#include <VBox/vmm/mm.h>
25#include <VBox/vmm/pgm.h>
26#include <VBox/log.h>
27#include <VBox/err.h>
28#include <iprt/assert.h>
29#include <iprt/string.h>
30
31#include "VBoxDD.h"
32
33
34/*********************************************************************************************************************************
35* Structures and Typedefs *
36*********************************************************************************************************************************/
37
38/**
39 * PC Bios instance data structure.
40 */
41typedef struct DEVPCARCH
42{
43 /** Pointer back to the device instance. */
44 PPDMDEVINS pDevIns;
45} DEVPCARCH, *PDEVPCARCH;
46
47
48
49/**
50 * @callback_method_impl{FNIOMIOPORTNEWIN, Math coprocessor.}
51 * @note offPort is absolute
52 */
53static DECLCALLBACK(VBOXSTRICTRC)
54pcarchIOPortFPURead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
55{
56 int rc;
57 NOREF(pvUser); NOREF(pDevIns); NOREF(pu32);
58 rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "Port=%#x cb=%d\n", offPort, cb);
59 if (rc == VINF_SUCCESS)
60 rc = VERR_IOM_IOPORT_UNUSED;
61 return rc;
62}
63
64/**
65 * @callback_method_impl{FNIOMIOPORTNEWOUT, Math coprocessor.}
66 * @note offPort is absolute
67 * @todo Add IGNNE support.
68 */
69static DECLCALLBACK(VBOXSTRICTRC)
70pcarchIOPortFPUWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
71{
72 int rc = VINF_SUCCESS;
73 NOREF(pvUser);
74 if (cb == 1)
75 {
76 switch (offPort)
77 {
78 /*
79 * Clear busy latch.
80 */
81 case 0xf0:
82 Log2(("PCARCH: FPU Clear busy latch u32=%#x\n", u32));
83/* This is triggered when booting Knoppix (3.7) */
84#if 0
85 if (!u32)
86 rc = PDMDeviceDBGFStop(pDevIns, RT_SRC_POS, "Port=%#x cb=%d u32=%#x\n", offPort, cb, u32);
87#endif
88 /* pDevIns->pHlp->pfnPICSetIrq(pDevIns, 13, 0); */
89 break;
90
91 /* Reset. */
92 case 0xf1:
93 Log2(("PCARCH: FPU Reset cb=%d u32=%#x\n", cb, u32));
94 /** @todo figure out what the difference between FPU ports 0xf0 and 0xf1 are... */
95 /* pDevIns->pHlp->pfnPICSetIrq(pDevIns, 13, 0); */
96 break;
97
98 /* opcode transfers */
99 case 0xf8:
100 case 0xfa:
101 case 0xfc:
102 default:
103 rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "Port=%#x cb=%d u32=%#x\n", offPort, cb, u32);
104 break;
105 }
106 /* this works better, but probably not entirely correct. */
107 PDMDevHlpISASetIrq(pDevIns, 13, 0);
108 }
109 else
110 rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "Port=%#x cb=%d u32=%#x\n", offPort, cb, u32);
111 return rc;
112}
113
114
115/**
116 * @callback_method_impl{FNIOMIOPORTIN, PS/2 system control port A.}
117 *
118 * @todo Check if the A20 enable/disable method implemented here in any way
119 * should cooperate with the one implemented in the PS/2 keyboard device.
120 * This probably belongs together in the PS/2 keyboard device (since that
121 * is where the "port B" mentioned by Ralph Brown is implemented).
122 *
123 * @remark Ralph Brown and friends have this to say about this port:
124 *
125 * @verbatim
1260092 RW PS/2 system control port A (port B is at PORT 0061h) (see #P0415)
127
128Bitfields for PS/2 system control port A:
129Bit(s) Description (Table P0415)
130 7-6 any bit set to 1 turns activity light on
131 5 unused
132 4 watchdog timout occurred
133 3 =0 RTC/CMOS security lock (on password area) unlocked
134 =1 CMOS locked (done by POST)
135 2 unused
136 1 A20 is active
137 0 =0 system reset or write
138 =1 pulse alternate reset pin (high-speed alternate CPU reset)
139Notes: once set, bit 3 may only be cleared by a power-on reset
140 on at least the C&T 82C235, bit 0 remains set through a CPU reset to
141 allow the BIOS to determine the reset method
142 on the PS/2 30-286 & "Tortuga" the INT 15h/87h memory copy does
143 not use this port for A20 control, but instead uses the keyboard
144 controller (8042). Reportedly this may cause the system to crash
145 when access to the 8042 is disabled in password server mode
146 (see #P0398).
147SeeAlso: #P0416,#P0417,MSR 00001000h
148 * @endverbatim
149 * @note offPort is absolute
150 */
151static DECLCALLBACK(VBOXSTRICTRC)
152pcarchIOPortPS2SysControlPortARead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
153{
154 RT_NOREF1(pvUser);
155 if (cb == 1)
156 {
157 *pu32 = PDMDevHlpA20IsEnabled(pDevIns) << 1;
158 return VINF_SUCCESS;
159 }
160 return PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "Port=%#x cb=%d\n", offPort, cb);
161}
162
163
164/**
165 * @callback_method_impl{FNIOMIOPORTOUT, PS/2 system control port A.}
166 * @see Remark and todo of pcarchIOPortPS2SysControlPortARead().
167 * @note offPort is absolute
168 */
169static DECLCALLBACK(VBOXSTRICTRC)
170pcarchIOPortPS2SysControlPortAWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
171{
172 NOREF(pvUser);
173 if (cb == 1)
174 {
175 /*
176 * Fast reset?
177 */
178 if (u32 & 1)
179 {
180 LogRel(("Reset initiated by system port A\n"));
181 return PDMDevHlpVMReset(pDevIns, PDMVMRESET_F_PORT_A);
182 }
183
184 /*
185 * A20 is the only thing we care about of the other stuff.
186 */
187 PDMDevHlpA20Set(pDevIns, !!(u32 & 2));
188 return VINF_SUCCESS;
189 }
190 return PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "Port=%#x cb=%d u32=%#x\n", offPort, cb, u32);
191}
192
193
194/**
195 * @callback_method_impl{FNIOMMMIONEWWRITE, Ignores writes to the reserved memory.}
196 * @note off is an absolute address.
197 */
198static DECLCALLBACK(VBOXSTRICTRC)
199pcarchReservedMemoryWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
200{
201 Log2(("pcarchReservedMemoryRead: %#RGp LB %#x %.*Rhxs\n", off, cb, RT_MIN(cb, 16), pv));
202 RT_NOREF(pDevIns, pvUser, off, pv, cb);
203 return VINF_SUCCESS;
204}
205
206
207/**
208 * @callback_method_impl{FNIOMMMIONEWREAD, The reserved memory reads as 0xff.}
209 * @note off is an absolute address.
210 */
211static DECLCALLBACK(VBOXSTRICTRC)
212pcarchReservedMemoryRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
213{
214 Log2(("pcarchReservedMemoryRead: %#RGp LB %#x\n", off, cb));
215 RT_NOREF(pDevIns, pvUser, off);
216 memset(pv, 0xff, cb);
217 return VINF_SUCCESS;
218}
219
220
221/**
222 * @interface_method_impl{PDMDEVREG,pfnConstruct}
223 */
224static DECLCALLBACK(int) pcarchConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
225{
226 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
227 PDEVPCARCH pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPCARCH);
228 int rc;
229 RT_NOREF(iInstance, pCfg);
230 Assert(iInstance == 0);
231
232 /*
233 * Validate configuration.
234 */
235 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "", "");
236
237 /*
238 * Init the data.
239 */
240 pThis->pDevIns = pDevIns;
241
242 /*
243 * Register I/O Ports
244 */
245 IOMIOPORTHANDLE hIoPorts;
246 rc = PDMDevHlpIoPortCreateFlagsAndMap(pDevIns, 0xf0 /*uPort*/, 0x10 /*cPorts*/, IOM_IOPORT_F_ABS,
247 pcarchIOPortFPUWrite, pcarchIOPortFPURead,
248 "Math Co-Processor (DOS/OS2 mode)", NULL /*paExtDescs*/, &hIoPorts);
249 AssertRCReturn(rc, rc);
250 rc = PDMDevHlpIoPortCreateFlagsAndMap(pDevIns, 0x92 /*uPort*/, 1 /*cPorts*/, IOM_IOPORT_F_ABS,
251 pcarchIOPortPS2SysControlPortAWrite, pcarchIOPortPS2SysControlPortARead,
252 "PS/2 system control port A (A20 and more)", NULL /*paExtDescs*/, &hIoPorts);
253 AssertRCReturn(rc, rc);
254
255 return VINF_SUCCESS;
256}
257
258
259/**
260 * The device registration structure.
261 */
262const PDMDEVREG g_DevicePcArch =
263{
264 /* .u32Version = */ PDM_DEVREG_VERSION,
265 /* .uReserved0 = */ 0,
266 /* .szName = */ "pcarch",
267 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
268 /* .fClass = */ PDM_DEVREG_CLASS_ARCH,
269 /* .cMaxInstances = */ 1,
270 /* .uSharedVersion = */ 42,
271 /* .cbInstanceShared = */ sizeof(DEVPCARCH),
272 /* .cbInstanceCC = */ 0,
273 /* .cbInstanceRC = */ 0,
274 /* .cMaxPciDevices = */ 0,
275 /* .cMaxMsixVectors = */ 0,
276 /* .pszDescription = */ "PC Architecture Device",
277#if defined(IN_RING3)
278 /* .pszRCMod = */ "",
279 /* .pszR0Mod = */ "",
280 /* .pfnConstruct = */ pcarchConstruct,
281 /* .pfnDestruct = */ NULL,
282 /* .pfnRelocate = */ NULL,
283 /* .pfnMemSetup = */ NULL,
284 /* .pfnPowerOn = */ NULL,
285 /* .pfnReset = */ NULL,
286 /* .pfnSuspend = */ NULL,
287 /* .pfnResume = */ NULL,
288 /* .pfnAttach = */ NULL,
289 /* .pfnDetach = */ NULL,
290 /* .pfnQueryInterface = */ NULL,
291 /* .pfnInitComplete = */ NULL,
292 /* .pfnPowerOff = */ NULL,
293 /* .pfnSoftReset = */ NULL,
294 /* .pfnReserved0 = */ NULL,
295 /* .pfnReserved1 = */ NULL,
296 /* .pfnReserved2 = */ NULL,
297 /* .pfnReserved3 = */ NULL,
298 /* .pfnReserved4 = */ NULL,
299 /* .pfnReserved5 = */ NULL,
300 /* .pfnReserved6 = */ NULL,
301 /* .pfnReserved7 = */ NULL,
302#elif defined(IN_RING0)
303 /* .pfnEarlyConstruct = */ NULL,
304 /* .pfnConstruct = */ NULL,
305 /* .pfnDestruct = */ NULL,
306 /* .pfnFinalDestruct = */ NULL,
307 /* .pfnRequest = */ NULL,
308 /* .pfnReserved0 = */ NULL,
309 /* .pfnReserved1 = */ NULL,
310 /* .pfnReserved2 = */ NULL,
311 /* .pfnReserved3 = */ NULL,
312 /* .pfnReserved4 = */ NULL,
313 /* .pfnReserved5 = */ NULL,
314 /* .pfnReserved6 = */ NULL,
315 /* .pfnReserved7 = */ NULL,
316#elif defined(IN_RC)
317 /* .pfnConstruct = */ NULL,
318 /* .pfnReserved0 = */ NULL,
319 /* .pfnReserved1 = */ NULL,
320 /* .pfnReserved2 = */ NULL,
321 /* .pfnReserved3 = */ NULL,
322 /* .pfnReserved4 = */ NULL,
323 /* .pfnReserved5 = */ NULL,
324 /* .pfnReserved6 = */ NULL,
325 /* .pfnReserved7 = */ NULL,
326#else
327# error "Not in IN_RING3, IN_RING0 or IN_RC!"
328#endif
329 /* .u32VersionEnd = */ PDM_DEVREG_VERSION
330};
331
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