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)
9 /* INCLUDES ******************************************************************/
13 /* DATA VARIABLES ************************************************************/
15 ULONG_PTR MmArchKsegBase
;
16 ULONG_PTR MmArchKsegBias
;
17 ULONG MmArchLargePageSize
;
18 BL_ADDRESS_RANGE MmArchKsegAddressRange
;
19 ULONG_PTR MmArchTopOfApplicationAddressSpace
;
20 ULONG_PTR Mmx86SelfMapBase
;
28 (*PBL_MM_RELOCATE_SELF_MAP
) (
32 PBL_MM_RELOCATE_SELF_MAP BlMmRelocateSelfMap
;
33 PBL_MM_FLUSH_TLB BlMmFlushTlb
;
35 ULONG MmDeferredMappingCount
;
37 /* FUNCTIONS *****************************************************************/
49 Mmx86pMapMemoryRegions (
51 _In_ PBL_MEMORY_DATA MemoryData
56 /* In phase 1 we don't initialize deferred mappings*/
63 /* Don't do anything if there's nothing to initialize */
64 if (!MmDeferredMappingCount
)
66 return STATUS_SUCCESS
;
74 EfiPrintf(L
"Deferred todo\r\n");
77 EfiPrintf(L
"Phase 1 TODO\r\n");
78 return STATUS_NOT_IMPLEMENTED
;
82 Mmx86TranslateVirtualAddress (
83 _In_ PVOID VirtualAddress
,
84 _Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress
,
85 _Out_opt_ PULONG CachingFlags
88 EfiPrintf(L
"paging TODO\r\n");
93 MmArchTranslateVirtualAddress (
94 _In_ PVOID VirtualAddress
,
95 _Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress
,
96 _Out_opt_ PULONG CachingFlags
99 PBL_MEMORY_DESCRIPTOR Descriptor
;
101 /* Check if paging is on */
102 if ((CurrentExecutionContext
) &&
103 (CurrentExecutionContext
->ContextFlags
& BL_CONTEXT_PAGING_ON
))
105 /* Yes -- we have to translate this from virtual */
106 return Mmx86TranslateVirtualAddress(VirtualAddress
,
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
);
117 /* Return the virtual address as the physical address */
120 PhysicalAddress
->HighPart
= 0;
121 PhysicalAddress
->LowPart
= (ULONG_PTR
)VirtualAddress
;
124 /* There's no caching on physical memory */
130 /* Success is if we found a descriptor */
131 return Descriptor
!= NULL
;
137 _In_ PBL_MEMORY_DATA MemoryData
,
138 _In_ BL_TRANSLATION_TYPE TranslationType
,
139 _In_ BL_TRANSLATION_TYPE RequestedTranslationType
144 /* For phase 2, just map deferred regions */
147 return Mmx86pMapMemoryRegions(2, MemoryData
);
150 /* What translation type are we switching to? */
151 switch (RequestedTranslationType
)
153 /* Physical memory */
156 /* Initialize everything to default/null values */
157 MmArchLargePageSize
= 1;
160 MmArchKsegAddressRange
.Minimum
= 0;
161 MmArchKsegAddressRange
.Maximum
= (ULONGLONG
)~0;
162 MmArchTopOfApplicationAddressSpace
= 0;
163 Mmx86SelfMapBase
= 0;
165 /* Set stub functions */
166 BlMmRelocateSelfMap
= MmArchNullFunction
;
167 BlMmFlushTlb
= MmArchNullFunction
;
170 Status
= STATUS_SUCCESS
;
175 Status
= STATUS_NOT_IMPLEMENTED
;
180 Status
= STATUS_NOT_SUPPORTED
;
184 Status
= STATUS_INVALID_PARAMETER
;