87 lines
2.5 KiB
C
87 lines
2.5 KiB
C
/**
|
|
* PROJECT: ExectOS
|
|
* COPYRIGHT: See COPYING.md in the top level directory
|
|
* FILE: xtldr/i686/memory.c
|
|
* DESCRIPTION: EFI memory management for i686 target
|
|
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
|
*/
|
|
|
|
#include <xtos.h>
|
|
|
|
|
|
/**
|
|
* Builds the actual memory mapping page table and enables paging. This routine exits EFI boot services as well.
|
|
*
|
|
* @param MemoryMappings
|
|
* Supplies a pointer to linked list containing all memory mappings.
|
|
*
|
|
* @param VirtualAddress
|
|
* Supplies a pointer to the next valid, free and available virtual address.
|
|
*
|
|
* @param ImageProtocol
|
|
* A pointer to the EFI loaded image protocol with information about where in memory the loader code was placed.
|
|
*
|
|
* @param PtePointer
|
|
* Supplies a pointer to memory area containing a Page Table Entries (PTE).
|
|
*
|
|
* @return This routine returns a status code.
|
|
*
|
|
* @since XT 1.0
|
|
*/
|
|
XTCDECL
|
|
EFI_STATUS
|
|
XtEnablePaging(IN PXTBL_PAGE_MAPPING PageMap)
|
|
{
|
|
PCPUID_REGISTERS CpuRegisters = NULL;
|
|
EFI_STATUS Status;
|
|
|
|
/* Prepare CPUID registers */
|
|
CpuRegisters->Leaf = CPUID_GET_CPU_FEATURES;
|
|
CpuRegisters->SubLeaf = 0;
|
|
CpuRegisters->Eax = 0;
|
|
CpuRegisters->Ebx = 0;
|
|
CpuRegisters->Ecx = 0;
|
|
CpuRegisters->Edx = 0;
|
|
|
|
/* Get CPUID */
|
|
ArCpuId(CpuRegisters);
|
|
|
|
/* Store PAE status from the CPUID results */
|
|
if(!(CpuRegisters->Edx & CPUID_FEATURES_EDX_PAE))
|
|
{
|
|
/* No PAE support */
|
|
XtLdrProtocol->Debug.Print(L"ERROR: PAE extension not supported by the CPU\n");
|
|
return STATUS_EFI_UNSUPPORTED;
|
|
}
|
|
|
|
/* Build page map */
|
|
Status = XtLdrProtocol->Memory.BuildPageMap(PageMap);
|
|
if(Status != STATUS_EFI_SUCCESS)
|
|
{
|
|
/* Failed to build page map */
|
|
return Status;
|
|
}
|
|
|
|
/* Exit EFI Boot Services */
|
|
XtLdrProtocol->Debug.Print(L"Exiting EFI boot services\n");
|
|
Status = XtLdrProtocol->Util.ExitBootServices();
|
|
if(Status != STATUS_EFI_SUCCESS)
|
|
{
|
|
/* Failed to exit boot services */
|
|
XtLdrProtocol->Debug.Print(L"Failed to exit boot services (Status code: %lx)\n", Status);
|
|
return STATUS_EFI_ABORTED;
|
|
}
|
|
|
|
/* Enable Physical Address Extension (PAE) */
|
|
ArWriteControlRegister(4, ArReadControlRegister(4) | CR4_PAE);
|
|
|
|
/* Write page mappings to CR3 */
|
|
ArWriteControlRegister(3, (UINT_PTR)PageMap->PtePointer);
|
|
|
|
/* Enable paging */
|
|
ArWriteControlRegister(0, ArReadControlRegister(0) | CR0_PG);
|
|
|
|
/* Return success */
|
|
return STATUS_EFI_SUCCESS;
|
|
}
|