1 /** @file 2 X64 processor specific header file to enable SMM profile. 3 4 Copyright (c) 2012 - 2015, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 **/ 14 15 #ifndef _SMM_PROFILE_ARCH_H_ 16 #define _SMM_PROFILE_ARCH_H_ 17 18 #pragma pack (1) 19 20 typedef struct _MSR_DS_AREA_STRUCT { 21 UINT64 BTSBufferBase; 22 UINT64 BTSIndex; 23 UINT64 BTSAbsoluteMaximum; 24 UINT64 BTSInterruptThreshold; 25 UINT64 PEBSBufferBase; 26 UINT64 PEBSIndex; 27 UINT64 PEBSAbsoluteMaximum; 28 UINT64 PEBSInterruptThreshold; 29 UINT64 PEBSCounterReset[2]; 30 UINT64 Reserved; 31 } MSR_DS_AREA_STRUCT; 32 33 typedef struct _BRANCH_TRACE_RECORD { 34 UINT64 LastBranchFrom; 35 UINT64 LastBranchTo; 36 UINT64 Rsvd0 : 4; 37 UINT64 BranchPredicted : 1; 38 UINT64 Rsvd1 : 59; 39 } BRANCH_TRACE_RECORD; 40 41 typedef struct _PEBS_RECORD { 42 UINT64 Rflags; 43 UINT64 LinearIP; 44 UINT64 Rax; 45 UINT64 Rbx; 46 UINT64 Rcx; 47 UINT64 Rdx; 48 UINT64 Rsi; 49 UINT64 Rdi; 50 UINT64 Rbp; 51 UINT64 Rsp; 52 UINT64 R8; 53 UINT64 R9; 54 UINT64 R10; 55 UINT64 R11; 56 UINT64 R12; 57 UINT64 R13; 58 UINT64 R14; 59 UINT64 R15; 60 } PEBS_RECORD; 61 62 #pragma pack () 63 64 #define PHYSICAL_ADDRESS_MASK ((1ull << 52) - SIZE_4KB) 65 66 /** 67 Update page table to map the memory correctly in order to make the instruction 68 which caused page fault execute successfully. And it also save the original page 69 table to be restored in single-step exception. 70 71 @param PageTable PageTable Address. 72 @param PFAddress The memory address which caused page fault exception. 73 @param CpuIndex The index of the processor. 74 @param ErrorCode The Error code of exception. 75 @param IsValidPFAddress The flag indicates if SMM profile data need be added. 76 77 **/ 78 VOID 79 RestorePageTableAbove4G ( 80 UINT64 *PageTable, 81 UINT64 PFAddress, 82 UINTN CpuIndex, 83 UINTN ErrorCode, 84 BOOLEAN *IsValidPFAddress 85 ); 86 87 /** 88 Create SMM page table for S3 path. 89 90 **/ 91 VOID 92 InitSmmS3Cr3 ( 93 VOID 94 ); 95 96 /** 97 Allocate pages for creating 4KB-page based on 2MB-page when page fault happens. 98 99 **/ 100 VOID 101 InitPagesForPFHandler ( 102 VOID 103 ); 104 105 #endif // _SMM_PROFILE_ARCH_H_ 106