- NDK 0.98, now with versionned headers. Too many changes to list, see the TinyKRNL...
[reactos.git] / reactos / ntoskrnl / ke / i386 / vdm.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ke/i386/vdm.c
6 * PURPOSE: Virtual DOS machine support
7 *
8 * PROGRAMMERS: David Welch (welch@mcmail.com)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #include <internal/debug.h>
15
16 #if defined (ALLOC_PRAGMA)
17 #pragma alloc_text(INIT, NtEarlyInitVdm)
18 #endif
19
20
21 /* GLOBALS *******************************************************************/
22
23 static UCHAR OrigIVT[1024];
24 static UCHAR OrigBDA[256];
25 /* static UCHAR OrigEBDA[]; */
26
27 extern VOID Ki386RetToV86Mode(PKV86M_REGISTERS InRegs,
28 PKV86M_REGISTERS OutRegs);
29
30 /* FUNCTIONS *****************************************************************/
31
32 VOID INIT_FUNCTION
33 NtEarlyInitVdm(VOID)
34 {
35 /* GCC 3.4 warns if NULL is passed in parameter 2 to the standard function memcpy */
36 PVOID start = (PVOID)0x0;
37
38 /*
39 * Save various BIOS data tables. At this point the lower 4MB memory
40 * map is still active so we can just copy the data from low memory.
41 */
42 memcpy(OrigIVT, start, 1024);
43 memcpy(OrigBDA, (PVOID)0x400, 256);
44 }
45
46 /*
47 * @implemented
48 */
49 NTSTATUS STDCALL NtVdmControl(ULONG ControlCode,
50 PVOID ControlData)
51 {
52 KPROCESSOR_MODE PreviousMode;
53 NTSTATUS Status = STATUS_SUCCESS;
54
55 PreviousMode = ExGetPreviousMode();
56
57 if (PreviousMode != KernelMode)
58 {
59 _SEH_TRY
60 {
61 switch (ControlCode)
62 {
63 case 0:
64 ProbeForWrite(ControlData,
65 1024,
66 1);
67 memcpy(ControlData, OrigIVT, 1024);
68 break;
69
70 case 1:
71 ProbeForWrite(ControlData,
72 256,
73 1);
74 memcpy(ControlData, OrigBDA, 256);
75 break;
76
77 case 2:
78 {
79 KV86M_REGISTERS V86Registers;
80
81 ProbeForWrite(ControlData,
82 sizeof(KV86M_REGISTERS),
83 1);
84 memcpy(&V86Registers,
85 ControlData,
86 sizeof(KV86M_REGISTERS));
87
88 /* FIXME: This should use ->VdmObjects */
89 KeGetCurrentProcess()->Unused = 1;
90 Ki386RetToV86Mode(&V86Registers, &V86Registers);
91
92 /* FIXME: This should use ->VdmObjects */
93 KeGetCurrentProcess()->Unused = 0;
94
95 memcpy(ControlData,
96 &V86Registers,
97 sizeof(KV86M_REGISTERS));
98 break;
99 }
100 }
101 }
102 _SEH_HANDLE
103 {
104 Status = _SEH_GetExceptionCode();
105 }
106 _SEH_END;
107 }
108
109 return Status;
110 }
111
112 /* EOF */