12 InitializeVideoAddressSpace(VOID
)
14 OBJECT_ATTRIBUTES ObjectAttributes
;
15 UNICODE_STRING PhysMemName
= RTL_CONSTANT_STRING(L
"\\Device\\PhysicalMemory");
26 * Open the physical memory section
28 InitializeObjectAttributes(&ObjectAttributes
,
33 Status
= ZwOpenSection(&PhysMemHandle
, SECTION_ALL_ACCESS
,
35 if (!NT_SUCCESS(Status
))
37 DbgPrint("Couldn't open \\Device\\PhysicalMemory\n");
42 * Map the BIOS and device registers into the address space
44 Offset
.QuadPart
= 0xa0000;
45 ViewSize
= 0x100000 - 0xa0000;
46 BaseAddress
= (PVOID
)0xa0000;
47 Status
= NtMapViewOfSection(PhysMemHandle
,
56 PAGE_EXECUTE_READWRITE
);
57 if (!NT_SUCCESS(Status
))
59 DbgPrint("Couldn't map physical memory (%x)\n", Status
);
60 NtClose(PhysMemHandle
);
63 NtClose(PhysMemHandle
);
64 if (BaseAddress
!= (PVOID
)0xa0000)
66 DbgPrint("Couldn't map physical memory at the right address "
67 "(was %x)\n", BaseAddress
);
72 * Map some memory to use for the non-BIOS parts of the v86 mode address
75 BaseAddress
= (PVOID
)0x1;
76 ViewSize
= 0xa0000 - 0x1000;
77 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
82 PAGE_EXECUTE_READWRITE
);
83 if (!NT_SUCCESS(Status
))
85 DbgPrint("Failed to allocate virtual memory (Status %x)\n", Status
);
88 if (BaseAddress
!= (PVOID
)0x0)
90 DbgPrint("Failed to allocate virtual memory at right address "
91 "(was %x)\n", BaseAddress
);
96 * Get the real mode IVT from the kernel
98 Status
= NtVdmControl(0, IVT
);
99 if (!NT_SUCCESS(Status
))
101 DbgPrint("NtVdmControl failed (status %x)\n", Status
);
106 * Copy the real mode IVT into the right place
108 NullAddress
= (PVOID
)0x0; /* Workaround for GCC 3.4 */
109 memcpy(NullAddress
, IVT
, 1024);
112 * Get the BDA from the kernel
114 Status
= NtVdmControl(1, BDA
);
115 if (!NT_SUCCESS(Status
))
117 DbgPrint("NtVdmControl failed (status %x)\n", Status
);
122 * Copy the BDA into the right place
124 memcpy((PVOID
)0x400, BDA
, 256);