[NTOS]: No good deed goes unpunished. Continuing the novel/saga from a couple of...
[reactos.git] / reactos / subsystems / win32 / csrss / video.c
1 /*
2 * PROJECT: ReactOS Client/Server Runtime subsystem
3 * LICENSE: GPL v2 or later - See COPYING in the top level directory
4 * FILE: subsystems/win32/csrss/video.c
5 * PURPOSE: Video memory initialization.
6 * PROGRAMMERS: ReactOS Development Team
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <csrss.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS *****************************************************************/
17
18 ULONG
19 InitializeVideoAddressSpace(VOID)
20 {
21 OBJECT_ATTRIBUTES ObjectAttributes;
22 UNICODE_STRING PhysMemName = RTL_CONSTANT_STRING(L"\\Device\\PhysicalMemory");
23 NTSTATUS Status;
24 HANDLE PhysMemHandle;
25 PVOID BaseAddress;
26 LARGE_INTEGER Offset;
27 SIZE_T ViewSize;
28 CHAR IVTAndBda[1024+256];
29
30 /* Open the physical memory section */
31 InitializeObjectAttributes(&ObjectAttributes,
32 &PhysMemName,
33 0,
34 NULL,
35 NULL);
36 Status = ZwOpenSection(&PhysMemHandle,
37 SECTION_ALL_ACCESS,
38 &ObjectAttributes);
39 if (!NT_SUCCESS(Status))
40 {
41 DPRINT1("Couldn't open \\Device\\PhysicalMemory\n");
42 return 0;
43 }
44
45 /* Map the BIOS and device registers into the address space */
46 Offset.QuadPart = 0xa0000;
47 ViewSize = 0x100000 - 0xa0000;
48 BaseAddress = (PVOID)0xa0000;
49 Status = ZwMapViewOfSection(PhysMemHandle,
50 NtCurrentProcess(),
51 &BaseAddress,
52 0,
53 ViewSize,
54 &Offset,
55 &ViewSize,
56 ViewUnmap,
57 0,
58 PAGE_EXECUTE_READWRITE);
59 if (!NT_SUCCESS(Status))
60 {
61 DPRINT1("Couldn't map physical memory (%x)\n", Status);
62 ZwClose(PhysMemHandle);
63 return 0;
64 }
65
66 /* Close physical memory section handle */
67 ZwClose(PhysMemHandle);
68
69 if (BaseAddress != (PVOID)0xa0000)
70 {
71 DPRINT1("Couldn't map physical memory at the right address (was %x)\n",
72 BaseAddress);
73 return 0;
74 }
75
76 /* Allocate some low memory to use for the non-BIOS
77 * parts of the v86 mode address space
78 */
79 BaseAddress = (PVOID)0x1;
80 ViewSize = 0xa0000 - 0x1000;
81 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
82 &BaseAddress,
83 0,
84 &ViewSize,
85 MEM_COMMIT,
86 PAGE_EXECUTE_READWRITE);
87 if (!NT_SUCCESS(Status))
88 {
89 DPRINT1("Failed to allocate virtual memory (Status %x)\n", Status);
90 return 0;
91 }
92 if (BaseAddress != (PVOID)0x0)
93 {
94 DPRINT1("Failed to allocate virtual memory at right address (was %x)\n",
95 BaseAddress);
96 return 0;
97 }
98
99 /* Get the real mode IVT and BDA from the kernel */
100 Status = NtVdmControl(VdmInitialize, IVTAndBda);
101 if (!NT_SUCCESS(Status))
102 {
103 DPRINT1("NtVdmControl failed (status %x)\n", Status);
104 return 0;
105 }
106
107 /* Return success */
108 return 1;
109 }
110
111 /* EOF */