1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox basic PC devices:
|
---|
4 | * PC architechture device
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * If you received this file as part of a commercial VirtualBox
|
---|
19 | * distribution, then only the terms of your commercial VirtualBox
|
---|
20 | * license agreement apply instead of the previous paragraph.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP LOG_GROUP_DEV_PC_ARCH
|
---|
27 | #include <VBox/pdm.h>
|
---|
28 | #include <VBox/mm.h>
|
---|
29 |
|
---|
30 | #include <VBox/log.h>
|
---|
31 | #include <iprt/assert.h>
|
---|
32 | #include <VBox/err.h>
|
---|
33 |
|
---|
34 | #include <string.h>
|
---|
35 |
|
---|
36 | #include "Builtins.h"
|
---|
37 |
|
---|
38 |
|
---|
39 | /*******************************************************************************
|
---|
40 | * Structures and Typedefs *
|
---|
41 | *******************************************************************************/
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * PC Bios instance data structure.
|
---|
45 | */
|
---|
46 | typedef struct DEVPCARCH
|
---|
47 | {
|
---|
48 | /** Pointer back to the device instance. */
|
---|
49 | PPDMDEVINS pDevIns;
|
---|
50 | } DEVPCARCH, *PDEVPCARCH;
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Port I/O Handler for math coprocessor IN operations.
|
---|
56 | *
|
---|
57 | * @returns VBox status code.
|
---|
58 | *
|
---|
59 | * @param pDevIns The device instance.
|
---|
60 | * @param pvUser User argument - ignored.
|
---|
61 | * @param uPort Port number used for the IN operation.
|
---|
62 | * @param pu32 Where to store the result.
|
---|
63 | * @param cb Number of bytes read.
|
---|
64 | */
|
---|
65 | static DECLCALLBACK(int) pcarchIOPortFPURead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
|
---|
66 | {
|
---|
67 | int rc;
|
---|
68 | NOREF(pvUser); NOREF(pDevIns); NOREF(pu32);
|
---|
69 | rc = PDMDeviceDBGFStop(pDevIns, PDM_SRC_POS, "Port=%#x cb=%d\n", Port, cb);
|
---|
70 | if (rc == VINF_SUCCESS)
|
---|
71 | rc = VERR_IOM_IOPORT_UNUSED;
|
---|
72 | return rc;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Port I/O Handler for math coprocessor OUT operations.
|
---|
77 | *
|
---|
78 | * @returns VBox status code.
|
---|
79 | *
|
---|
80 | * @param pDevIns The device instance.
|
---|
81 | * @param pvUser User argument - ignored.
|
---|
82 | * @param uPort Port number used for the IN operation.
|
---|
83 | * @param u32 The value to output.
|
---|
84 | * @param cb The value size in bytes.
|
---|
85 | * @todo Add IGNNE support.
|
---|
86 | */
|
---|
87 | static DECLCALLBACK(int) pcarchIOPortFPUWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
|
---|
88 | {
|
---|
89 | int rc = VINF_SUCCESS;
|
---|
90 | NOREF(pvUser);
|
---|
91 | if (cb == 1)
|
---|
92 | {
|
---|
93 | switch (Port)
|
---|
94 | {
|
---|
95 | /*
|
---|
96 | * Clear busy latch.
|
---|
97 | */
|
---|
98 | case 0xf0:
|
---|
99 | Log2(("PCARCH: FPU Clear busy latch u32=%#x\n", u32));
|
---|
100 | /* This is triggered when booting Knoppix (3.7) */
|
---|
101 | #if 0
|
---|
102 | if (!u32)
|
---|
103 | rc = PDMDeviceDBGFStop(pDevIns, PDM_SRC_POS, "Port=%#x cb=%d u32=%#x\n", Port, cb, u32);
|
---|
104 | #endif
|
---|
105 | /* pDevIns->pDevHlp->pfnPICSetIrq(pDevIns, 13, 0); */
|
---|
106 | break;
|
---|
107 |
|
---|
108 | /* Reset. */
|
---|
109 | case 0xf1:
|
---|
110 | Log2(("PCARCH: FPU Reset cb=%d u32=%#x\n", Port, cb, u32));
|
---|
111 | /** @todo figure out what the difference between FPU ports 0xf0 and 0xf1 are... */
|
---|
112 | /* pDevIns->pDevHlp->pfnPICSetIrq(pDevIns, 13, 0); */
|
---|
113 | break;
|
---|
114 |
|
---|
115 | /* opcode transfers */
|
---|
116 | case 0xf8:
|
---|
117 | case 0xfa:
|
---|
118 | case 0xfc:
|
---|
119 | default:
|
---|
120 | rc = PDMDeviceDBGFStop(pDevIns, PDM_SRC_POS, "Port=%#x cb=%d u32=%#x\n", Port, cb, u32);
|
---|
121 | break;
|
---|
122 | }
|
---|
123 | /* this works better, but probably not entirely correct. */
|
---|
124 | PDMDevHlpISASetIrq(pDevIns, 13, 0);
|
---|
125 | }
|
---|
126 | else
|
---|
127 | rc = PDMDeviceDBGFStop(pDevIns, PDM_SRC_POS, "Port=%#x cb=%d u32=%#x\n", Port, cb, u32);
|
---|
128 | return rc;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Port I/O Handler for PS/2 system control port A IN operations.
|
---|
134 | *
|
---|
135 | * @returns VBox status code.
|
---|
136 | *
|
---|
137 | * @param pDevIns The device instance.
|
---|
138 | * @param pvUser User argument - ignored.
|
---|
139 | * @param uPort Port number used for the IN operation.
|
---|
140 | * @param pu32 Where to store the result.
|
---|
141 | * @param cb Number of bytes read.
|
---|
142 | *
|
---|
143 | * @todo Check if the A20 enable/disable method implemented here in any way
|
---|
144 | * should cooperate with the one implemented in the PS/2 keyboard device.
|
---|
145 | * This probably belongs together in the PS/2 keyboard device (since that
|
---|
146 | * is where the "port B" mentioned by Ralph Brown is implemented).
|
---|
147 | *
|
---|
148 | * @remark Ralph Brown and friends have this to say about this port:
|
---|
149 | *
|
---|
150 | * 0092 RW PS/2 system control port A (port B is at PORT 0061h) (see #P0415)
|
---|
151 | *
|
---|
152 | * Bitfields for PS/2 system control port A:
|
---|
153 | * Bit(s) Description (Table P0415)
|
---|
154 | * 7-6 any bit set to 1 turns activity light on
|
---|
155 | * 5 unused
|
---|
156 | * 4 watchdog timout occurred
|
---|
157 | * 3 =0 RTC/CMOS security lock (on password area) unlocked
|
---|
158 | * =1 CMOS locked (done by POST)
|
---|
159 | * 2 unused
|
---|
160 | * 1 A20 is active
|
---|
161 | * 0 =0 system reset or write
|
---|
162 | * =1 pulse alternate reset pin (high-speed alternate CPU reset)
|
---|
163 | * Notes: once set, bit 3 may only be cleared by a power-on reset
|
---|
164 | * on at least the C&T 82C235, bit 0 remains set through a CPU reset to
|
---|
165 | * allow the BIOS to determine the reset method
|
---|
166 | * on the PS/2 30-286 & "Tortuga" the INT 15h/87h memory copy does
|
---|
167 | * not use this port for A20 control, but instead uses the keyboard
|
---|
168 | * controller (8042). Reportedly this may cause the system to crash
|
---|
169 | * when access to the 8042 is disabled in password server mode
|
---|
170 | * (see #P0398).
|
---|
171 | * SeeAlso: #P0416,#P0417,MSR 00001000h
|
---|
172 | */
|
---|
173 | static DECLCALLBACK(int) pcarchIOPortPS2SysControlPortARead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
|
---|
174 | {
|
---|
175 | if (cb == 1)
|
---|
176 | {
|
---|
177 | *pu32 = PDMDevHlpA20IsEnabled(pDevIns) << 1;
|
---|
178 | return VINF_SUCCESS;
|
---|
179 | }
|
---|
180 | return PDMDeviceDBGFStop(pDevIns, PDM_SRC_POS, "Port=%#x cb=%d\n", Port, cb);
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Port I/O Handler for PS/2 system control port A OUT operations.
|
---|
186 | *
|
---|
187 | * @returns VBox status code.
|
---|
188 | *
|
---|
189 | * @param pDevIns The device instance.
|
---|
190 | * @param pvUser User argument - ignored.
|
---|
191 | * @param uPort Port number used for the IN operation.
|
---|
192 | * @param u32 The value to output.
|
---|
193 | * @param cb The value size in bytes.
|
---|
194 | * @see Remark and todo of pcarchIOPortPS2SysControlPortARead().
|
---|
195 | */
|
---|
196 | static DECLCALLBACK(int) pcarchIOPortPS2SysControlPortAWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
|
---|
197 | {
|
---|
198 | NOREF(pvUser);
|
---|
199 | if (cb == 1)
|
---|
200 | {
|
---|
201 | /*
|
---|
202 | * Fast reset?
|
---|
203 | */
|
---|
204 | if (u32 & 1)
|
---|
205 | return PDMDevHlpVMReset(pDevIns);
|
---|
206 |
|
---|
207 | /*
|
---|
208 | * A20 is the only thing we care about of the other stuff.
|
---|
209 | */
|
---|
210 | PDMDevHlpA20Set(pDevIns, !!(u32 & 2));
|
---|
211 | return VINF_SUCCESS;
|
---|
212 | }
|
---|
213 | return PDMDeviceDBGFStop(pDevIns, PDM_SRC_POS, "Port=%#x cb=%d u32=%#x\n", Port, cb, u32);
|
---|
214 | }
|
---|
215 |
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Construct a device instance for a VM.
|
---|
219 | *
|
---|
220 | * @returns VBox status.
|
---|
221 | * @param pDevIns The device instance data.
|
---|
222 | * If the registration structure is needed, pDevIns->pDevReg points to it.
|
---|
223 | * @param iInstance Instance number. Use this to figure out which registers and such to use.
|
---|
224 | * The device number is also found in pDevIns->iInstance, but since it's
|
---|
225 | * likely to be freqently used PDM passes it as parameter.
|
---|
226 | * @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
|
---|
227 | * of the device instance. It's also found in pDevIns->pCfgHandle, but like
|
---|
228 | * iInstance it's expected to be used a bit in this function.
|
---|
229 | */
|
---|
230 | static DECLCALLBACK(int) pcarchConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfgHandle)
|
---|
231 | {
|
---|
232 | PDEVPCARCH pData = PDMINS2DATA(pDevIns, PDEVPCARCH);
|
---|
233 | int rc;
|
---|
234 | Assert(iInstance == 0);
|
---|
235 |
|
---|
236 | /*
|
---|
237 | * Validate configuration.
|
---|
238 | */
|
---|
239 | if (!CFGMR3AreValuesValid(pCfgHandle, "\0"))
|
---|
240 | return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
|
---|
241 |
|
---|
242 | /*
|
---|
243 | * Init the data.
|
---|
244 | */
|
---|
245 | pData->pDevIns = pDevIns;
|
---|
246 |
|
---|
247 | /*
|
---|
248 | * Register I/O Ports
|
---|
249 | */
|
---|
250 | rc = PDMDevHlpIOPortRegister(pDevIns, 0xF0, 0x10, NULL, pcarchIOPortFPUWrite, pcarchIOPortFPURead, NULL, NULL, "Math Co-Processor (DOS/OS2 mode)");
|
---|
251 | if (VBOX_FAILURE(rc))
|
---|
252 | return rc;
|
---|
253 | rc = PDMDevHlpIOPortRegister(pDevIns, 0x92, 1, NULL, pcarchIOPortPS2SysControlPortAWrite, pcarchIOPortPS2SysControlPortARead, NULL, NULL, "PS/2 system control port A (A20 and more)");
|
---|
254 | if (VBOX_FAILURE(rc))
|
---|
255 | return rc;
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * Reserve ROM/MMIO areas:
|
---|
259 | * 1. 0x000a0000-0x000fffff
|
---|
260 | * 2. 0xfff80000-0xffffffff
|
---|
261 | */
|
---|
262 | rc = PDMDevHlpPhysReserve(pDevIns, 0x000a0000, 0x50000, "Low ROM Region");
|
---|
263 | if (VBOX_FAILURE(rc))
|
---|
264 | return rc;
|
---|
265 | rc = PDMDevHlpPhysReserve(pDevIns, 0xfff80000, 0x80000, "High ROM Region");
|
---|
266 | if (VBOX_FAILURE(rc))
|
---|
267 | return rc;
|
---|
268 |
|
---|
269 | return VINF_SUCCESS;
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | /**
|
---|
274 | * The device registration structure.
|
---|
275 | */
|
---|
276 | const PDMDEVREG g_DevicePcArch =
|
---|
277 | {
|
---|
278 | /* u32Version */
|
---|
279 | PDM_DEVREG_VERSION,
|
---|
280 | /* szDeviceName */
|
---|
281 | "pcarch",
|
---|
282 | /* szGCMod */
|
---|
283 | "",
|
---|
284 | /* szR0Mod */
|
---|
285 | "",
|
---|
286 | /* pszDescription */
|
---|
287 | "PC Architecture Device",
|
---|
288 | /* fFlags */
|
---|
289 | PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32,
|
---|
290 | /* fClass */
|
---|
291 | PDM_DEVREG_CLASS_ARCH,
|
---|
292 | /* cMaxInstances */
|
---|
293 | 1,
|
---|
294 | /* cbInstance */
|
---|
295 | sizeof(DEVPCARCH),
|
---|
296 | /* pfnConstruct */
|
---|
297 | pcarchConstruct,
|
---|
298 | /* pfnDestruct */
|
---|
299 | NULL,
|
---|
300 | /* pfnRelocate */
|
---|
301 | NULL,
|
---|
302 | /* pfnIOCtl */
|
---|
303 | NULL,
|
---|
304 | /* pfnPowerOn */
|
---|
305 | NULL,
|
---|
306 | /* pfnReset */
|
---|
307 | NULL,
|
---|
308 | /* pfnSuspend */
|
---|
309 | NULL,
|
---|
310 | /* pfnResume */
|
---|
311 | NULL,
|
---|
312 | /* pfnAttach */
|
---|
313 | NULL,
|
---|
314 | /* pfnDetach */
|
---|
315 | NULL,
|
---|
316 | /* pfnQueryInterface. */
|
---|
317 | NULL,
|
---|
318 | /* pfnInitComplete. */
|
---|
319 | NULL
|
---|
320 | };
|
---|
321 |
|
---|