VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/VBoxAppleSim/VBoxAppleSim.c@ 35645

Last change on this file since 35645 was 35645, checked in by vboxsync, 14 years ago

EFI64: don't let Mac guest call for debugger on "acpi shutdown".

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1/* $Id: VBoxAppleSim.c 35645 2011-01-20 09:11:41Z vboxsync $ */
2/** @file
3 * VBoxAppleSim.c - VirtualBox Apple Firmware simulation support
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <Library/BaseMemoryLib.h>
23#include <Library/DebugLib.h>
24#include <Library/UefiBootServicesTableLib.h>
25#include <Library/UefiLib.h>
26
27#include <Protocol/DevicePathToText.h>
28
29#include <IndustryStandard/Acpi10.h>
30#include <IndustryStandard/Acpi20.h>
31#include <IndustryStandard/SmBios.h>
32
33#include <Guid/SmBios.h>
34#include <Guid/Acpi.h>
35#include <Guid/Mps.h>
36
37#include "VBoxPkg.h"
38#include "DevEFI.h"
39#include "iprt/asm.h"
40
41
42/*
43 * External functions
44 */
45EFI_STATUS EFIAPI
46CpuUpdateDataHub(EFI_BOOT_SERVICES * bs,
47 UINT64 FSBFrequency,
48 UINT64 TSCFrequency,
49 UINT64 CPUFrequency);
50
51EFI_STATUS EFIAPI
52InitializeConsoleSim (IN EFI_HANDLE ImageHandle,
53 IN EFI_SYSTEM_TABLE *SystemTable);
54
55
56/*
57 * Internal Functions *
58 */
59static UINT32
60GetVmVariable(UINT32 Variable, CHAR8* Buffer, UINT32 Size )
61{
62 UINT32 VarLen, i;
63
64
65 ASMOutU32(EFI_INFO_PORT, Variable);
66 VarLen = ASMInU32(EFI_INFO_PORT);
67
68 for (i=0; i < VarLen && i < Size; i++)
69 {
70 Buffer[i] = ASMInU8(EFI_INFO_PORT);
71 }
72
73 return VarLen;
74}
75
76/*
77 * GUIDs
78 */
79EFI_GUID gEfiAppleNvramGuid = {
80 0x4D1EDE05, 0x38C7, 0x4A6A, {0x9C, 0xC6, 0x4B, 0xCC, 0xA8, 0xB3, 0x8C, 0x14 }
81};
82
83EFI_GUID gEfiAppleBootGuid = {
84 0x7C436110, 0xAB2A, 0x4BBB, {0xA8, 0x80, 0xFE, 0x41, 0x99, 0x5C, 0x9F, 0x82}
85};
86
87EFI_GUID gEfiAppleVarGuid = {
88 0x91BD12FE, 0xF6C3, 0x44FB, {0xA5, 0xB7, 0x51, 0x22, 0xAB, 0x30, 0x3A, 0xE0}
89};
90
91EFI_GUID gEfiUnknown1ProtocolGuid = {
92 0xDD8E06AC, 0x00E2, 0x49A9, {0x88, 0x8F, 0xFA, 0x46, 0xDE, 0xD4, 0x0A, 0x52}
93};
94
95/*
96 * Typedefs
97 */
98typedef struct _APPLE_GETVAR_PROTOCOL APPLE_GETVAR_PROTOCOL;
99
100typedef
101EFI_STATUS
102(EFIAPI *APPLE_GETVAR_PROTOCOL_GET_DEVICE_PROPS) (
103 IN APPLE_GETVAR_PROTOCOL *This,
104 IN CHAR8 *Buffer,
105 IN OUT UINT32 *BufferSize);
106
107
108struct _APPLE_GETVAR_PROTOCOL {
109 EFI_STATUS(EFIAPI *Unknown0)(IN VOID *);
110 EFI_STATUS(EFIAPI *Unknown1)(IN VOID *);
111 EFI_STATUS(EFIAPI *Unknown2)(IN VOID *);
112 EFI_STATUS(EFIAPI *Unknown3)(IN VOID *);
113 EFI_STATUS(EFIAPI *Unknown4)(IN VOID *);
114 APPLE_GETVAR_PROTOCOL_GET_DEVICE_PROPS GetDevProps;
115};
116
117
118#define IMPL_STUB(iface, num) \
119 EFI_STATUS EFIAPI \
120 iface##Unknown##num(IN VOID *This) \
121 { \
122 Print(L"Unknown%d of %a called", num, #iface); \
123 return EFI_SUCCESS; \
124 }
125
126IMPL_STUB(GetVar, 0)
127IMPL_STUB(GetVar, 1)
128IMPL_STUB(GetVar, 2)
129IMPL_STUB(GetVar, 3)
130IMPL_STUB(GetVar, 4)
131
132EFI_STATUS EFIAPI
133GetDeviceProps(IN APPLE_GETVAR_PROTOCOL *This,
134 IN CHAR8 *Buffer,
135 IN OUT UINT32 *BufferSize)
136{
137 UINT32 BufLen = *BufferSize, DataLen;
138
139 DataLen = GetVmVariable(EFI_INFO_INDEX_DEVICE_PROPS, Buffer, BufLen);
140 *BufferSize = DataLen;
141
142 if (DataLen > BufLen)
143 return EFI_BUFFER_TOO_SMALL;
144
145 return EFI_SUCCESS;
146}
147
148APPLE_GETVAR_PROTOCOL gPrivateVarHandler =
149{
150 GetVarUnknown0,
151 GetVarUnknown1,
152 GetVarUnknown2,
153 GetVarUnknown3,
154 GetVarUnknown4,
155 GetDeviceProps
156};
157
158EFI_STATUS EFIAPI
159UnknownHandlerImpl()
160{
161 Print(L"Unknown called\n");
162 return EFI_SUCCESS;
163}
164
165/* array of pointers to function */
166EFI_STATUS (EFIAPI *gUnknownProtoHandler[])() =
167{
168 UnknownHandlerImpl,
169 UnknownHandlerImpl,
170 UnknownHandlerImpl,
171 UnknownHandlerImpl,
172 UnknownHandlerImpl,
173 UnknownHandlerImpl,
174 UnknownHandlerImpl,
175 UnknownHandlerImpl,
176 UnknownHandlerImpl,
177 UnknownHandlerImpl,
178 UnknownHandlerImpl,
179 UnknownHandlerImpl,
180 UnknownHandlerImpl,
181 UnknownHandlerImpl,
182 UnknownHandlerImpl,
183 UnknownHandlerImpl,
184 UnknownHandlerImpl,
185 UnknownHandlerImpl
186};
187
188EFI_STATUS EFIAPI
189SetPrivateVarProto(IN EFI_HANDLE ImageHandle, EFI_BOOT_SERVICES * bs)
190{
191 EFI_STATUS rc;
192
193 rc = gBS->InstallMultipleProtocolInterfaces (
194 &ImageHandle,
195 &gEfiAppleVarGuid,
196 &gPrivateVarHandler,
197 NULL
198 );
199 ASSERT_EFI_ERROR (rc);
200
201 return EFI_SUCCESS;
202}
203
204EFI_STATUS EFIAPI
205SetProperVariables(IN EFI_HANDLE ImageHandle, EFI_RUNTIME_SERVICES * rs)
206{
207 EFI_STATUS rc;
208 UINT32 vBackgroundClear = 0x00000000;
209 UINT32 vFwFeatures = 0x80000015;
210 UINT32 vFwFeaturesMask = 0x800003ff;
211
212 // -legacy acpi=0xffffffff acpi_debug=0xfffffff panic_io_port=0xef11 io=0xfffffffe trace=4096 io=0xffffffef -v serial=2 serialbaud=9600
213 // 0x10 makes kdb default, thus 0x15e for kdb, 0x14e for gdb
214
215 //static const CHAR8 vBootArgs[] = "debug=0x15e keepsyms=1 acpi=0xffffffff acpi_debug=0xff acpi_level=7 -v -x32 -s"; // or just "debug=0x8 -legacy"
216 // 0x14e for serial output
217 //static const CHAR8 vDefBootArgs[] = "debug=0x146 keepsyms=1 -v -serial=0x1";
218 //static const CHAR8 vDefBootArgs[] = "keepsyms=1 -v -serial=0x1";
219 static const CHAR8 vDefBootArgs[] = "-v";
220 CHAR8 vBootArgs[256];
221 UINT32 BootArgsLen;
222
223 BootArgsLen = GetVmVariable(EFI_INFO_INDEX_BOOT_ARGS, vBootArgs, sizeof vBootArgs);
224 if (BootArgsLen <= 1)
225 {
226 BootArgsLen = sizeof vDefBootArgs;
227 CopyMem(vBootArgs, vDefBootArgs, BootArgsLen);
228 }
229 rc = rs->SetVariable(L"BackgroundClear",
230 &gEfiAppleNvramGuid,
231 /* EFI_VARIABLE_NON_VOLATILE | */ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
232 sizeof(vBackgroundClear), &vBackgroundClear);
233
234 rc = rs->SetVariable(L"FirmwareFeatures",
235 &gEfiAppleNvramGuid,
236 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
237 sizeof(vFwFeatures), &vFwFeatures);
238
239 rc = rs->SetVariable(L"FirmwareFeaturesMask",
240 &gEfiAppleNvramGuid,
241 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
242 sizeof(vFwFeaturesMask), &vFwFeaturesMask);
243
244 rc = rs->SetVariable(L"boot-args",
245 &gEfiAppleBootGuid,
246 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
247 BootArgsLen, &vBootArgs);
248
249 return EFI_SUCCESS;
250}
251
252/**
253 * VBoxInitAppleSim entry point.
254 *
255 * @returns EFI status code.
256 *
257 * @param ImageHandle The image handle.
258 * @param SystemTable The system table pointer.
259 */
260EFI_STATUS EFIAPI
261VBoxInitAppleSim(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
262{
263 EFI_STATUS rc;
264 UINT64 FSBFrequency;
265 UINT64 TSCFrequency;
266 UINT64 CPUFrequency;
267
268 rc = SetProperVariables(ImageHandle, SystemTable->RuntimeServices);
269 ASSERT_EFI_ERROR (rc);
270
271 rc = SetPrivateVarProto(ImageHandle, gBS);
272 ASSERT_EFI_ERROR (rc);
273
274 GetVmVariable(EFI_INFO_INDEX_FSB_FREQUENCY, (CHAR8*)&FSBFrequency, sizeof FSBFrequency);
275 GetVmVariable(EFI_INFO_INDEX_TSC_FREQUENCY, (CHAR8*)&TSCFrequency, sizeof TSCFrequency);
276 GetVmVariable(EFI_INFO_INDEX_CPU_FREQUENCY, (CHAR8*)&CPUFrequency, sizeof CPUFrequency);
277
278 rc = CpuUpdateDataHub(gBS, FSBFrequency, TSCFrequency, CPUFrequency);
279 ASSERT_EFI_ERROR (rc);
280
281 rc = InitializeConsoleSim(ImageHandle, SystemTable);
282 ASSERT_EFI_ERROR (rc);
283
284 rc = gBS->InstallMultipleProtocolInterfaces (
285 &ImageHandle,
286 &gEfiUnknown1ProtocolGuid,
287 gUnknownProtoHandler,
288 NULL
289 );
290 ASSERT_EFI_ERROR (rc);
291
292 return EFI_SUCCESS;
293}
294
295EFI_STATUS EFIAPI
296VBoxDeinitAppleSim(IN EFI_HANDLE ImageHandle)
297{
298 return EFI_SUCCESS;
299}
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