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