[BOOTLIB]: Implement MmArchTranslateVirtualAddress for non-paging mode. Stub Mmx86Tra...
[reactos.git] / reactos / boot / environ / lib / mm / i386 / mmx86.c
1 /*
2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/mm/i386/mmx86.c
5 * PURPOSE: Boot Library Memory Manager x86-Specific Code
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "bl.h"
12
13 /* DATA VARIABLES ************************************************************/
14
15 ULONG_PTR MmArchKsegBase;
16 ULONG_PTR MmArchKsegBias;
17 ULONG MmArchLargePageSize;
18 BL_ADDRESS_RANGE MmArchKsegAddressRange;
19 ULONG_PTR MmArchTopOfApplicationAddressSpace;
20 ULONG_PTR Mmx86SelfMapBase;
21
22 typedef VOID
23 (*PBL_MM_FLUSH_TLB) (
24 VOID
25 );
26
27 typedef VOID
28 (*PBL_MM_RELOCATE_SELF_MAP) (
29 VOID
30 );
31
32 PBL_MM_RELOCATE_SELF_MAP BlMmRelocateSelfMap;
33 PBL_MM_FLUSH_TLB BlMmFlushTlb;
34
35 ULONG MmDeferredMappingCount;
36
37 /* FUNCTIONS *****************************************************************/
38
39 VOID
40 MmArchNullFunction (
41 VOID
42 )
43 {
44 /* Nothing to do */
45 return;
46 }
47
48 NTSTATUS
49 Mmx86pMapMemoryRegions (
50 _In_ ULONG Phase,
51 _In_ PBL_MEMORY_DATA MemoryData
52 )
53 {
54 BOOLEAN DoDeferred;
55
56 /* In phase 1 we don't initialize deferred mappings*/
57 if (Phase == 1)
58 {
59 DoDeferred = 0;
60 }
61 else
62 {
63 /* Don't do anything if there's nothing to initialize */
64 if (!MmDeferredMappingCount)
65 {
66 return STATUS_SUCCESS;
67 }
68
69 DoDeferred = 1;
70 }
71
72 if (DoDeferred)
73 {
74 EfiPrintf(L"Deferred todo\r\n");
75 }
76
77 EfiPrintf(L"Phase 1 TODO\r\n");
78 return STATUS_NOT_IMPLEMENTED;
79 }
80
81 BOOLEAN
82 Mmx86TranslateVirtualAddress (
83 _In_ PVOID VirtualAddress,
84 _Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress,
85 _Out_opt_ PULONG CachingFlags
86 )
87 {
88 EfiPrintf(L"paging TODO\r\n");
89 return FALSE;
90 }
91
92 BOOLEAN
93 MmArchTranslateVirtualAddress (
94 _In_ PVOID VirtualAddress,
95 _Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress,
96 _Out_opt_ PULONG CachingFlags
97 )
98 {
99 PBL_MEMORY_DESCRIPTOR Descriptor;
100
101 /* Check if paging is on */
102 if ((CurrentExecutionContext) &&
103 (CurrentExecutionContext->ContextFlags & BL_CONTEXT_PAGING_ON))
104 {
105 /* Yes -- we have to translate this from virtual */
106 return Mmx86TranslateVirtualAddress(VirtualAddress,
107 PhysicalAddress,
108 CachingFlags);
109 }
110
111 /* Look in all descriptors except truncated and firmware ones */
112 Descriptor = MmMdFindDescriptor(BL_MM_INCLUDE_NO_FIRMWARE_MEMORY &
113 ~BL_MM_INCLUDE_TRUNCATED_MEMORY,
114 BL_MM_REMOVE_PHYSICAL_REGION_FLAG,
115 (ULONG_PTR)VirtualAddress >> PAGE_SHIFT);
116
117 /* Return the virtual address as the physical address */
118 if (PhysicalAddress)
119 {
120 PhysicalAddress->HighPart = 0;
121 PhysicalAddress->LowPart = (ULONG_PTR)VirtualAddress;
122 }
123
124 /* There's no caching on physical memory */
125 if (CachingFlags)
126 {
127 *CachingFlags = 0;
128 }
129
130 /* Success is if we found a descriptor */
131 return Descriptor != NULL;
132 }
133
134 NTSTATUS
135 MmArchInitialize (
136 _In_ ULONG Phase,
137 _In_ PBL_MEMORY_DATA MemoryData,
138 _In_ BL_TRANSLATION_TYPE TranslationType,
139 _In_ BL_TRANSLATION_TYPE RequestedTranslationType
140 )
141 {
142 NTSTATUS Status;
143
144 /* For phase 2, just map deferred regions */
145 if (Phase != 1)
146 {
147 return Mmx86pMapMemoryRegions(2, MemoryData);
148 }
149
150 /* What translation type are we switching to? */
151 switch (RequestedTranslationType)
152 {
153 /* Physical memory */
154 case BlNone:
155
156 /* Initialize everything to default/null values */
157 MmArchLargePageSize = 1;
158 MmArchKsegBase = 0;
159 MmArchKsegBias = 0;
160 MmArchKsegAddressRange.Minimum = 0;
161 MmArchKsegAddressRange.Maximum = (ULONGLONG)~0;
162 MmArchTopOfApplicationAddressSpace = 0;
163 Mmx86SelfMapBase = 0;
164
165 /* Set stub functions */
166 BlMmRelocateSelfMap = MmArchNullFunction;
167 BlMmFlushTlb = MmArchNullFunction;
168
169 /* Set success */
170 Status = STATUS_SUCCESS;
171 break;
172
173 case BlVirtual:
174
175 Status = STATUS_NOT_IMPLEMENTED;
176 break;
177
178 case BlPae:
179
180 Status = STATUS_NOT_SUPPORTED;
181 break;
182
183 default:
184 Status = STATUS_INVALID_PARAMETER;
185 break;
186 }
187
188 return Status;
189
190 }