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