bb55eccc3ec4514b97144f18faf3a51306a19062
[reactos.git] / reactos / subsys / csrss / video.c
1 #include <ddk/ntddk.h>
2
3 ULONG
4 InitializeVideoAddressSpace(VOID)
5 {
6 OBJECT_ATTRIBUTES ObjectAttributes;
7 UNICODE_STRING PhysMemName;
8 NTSTATUS Status;
9 HANDLE PhysMemHandle;
10 PVOID BaseAddress;
11 LARGE_INTEGER Offset;
12 ULONG ViewSize;
13 PUCHAR TextMap;
14 CHAR IVT[1024];
15 CHAR BDA[256];
16
17 /*
18 * Open the physical memory section
19 */
20 RtlInitUnicodeString(&PhysMemName, L"\\Device\\PhysicalMemory");
21 InitializeObjectAttributes(&ObjectAttributes,
22 &PhysMemName,
23 0,
24 NULL,
25 NULL);
26 Status = NtOpenSection(&PhysMemHandle, SECTION_ALL_ACCESS,
27 &ObjectAttributes);
28 if (!NT_SUCCESS(Status))
29 {
30 DbgPrint("Couldn't open \\Device\\PhysicalMemory\n");
31 return(0);
32 }
33
34 /*
35 * Map the BIOS and device registers into the address space
36 */
37 Offset.QuadPart = 0xa0000;
38 ViewSize = 0x100000 - 0xa0000;
39 BaseAddress = (PVOID)0xa0000;
40 Status = NtMapViewOfSection(PhysMemHandle,
41 NtCurrentProcess(),
42 &BaseAddress,
43 0,
44 8192,
45 &Offset,
46 &ViewSize,
47 ViewUnmap,
48 0,
49 PAGE_EXECUTE_READWRITE);
50 if (!NT_SUCCESS(Status))
51 {
52 DbgPrint("Couldn't map physical memory (%x)\n", Status);
53 NtClose(PhysMemHandle);
54 return(0);
55 }
56 NtClose(PhysMemHandle);
57 if (BaseAddress != (PVOID)0xa0000)
58 {
59 DbgPrint("Couldn't map physical memory at the right address "
60 "(was %x)\n", BaseAddress);
61 return(0);
62 }
63
64 /*
65 * Map some memory to use for the non-BIOS parts of the v86 mode address
66 * space
67 */
68 BaseAddress = (PVOID)0x1;
69 ViewSize = 0xa0000 - 0x1000;
70 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
71 &BaseAddress,
72 0,
73 &ViewSize,
74 MEM_COMMIT,
75 PAGE_EXECUTE_READWRITE);
76 if (!NT_SUCCESS(Status))
77 {
78 DbgPrint("Failed to allocate virtual memory (Status %x)\n", Status);
79 return(0);
80 }
81 if (BaseAddress != (PVOID)0x0)
82 {
83 DbgPrint("Failed to allocate virtual memory at right address "
84 "(was %x)\n", BaseAddress);
85 return(0);
86 }
87
88 /*
89 * Get the real mode IVT from the kernel
90 */
91 Status = NtVdmControl(0, IVT);
92 if (!NT_SUCCESS(Status))
93 {
94 DbgPrint("NtVdmControl failed (status %x)\n", Status);
95 return(0);
96 }
97
98 /*
99 * Copy the real mode IVT into the right place
100 */
101 memcpy((PVOID)0x0, IVT, 1024);
102
103 /*
104 * Get the BDA from the kernel
105 */
106 Status = NtVdmControl(1, BDA);
107 if (!NT_SUCCESS(Status))
108 {
109 DbgPrint("NtVdmControl failed (status %x)\n", Status);
110 return(0);
111 }
112
113 /*
114 * Copy the BDA into the right place
115 */
116 memcpy((PVOID)0x400, BDA, 256);
117
118 return(1);
119 }