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