1 | /* $Id: VBoxBFE.cpp 33590 2010-10-29 08:55:09Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Basic Frontend (BFE): VBoxBFE main routines.
|
---|
4 | *
|
---|
5 | * VBoxBFE is a limited frontend that sits directly on the Virtual Machine
|
---|
6 | * Manager (VMM) and does _not_ use COM to communicate.
|
---|
7 | * On Linux and Windows, VBoxBFE is based on SDL; on L4 it's based on the
|
---|
8 | * L4 console. Much of the code has been copied over from the other frontends
|
---|
9 | * in VBox/Main/ and src/Frontends/VBoxSDL/.
|
---|
10 | */
|
---|
11 |
|
---|
12 | /*
|
---|
13 | * Copyright (C) 2006-2009 Oracle Corporation
|
---|
14 | *
|
---|
15 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
16 | * available from http://www.virtualbox.org. This file is free software;
|
---|
17 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
18 | * General Public License (GPL) as published by the Free Software
|
---|
19 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
20 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
21 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*******************************************************************************
|
---|
25 | * Header Files *
|
---|
26 | *******************************************************************************/
|
---|
27 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
28 |
|
---|
29 | #ifndef VBOXBFE_WITHOUT_COM
|
---|
30 | # include <VBox/com/Guid.h>
|
---|
31 | # include <VBox/com/string.h>
|
---|
32 | using namespace com;
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include <VBox/types.h>
|
---|
36 | #include <VBox/err.h>
|
---|
37 | #include <VBox/log.h>
|
---|
38 | #include <VBox/param.h>
|
---|
39 | #include <VBox/pdm.h>
|
---|
40 | #include <VBox/version.h>
|
---|
41 | #ifdef VBOXBFE_WITH_USB
|
---|
42 | # include <VBox/vusb.h>
|
---|
43 | #endif
|
---|
44 | #ifdef VBOX_WITH_HGCM
|
---|
45 | # include <VBox/shflsvc.h>
|
---|
46 | #endif
|
---|
47 | #include <iprt/alloc.h>
|
---|
48 | #include <iprt/alloca.h>
|
---|
49 | #include <iprt/assert.h>
|
---|
50 | #include <iprt/ctype.h>
|
---|
51 | #include <iprt/file.h>
|
---|
52 | #include <iprt/path.h>
|
---|
53 | #include <iprt/initterm.h>
|
---|
54 | #include <iprt/semaphore.h>
|
---|
55 | #include <iprt/stream.h>
|
---|
56 | #include <iprt/string.h>
|
---|
57 | #include <iprt/thread.h>
|
---|
58 | #include <iprt/uuid.h>
|
---|
59 |
|
---|
60 | #include "VBoxBFE.h"
|
---|
61 |
|
---|
62 | #include <stdio.h>
|
---|
63 | #include <stdlib.h> /* putenv */
|
---|
64 | #include <errno.h>
|
---|
65 |
|
---|
66 | #if defined(RT_OS_LINUX) || defined(RT_OS_L4)
|
---|
67 | #include <fcntl.h>
|
---|
68 | #include <net/if.h>
|
---|
69 | #include <sys/ioctl.h>
|
---|
70 | #include <linux/if_tun.h>
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | #include "ConsoleImpl.h"
|
---|
74 | #include "DisplayImpl.h"
|
---|
75 | #include "MouseImpl.h"
|
---|
76 | #include "KeyboardImpl.h"
|
---|
77 | #include "VMMDev.h"
|
---|
78 | #include "StatusImpl.h"
|
---|
79 | #include "Framebuffer.h"
|
---|
80 | #include "MachineDebuggerImpl.h"
|
---|
81 | #ifdef VBOXBFE_WITH_USB
|
---|
82 | # include "HostUSBImpl.h"
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | #if defined(USE_SDL) && ! defined(RT_OS_L4)
|
---|
86 | #include "SDLConsole.h"
|
---|
87 | #include "SDLFramebuffer.h"
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | #ifdef RT_OS_L4
|
---|
91 | #include "L4Console.h"
|
---|
92 | #include "L4Framebuffer.h"
|
---|
93 | #include "L4IDLInterface.h"
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | #ifdef RT_OS_L4
|
---|
97 | # include <l4/sys/ktrace.h>
|
---|
98 | # include <l4/vboxserver/file.h>
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | /*******************************************************************************
|
---|
102 | * Defined Constants And Macros *
|
---|
103 | *******************************************************************************/
|
---|
104 |
|
---|
105 | #define VBOXSDL_ADVANCED_OPTIONS
|
---|
106 | #define MAC_STRING_LEN 12
|
---|
107 |
|
---|
108 |
|
---|
109 | /*******************************************************************************
|
---|
110 | * Internal Functions *
|
---|
111 | *******************************************************************************/
|
---|
112 | static DECLCALLBACK(int) vboxbfeConfigConstructor(PVM pVM, void *pvUser);
|
---|
113 | static DECLCALLBACK(void) vmstateChangeCallback(PVM pVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
|
---|
114 | static DECLCALLBACK(void) setVMErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
|
---|
115 | const char *pszFormat, va_list args);
|
---|
116 | static DECLCALLBACK(int) VMPowerUpThread(RTTHREAD Thread, void *pvUser);
|
---|
117 |
|
---|
118 |
|
---|
119 | /*******************************************************************************
|
---|
120 | * Global Variables *
|
---|
121 | *******************************************************************************/
|
---|
122 |
|
---|
123 | PVM gpVM = NULL;
|
---|
124 | Mouse *gMouse = NULL;
|
---|
125 | Display *gDisplay = NULL;
|
---|
126 | Keyboard *gKeyboard = NULL;
|
---|
127 | VMMDev *gVMMDev = NULL;
|
---|
128 | Framebuffer *gFramebuffer = NULL;
|
---|
129 | MachineDebugger *gMachineDebugger = NULL;
|
---|
130 | VMStatus *gStatus = NULL;
|
---|
131 | Console *gConsole = NULL;
|
---|
132 | #ifdef VBOXBFE_WITH_USB
|
---|
133 | HostUSB *gHostUSB = NULL;
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | VMSTATE machineState = VMSTATE_CREATING;
|
---|
137 |
|
---|
138 | static PPDMLED mapFDLeds[2] = {0};
|
---|
139 |
|
---|
140 | /** flag whether keyboard/mouse events are grabbed */
|
---|
141 | #ifdef RT_OS_L4
|
---|
142 | /** see <l4/input/macros.h> for key definitions */
|
---|
143 | int gHostKey; /* not used */
|
---|
144 | int gHostKeySym = KEY_RIGHTCTRL;
|
---|
145 | #elif defined (DEBUG_dmik)
|
---|
146 | // my mini kbd doesn't have RCTRL...
|
---|
147 | int gHostKey = KMOD_RSHIFT;
|
---|
148 | int gHostKeySym = SDLK_RSHIFT;
|
---|
149 | #else
|
---|
150 | int gHostKey = KMOD_RCTRL;
|
---|
151 | int gHostKeySym = SDLK_RCTRL;
|
---|
152 | #endif
|
---|
153 | bool gfAllowFullscreenToggle = true;
|
---|
154 |
|
---|
155 | static bool g_fIOAPIC = false;
|
---|
156 | static bool g_fACPI = true;
|
---|
157 | static bool g_fAudio = false;
|
---|
158 | #ifdef VBOXBFE_WITH_USB
|
---|
159 | static bool g_fUSB = false;
|
---|
160 | #endif
|
---|
161 | static char *g_pszHdaFile = NULL;
|
---|
162 | static bool g_fHdaSpf = false;
|
---|
163 | static char *g_pszHdbFile = NULL;
|
---|
164 | static bool g_fHdbSpf = false;
|
---|
165 | static char *g_pszCdromFile = NULL;
|
---|
166 | static char *g_pszFdaFile = NULL;
|
---|
167 | const char *g_pszStateFile = NULL;
|
---|
168 | static const char *g_pszBootDevice = "IDE";
|
---|
169 | static uint32_t g_u32MemorySizeMB = 128;
|
---|
170 | static uint32_t g_u32VRamSize = 4 * _1M;
|
---|
171 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
172 | static bool g_fRawR0 = true;
|
---|
173 | static bool g_fRawR3 = true;
|
---|
174 | static bool g_fPATM = true;
|
---|
175 | static bool g_fCSAM = true;
|
---|
176 | #endif
|
---|
177 | static bool g_fRestoreState = false;
|
---|
178 | static const char *g_pszShareDir[MaxSharedFolders];
|
---|
179 | static const char *g_pszShareName[MaxSharedFolders];
|
---|
180 | static bool g_fShareReadOnly[MaxSharedFolders];
|
---|
181 | static unsigned g_uNumShares;
|
---|
182 | static bool g_fPreAllocRam = false;
|
---|
183 | static int g_iBootMenu = 2;
|
---|
184 | static bool g_fReleaseLog = true; /**< Set if we should open the release. */
|
---|
185 | const char *g_pszProgressString;
|
---|
186 | unsigned g_uProgressPercent = ~0U;
|
---|
187 |
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Network device config info.
|
---|
191 | */
|
---|
192 | typedef struct BFENetworkDevice
|
---|
193 | {
|
---|
194 | enum
|
---|
195 | {
|
---|
196 | NOT_CONFIGURED = 0,
|
---|
197 | NONE,
|
---|
198 | NAT,
|
---|
199 | HIF,
|
---|
200 | INTNET
|
---|
201 | } enmType; /**< The type of network driver. */
|
---|
202 | bool fSniff; /**< Set if the network sniffer should be installed. */
|
---|
203 | const char *pszSniff; /**< Output file for the network sniffer. */
|
---|
204 | RTMAC Mac; /**< The mac address for the device. */
|
---|
205 | const char *pszName; /**< The device name of a HIF device. The name of the internal network. */
|
---|
206 | #ifdef RT_OS_OS2
|
---|
207 | bool fHaveConnectTo; /**< Whether fConnectTo is set. */
|
---|
208 | int32_t iConnectTo; /**< The lanX to connect to (bridge with). */
|
---|
209 | #elif 1//defined(RT_OS_LINUX)
|
---|
210 | bool fHaveFd; /**< Set if fd is valid. */
|
---|
211 | int32_t fd; /**< The file descriptor of a HIF device.*/
|
---|
212 | #endif
|
---|
213 | } BFENETDEV, *PBFENETDEV;
|
---|
214 |
|
---|
215 | /** Array of network device configurations. */
|
---|
216 | static BFENETDEV g_aNetDevs[NetworkAdapterCount];
|
---|
217 |
|
---|
218 |
|
---|
219 | /** @todo currently this is only set but never read. */
|
---|
220 | static char szError[512];
|
---|
221 |
|
---|
222 |
|
---|
223 | /**
|
---|
224 | */
|
---|
225 | bool fActivateHGCM()
|
---|
226 | {
|
---|
227 | return !!(g_uNumShares > 0);
|
---|
228 | }
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Converts the passed in network option
|
---|
232 | *
|
---|
233 | * @returns Index into g_aNetDevs on success. (positive)
|
---|
234 | * @returns VERR_INVALID_PARAMETER on failure. (negative)
|
---|
235 | * @param pszArg The argument.
|
---|
236 | * @param cchRoot The length of the argument root.
|
---|
237 | */
|
---|
238 | static int networkArg2Index(const char *pszArg, int cchRoot)
|
---|
239 | {
|
---|
240 | uint32_t n;
|
---|
241 | int rc = RTStrToUInt32Ex(&pszArg[cchRoot], NULL, 10, &n);
|
---|
242 | if (RT_FAILURE(rc))
|
---|
243 | {
|
---|
244 | RTPrintf("Error: invalid network device option (rc=%Rrc): %s\n", rc, pszArg);
|
---|
245 | return -1;
|
---|
246 | }
|
---|
247 | if (n < 1 || n > NetworkAdapterCount)
|
---|
248 | {
|
---|
249 | RTPrintf("Error: The network device number is out of range: %RU32 (1 <= 0 <= %u) (%s)\n",
|
---|
250 | n, NetworkAdapterCount, pszArg);
|
---|
251 | return -1;
|
---|
252 | }
|
---|
253 | return n;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Generates a new unique MAC address based on our vendor ID and
|
---|
258 | * parts of a GUID.
|
---|
259 | *
|
---|
260 | * @returns iprt status code
|
---|
261 | * @param pAddress An array into which to store the newly generated address
|
---|
262 | */
|
---|
263 | int GenerateMACAddress(char pszAddress[MAC_STRING_LEN + 1])
|
---|
264 | {
|
---|
265 | /*
|
---|
266 | * Our strategy is as follows: the first three bytes are our fixed
|
---|
267 | * vendor ID (080027). The remaining 3 bytes will be taken from the
|
---|
268 | * start of a GUID. This is a fairly safe algorithm.
|
---|
269 | */
|
---|
270 | LogFlowFunc(("called\n"));
|
---|
271 | RTUUID uuid;
|
---|
272 | int rc = RTUuidCreate(&uuid);
|
---|
273 | if (RT_FAILURE(rc))
|
---|
274 | {
|
---|
275 | LogFlowFunc(("RTUuidCreate failed, returning %Rrc\n", rc));
|
---|
276 | return rc;
|
---|
277 | }
|
---|
278 | RTStrPrintf(pszAddress, MAC_STRING_LEN + 1, "080027%02X%02X%02X",
|
---|
279 | uuid.au8[0], uuid.au8[1], uuid.au8[2]);
|
---|
280 | LogFlowFunc(("generated MAC: '%s'\n", pszAddress));
|
---|
281 | return VINF_SUCCESS;
|
---|
282 | }
|
---|
283 |
|
---|
284 | /**
|
---|
285 | * Print a syntax error.
|
---|
286 | *
|
---|
287 | * @returns return value for main().
|
---|
288 | * @param pszMsg The message format string.
|
---|
289 | * @param ... Format arguments.
|
---|
290 | */
|
---|
291 | static int SyntaxError(const char *pszMsg, ...)
|
---|
292 | {
|
---|
293 | va_list va;
|
---|
294 | RTPrintf("error: ");
|
---|
295 | va_start(va, pszMsg);
|
---|
296 | RTPrintfV(pszMsg, va);
|
---|
297 | va_end(va);
|
---|
298 | return 1;
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | /**
|
---|
303 | * Print a fatal error.
|
---|
304 | *
|
---|
305 | * @returns return value for main().
|
---|
306 | * @param pszMsg The message format string.
|
---|
307 | * @param ... Format arguments.
|
---|
308 | */
|
---|
309 | static int FatalError(const char *pszMsg, ...)
|
---|
310 | {
|
---|
311 | va_list va;
|
---|
312 | RTPrintf("fatal error: ");
|
---|
313 | va_start(va, pszMsg);
|
---|
314 | RTPrintfV(pszMsg, va);
|
---|
315 | va_end(va);
|
---|
316 | return 1;
|
---|
317 | }
|
---|
318 |
|
---|
319 | /**
|
---|
320 | * Start progress display.
|
---|
321 | */
|
---|
322 | void startProgressInfo(const char *pszStr)
|
---|
323 | {
|
---|
324 | g_pszProgressString = pszStr;
|
---|
325 | g_uProgressPercent = 0;
|
---|
326 | }
|
---|
327 |
|
---|
328 | /**
|
---|
329 | * Update progress display.
|
---|
330 | */
|
---|
331 | int callProgressInfo(PVM pVM, unsigned uPercent, void *pvUser)
|
---|
332 | {
|
---|
333 | if (gConsole)
|
---|
334 | gConsole->progressInfo(pVM, uPercent, pvUser);
|
---|
335 | return VINF_SUCCESS;
|
---|
336 | }
|
---|
337 |
|
---|
338 | /**
|
---|
339 | * End progress display.
|
---|
340 | */
|
---|
341 | void endProgressInfo(void)
|
---|
342 | {
|
---|
343 | g_uProgressPercent = ~0U;
|
---|
344 | }
|
---|
345 |
|
---|
346 |
|
---|
347 | /**
|
---|
348 | * Print program usage.
|
---|
349 | */
|
---|
350 | static void show_usage()
|
---|
351 | {
|
---|
352 | RTPrintf("Usage:\n"
|
---|
353 | " -hda <file> Set first hard disk to file\n"
|
---|
354 | " -hdb <file> Set second hard disk to file\n"
|
---|
355 | " -fda <file> Set first floppy disk to file\n"
|
---|
356 | " -cdrom <file> Set CDROM to file/device ('none' to unmount)\n"
|
---|
357 | " -boot <a|c|d> Set boot device (a = floppy, c = first hard disk, d = DVD)\n"
|
---|
358 | " -boot menu <0|1|2> Boot menu (0 = disable, 1 = menu only, 2 = message + menu)\n"
|
---|
359 | " -m <size> Set memory size in megabytes (default 128MB)\n"
|
---|
360 | " -vram <size> Set size of video memory in megabytes\n"
|
---|
361 | " -prealloc Force RAM pre-allocation\n"
|
---|
362 | " -fullscreen Start VM in fullscreen mode\n"
|
---|
363 | " -statefile <file> Define the file name for VM save/restore\n"
|
---|
364 | " -restore Restore the VM if the statefile exists, normal start otherwise\n"
|
---|
365 | " -nofstoggle Forbid switching to/from fullscreen mode\n"
|
---|
366 | " -share <dir> <name> [readonly]\n"
|
---|
367 | " Share directory <dir> as name <name>. Optionally read-only.\n"
|
---|
368 | " -nohostkey Disable hostkey\n"
|
---|
369 | " -[no]acpi Enable or disable ACPI (default: enabled)\n"
|
---|
370 | " -[no]ioapic Enable or disable the IO-APIC (default: disabled)\n"
|
---|
371 | " -audio Enable audio\n"
|
---|
372 | #ifndef RT_OS_L4
|
---|
373 | " -natdev<1-N> [mac] Use NAT networking on network adapter <N>. Use hardware\n"
|
---|
374 | " address <mac> if specified.\n"
|
---|
375 | #endif
|
---|
376 | " -hifdev<1-N> Use Host Interface Networking with host interface <int>\n"
|
---|
377 | " <int> [mac] on network adapter <N>. Use hardware address <mac> if\n"
|
---|
378 | " specified.\n"
|
---|
379 | #ifndef RT_OS_L4
|
---|
380 | " -intnet<1-N> Attach network adapter <N> to internal network <net>. Use\n"
|
---|
381 | " <net> [mac] hardware address <mac> if specified.\n"
|
---|
382 | #endif
|
---|
383 | #if 0
|
---|
384 | " -netsniff<1-N> Enable packet sniffer\n"
|
---|
385 | #endif
|
---|
386 | #ifdef RT_OS_OS2
|
---|
387 | " -brdev<1-N> lan<X> Bridge network adaptor <N> with the 'lanX' device.\n"
|
---|
388 | #endif
|
---|
389 | #ifdef RT_OS_LINUX
|
---|
390 | " -tapfd<1-N> <fd> Use existing TAP device, don't allocate\n"
|
---|
391 | #endif
|
---|
392 | " -vrdp [port] Listen for VRDP connections on port (default if not specified)\n"
|
---|
393 | #ifdef VBOX_SECURELABEL
|
---|
394 | " -securelabel Display a secure VM label at the top of the screen\n"
|
---|
395 | " -seclabelfnt TrueType (.ttf) font file for secure session label\n"
|
---|
396 | " -seclabelsiz Font point size for secure session label (default 12)\n"
|
---|
397 | #endif
|
---|
398 | " -[no]rellog Enable or disable the release log './VBoxBFE.log' (default: enabled)\n"
|
---|
399 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
400 | " -[no]rawr0 Enable or disable raw ring 3\n"
|
---|
401 | " -[no]rawr3 Enable or disable raw ring 0\n"
|
---|
402 | " -[no]patm Enable or disable PATM\n"
|
---|
403 | " -[no]csam Enable or disable CSAM\n"
|
---|
404 | #endif
|
---|
405 | #ifdef RT_OS_L4
|
---|
406 | " -env <var=value> Set the given environment variable to \"value\"\n"
|
---|
407 | #endif
|
---|
408 | "\n");
|
---|
409 | }
|
---|
410 |
|
---|
411 |
|
---|
412 | /** entry point */
|
---|
413 | extern "C" DECLEXPORT(int) TrustedMain (int argc, char **argv, char **envp)
|
---|
414 | {
|
---|
415 | bool fFullscreen = false;
|
---|
416 | int32_t portVRDP = -1;
|
---|
417 | #ifdef VBOX_SECURELABEL
|
---|
418 | bool fSecureLabel = false;
|
---|
419 | uint32_t secureLabelPointSize = 12;
|
---|
420 | char *secureLabelFontFile = NULL;
|
---|
421 | #endif
|
---|
422 | #ifdef RT_OS_L4
|
---|
423 | uint32_t u32MaxVRAM;
|
---|
424 | #endif
|
---|
425 | int rc = VINF_SUCCESS;
|
---|
426 |
|
---|
427 | RTPrintf(VBOX_PRODUCT " Simple SDL GUI built %s %s\n", __DATE__, __TIME__);
|
---|
428 |
|
---|
429 | // less than one parameter is not possible
|
---|
430 | if (argc < 2)
|
---|
431 | {
|
---|
432 | show_usage();
|
---|
433 | return 1;
|
---|
434 | }
|
---|
435 |
|
---|
436 | /*
|
---|
437 | * Parse the command line arguments.
|
---|
438 | */
|
---|
439 | for (int curArg = 1; curArg < argc; curArg++)
|
---|
440 | {
|
---|
441 | const char * const pszArg = argv[curArg];
|
---|
442 | if (strcmp(pszArg, "-boot") == 0)
|
---|
443 | {
|
---|
444 | if (++curArg >= argc)
|
---|
445 | return SyntaxError("missing argument for boot drive!\n");
|
---|
446 | if (strlen(argv[curArg]) != 1)
|
---|
447 | return SyntaxError("invalid argument for boot drive! (%s)\n", argv[curArg]);
|
---|
448 | rc = VINF_SUCCESS;
|
---|
449 | switch (argv[curArg][0])
|
---|
450 | {
|
---|
451 | case 'a':
|
---|
452 | {
|
---|
453 | g_pszBootDevice = "FLOPPY";
|
---|
454 | break;
|
---|
455 | }
|
---|
456 |
|
---|
457 | case 'c':
|
---|
458 | {
|
---|
459 | g_pszBootDevice = "IDE";
|
---|
460 | break;
|
---|
461 | }
|
---|
462 |
|
---|
463 | case 'd':
|
---|
464 | {
|
---|
465 | g_pszBootDevice = "DVD";
|
---|
466 | break;
|
---|
467 | }
|
---|
468 |
|
---|
469 | default:
|
---|
470 | return SyntaxError("wrong argument for boot drive! (%s)\n", argv[curArg]);
|
---|
471 | }
|
---|
472 | }
|
---|
473 | else if (strcmp(pszArg, "-bootmenu") == 0)
|
---|
474 | {
|
---|
475 | if (++curArg >= argc)
|
---|
476 | return SyntaxError("missing argument for boot menu!\n");
|
---|
477 | if (strlen(argv[curArg]) != 1 || *argv[curArg] < '0' || *argv[curArg] > '2')
|
---|
478 | return SyntaxError("invalid argument for boot menu! (%s)\n", argv[curArg]);
|
---|
479 | rc = VINF_SUCCESS;
|
---|
480 | g_iBootMenu = *argv[curArg] - 0;
|
---|
481 | }
|
---|
482 | else if (strcmp(pszArg, "-m") == 0)
|
---|
483 | {
|
---|
484 | if (++curArg >= argc)
|
---|
485 | return SyntaxError("missing argument for memory size!\n");
|
---|
486 | rc = RTStrToUInt32Ex(argv[curArg], NULL, 0, &g_u32MemorySizeMB);
|
---|
487 | if (RT_FAILURE(rc))
|
---|
488 | return SyntaxError("bad memory size: %s (error %Rrc)\n",
|
---|
489 | argv[curArg], rc);
|
---|
490 | }
|
---|
491 | else if (strcmp(pszArg, "-vram") == 0)
|
---|
492 | {
|
---|
493 | if (++curArg >= argc)
|
---|
494 | return SyntaxError("missing argument for vram size!\n");
|
---|
495 | uint32_t uVRAMMB;
|
---|
496 | rc = RTStrToUInt32Ex(argv[curArg], NULL, 0, &uVRAMMB);
|
---|
497 | g_u32VRamSize = uVRAMMB * _1M;
|
---|
498 | if (RT_FAILURE(rc))
|
---|
499 | return SyntaxError("bad video ram size: %s (error %Rrc)\n",
|
---|
500 | argv[curArg], rc);
|
---|
501 | }
|
---|
502 | else if (strcmp(pszArg, "-statefile") == 0)
|
---|
503 | {
|
---|
504 | if (++curArg >= argc)
|
---|
505 | return SyntaxError("missing argument for restore!\n");
|
---|
506 | g_pszStateFile = argv[curArg];
|
---|
507 | }
|
---|
508 | else if (strcmp(pszArg, "-restore") == 0)
|
---|
509 | g_fRestoreState = true;
|
---|
510 | else if (strcmp(pszArg, "-share") == 0)
|
---|
511 | {
|
---|
512 | if (g_uNumShares >= MaxSharedFolders)
|
---|
513 | return SyntaxError("too many shared folders specified!\n");
|
---|
514 | if (++curArg >= argc)
|
---|
515 | return SyntaxError("missing 1s argument for share!\n");
|
---|
516 | g_pszShareDir[g_uNumShares] = argv[curArg];
|
---|
517 | if (++curArg >= argc)
|
---|
518 | return SyntaxError("missing 2nd argument for share!\n");
|
---|
519 | g_pszShareName[g_uNumShares] = argv[curArg];
|
---|
520 | if (curArg < argc-1 && strcmp(argv[curArg+1], "readonly") == 0)
|
---|
521 | {
|
---|
522 | g_fShareReadOnly[g_uNumShares] = true;
|
---|
523 | curArg++;
|
---|
524 | }
|
---|
525 | g_uNumShares++;
|
---|
526 | }
|
---|
527 | else if (strcmp(pszArg, "-fullscreen") == 0)
|
---|
528 | fFullscreen = true;
|
---|
529 | else if (strcmp(pszArg, "-nofstoggle") == 0)
|
---|
530 | gfAllowFullscreenToggle = false;
|
---|
531 | else if (strcmp(pszArg, "-nohostkey") == 0)
|
---|
532 | {
|
---|
533 | gHostKey = 0;
|
---|
534 | gHostKeySym = 0;
|
---|
535 | }
|
---|
536 | else if (strcmp(pszArg, "-acpi") == 0)
|
---|
537 | g_fACPI = true;
|
---|
538 | else if (strcmp(pszArg, "-noacpi") == 0)
|
---|
539 | g_fACPI = false;
|
---|
540 | else if (strcmp(pszArg, "-ioapic") == 0)
|
---|
541 | g_fIOAPIC = true;
|
---|
542 | else if (strcmp(pszArg, "-noioapic") == 0)
|
---|
543 | g_fIOAPIC = false;
|
---|
544 | else if (strcmp(pszArg, "-audio") == 0)
|
---|
545 | g_fAudio = true;
|
---|
546 | #ifdef VBOXBFE_WITH_USB
|
---|
547 | else if (strcmp(pszArg, "-usb") == 0)
|
---|
548 | g_fUSB = true;
|
---|
549 | #endif
|
---|
550 | else if (strcmp(pszArg, "-hda") == 0)
|
---|
551 | {
|
---|
552 | if (++curArg >= argc)
|
---|
553 | return SyntaxError("missing file name for first hard disk!\n");
|
---|
554 |
|
---|
555 | /* resolve it. */
|
---|
556 | if (RTPathExists(argv[curArg]))
|
---|
557 | g_pszHdaFile = RTPathRealDup(argv[curArg]);
|
---|
558 | if (!g_pszHdaFile)
|
---|
559 | return SyntaxError("The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]);
|
---|
560 | }
|
---|
561 | else if (strcmp(pszArg, "-hdaspf") == 0)
|
---|
562 | {
|
---|
563 | g_fHdaSpf = true;
|
---|
564 | }
|
---|
565 | else if (strcmp(pszArg, "-hdb") == 0)
|
---|
566 | {
|
---|
567 | if (++curArg >= argc)
|
---|
568 | return SyntaxError("missing file name for second hard disk!\n");
|
---|
569 |
|
---|
570 | /* resolve it. */
|
---|
571 | if (RTPathExists(argv[curArg]))
|
---|
572 | g_pszHdbFile = RTPathRealDup(argv[curArg]);
|
---|
573 | if (!g_pszHdbFile)
|
---|
574 | return SyntaxError("The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]);
|
---|
575 | }
|
---|
576 | else if (strcmp(pszArg, "-hdbspf") == 0)
|
---|
577 | {
|
---|
578 | g_fHdbSpf = true;
|
---|
579 | }
|
---|
580 | else if (strcmp(pszArg, "-fda") == 0)
|
---|
581 | {
|
---|
582 | if (++curArg >= argc)
|
---|
583 | return SyntaxError("missing file/device name for first floppy disk!\n");
|
---|
584 |
|
---|
585 | /* resolve it. */
|
---|
586 | if (RTPathExists(argv[curArg]))
|
---|
587 | g_pszFdaFile = RTPathRealDup(argv[curArg]);
|
---|
588 | if (!g_pszFdaFile)
|
---|
589 | return SyntaxError("The path to the specified floppy disk, '%s', could not be resolved.\n", argv[curArg]);
|
---|
590 | }
|
---|
591 | else if (strcmp(pszArg, "-cdrom") == 0)
|
---|
592 | {
|
---|
593 | if (++curArg >= argc)
|
---|
594 | return SyntaxError("missing file/device name for first hard disk!\n");
|
---|
595 |
|
---|
596 | /* resolve it. */
|
---|
597 | if (RTPathExists(argv[curArg]))
|
---|
598 | g_pszCdromFile = RTPathRealDup(argv[curArg]);
|
---|
599 | if (!g_pszCdromFile)
|
---|
600 | return SyntaxError("The path to the specified cdrom, '%s', could not be resolved.\n", argv[curArg]);
|
---|
601 | }
|
---|
602 | #ifdef RT_OS_L4
|
---|
603 | /* This is leaving a lot of dead code in the L4 version of course,
|
---|
604 | but I don't think that that is a major problem. We may even
|
---|
605 | activate it sometime... */
|
---|
606 | else if ( strncmp(pszArg, "-hifdev", 7) == 0
|
---|
607 | || strncmp(pszArg, "-nonetd", 7) == 0)
|
---|
608 | #else
|
---|
609 | else if ( strncmp(pszArg, "-natdev", 7) == 0
|
---|
610 | || strncmp(pszArg, "-hifdev", 7) == 0
|
---|
611 | || strncmp(pszArg, "-nonetd", 7) == 0
|
---|
612 | || strncmp(pszArg, "-intnet", 7) == 0)
|
---|
613 | #endif
|
---|
614 | {
|
---|
615 | int i = networkArg2Index(pszArg, 7);
|
---|
616 | if (i < 0)
|
---|
617 | return 1;
|
---|
618 | g_aNetDevs[i].enmType = !strncmp(pszArg, "-natdev", 7)
|
---|
619 | ? BFENETDEV::NAT
|
---|
620 | : !strncmp(pszArg, "-hifdev", 7)
|
---|
621 | ? BFENETDEV::HIF
|
---|
622 | : !strncmp(pszArg, "-intnet", 7)
|
---|
623 | ? BFENETDEV::INTNET
|
---|
624 | : BFENETDEV::NONE;
|
---|
625 |
|
---|
626 | /* The HIF device name / The Internal Network name. */
|
---|
627 | g_aNetDevs[i].pszName = NULL;
|
---|
628 | if ( g_aNetDevs[i].enmType == BFENETDEV::HIF
|
---|
629 | || g_aNetDevs[i].enmType == BFENETDEV::INTNET)
|
---|
630 | {
|
---|
631 | if (curArg + 1 >= argc)
|
---|
632 | return SyntaxError(g_aNetDevs[i].enmType == BFENETDEV::HIF
|
---|
633 | ? "The TAP network device name is missing! (%s)\n"
|
---|
634 | : "The internal network name is missing! (%s)\n"
|
---|
635 | , pszArg);
|
---|
636 | g_aNetDevs[i].pszName = argv[++curArg];
|
---|
637 | }
|
---|
638 |
|
---|
639 | /* The MAC address. */
|
---|
640 | const char *pszMac;
|
---|
641 | char szMacGen[MAC_STRING_LEN + 1];
|
---|
642 | if ((curArg + 1 < argc) && (argv[curArg + 1][0] != '-'))
|
---|
643 | pszMac = argv[++curArg];
|
---|
644 | else
|
---|
645 | {
|
---|
646 | rc = GenerateMACAddress(szMacGen);
|
---|
647 | if (RT_FAILURE(rc))
|
---|
648 | return SyntaxError("failed to generate a hardware address for network device %d (error %Rrc)\n",
|
---|
649 | i, rc);
|
---|
650 | pszMac = szMacGen;
|
---|
651 | }
|
---|
652 | if (strlen(pszMac) != MAC_STRING_LEN)
|
---|
653 | return SyntaxError("The network MAC address has an invalid length: %s (%s)\n", pszMac, pszArg);
|
---|
654 | for (unsigned j = 0; j < RT_ELEMENTS(g_aNetDevs[i].Mac.au8); j++)
|
---|
655 | {
|
---|
656 | char c1 = RT_C_TO_UPPER(*pszMac++) - '0';
|
---|
657 | if (c1 > 9)
|
---|
658 | c1 -= 7;
|
---|
659 | char c2 = RT_C_TO_UPPER(*pszMac++) - '0';
|
---|
660 | if (c2 > 9)
|
---|
661 | c2 -= 7;
|
---|
662 | if (c2 > 16 || c1 > 16)
|
---|
663 | return SyntaxError("Invalid MAC address: %s\n", argv[curArg]);
|
---|
664 | g_aNetDevs[i].Mac.au8[j] = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
|
---|
665 | }
|
---|
666 | }
|
---|
667 | else if (strncmp(pszArg, "-netsniff", 9) == 0)
|
---|
668 | {
|
---|
669 | int i = networkArg2Index(pszArg, 9);
|
---|
670 | if (i < 0)
|
---|
671 | return 1;
|
---|
672 | g_aNetDevs[i].fSniff = true;
|
---|
673 | /** @todo filename */
|
---|
674 | }
|
---|
675 | #ifdef RT_OS_OS2
|
---|
676 | else if (strncmp(pszArg, "-brdev", 6) == 0)
|
---|
677 | {
|
---|
678 | int i = networkArg2Index(pszArg, 6);
|
---|
679 | if (i < 0)
|
---|
680 | return 1;
|
---|
681 | if (g_aNetDevs[i].enmType != BFENETDEV::HIF)
|
---|
682 | return SyntaxError("%d is not a hif device! Make sure you put the -hifdev argument first.\n", i);
|
---|
683 | if (++curArg >= argc)
|
---|
684 | return SyntaxError("missing argument for %s!\n", pszArg);
|
---|
685 | if ( strncmp(argv[curArg], "lan", 3)
|
---|
686 | || argv[curArg][3] < '0'
|
---|
687 | || argv[curArg][3] >= '8'
|
---|
688 | || argv[curArg][4])
|
---|
689 | return SyntaxError("bad interface name '%s' specified with '%s'. Expected 'lan0', 'lan1' and similar.\n",
|
---|
690 | argv[curArg], pszArg);
|
---|
691 | g_aNetDevs[i].iConnectTo = argv[curArg][3] - '0';
|
---|
692 | g_aNetDevs[i].fHaveConnectTo = true;
|
---|
693 | }
|
---|
694 | #endif
|
---|
695 | #ifdef RT_OS_LINUX
|
---|
696 | else if (strncmp(pszArg, "-tapfd", 6) == 0)
|
---|
697 | {
|
---|
698 | int i = networkArg2Index(pszArg, 6);
|
---|
699 | if (i < 0)
|
---|
700 | return 1;
|
---|
701 | if (++curArg >= argc)
|
---|
702 | return SyntaxError("missing argument for %s!\n", pszArg);
|
---|
703 | rc = RTStrToInt32Ex(argv[curArg], NULL, 0, &g_aNetDevs[i].fd);
|
---|
704 | if (RT_FAILURE(rc))
|
---|
705 | return SyntaxError("bad tap file descriptor: %s (error %Rrc)\n", argv[curArg], rc);
|
---|
706 | g_aNetDevs[i].fHaveFd = true;
|
---|
707 | }
|
---|
708 | #endif /* RT_OS_LINUX */
|
---|
709 | else if (strcmp(pszArg, "-vrdp") == 0)
|
---|
710 | {
|
---|
711 | // -vrdp might take a port number (positive).
|
---|
712 | portVRDP = 0; // indicate that it was encountered.
|
---|
713 | if (curArg + 1 < argc && argv[curArg + 1][0] != '-')
|
---|
714 | {
|
---|
715 | rc = RTStrToInt32Ex(argv[curArg], NULL, 0, &portVRDP);
|
---|
716 | if (RT_FAILURE(rc))
|
---|
717 | return SyntaxError("cannot vrpd port: %s (%Rrc)\n", argv[curArg], rc);
|
---|
718 | if (portVRDP < 0 || portVRDP >= 0x10000)
|
---|
719 | return SyntaxError("vrdp port number is out of range: %RI32\n", portVRDP);
|
---|
720 | }
|
---|
721 | }
|
---|
722 | #ifdef VBOX_SECURELABEL
|
---|
723 | else if (strcmp(pszArg, "-securelabel") == 0)
|
---|
724 | {
|
---|
725 | fSecureLabel = true;
|
---|
726 | LogFlow(("Secure labelling turned on\n"));
|
---|
727 | }
|
---|
728 | else if (strcmp(pszArg, "-seclabelfnt") == 0)
|
---|
729 | {
|
---|
730 | if (++curArg >= argc)
|
---|
731 | return SyntaxError("missing font file name for secure label!\n");
|
---|
732 | secureLabelFontFile = argv[curArg];
|
---|
733 | }
|
---|
734 | else if (strcmp(pszArg, "-seclabelsiz") == 0)
|
---|
735 | {
|
---|
736 | if (++curArg >= argc)
|
---|
737 | return SyntaxError("missing font point size for secure label!\n");
|
---|
738 | secureLabelPointSize = atoi(argv[curArg]);
|
---|
739 | }
|
---|
740 | #endif
|
---|
741 | else if (strcmp(pszArg, "-rellog") == 0)
|
---|
742 | g_fReleaseLog = true;
|
---|
743 | else if (strcmp(pszArg, "-norellog") == 0)
|
---|
744 | g_fReleaseLog = false;
|
---|
745 | else if (strcmp(pszArg, "-prealloc") == 0)
|
---|
746 | g_fPreAllocRam = true;
|
---|
747 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
748 | else if (strcmp(pszArg, "-rawr0") == 0)
|
---|
749 | g_fRawR0 = true;
|
---|
750 | else if (strcmp(pszArg, "-norawr0") == 0)
|
---|
751 | g_fRawR0 = false;
|
---|
752 | else if (strcmp(pszArg, "-rawr3") == 0)
|
---|
753 | g_fRawR3 = true;
|
---|
754 | else if (strcmp(pszArg, "-norawr3") == 0)
|
---|
755 | g_fRawR3 = false;
|
---|
756 | else if (strcmp(pszArg, "-patm") == 0)
|
---|
757 | g_fPATM = true;
|
---|
758 | else if (strcmp(pszArg, "-nopatm") == 0)
|
---|
759 | g_fPATM = false;
|
---|
760 | else if (strcmp(pszArg, "-csam") == 0)
|
---|
761 | g_fCSAM = true;
|
---|
762 | else if (strcmp(pszArg, "-nocsam") == 0)
|
---|
763 | g_fCSAM = false;
|
---|
764 | #endif /* VBOXSDL_ADVANCED_OPTIONS */
|
---|
765 | #ifdef RT_OS_L4
|
---|
766 | else if (strcmp(pszArg, "-env") == 0)
|
---|
767 | ++curArg;
|
---|
768 | #endif /* RT_OS_L4 */
|
---|
769 | /* just show the help screen */
|
---|
770 | else
|
---|
771 | {
|
---|
772 | SyntaxError("unrecognized argument '%s'\n", pszArg);
|
---|
773 | show_usage();
|
---|
774 | return 1;
|
---|
775 | }
|
---|
776 | }
|
---|
777 |
|
---|
778 | gMachineDebugger = new MachineDebugger();
|
---|
779 | gStatus = new VMStatus();
|
---|
780 | gKeyboard = new Keyboard();
|
---|
781 | gMouse = new Mouse();
|
---|
782 | if (FAILED(gMouse->FinalConstruct()))
|
---|
783 | goto leave;
|
---|
784 | gVMMDev = new VMMDev();
|
---|
785 | gDisplay = new Display();
|
---|
786 | #if defined(USE_SDL)
|
---|
787 | /* First console, then framebuffer!! */
|
---|
788 | gConsole = new SDLConsole();
|
---|
789 | gFramebuffer = new SDLFramebuffer();
|
---|
790 | #elif defined(RT_OS_L4)
|
---|
791 | gConsole = new L4Console();
|
---|
792 | gFramebuffer = new L4Framebuffer();
|
---|
793 | #else
|
---|
794 | #error "todo"
|
---|
795 | #endif
|
---|
796 | if (!gConsole->initialized())
|
---|
797 | goto leave;
|
---|
798 | gDisplay->SetFramebuffer(0, gFramebuffer);
|
---|
799 |
|
---|
800 | /* start with something in the titlebar */
|
---|
801 | gConsole->updateTitlebar();
|
---|
802 |
|
---|
803 | /*
|
---|
804 | * Start the VM execution thread. This has to be done
|
---|
805 | * asynchronously as powering up can take some time
|
---|
806 | * (accessing devices such as the host DVD drive). In
|
---|
807 | * the meantime, we have to service the SDL event loop.
|
---|
808 | */
|
---|
809 |
|
---|
810 | RTTHREAD thread;
|
---|
811 | rc = RTThreadCreate(&thread, VMPowerUpThread, 0, 0, RTTHREADTYPE_MAIN_WORKER, 0, "PowerUp");
|
---|
812 | if (RT_FAILURE(rc))
|
---|
813 | {
|
---|
814 | RTPrintf("Error: Thread creation failed with %d\n", rc);
|
---|
815 | return -1;
|
---|
816 | }
|
---|
817 |
|
---|
818 | #ifdef RT_OS_L4
|
---|
819 | /* Start the external IDL interface */
|
---|
820 | L4CtrlInit();
|
---|
821 | #endif
|
---|
822 |
|
---|
823 | /* loop until the powerup processing is done */
|
---|
824 | do
|
---|
825 | {
|
---|
826 | #if defined(VBOXBFE_WITH_X11) && defined(USE_SDL)
|
---|
827 | if ( machineState == VMSTATE_CREATING
|
---|
828 | || machineState == VMSTATE_LOADING)
|
---|
829 | {
|
---|
830 | int event = gConsole->eventWait();
|
---|
831 |
|
---|
832 | switch (event)
|
---|
833 | {
|
---|
834 | case CONEVENT_USR_SCREENRESIZE:
|
---|
835 | LogFlow(("CONEVENT_USR_SCREENRESIZE\n"));
|
---|
836 | gFramebuffer->resize();
|
---|
837 | /* notify the display that the resize has been completed */
|
---|
838 | gDisplay->ResizeCompleted();
|
---|
839 | break;
|
---|
840 |
|
---|
841 | case CONEVENT_USR_TITLEBARUPDATE:
|
---|
842 | gConsole->updateTitlebar();
|
---|
843 | break;
|
---|
844 |
|
---|
845 | case CONEVENT_USR_QUIT:
|
---|
846 | RTPrintf("Error: failed to power up VM! No error text available.\n");
|
---|
847 | goto leave;
|
---|
848 | }
|
---|
849 | }
|
---|
850 | else
|
---|
851 | #endif
|
---|
852 | RTThreadSleep(1000);
|
---|
853 | }
|
---|
854 | while ( machineState == VMSTATE_CREATING
|
---|
855 | || machineState == VMSTATE_LOADING);
|
---|
856 |
|
---|
857 | if (machineState == VMSTATE_TERMINATED)
|
---|
858 | goto leave;
|
---|
859 |
|
---|
860 | /* did the power up succeed? */
|
---|
861 | if (machineState != VMSTATE_RUNNING)
|
---|
862 | {
|
---|
863 | RTPrintf("Error: failed to power up VM! No error text available (rc = 0x%x state = %d)\n", rc, machineState);
|
---|
864 | goto leave;
|
---|
865 | }
|
---|
866 |
|
---|
867 | gConsole->updateTitlebar();
|
---|
868 |
|
---|
869 | #ifdef RT_OS_L4
|
---|
870 | /* The L4 console provides (currently) a fixed resolution. */
|
---|
871 | if (g_u32VRamSize >= gFramebuffer->getHostXres()
|
---|
872 | * gFramebuffer->getHostYres()
|
---|
873 | * (gDisplay->getBitsPerPixel() / 8))
|
---|
874 | gDisplay->SetVideoModeHint(gFramebuffer->getHostXres(), gFramebuffer->getHostYres(), 0, 0);
|
---|
875 |
|
---|
876 | /* Limit the VRAM of the guest to the amount of memory we got actually
|
---|
877 | * mapped from the L4 console. */
|
---|
878 | u32MaxVRAM = (gFramebuffer->getHostYres() + 18) /* don't omit the status bar */
|
---|
879 | * gFramebuffer->getHostXres()
|
---|
880 | * (gFramebuffer->getHostBitsPerPixel() / 8);
|
---|
881 | if (g_u32VRamSize > u32MaxVRAM)
|
---|
882 | {
|
---|
883 | RTPrintf("Limiting the video memory to %u bytes\n", u32MaxVRAM);
|
---|
884 | g_u32VRamSize = u32MaxVRAM;
|
---|
885 | }
|
---|
886 | #endif
|
---|
887 |
|
---|
888 | /*
|
---|
889 | * Main event loop
|
---|
890 | */
|
---|
891 | LogFlow(("VBoxSDL: Entering big event loop\n"));
|
---|
892 |
|
---|
893 | while (1)
|
---|
894 | {
|
---|
895 | int event = gConsole->eventWait();
|
---|
896 |
|
---|
897 | switch (event)
|
---|
898 | {
|
---|
899 | case CONEVENT_NONE:
|
---|
900 | /* Handled internally */
|
---|
901 | break;
|
---|
902 |
|
---|
903 | case CONEVENT_QUIT:
|
---|
904 | case CONEVENT_USR_QUIT:
|
---|
905 | goto leave;
|
---|
906 |
|
---|
907 | case CONEVENT_SCREENUPDATE:
|
---|
908 | /// @todo that somehow doesn't seem to work!
|
---|
909 | gFramebuffer->repaint();
|
---|
910 | break;
|
---|
911 |
|
---|
912 | case CONEVENT_USR_TITLEBARUPDATE:
|
---|
913 | gConsole->updateTitlebar();
|
---|
914 | break;
|
---|
915 |
|
---|
916 | case CONEVENT_USR_SCREENRESIZE:
|
---|
917 | {
|
---|
918 | LogFlow(("CONEVENT_USR_SCREENRESIZE\n"));
|
---|
919 | gFramebuffer->resize();
|
---|
920 | /* notify the display that the resize has been completed */
|
---|
921 | gDisplay->ResizeCompleted();
|
---|
922 | break;
|
---|
923 | }
|
---|
924 |
|
---|
925 | #ifdef VBOX_SECURELABEL
|
---|
926 | case CONEVENT_USR_SECURELABELUPDATE:
|
---|
927 | {
|
---|
928 | /*
|
---|
929 | * Query the new label text
|
---|
930 | */
|
---|
931 | Bstr key = VBOXSDL_SECURELABEL_EXTRADATA;
|
---|
932 | Bstr label;
|
---|
933 | gMachine->COMGETTER(ExtraData)(key, label.asOutParam());
|
---|
934 | Utf8Str labelUtf8 = label;
|
---|
935 | /*
|
---|
936 | * Now update the label
|
---|
937 | */
|
---|
938 | gFramebuffer->setSecureLabelText(labelUtf8.raw());
|
---|
939 | break;
|
---|
940 | }
|
---|
941 | #endif /* VBOX_SECURELABEL */
|
---|
942 |
|
---|
943 | }
|
---|
944 |
|
---|
945 | }
|
---|
946 |
|
---|
947 | leave:
|
---|
948 | LogFlow(("Returning from main()!\n"));
|
---|
949 |
|
---|
950 | if (gpVM)
|
---|
951 | {
|
---|
952 | /*
|
---|
953 | * If get here because the guest terminated using ACPI off we don't have to
|
---|
954 | * switch off the VM because we were notified via vmstateChangeCallback()
|
---|
955 | * that this already happened. In any other case stop the VM before killing her.
|
---|
956 | */
|
---|
957 | if (machineState != VMSTATE_OFF)
|
---|
958 | {
|
---|
959 | /* Power off VM */
|
---|
960 | rc = VMR3PowerOff(gpVM);
|
---|
961 | AssertRC(rc);
|
---|
962 | }
|
---|
963 |
|
---|
964 | /* And destroy it */
|
---|
965 | rc = VMR3Destroy(gpVM);
|
---|
966 | AssertRC(rc);
|
---|
967 | }
|
---|
968 |
|
---|
969 | delete gFramebuffer;
|
---|
970 | delete gConsole;
|
---|
971 | delete gDisplay;
|
---|
972 | delete gKeyboard;
|
---|
973 | gMouse->FinalRelease();
|
---|
974 | delete gMouse;
|
---|
975 | delete gStatus;
|
---|
976 | delete gMachineDebugger;
|
---|
977 |
|
---|
978 | RTLogFlush(NULL);
|
---|
979 | return RT_FAILURE (rc) ? 1 : 0;
|
---|
980 | }
|
---|
981 |
|
---|
982 |
|
---|
983 | #ifndef VBOX_WITH_HARDENING
|
---|
984 | /**
|
---|
985 | * Main entry point.
|
---|
986 | */
|
---|
987 | int main(int argc, char **argv)
|
---|
988 | {
|
---|
989 | # ifdef RT_OS_L4
|
---|
990 | # ifndef L4API_l4v2onv4
|
---|
991 | /* clear Fiasco kernel trace buffer */
|
---|
992 | fiasco_tbuf_clear();
|
---|
993 | # endif
|
---|
994 | /* set the environment. Must be done before the runtime is
|
---|
995 | initialised. Yes, it really must. */
|
---|
996 | for (int i = 0; i < argc; i++)
|
---|
997 | if (strcmp(argv[i], "-env") == 0)
|
---|
998 | {
|
---|
999 | if (++i >= argc)
|
---|
1000 | return SyntaxError("missing argument to -env (format: var=value)!\n");
|
---|
1001 | /* add it to the environment */
|
---|
1002 | if (putenv(argv[i]) != 0)
|
---|
1003 | return SyntaxError("Error setting environment string %s.\n", argv[i]);
|
---|
1004 | }
|
---|
1005 | # endif /* RT_OS_L4 */
|
---|
1006 |
|
---|
1007 | /*
|
---|
1008 | * Before we do *anything*, we initialize the runtime.
|
---|
1009 | */
|
---|
1010 | int rc = RTR3Init();
|
---|
1011 | if (RT_FAILURE(rc))
|
---|
1012 | return FatalError("RTR3Init failed rc=%Rrc\n", rc);
|
---|
1013 |
|
---|
1014 | return TrustedMain(argc, argv, NULL);
|
---|
1015 | }
|
---|
1016 | #endif /* !VBOX_WITH_HARDENING */
|
---|
1017 |
|
---|
1018 |
|
---|
1019 | /**
|
---|
1020 | * VM state callback function. Called by the VMM
|
---|
1021 | * using its state machine states.
|
---|
1022 | *
|
---|
1023 | * Primarily used to handle VM initiated power off, suspend and state saving,
|
---|
1024 | * but also for doing termination completed work (VMSTATE_TERMINATE).
|
---|
1025 | *
|
---|
1026 | * In general this function is called in the context of the EMT.
|
---|
1027 | *
|
---|
1028 | * @todo machineState is set to VMSTATE_RUNNING before all devices have received power on events
|
---|
1029 | * this can prematurely allow the main thread to enter the event loop
|
---|
1030 | *
|
---|
1031 | * @param pVM The VM handle.
|
---|
1032 | * @param enmState The new state.
|
---|
1033 | * @param enmOldState The old state.
|
---|
1034 | * @param pvUser The user argument.
|
---|
1035 | */
|
---|
1036 | static DECLCALLBACK(void) vmstateChangeCallback(PVM pVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser)
|
---|
1037 | {
|
---|
1038 | LogFlow(("vmstateChangeCallback: changing state from %d to %d\n", enmOldState, enmState));
|
---|
1039 | machineState = enmState;
|
---|
1040 |
|
---|
1041 | switch (enmState)
|
---|
1042 | {
|
---|
1043 | /*
|
---|
1044 | * The VM has terminated
|
---|
1045 | */
|
---|
1046 | case VMSTATE_OFF:
|
---|
1047 | {
|
---|
1048 | gConsole->eventQuit();
|
---|
1049 | break;
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | /*
|
---|
1053 | * The VM has been completely destroyed.
|
---|
1054 | *
|
---|
1055 | * Note: This state change can happen at two points:
|
---|
1056 | * 1) At the end of VMR3Destroy() if it was not called from EMT.
|
---|
1057 | * 2) At the end of vmR3EmulationThread if VMR3Destroy() was called by EMT.
|
---|
1058 | */
|
---|
1059 | case VMSTATE_TERMINATED:
|
---|
1060 | {
|
---|
1061 | break;
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | default: /* shut up gcc */
|
---|
1065 | break;
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 |
|
---|
1070 | /**
|
---|
1071 | * VM error callback function. Called by the various VM components.
|
---|
1072 | *
|
---|
1073 | * @param pVM The VM handle.
|
---|
1074 | * @param pvUser The user argument.
|
---|
1075 | * @param rc VBox status code.
|
---|
1076 | * @param pszError Error message format string.
|
---|
1077 | * @param args Error message arguments.
|
---|
1078 | * @thread EMT.
|
---|
1079 | */
|
---|
1080 | DECLCALLBACK(void) setVMErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
|
---|
1081 | const char *pszFormat, va_list args)
|
---|
1082 | {
|
---|
1083 | /** @todo accessing shared resource without any kind of synchronization */
|
---|
1084 | if (RT_SUCCESS(rc))
|
---|
1085 | szError[0] = '\0';
|
---|
1086 | else
|
---|
1087 | {
|
---|
1088 | va_list va2;
|
---|
1089 | va_copy(va2, args); /* Have to make a copy here or GCC will break. */
|
---|
1090 | RTStrPrintf(szError, sizeof(szError),
|
---|
1091 | "%N!\nVBox status code: %d (%Rrc)", pszFormat, &va2, rc, rc);
|
---|
1092 | RTPrintf("%s\n", szError);
|
---|
1093 | va_end(va2);
|
---|
1094 | }
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 |
|
---|
1098 | /**
|
---|
1099 | * VM Runtime error callback function. Called by the various VM components.
|
---|
1100 | *
|
---|
1101 | * @param pVM The VM handle.
|
---|
1102 | * @param pvUser The user argument.
|
---|
1103 | * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
|
---|
1104 | * @param pszErrorId Error ID string.
|
---|
1105 | * @param pszError Error message format string.
|
---|
1106 | * @param va Error message arguments.
|
---|
1107 | * @thread EMT.
|
---|
1108 | */
|
---|
1109 | DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFlags,
|
---|
1110 | const char *pszErrorId,
|
---|
1111 | const char *pszFormat, va_list va)
|
---|
1112 | {
|
---|
1113 | va_list va2;
|
---|
1114 | va_copy(va2, va); /* Have to make a copy here or GCC/AMD64 will break. */
|
---|
1115 | RTPrintf("%s: %s!\n%N!\n",
|
---|
1116 | fFlags & VMSETRTERR_FLAGS_FATAL ? "Error" : "Warning",
|
---|
1117 | pszErrorId, pszFormat, &va2);
|
---|
1118 | RTStrmFlush(g_pStdErr);
|
---|
1119 | va_end(va2);
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 |
|
---|
1123 | /** VM asynchronous operations thread */
|
---|
1124 | DECLCALLBACK(int) VMPowerUpThread(RTTHREAD Thread, void *pvUser)
|
---|
1125 | {
|
---|
1126 | int rc = VINF_SUCCESS;
|
---|
1127 | int rc2;
|
---|
1128 |
|
---|
1129 | /*
|
---|
1130 | * Setup the release log instance in current directory.
|
---|
1131 | */
|
---|
1132 | if (g_fReleaseLog)
|
---|
1133 | {
|
---|
1134 | static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
|
---|
1135 | static char s_szError[RTPATH_MAX + 128] = "";
|
---|
1136 | PRTLOGGER pLogger;
|
---|
1137 | rc2 = RTLogCreateEx(&pLogger, RTLOGFLAGS_PREFIX_TIME_PROG, "all",
|
---|
1138 | "VBOX_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups,
|
---|
1139 | RTLOGDEST_FILE, s_szError, sizeof(s_szError), "./VBoxBFE.log");
|
---|
1140 | if (RT_SUCCESS(rc2))
|
---|
1141 | {
|
---|
1142 | /* some introductory information */
|
---|
1143 | RTTIMESPEC TimeSpec;
|
---|
1144 | char szNowUct[64];
|
---|
1145 | RTTimeSpecToString(RTTimeNow(&TimeSpec), szNowUct, sizeof(szNowUct));
|
---|
1146 | RTLogRelLogger(pLogger, 0, ~0U,
|
---|
1147 | "VBoxBFE %s (%s %s) release log\n"
|
---|
1148 | "Log opened %s\n",
|
---|
1149 | VBOX_VERSION_STRING, __DATE__, __TIME__,
|
---|
1150 | szNowUct);
|
---|
1151 |
|
---|
1152 | /* register this logger as the release logger */
|
---|
1153 | RTLogRelSetDefaultInstance(pLogger);
|
---|
1154 | }
|
---|
1155 | else
|
---|
1156 | RTPrintf("Could not open release log (%s)\n", s_szError);
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | /*
|
---|
1160 | * Start VM (also from saved state) and track progress
|
---|
1161 | */
|
---|
1162 | LogFlow(("VMPowerUp\n"));
|
---|
1163 |
|
---|
1164 | /*
|
---|
1165 | * Create empty VM.
|
---|
1166 | */
|
---|
1167 | rc = VMR3Create(1, NULL, setVMErrorCallback, NULL, vboxbfeConfigConstructor, NULL, &gpVM);
|
---|
1168 | if (RT_FAILURE(rc))
|
---|
1169 | {
|
---|
1170 | RTPrintf("Error: VM creation failed with %Rrc.\n", rc);
|
---|
1171 | goto failure;
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 |
|
---|
1175 | /*
|
---|
1176 | * Register VM state change handler
|
---|
1177 | */
|
---|
1178 | rc = VMR3AtStateRegister(gpVM, vmstateChangeCallback, NULL);
|
---|
1179 | if (RT_FAILURE(rc))
|
---|
1180 | {
|
---|
1181 | RTPrintf("Error: VMR3AtStateRegister failed with %Rrc.\n", rc);
|
---|
1182 | goto failure;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | #ifdef VBOX_WITH_HGCM
|
---|
1186 | /*
|
---|
1187 | * Add shared folders to the VM
|
---|
1188 | */
|
---|
1189 | if (fActivateHGCM() && gVMMDev->isShFlActive())
|
---|
1190 | {
|
---|
1191 | for (unsigned i=0; i<g_uNumShares; i++)
|
---|
1192 | {
|
---|
1193 | VBOXHGCMSVCPARM parms[SHFL_CPARMS_ADD_MAPPING];
|
---|
1194 | SHFLSTRING *pFolderName, *pMapName;
|
---|
1195 | int cbString;
|
---|
1196 | PRTUTF16 aHostPath, aMapName;
|
---|
1197 |
|
---|
1198 | rc2 = RTStrToUtf16(g_pszShareDir[i], &aHostPath);
|
---|
1199 | AssertRC(rc2);
|
---|
1200 | rc2 = RTStrToUtf16(g_pszShareName[i], &aMapName);
|
---|
1201 | AssertRC(rc2);
|
---|
1202 |
|
---|
1203 | cbString = (RTUtf16Len (aHostPath) + 1) * sizeof (RTUTF16);
|
---|
1204 | pFolderName = (SHFLSTRING *) RTMemAllocZ (sizeof (SHFLSTRING) + cbString);
|
---|
1205 | Assert (pFolderName);
|
---|
1206 | memcpy (pFolderName->String.ucs2, aHostPath, cbString);
|
---|
1207 |
|
---|
1208 | pFolderName->u16Size = cbString;
|
---|
1209 | pFolderName->u16Length = cbString - sizeof(RTUTF16);
|
---|
1210 |
|
---|
1211 | parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
1212 | parms[0].u.pointer.addr = pFolderName;
|
---|
1213 | parms[0].u.pointer.size = sizeof (SHFLSTRING) + cbString;
|
---|
1214 |
|
---|
1215 | cbString = (RTUtf16Len (aMapName) + 1) * sizeof (RTUTF16);
|
---|
1216 | pMapName = (SHFLSTRING *) RTMemAllocZ (sizeof(SHFLSTRING) + cbString);
|
---|
1217 | Assert (pMapName);
|
---|
1218 | memcpy (pMapName->String.ucs2, aMapName, cbString);
|
---|
1219 |
|
---|
1220 | pMapName->u16Size = cbString;
|
---|
1221 | pMapName->u16Length = cbString - sizeof (RTUTF16);
|
---|
1222 |
|
---|
1223 | parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
1224 | parms[1].u.pointer.addr = pMapName;
|
---|
1225 | parms[1].u.pointer.size = sizeof (SHFLSTRING) + cbString;
|
---|
1226 |
|
---|
1227 | parms[2].type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
1228 | parms[2].u.uint32 = !g_fShareReadOnly[i];
|
---|
1229 |
|
---|
1230 | rc2 = gVMMDev->hgcmHostCall ("VBoxSharedFolders",
|
---|
1231 | SHFL_FN_ADD_MAPPING, SHFL_CPARMS_ADD_MAPPING, &parms[0]);
|
---|
1232 | AssertRC(rc2);
|
---|
1233 | LogRel(("Added share %s: (%s)\n", g_pszShareName[i], g_pszShareDir[i]));
|
---|
1234 | RTMemFree (pFolderName);
|
---|
1235 | RTMemFree (pMapName);
|
---|
1236 | RTUtf16Free (aHostPath);
|
---|
1237 | RTUtf16Free (aMapName);
|
---|
1238 | }
|
---|
1239 | }
|
---|
1240 | #endif
|
---|
1241 |
|
---|
1242 | #ifdef VBOXBFE_WITH_USB
|
---|
1243 | /*
|
---|
1244 | * Capture USB devices.
|
---|
1245 | */
|
---|
1246 | if (g_fUSB)
|
---|
1247 | {
|
---|
1248 | gHostUSB = new HostUSB();
|
---|
1249 | gHostUSB->init(gpVM);
|
---|
1250 | }
|
---|
1251 | #endif /* VBOXBFE_WITH_USB */
|
---|
1252 |
|
---|
1253 | /*
|
---|
1254 | * Power on the VM (i.e. start executing).
|
---|
1255 | */
|
---|
1256 | if (RT_SUCCESS(rc))
|
---|
1257 | {
|
---|
1258 | if ( g_fRestoreState
|
---|
1259 | && g_pszStateFile
|
---|
1260 | && *g_pszStateFile
|
---|
1261 | && RTPathExists(g_pszStateFile))
|
---|
1262 | {
|
---|
1263 | startProgressInfo("Restoring");
|
---|
1264 | rc = VMR3LoadFromFile(gpVM, g_pszStateFile, callProgressInfo, (uintptr_t)NULL);
|
---|
1265 | endProgressInfo();
|
---|
1266 | if (RT_SUCCESS(rc))
|
---|
1267 | {
|
---|
1268 | rc = VMR3Resume(gpVM);
|
---|
1269 | AssertRC(rc);
|
---|
1270 | gDisplay->setRunning();
|
---|
1271 | }
|
---|
1272 | else
|
---|
1273 | AssertMsgFailed(("VMR3LoadFromFile failed, rc=%Rrc\n", rc));
|
---|
1274 | }
|
---|
1275 | else
|
---|
1276 | {
|
---|
1277 | rc = VMR3PowerOn(gpVM);
|
---|
1278 | if (RT_FAILURE(rc))
|
---|
1279 | AssertMsgFailed(("VMR3PowerOn failed, rc=%Rrc\n", rc));
|
---|
1280 | }
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | /*
|
---|
1284 | * On failure destroy the VM.
|
---|
1285 | */
|
---|
1286 | if (RT_FAILURE(rc))
|
---|
1287 | goto failure;
|
---|
1288 |
|
---|
1289 | return 0;
|
---|
1290 |
|
---|
1291 | failure:
|
---|
1292 | if (gpVM)
|
---|
1293 | {
|
---|
1294 | rc2 = VMR3Destroy(gpVM);
|
---|
1295 | AssertRC(rc2);
|
---|
1296 | gpVM = NULL;
|
---|
1297 | }
|
---|
1298 | machineState = VMSTATE_TERMINATED;
|
---|
1299 |
|
---|
1300 | return 0;
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | /**
|
---|
1304 | * Register the main drivers.
|
---|
1305 | *
|
---|
1306 | * @returns VBox status code.
|
---|
1307 | * @param pCallbacks Pointer to the callback table.
|
---|
1308 | * @param u32Version VBox version number.
|
---|
1309 | */
|
---|
1310 | DECLCALLBACK(int) VBoxDriversRegister(PCPDMDRVREGCB pCallbacks, uint32_t u32Version)
|
---|
1311 | {
|
---|
1312 | int rc;
|
---|
1313 |
|
---|
1314 | LogFlow(("VBoxDriversRegister: u32Version=%#x\n", u32Version));
|
---|
1315 | AssertReleaseMsg(u32Version == VBOX_VERSION, ("u32Version=%#x VBOX_VERSION=%#x\n", u32Version, VBOX_VERSION));
|
---|
1316 |
|
---|
1317 | rc = pCallbacks->pfnRegister(pCallbacks, &Mouse::DrvReg);
|
---|
1318 | AssertRC(rc);
|
---|
1319 | if (RT_FAILURE(rc))
|
---|
1320 | return rc;
|
---|
1321 | rc = pCallbacks->pfnRegister(pCallbacks, &Keyboard::DrvReg);
|
---|
1322 | AssertRC(rc);
|
---|
1323 | if (RT_FAILURE(rc))
|
---|
1324 | return rc;
|
---|
1325 |
|
---|
1326 | rc = pCallbacks->pfnRegister(pCallbacks, &Display::DrvReg);
|
---|
1327 | AssertRC(rc);
|
---|
1328 | if (RT_FAILURE(rc))
|
---|
1329 | return rc;
|
---|
1330 | rc = pCallbacks->pfnRegister(pCallbacks, &VMMDev::DrvReg);
|
---|
1331 | AssertRC(rc);
|
---|
1332 | if (RT_FAILURE(rc))
|
---|
1333 | return rc;
|
---|
1334 |
|
---|
1335 | rc = pCallbacks->pfnRegister(pCallbacks, &VMStatus::DrvReg);
|
---|
1336 | if (RT_FAILURE(rc))
|
---|
1337 | return rc;
|
---|
1338 |
|
---|
1339 | return VINF_SUCCESS;
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 |
|
---|
1343 | /**
|
---|
1344 | * Constructs the VMM configuration tree.
|
---|
1345 | *
|
---|
1346 | * @returns VBox status code.
|
---|
1347 | * @param pVM VM handle.
|
---|
1348 | */
|
---|
1349 | static DECLCALLBACK(int) vboxbfeConfigConstructor(PVM pVM, void *pvUser)
|
---|
1350 | {
|
---|
1351 | int rcAll = VINF_SUCCESS;
|
---|
1352 | int rc;
|
---|
1353 |
|
---|
1354 | #define UPDATE_RC() do { if (RT_FAILURE(rc) && RT_SUCCESS(rcAll)) rcAll = rc; } while (0)
|
---|
1355 |
|
---|
1356 | /*
|
---|
1357 | * Root values.
|
---|
1358 | */
|
---|
1359 | PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
|
---|
1360 | rc = CFGMR3InsertString(pRoot, "Name", "Default VM"); UPDATE_RC();
|
---|
1361 | rc = CFGMR3InsertInteger(pRoot, "RamSize", g_u32MemorySizeMB * _1M); UPDATE_RC();
|
---|
1362 | rc = CFGMR3InsertInteger(pRoot, "RamHoleSize", 512U * _1M); UPDATE_RC();
|
---|
1363 | if (g_fPreAllocRam)
|
---|
1364 | {
|
---|
1365 | rc = CFGMR3InsertInteger(pRoot, "RamPreAlloc", 1); UPDATE_RC();
|
---|
1366 | }
|
---|
1367 | rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); UPDATE_RC();
|
---|
1368 | #ifdef VBOXSDL_ADVANCED_OPTIONS
|
---|
1369 | rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", g_fRawR3); UPDATE_RC();
|
---|
1370 | rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", g_fRawR0); UPDATE_RC();
|
---|
1371 | rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", g_fPATM); UPDATE_RC();
|
---|
1372 | rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", g_fCSAM); UPDATE_RC();
|
---|
1373 | #else
|
---|
1374 | rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); UPDATE_RC();
|
---|
1375 | rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); UPDATE_RC();
|
---|
1376 | rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); UPDATE_RC();
|
---|
1377 | rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); UPDATE_RC();
|
---|
1378 | #endif
|
---|
1379 |
|
---|
1380 | /*
|
---|
1381 | * PDM.
|
---|
1382 | */
|
---|
1383 | rc = PDMR3RegisterDrivers(pVM, VBoxDriversRegister); UPDATE_RC();
|
---|
1384 |
|
---|
1385 | /*
|
---|
1386 | * Devices
|
---|
1387 | */
|
---|
1388 | PCFGMNODE pDevices = NULL;
|
---|
1389 | rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); UPDATE_RC();
|
---|
1390 | /* device */
|
---|
1391 | PCFGMNODE pDev = NULL;
|
---|
1392 | PCFGMNODE pInst = NULL;
|
---|
1393 | PCFGMNODE pCfg = NULL;
|
---|
1394 | PCFGMNODE pLunL0 = NULL;
|
---|
1395 | PCFGMNODE pLunL1 = NULL;
|
---|
1396 | PCFGMNODE pDrv = NULL;
|
---|
1397 |
|
---|
1398 | /*
|
---|
1399 | * PC Arch.
|
---|
1400 | */
|
---|
1401 | rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); UPDATE_RC();
|
---|
1402 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1403 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1404 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1405 |
|
---|
1406 | /*
|
---|
1407 | * PC Bios.
|
---|
1408 | */
|
---|
1409 | rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); UPDATE_RC();
|
---|
1410 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1411 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1412 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1413 | rc = CFGMR3InsertInteger(pCfg, "RamSize", g_u32MemorySizeMB * _1M); UPDATE_RC();
|
---|
1414 | rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", 512U * _1M); UPDATE_RC();
|
---|
1415 | rc = CFGMR3InsertString(pCfg, "BootDevice0", g_pszBootDevice); UPDATE_RC();
|
---|
1416 | rc = CFGMR3InsertString(pCfg, "BootDevice1", "NONE"); UPDATE_RC();
|
---|
1417 | rc = CFGMR3InsertString(pCfg, "BootDevice2", "NONE"); UPDATE_RC();
|
---|
1418 | rc = CFGMR3InsertString(pCfg, "BootDevice3", "NONE"); UPDATE_RC();
|
---|
1419 | rc = CFGMR3InsertString(pCfg, "HardDiskDevice", "piix3ide"); UPDATE_RC();
|
---|
1420 | rc = CFGMR3InsertString(pCfg, "FloppyDevice", "i82078"); UPDATE_RC();
|
---|
1421 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", g_fIOAPIC); UPDATE_RC();
|
---|
1422 | RTUUID Uuid;
|
---|
1423 | RTUuidClear(&Uuid);
|
---|
1424 | rc = CFGMR3InsertBytes(pCfg, "UUID", &Uuid, sizeof(Uuid)); UPDATE_RC();
|
---|
1425 |
|
---|
1426 | /*
|
---|
1427 | * ACPI
|
---|
1428 | */
|
---|
1429 | if (g_fACPI)
|
---|
1430 | {
|
---|
1431 | rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); UPDATE_RC();
|
---|
1432 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1433 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1434 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1435 | rc = CFGMR3InsertInteger(pCfg, "RamSize", g_u32MemorySizeMB * _1M); UPDATE_RC();
|
---|
1436 | rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", 512U * _1M); UPDATE_RC();
|
---|
1437 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", g_fIOAPIC); UPDATE_RC();
|
---|
1438 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); UPDATE_RC();
|
---|
1439 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC();
|
---|
1440 |
|
---|
1441 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1442 | rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); UPDATE_RC();
|
---|
1443 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1444 | }
|
---|
1445 |
|
---|
1446 | /*
|
---|
1447 | * PCI bus.
|
---|
1448 | */
|
---|
1449 | rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ UPDATE_RC();
|
---|
1450 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1451 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1452 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1453 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", g_fIOAPIC); UPDATE_RC();
|
---|
1454 |
|
---|
1455 | /*
|
---|
1456 | * DMA
|
---|
1457 | */
|
---|
1458 | rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); UPDATE_RC();
|
---|
1459 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1460 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1461 |
|
---|
1462 | /*
|
---|
1463 | * PCI bus.
|
---|
1464 | */
|
---|
1465 | rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ UPDATE_RC();
|
---|
1466 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1467 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1468 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1469 |
|
---|
1470 | /*
|
---|
1471 | * PS/2 keyboard & mouse.
|
---|
1472 | */
|
---|
1473 | rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); UPDATE_RC();
|
---|
1474 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1475 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1476 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1477 |
|
---|
1478 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1479 | rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); UPDATE_RC();
|
---|
1480 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1481 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); UPDATE_RC();
|
---|
1482 |
|
---|
1483 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pDrv); UPDATE_RC();
|
---|
1484 | rc = CFGMR3InsertString(pDrv, "Driver", "MainKeyboard"); UPDATE_RC();
|
---|
1485 | rc = CFGMR3InsertNode(pDrv, "Config", &pCfg); UPDATE_RC();
|
---|
1486 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)gKeyboard); UPDATE_RC();
|
---|
1487 |
|
---|
1488 | rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); UPDATE_RC();
|
---|
1489 | rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); UPDATE_RC();
|
---|
1490 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1491 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); UPDATE_RC();
|
---|
1492 |
|
---|
1493 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pDrv); UPDATE_RC();
|
---|
1494 | rc = CFGMR3InsertString(pDrv, "Driver", "MainMouse"); UPDATE_RC();
|
---|
1495 | rc = CFGMR3InsertNode(pDrv, "Config", &pCfg); UPDATE_RC();
|
---|
1496 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)gMouse); UPDATE_RC();
|
---|
1497 |
|
---|
1498 |
|
---|
1499 | /*
|
---|
1500 | * i82078 Floppy drive controller
|
---|
1501 | */
|
---|
1502 | rc = CFGMR3InsertNode(pDevices, "i82078", &pDev); UPDATE_RC();
|
---|
1503 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1504 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); UPDATE_RC();
|
---|
1505 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1506 | rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); UPDATE_RC();
|
---|
1507 | rc = CFGMR3InsertInteger(pCfg, "DMA", 2); UPDATE_RC();
|
---|
1508 | rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); UPDATE_RC();
|
---|
1509 | rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); UPDATE_RC();
|
---|
1510 |
|
---|
1511 | /* Attach the status driver */
|
---|
1512 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); UPDATE_RC();
|
---|
1513 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); UPDATE_RC();
|
---|
1514 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1515 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&mapFDLeds[0]); UPDATE_RC();
|
---|
1516 | rc = CFGMR3InsertInteger(pCfg, "First", 0); UPDATE_RC();
|
---|
1517 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); UPDATE_RC();
|
---|
1518 |
|
---|
1519 | if (g_pszFdaFile)
|
---|
1520 | {
|
---|
1521 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1522 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); UPDATE_RC();
|
---|
1523 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1524 | rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); UPDATE_RC();
|
---|
1525 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); UPDATE_RC();
|
---|
1526 |
|
---|
1527 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pDrv); UPDATE_RC();
|
---|
1528 | rc = CFGMR3InsertString(pDrv, "Driver", "RawImage"); UPDATE_RC();
|
---|
1529 | rc = CFGMR3InsertNode(pDrv, "Config", &pCfg); UPDATE_RC();
|
---|
1530 | rc = CFGMR3InsertString(pCfg, "Path", g_pszFdaFile); UPDATE_RC();
|
---|
1531 | }
|
---|
1532 |
|
---|
1533 | /*
|
---|
1534 | * i8254 Programmable Interval Timer And Dummy Speaker
|
---|
1535 | */
|
---|
1536 | rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); UPDATE_RC();
|
---|
1537 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1538 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1539 | #ifdef DEBUG
|
---|
1540 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1541 | #endif
|
---|
1542 |
|
---|
1543 | /*
|
---|
1544 | * i8259 Programmable Interrupt Controller.
|
---|
1545 | */
|
---|
1546 | rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); UPDATE_RC();
|
---|
1547 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1548 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1549 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1550 |
|
---|
1551 | /*
|
---|
1552 | * Advanced Programmable Interrupt Controller.
|
---|
1553 | */
|
---|
1554 | rc = CFGMR3InsertNode(pDevices, "apic", &pDev); UPDATE_RC();
|
---|
1555 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1556 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1557 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1558 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", g_fIOAPIC); UPDATE_RC();
|
---|
1559 |
|
---|
1560 | /*
|
---|
1561 | * I/O Advanced Programmable Interrupt Controller.
|
---|
1562 | */
|
---|
1563 | if (g_fIOAPIC)
|
---|
1564 | {
|
---|
1565 | rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); UPDATE_RC();
|
---|
1566 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1567 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1568 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | /*
|
---|
1572 | * RTC MC146818.
|
---|
1573 | */
|
---|
1574 | rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); UPDATE_RC();
|
---|
1575 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1576 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1577 |
|
---|
1578 | /*
|
---|
1579 | * Serial ports
|
---|
1580 | */
|
---|
1581 | rc = CFGMR3InsertNode(pDevices, "serial", &pDev); UPDATE_RC();
|
---|
1582 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1583 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1584 | rc = CFGMR3InsertInteger(pCfg, "IRQ", 4); UPDATE_RC();
|
---|
1585 | rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f8); UPDATE_RC();
|
---|
1586 |
|
---|
1587 | rc = CFGMR3InsertNode(pDev, "1", &pInst); UPDATE_RC();
|
---|
1588 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1589 | rc = CFGMR3InsertInteger(pCfg, "IRQ", 3); UPDATE_RC();
|
---|
1590 | rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x2f8); UPDATE_RC();
|
---|
1591 |
|
---|
1592 | /*
|
---|
1593 | * VGA.
|
---|
1594 | */
|
---|
1595 | rc = CFGMR3InsertNode(pDevices, "vga", &pDev); UPDATE_RC();
|
---|
1596 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1597 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1598 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); UPDATE_RC();
|
---|
1599 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC();
|
---|
1600 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1601 | rc = CFGMR3InsertInteger(pCfg, "VRamSize", g_u32VRamSize); UPDATE_RC();
|
---|
1602 |
|
---|
1603 | /* Default: no bios logo. */
|
---|
1604 | rc = CFGMR3InsertInteger(pCfg, "FadeIn", 1); UPDATE_RC();
|
---|
1605 | rc = CFGMR3InsertInteger(pCfg, "FadeOut", 0); UPDATE_RC();
|
---|
1606 | rc = CFGMR3InsertInteger(pCfg, "LogoTime", 0); UPDATE_RC();
|
---|
1607 | rc = CFGMR3InsertString(pCfg, "LogoFile", ""); UPDATE_RC();
|
---|
1608 |
|
---|
1609 | /* Boot menu */
|
---|
1610 | rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", g_iBootMenu); UPDATE_RC();
|
---|
1611 |
|
---|
1612 | #ifdef RT_OS_L4
|
---|
1613 | /* XXX hard-coded */
|
---|
1614 | rc = CFGMR3InsertInteger(pCfg, "HeightReduction", 18); UPDATE_RC();
|
---|
1615 | rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", 1); UPDATE_RC();
|
---|
1616 | char szBuf[64];
|
---|
1617 | /* Tell the guest which is the ideal video mode to use */
|
---|
1618 | RTStrPrintf(szBuf, sizeof(szBuf), "%dx%dx%d",
|
---|
1619 | gFramebuffer->getHostXres(),
|
---|
1620 | gFramebuffer->getHostYres(),
|
---|
1621 | gFramebuffer->getHostBitsPerPixel());
|
---|
1622 | rc = CFGMR3InsertString(pCfg, "CustomVideoMode1", szBuf); UPDATE_RC();
|
---|
1623 | #endif
|
---|
1624 |
|
---|
1625 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1626 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); UPDATE_RC();
|
---|
1627 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1628 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)gDisplay); UPDATE_RC();
|
---|
1629 |
|
---|
1630 | /*
|
---|
1631 | * IDE (update this when the main interface changes)
|
---|
1632 | */
|
---|
1633 | rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ UPDATE_RC();
|
---|
1634 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1635 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1636 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 1); UPDATE_RC();
|
---|
1637 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 1); UPDATE_RC();
|
---|
1638 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1639 |
|
---|
1640 | if (g_pszHdaFile)
|
---|
1641 | {
|
---|
1642 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1643 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); UPDATE_RC();
|
---|
1644 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1645 | rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); UPDATE_RC();
|
---|
1646 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); UPDATE_RC();
|
---|
1647 |
|
---|
1648 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pDrv); UPDATE_RC();
|
---|
1649 | rc = CFGMR3InsertString(pDrv, "Driver", "VD"); UPDATE_RC();
|
---|
1650 | rc = CFGMR3InsertNode(pDrv, "Config", &pCfg); UPDATE_RC();
|
---|
1651 | rc = CFGMR3InsertString(pCfg, "Path", g_pszHdaFile); UPDATE_RC();
|
---|
1652 |
|
---|
1653 | if (g_fHdaSpf)
|
---|
1654 | {
|
---|
1655 | rc = CFGMR3InsertString(pCfg, "Format", "SPF"); UPDATE_RC();
|
---|
1656 | }
|
---|
1657 | else
|
---|
1658 | {
|
---|
1659 | char *pcExt = RTPathExt(g_pszHdaFile);
|
---|
1660 | if ((pcExt) && (!strcmp(pcExt, ".vdi")))
|
---|
1661 | {
|
---|
1662 | rc = CFGMR3InsertString(pCfg, "Format", "VDI"); UPDATE_RC();
|
---|
1663 | }
|
---|
1664 | else
|
---|
1665 | {
|
---|
1666 | rc = CFGMR3InsertString(pCfg, "Format", "VMDK"); UPDATE_RC();
|
---|
1667 | }
|
---|
1668 | }
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 | if (g_pszHdbFile)
|
---|
1672 | {
|
---|
1673 | rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL1); UPDATE_RC();
|
---|
1674 | rc = CFGMR3InsertString(pLunL1, "Driver", "Block"); UPDATE_RC();
|
---|
1675 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); UPDATE_RC();
|
---|
1676 | rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); UPDATE_RC();
|
---|
1677 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); UPDATE_RC();
|
---|
1678 |
|
---|
1679 | rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pDrv); UPDATE_RC();
|
---|
1680 | rc = CFGMR3InsertString(pDrv, "Driver", "VD"); UPDATE_RC();
|
---|
1681 | rc = CFGMR3InsertNode(pDrv, "Config", &pCfg); UPDATE_RC();
|
---|
1682 | rc = CFGMR3InsertString(pCfg, "Path", g_pszHdbFile); UPDATE_RC();
|
---|
1683 |
|
---|
1684 | if (g_fHdbSpf)
|
---|
1685 | {
|
---|
1686 | rc = CFGMR3InsertString(pCfg, "Format", "SPF"); UPDATE_RC();
|
---|
1687 | }
|
---|
1688 | else
|
---|
1689 | {
|
---|
1690 | char *pcExt = RTPathExt(g_pszHdbFile);
|
---|
1691 | if ((pcExt) && (!strcmp(pcExt, ".vdi")))
|
---|
1692 | {
|
---|
1693 | rc = CFGMR3InsertString(pCfg, "Format", "VDI"); UPDATE_RC();
|
---|
1694 | }
|
---|
1695 | else
|
---|
1696 | {
|
---|
1697 | rc = CFGMR3InsertString(pCfg, "Format", "VMDK"); UPDATE_RC();
|
---|
1698 | }
|
---|
1699 | }
|
---|
1700 | }
|
---|
1701 |
|
---|
1702 | if (g_pszCdromFile)
|
---|
1703 | {
|
---|
1704 | // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
|
---|
1705 | rc = CFGMR3InsertNode(pInst, "LUN#2", &pLunL0); UPDATE_RC();
|
---|
1706 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); UPDATE_RC();
|
---|
1707 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1708 | rc = CFGMR3InsertString(pCfg, "Type", "DVD"); UPDATE_RC();
|
---|
1709 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); UPDATE_RC();
|
---|
1710 |
|
---|
1711 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pDrv); UPDATE_RC();
|
---|
1712 | rc = CFGMR3InsertString(pDrv, "Driver", "MediaISO"); UPDATE_RC();
|
---|
1713 | rc = CFGMR3InsertNode(pDrv, "Config", &pCfg); UPDATE_RC();
|
---|
1714 | rc = CFGMR3InsertString(pCfg, "Path", g_pszCdromFile); UPDATE_RC();
|
---|
1715 | }
|
---|
1716 |
|
---|
1717 | /*
|
---|
1718 | * Network adapters
|
---|
1719 | */
|
---|
1720 | rc = CFGMR3InsertNode(pDevices, "pcnet", &pDev); UPDATE_RC();
|
---|
1721 | for (ULONG ulInstance = 0; ulInstance < NetworkAdapterCount; ulInstance++)
|
---|
1722 | {
|
---|
1723 | if (g_aNetDevs[ulInstance].enmType != BFENETDEV::NOT_CONFIGURED)
|
---|
1724 | {
|
---|
1725 | char szInstance[4];
|
---|
1726 | RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
|
---|
1727 | rc = CFGMR3InsertNode(pDev, szInstance, &pInst); UPDATE_RC();
|
---|
1728 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); UPDATE_RC();
|
---|
1729 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo",
|
---|
1730 | !ulInstance ? 3 : ulInstance - 1 + 8); UPDATE_RC();
|
---|
1731 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC();
|
---|
1732 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1733 | rc = CFGMR3InsertBytes(pCfg, "MAC", &g_aNetDevs[ulInstance].Mac, sizeof(RTMAC));
|
---|
1734 | UPDATE_RC();
|
---|
1735 |
|
---|
1736 | /*
|
---|
1737 | * Enable the packet sniffer if requested.
|
---|
1738 | */
|
---|
1739 | if (g_aNetDevs[ulInstance].fSniff)
|
---|
1740 | {
|
---|
1741 | /* insert the sniffer filter driver. */
|
---|
1742 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1743 | rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); UPDATE_RC();
|
---|
1744 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1745 | if (g_aNetDevs[ulInstance].pszSniff)
|
---|
1746 | {
|
---|
1747 | rc = CFGMR3InsertString(pCfg, "File", g_aNetDevs[ulInstance].pszSniff);
|
---|
1748 | UPDATE_RC();
|
---|
1749 | }
|
---|
1750 | }
|
---|
1751 |
|
---|
1752 | /*
|
---|
1753 | * Create the driver config (if any).
|
---|
1754 | */
|
---|
1755 | if (g_aNetDevs[ulInstance].enmType != BFENETDEV::NONE)
|
---|
1756 | {
|
---|
1757 | if (g_aNetDevs[ulInstance].fSniff)
|
---|
1758 | {
|
---|
1759 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); UPDATE_RC();
|
---|
1760 | }
|
---|
1761 | else
|
---|
1762 | {
|
---|
1763 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1764 | }
|
---|
1765 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | /*
|
---|
1769 | * Configure the driver.
|
---|
1770 | */
|
---|
1771 | if (g_aNetDevs[ulInstance].enmType == BFENETDEV::NAT)
|
---|
1772 | {
|
---|
1773 | rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); UPDATE_RC();
|
---|
1774 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1775 | /* (Port forwarding goes here.) */
|
---|
1776 | }
|
---|
1777 | else if (g_aNetDevs[ulInstance].enmType == BFENETDEV::HIF)
|
---|
1778 | {
|
---|
1779 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); UPDATE_RC();
|
---|
1780 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1781 |
|
---|
1782 | #if defined(RT_OS_LINUX)
|
---|
1783 | if (g_aNetDevs[ulInstance].fHaveFd)
|
---|
1784 | {
|
---|
1785 | rc = CFGMR3InsertString(pCfg, "Device", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
|
---|
1786 | rc = CFGMR3InsertInteger(pCfg, "FileHandle", g_aNetDevs[ulInstance].fd); UPDATE_RC();
|
---|
1787 | }
|
---|
1788 | else
|
---|
1789 | #endif
|
---|
1790 | {
|
---|
1791 | #if defined(RT_OS_LINUX) || defined(RT_OS_L4)
|
---|
1792 | /*
|
---|
1793 | * Create/Open the TAP the device.
|
---|
1794 | */
|
---|
1795 | RTFILE tapFD;
|
---|
1796 | rc = RTFileOpen(&tapFD, "/dev/net/tun",
|
---|
1797 | RTFILE_O_READWRITE | RTFILE_O_OPEN |
|
---|
1798 | RTFILE_O_DENY_NONE | RTFILE_O_INHERIT);
|
---|
1799 | if (RT_FAILURE(rc))
|
---|
1800 | {
|
---|
1801 | FatalError("Failed to open /dev/net/tun: %Rrc\n", rc);
|
---|
1802 | return rc;
|
---|
1803 | }
|
---|
1804 |
|
---|
1805 | struct ifreq IfReq;
|
---|
1806 | memset(&IfReq, 0, sizeof(IfReq));
|
---|
1807 | if (g_aNetDevs[ulInstance].pszName && g_aNetDevs[ulInstance].pszName[0])
|
---|
1808 | {
|
---|
1809 | size_t cch = strlen(g_aNetDevs[ulInstance].pszName);
|
---|
1810 | if (cch >= sizeof(IfReq.ifr_name))
|
---|
1811 | {
|
---|
1812 | FatalError("HIF name too long for device #%d: %s\n",
|
---|
1813 | ulInstance + 1, g_aNetDevs[ulInstance].pszName);
|
---|
1814 | return VERR_BUFFER_OVERFLOW;
|
---|
1815 | }
|
---|
1816 | memcpy(IfReq.ifr_name, g_aNetDevs[ulInstance].pszName, cch + 1);
|
---|
1817 | }
|
---|
1818 | else
|
---|
1819 | strcpy(IfReq.ifr_name, "tun%d");
|
---|
1820 | IfReq.ifr_flags = IFF_TAP | IFF_NO_PI;
|
---|
1821 | rc = ioctl(tapFD, TUNSETIFF, &IfReq);
|
---|
1822 | if (rc)
|
---|
1823 | {
|
---|
1824 | int rc2 = RTErrConvertFromErrno(errno);
|
---|
1825 | FatalError("ioctl TUNSETIFF '%s' failed: errno=%d rc=%d (%Rrc)\n",
|
---|
1826 | IfReq.ifr_name, errno, rc, rc2);
|
---|
1827 | return rc2;
|
---|
1828 | }
|
---|
1829 |
|
---|
1830 | rc = fcntl(tapFD, F_SETFL, O_NONBLOCK);
|
---|
1831 | if (rc)
|
---|
1832 | {
|
---|
1833 | int rc2 = RTErrConvertFromErrno(errno);
|
---|
1834 | FatalError("fcntl F_SETFL/O_NONBLOCK '%s' failed: errno=%d rc=%d (%Rrc)\n",
|
---|
1835 | IfReq.ifr_name, errno, rc, rc2);
|
---|
1836 | return rc2;
|
---|
1837 | }
|
---|
1838 |
|
---|
1839 | rc = CFGMR3InsertString(pCfg, "Device", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
|
---|
1840 | rc = CFGMR3InsertInteger(pCfg, "FileHandle", (RTFILE)tapFD); UPDATE_RC();
|
---|
1841 |
|
---|
1842 | #elif defined(RT_OS_SOLARIS)
|
---|
1843 | rc = CFGMR3InsertString(pCfg, "Device", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
|
---|
1844 | # ifdef VBOX_WITH_CROSSBOW
|
---|
1845 | rc = CFGMR3InsertBytes(pCfg, "MAC", &g_aNetDevs[ulInstance].Mac, sizeof(g_aNetDevs[ulInstance].Mac));
|
---|
1846 | UPDATE_RC();
|
---|
1847 | # endif
|
---|
1848 |
|
---|
1849 | #elif defined(RT_OS_OS2)
|
---|
1850 | /*
|
---|
1851 | * The TAP driver does all the opening and setting up,
|
---|
1852 | * as it was originally was meant to be (stupid fork() problems).
|
---|
1853 | */
|
---|
1854 | rc = CFGMR3InsertString(pCfg, "Device", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
|
---|
1855 | if (g_aNetDevs[ulInstance].fHaveConnectTo)
|
---|
1856 | {
|
---|
1857 | rc = CFGMR3InsertInteger(pCfg, "ConnectTo", g_aNetDevs[ulInstance].iConnectTo);
|
---|
1858 | UPDATE_RC();
|
---|
1859 | }
|
---|
1860 | #elif defined(RT_OS_WINDOWS)
|
---|
1861 | /*
|
---|
1862 | * We need the GUID too here...
|
---|
1863 | */
|
---|
1864 | rc = CFGMR3InsertString(pCfg, "Device", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
|
---|
1865 | rc = CFGMR3InsertString(pCfg, "HostInterfaceName", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
|
---|
1866 | rc = CFGMR3InsertString(pCfg, "GUID", g_aNetDevs[ulInstance].pszName /*pszGUID*/); UPDATE_RC();
|
---|
1867 |
|
---|
1868 |
|
---|
1869 | #else
|
---|
1870 | FatalError("Name based HIF devices not implemented yet for this host platform\n");
|
---|
1871 | return VERR_NOT_IMPLEMENTED;
|
---|
1872 | #endif
|
---|
1873 | }
|
---|
1874 | }
|
---|
1875 | else if (g_aNetDevs[ulInstance].enmType == BFENETDEV::INTNET)
|
---|
1876 | {
|
---|
1877 | /*
|
---|
1878 | * Internal networking.
|
---|
1879 | */
|
---|
1880 | rc = CFGMR3InsertString(pCfg, "Network", g_aNetDevs[ulInstance].pszName); UPDATE_RC();
|
---|
1881 | }
|
---|
1882 | }
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | /*
|
---|
1886 | * VMM Device
|
---|
1887 | */
|
---|
1888 | rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); UPDATE_RC();
|
---|
1889 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1890 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1891 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1892 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); UPDATE_RC();
|
---|
1893 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC();
|
---|
1894 | rc = CFGMR3InsertInteger(pCfg, "RamSize", g_u32MemorySizeMB * _1M); UPDATE_RC();
|
---|
1895 |
|
---|
1896 | /* the VMM device's Main driver */
|
---|
1897 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1898 | rc = CFGMR3InsertString(pLunL0, "Driver", "HGCM"); UPDATE_RC();
|
---|
1899 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1900 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)gVMMDev); UPDATE_RC();
|
---|
1901 |
|
---|
1902 | /*
|
---|
1903 | * AC'97 ICH audio
|
---|
1904 | */
|
---|
1905 | if (g_fAudio)
|
---|
1906 | {
|
---|
1907 | rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); UPDATE_RC();
|
---|
1908 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1909 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1910 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); UPDATE_RC();
|
---|
1911 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC();
|
---|
1912 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg);
|
---|
1913 |
|
---|
1914 | /* the Audio driver */
|
---|
1915 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1916 | rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); UPDATE_RC();
|
---|
1917 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1918 | #ifdef RT_OS_WINDOWS
|
---|
1919 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); UPDATE_RC();
|
---|
1920 | #elif defined(RT_OS_DARWIN)
|
---|
1921 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); UPDATE_RC();
|
---|
1922 | #elif defined(RT_OS_LINUX)
|
---|
1923 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); UPDATE_RC();
|
---|
1924 | #elif defined(RT_OS_SOLARIS)
|
---|
1925 | # ifdef VBOX_WITH_SOLARIS_OSS
|
---|
1926 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); UPDATE_RC();
|
---|
1927 | # else
|
---|
1928 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); UPDATE_RC();
|
---|
1929 | # endif
|
---|
1930 | #elif defined(RT_OS_L4)
|
---|
1931 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); UPDATE_RC();
|
---|
1932 | #else /* portme */
|
---|
1933 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "none"); UPDATE_RC();
|
---|
1934 | #endif /* !RT_OS_WINDOWS */
|
---|
1935 | }
|
---|
1936 |
|
---|
1937 | #ifdef VBOXBFE_WITH_USB
|
---|
1938 | /*
|
---|
1939 | * The USB Controller.
|
---|
1940 | */
|
---|
1941 | if (g_fUSB)
|
---|
1942 | {
|
---|
1943 | rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); UPDATE_RC();
|
---|
1944 | rc = CFGMR3InsertNode(pDev, "0", &pInst); UPDATE_RC();
|
---|
1945 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); UPDATE_RC();
|
---|
1946 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ UPDATE_RC();
|
---|
1947 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); UPDATE_RC();
|
---|
1948 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); UPDATE_RC();
|
---|
1949 |
|
---|
1950 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); UPDATE_RC();
|
---|
1951 | rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); UPDATE_RC();
|
---|
1952 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); UPDATE_RC();
|
---|
1953 | }
|
---|
1954 | #endif /* VBOXBFE_WITH_USB */
|
---|
1955 |
|
---|
1956 | #undef UPDATE_RC
|
---|
1957 | #undef UPDATE_RC
|
---|
1958 |
|
---|
1959 | VMR3AtRuntimeErrorRegister (pVM, setVMRuntimeErrorCallback, NULL);
|
---|
1960 |
|
---|
1961 | return rc;
|
---|
1962 | }
|
---|
1963 |
|
---|