VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/VBoxBFE.cpp@ 4644

Last change on this file since 4644 was 4644, checked in by vboxsync, 17 years ago

OS/2 hif support. the parsing of a couple of network arguments.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette