2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/vdm/vdmmain.c
5 * PURPOSE: VDM Support Services
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Aleksey Bragin (aleksey@reactos.org)
10 /* INCLUDES ******************************************************************/
16 /* GLOBALS *******************************************************************/
19 /* PRIVATE FUNCTIONS *********************************************************/
23 Ki386VdmEnablePentiumExtentions(VOID
)
25 DPRINT1("VME detected but not yet supported\n");
30 KeI386VdmInitialize(VOID
)
33 OBJECT_ATTRIBUTES ObjectAttributes
;
36 UCHAR KeyValueInfo
[sizeof(KEY_VALUE_BASIC_INFORMATION
) + 30];
39 /* Make sure that there is a WOW key */
40 RtlInitUnicodeString(&Name
,
41 L
"\\Registry\\Machine\\System\\CurrentControlSet\\"
43 InitializeObjectAttributes(&ObjectAttributes
,
48 Status
= ZwOpenKey(&RegHandle
, KEY_READ
, &ObjectAttributes
);
49 if (!NT_SUCCESS(Status
)) return;
51 /* Check if VME is enabled */
52 RtlInitUnicodeString(&Name
, L
"DisableVme");
53 Status
= ZwQueryValueKey(RegHandle
,
55 KeyValueBasicInformation
,
59 if (!NT_SUCCESS(Status
))
61 /* Not present, so check if the CPU supports VME */
62 if (KeGetPcr()->Prcb
->FeatureBits
& KF_V86_VIS
)
64 /* Enable them. FIXME: Use IPI */
65 Ki386VdmEnablePentiumExtentions();
66 KeI386VirtualIntExtensions
= TRUE
;
76 VdmpInitialize(PVOID ControlData
)
78 OBJECT_ATTRIBUTES ObjectAttributes
;
79 UNICODE_STRING PhysMemName
= RTL_CONSTANT_STRING(L
"\\Device\\PhysicalMemory");
83 PVOID NullAddress
= NULL
;
87 /* Open the physical memory section */
88 InitializeObjectAttributes(&ObjectAttributes
,
93 Status
= ZwOpenSection(&PhysMemHandle
,
96 if (!NT_SUCCESS(Status
))
98 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
102 /* Map the BIOS and device registers into the address space */
104 ViewSize
= PAGE_SIZE
;
106 Status
= ZwMapViewOfSection(PhysMemHandle
,
116 if (!NT_SUCCESS(Status
))
118 DPRINT1("Couldn't map physical memory (%x)\n", Status
);
119 ZwClose(PhysMemHandle
);
123 /* Now, copy the first physical page into the first virtual page */
126 RtlMoveMemory(NullAddress
, BaseAddress
, ViewSize
);
128 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
131 Status
= _SEH2_GetExceptionCode();
135 if (!NT_SUCCESS(Status
))
137 DPRINT1("Couldn't copy first page (%x)\n", Status
);
138 ZwClose(PhysMemHandle
);
139 ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress
);
143 /* Close physical memory section handle */
144 ZwClose(PhysMemHandle
);
146 /* Unmap the section */
147 Status
= ZwUnmapViewOfSection(NtCurrentProcess(), BaseAddress
);
149 if (!NT_SUCCESS(Status
))
151 DPRINT1("Couldn't unmap the section (%x)\n", Status
);
155 return STATUS_SUCCESS
;
158 /* PUBLIC FUNCTIONS **********************************************************/
165 NtVdmControl(IN ULONG ControlCode
,
166 IN PVOID ControlData
)
171 /* Check which control code this is */
174 /* VDM Execution start */
175 case VdmStartExecution
:
177 /* Call the sub-function */
178 Status
= VdmpStartExecution();
183 /* Call the init sub-function */
184 Status
= VdmpInitialize(ControlData
);
190 DPRINT1("Unknown VDM call: %lx\n", ControlCode
);
191 Status
= STATUS_INVALID_PARAMETER
;
194 /* Return the status */