4 InitializeVideoAddressSpace(VOID
)
6 OBJECT_ATTRIBUTES ObjectAttributes
;
7 UNICODE_STRING PhysMemName
;
18 * Open the physical memory section
20 RtlInitUnicodeString(&PhysMemName
, L
"\\Device\\PhysicalMemory");
21 InitializeObjectAttributes(&ObjectAttributes
,
26 Status
= NtOpenSection(&PhysMemHandle
, SECTION_ALL_ACCESS
,
28 if (!NT_SUCCESS(Status
))
30 DbgPrint("Couldn't open \\Device\\PhysicalMemory\n");
35 * Map the BIOS and device registers into the address space
37 Offset
.QuadPart
= 0xa0000;
38 ViewSize
= 0x100000 - 0xa0000;
39 BaseAddress
= (PVOID
)0xa0000;
40 Status
= NtMapViewOfSection(PhysMemHandle
,
49 PAGE_EXECUTE_READWRITE
);
50 if (!NT_SUCCESS(Status
))
52 DbgPrint("Couldn't map physical memory (%x)\n", Status
);
53 NtClose(PhysMemHandle
);
56 NtClose(PhysMemHandle
);
57 if (BaseAddress
!= (PVOID
)0xa0000)
59 DbgPrint("Couldn't map physical memory at the right address "
60 "(was %x)\n", BaseAddress
);
65 * Map some memory to use for the non-BIOS parts of the v86 mode address
68 BaseAddress
= (PVOID
)0x1;
69 ViewSize
= 0xa0000 - 0x1000;
70 Status
= ZwAllocateVirtualMemory(NtCurrentProcess(),
75 PAGE_EXECUTE_READWRITE
);
76 if (!NT_SUCCESS(Status
))
78 DbgPrint("Failed to allocate virtual memory (Status %x)\n", Status
);
81 if (BaseAddress
!= (PVOID
)0x0)
83 DbgPrint("Failed to allocate virtual memory at right address "
84 "(was %x)\n", BaseAddress
);
89 * Get the real mode IVT from the kernel
91 Status
= NtVdmControl(0, IVT
);
92 if (!NT_SUCCESS(Status
))
94 DbgPrint("NtVdmControl failed (status %x)\n", Status
);
99 * Copy the real mode IVT into the right place
101 memcpy((PVOID
)0x0, IVT
, 1024);
104 * Get the BDA from the kernel
106 Status
= NtVdmControl(1, BDA
);
107 if (!NT_SUCCESS(Status
))
109 DbgPrint("NtVdmControl failed (status %x)\n", Status
);
114 * Copy the BDA into the right place
116 memcpy((PVOID
)0x400, BDA
, 256);