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