TianoCore EDK2 master
No Matches
CpuPaging.c File Reference

Go to the source code of this file.

Data Structures



#define IA32_PG_P   BIT0
#define IA32_PG_RW   BIT1
#define IA32_PG_U   BIT2
#define IA32_PG_A   BIT5
#define IA32_PG_D   BIT6
#define IA32_PG_PS   BIT7
#define IA32_PG_NX   BIT63
#define PAGING_4K_ADDRESS_MASK_64   0x000FFFFFFFFFF000ull
#define PAGING_2M_ADDRESS_MASK_64   0x000FFFFFFFE00000ull
#define PAGING_1G_ADDRESS_MASK_64   0x000FFFFFC0000000ull
#define PAGING_512G_ADDRESS_MASK_64   0x000FFF8000000000ull


  PageNone , Page4K , Page2M , Page1G ,
  PageNone = 0 , PageMin = 1 , Page4K = PageMin , Page2M = 2 ,
  Page1G = 3 , Page512G = 4 , PageMax = Page512G , PageNone ,
  Page4K , Page2M , Page1G


BOOLEAN IsIa32PaeSupported (VOID)
VOID * AllocatePageTableMemory (IN UINTN Pages)
PAGE_ATTRIBUTE GetPageTableTopLevelType (VOID)
VOID * GetPageTableEntry (IN PHYSICAL_ADDRESS Address, OUT PAGE_ATTRIBUTE *PageAttribute)
RETURN_STATUS SplitPage (IN UINT64 *PageEntry, IN PAGE_ATTRIBUTE PageAttribute, IN PAGE_ATTRIBUTE SplitAttribute, IN BOOLEAN Recursively)
RETURN_STATUS EFIAPI ConvertMemoryPageAttributes (IN PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
EFI_STATUS EnablePaePageTable (VOID)
VOID EFIAPI GetStackBase (IN OUT VOID *Buffer)
VOID SetupStackGuardPage (VOID)
EFI_STATUS EFIAPI MemoryDiscoveredPpiNotifyCallback (IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)


PAGE_ATTRIBUTE_TABLE mPageAttributeTable []

Detailed Description

Basic paging support for the CPU to enable Stack Guard.

Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CpuPaging.c.

Macro Definition Documentation

◆ IA32_PG_A

#define IA32_PG_A   BIT5

Definition at line 22 of file CpuPaging.c.

◆ IA32_PG_D

#define IA32_PG_D   BIT6

Definition at line 23 of file CpuPaging.c.

◆ IA32_PG_NX

#define IA32_PG_NX   BIT63

Definition at line 25 of file CpuPaging.c.

◆ IA32_PG_P

#define IA32_PG_P   BIT0

Definition at line 19 of file CpuPaging.c.

◆ IA32_PG_PS

#define IA32_PG_PS   BIT7

Definition at line 24 of file CpuPaging.c.

◆ IA32_PG_RW

#define IA32_PG_RW   BIT1

Definition at line 20 of file CpuPaging.c.

◆ IA32_PG_U

#define IA32_PG_U   BIT2

Definition at line 21 of file CpuPaging.c.



Definition at line 27 of file CpuPaging.c.


(IA32_PG_D | IA32_PG_A | IA32_PG_NX | IA32_PG_U | \

Definition at line 28 of file CpuPaging.c.


#define PAGING_1G_ADDRESS_MASK_64   0x000FFFFFC0000000ull

Definition at line 34 of file CpuPaging.c.


#define PAGING_2M_ADDRESS_MASK_64   0x000FFFFFFFE00000ull

Definition at line 33 of file CpuPaging.c.


#define PAGING_4K_ADDRESS_MASK_64   0x000FFFFFFFFFF000ull

Definition at line 32 of file CpuPaging.c.


#define PAGING_512G_ADDRESS_MASK_64   0x000FFF8000000000ull

Definition at line 35 of file CpuPaging.c.



Definition at line 31 of file CpuPaging.c.

Enumeration Type Documentation



Definition at line 37 of file CpuPaging.c.

Function Documentation

◆ AllocatePageTableMemory()

VOID * AllocatePageTableMemory ( IN UINTN  Pages)

This API provides a way to allocate memory for page table.

PagesThe number of 4 KB pages to allocate.
A pointer to the allocated buffer or NULL if allocation fails.

Definition at line 106 of file CpuPaging.c.

◆ ConvertMemoryPageAttributes()

RETURN_STATUS EFIAPI ConvertMemoryPageAttributes ( IN PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Attributes 

This function modifies the page attributes for the memory region specified by BaseAddress and Length from their current attributes to the attributes specified by Attributes.

Caller should make sure BaseAddress and Length is at page boundary.

[in]BaseAddressStart address of a memory region.
[in]LengthSize in bytes of the memory region.
[in]AttributesBit mask of attributes to modify.
Return values
RETURN_SUCCESSThe attributes were modified for the memory region.
RETURN_INVALID_PARAMETERLength is zero; or, Attributes specified an illegal combination of attributes that cannot be set together; or Addressis not 4KB aligned.
RETURN_OUT_OF_RESOURCESThere are not enough system resources to modify the attributes.
RETURN_UNSUPPORTEDCannot modify the attributes of given memory.

Definition at line 283 of file CpuPaging.c.

◆ EnablePaePageTable()

EFI_STATUS EnablePaePageTable ( VOID  )

Enable PAE Page Table.

Return values
EFI_SUCCESSThe PAE Page Table was enabled successfully.
EFI_OUT_OF_RESOURCESThe PAE Page Table could not be enabled due to lack of available memory.

Definition at line 361 of file CpuPaging.c.

◆ GetPageTableEntry()

VOID * GetPageTableEntry ( IN PHYSICAL_ADDRESS  Address,
OUT PAGE_ATTRIBUTE *  PageAttribute 

Return page table entry matching the address.

[in]AddressThe address to be checked.
[out]PageAttributesThe page attribute of the page entry.
The page entry.

Definition at line 148 of file CpuPaging.c.

◆ GetPageTableTopLevelType()

PAGE_ATTRIBUTE GetPageTableTopLevelType ( VOID  )

Get the type of top level page table.

Return values
Page512GPML4 paging.
Page1GPAE paging.

Definition at line 128 of file CpuPaging.c.

◆ GetStackBase()

VOID EFIAPI GetStackBase ( IN OUT VOID *  Buffer)

Get the base address of current AP's stack.

This function is called in AP's context and assumes that whole calling stacks (till this function) consumed by AP's wakeup procedure will not exceed 4KB.

PcdCpuApStackSize must be configured with value taking the Guard page into account.

[in,out]BufferThe pointer to private data buffer.

Definition at line 444 of file CpuPaging.c.

◆ IsIa32PaeSupported()

BOOLEAN IsIa32PaeSupported ( VOID  )

The function will check if IA32 PAE is supported.

Return values
TRUEIA32 PAE is supported.
FALSEIA32 PAE is not supported.

Definition at line 79 of file CpuPaging.c.

◆ MemoryDiscoveredPpiNotifyCallback()

EFI_STATUS EFIAPI MemoryDiscoveredPpiNotifyCallback ( IN EFI_PEI_SERVICES **  PeiServices,
IN VOID *  Ppi 

Enable/setup stack guard for each processor if PcdCpuStackGuard is set to TRUE.

Doing this in the memory-discovered callback is to make sure the Stack Guard feature to cover as most PEI code as possible.

[in]PeiServicesGeneral purpose services available to every PEIM.
[in]NotifyDescriptorThe notification structure this PEIM registered on install.
[in]PpiThe memory discovered PPI. Not used.
Return values
EFI_SUCCESSThe function completed successfully.
othersThere's error in MP initialization.

Definition at line 549 of file CpuPaging.c.

◆ SetupStackGuardPage()

VOID SetupStackGuardPage ( VOID  )

Setup stack Guard page at the stack base of each processor. BSP and APs have different way to get stack base address.

Definition at line 464 of file CpuPaging.c.

◆ SplitPage()

RETURN_STATUS SplitPage ( IN UINT64 *  PageEntry,
IN PAGE_ATTRIBUTE  SplitAttribute,
IN BOOLEAN  Recursively 

This function splits one page entry to smaller page entries.

[in]PageEntryThe page entry to be splitted.
[in]PageAttributeThe page attribute of the page entry.
[in]SplitAttributeHow to split the page entry.
[in]RecursivelyDo the split recursively or not.
Return values
RETURN_SUCCESSThe page entry is splitted.
RETURN_INVALID_PARAMETERIf target page attribute is invalid
RETURN_OUT_OF_RESOURCESNo resource to split page entry.

Definition at line 205 of file CpuPaging.c.

Variable Documentation

◆ mPageAttributeTable

PAGE_ATTRIBUTE_TABLE mPageAttributeTable[]
Initial value:
= {
{ PageNone, 0, 0, 0, 0 },
{ Page4K, SIZE_4KB, PAGING_4K_ADDRESS_MASK_64, 12, 9 },
{ Page2M, SIZE_2MB, PAGING_2M_ADDRESS_MASK_64, 21, 9 },
{ Page1G, SIZE_1GB, PAGING_1G_ADDRESS_MASK_64, 30, 9 },
{ Page512G, SIZE_512GB, PAGING_512G_ADDRESS_MASK_64, 39, 9 },

Definition at line 55 of file CpuPaging.c.

◆ mPostMemNotifyList

Initial value:
= {
EFI_STATUS EFIAPI MemoryDiscoveredPpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: CpuPaging.c:549

Definition at line 63 of file CpuPaging.c.