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