]>
Commit | Line | Data |
---|---|---|
0a70d1c3 JF |
1 | /** @file |
2 | Execute Disable feature. | |
3 | ||
4 | Copyright (c) 2017, 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 | #include "CpuCommonFeatures.h" | |
16 | ||
17 | /** | |
18 | Detects if Execute Disable feature supported on current processor. | |
19 | ||
20 | @param[in] ProcessorNumber The index of the CPU executing this function. | |
21 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION | |
22 | structure for the CPU executing this function. | |
23 | @param[in] ConfigData A pointer to the configuration buffer returned | |
24 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if | |
25 | CPU_FEATURE_GET_CONFIG_DATA was not provided in | |
26 | RegisterCpuFeature(). | |
27 | ||
28 | @retval TRUE Execute Disable feature is supported. | |
29 | @retval FALSE Execute Disable feature is not supported. | |
30 | ||
31 | @note This service could be called by BSP/APs. | |
32 | **/ | |
33 | BOOLEAN | |
34 | EFIAPI | |
35 | ExecuteDisableSupport ( | |
36 | IN UINTN ProcessorNumber, | |
37 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, | |
38 | IN VOID *ConfigData OPTIONAL | |
39 | ) | |
40 | { | |
41 | UINT32 Eax; | |
42 | CPUID_EXTENDED_CPU_SIG_EDX Edx; | |
43 | ||
44 | AsmCpuid (CPUID_EXTENDED_FUNCTION, &Eax, NULL, NULL, NULL); | |
45 | if (Eax <= CPUID_EXTENDED_FUNCTION) { | |
46 | // | |
47 | // Extended CPUID functions are not supported on this processor. | |
48 | // | |
49 | return FALSE; | |
50 | } | |
51 | ||
52 | AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &Edx.Uint32); | |
53 | return (Edx.Bits.NX != 0); | |
54 | } | |
55 | ||
56 | /** | |
57 | Initializes Execute Disable feature to specific state. | |
58 | ||
59 | @param[in] ProcessorNumber The index of the CPU executing this function. | |
60 | @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION | |
61 | structure for the CPU executing this function. | |
62 | @param[in] ConfigData A pointer to the configuration buffer returned | |
63 | by CPU_FEATURE_GET_CONFIG_DATA. NULL if | |
64 | CPU_FEATURE_GET_CONFIG_DATA was not provided in | |
65 | RegisterCpuFeature(). | |
66 | @param[in] State If TRUE, then the Execute Disable feature must be enabled. | |
67 | If FALSE, then the Execute Disable feature must be disabled. | |
68 | ||
69 | @retval RETURN_SUCCESS Execute Disable feature is initialized. | |
70 | ||
71 | @note This service could be called by BSP only. | |
72 | **/ | |
73 | RETURN_STATUS | |
74 | EFIAPI | |
75 | ExecuteDisableInitialize ( | |
76 | IN UINTN ProcessorNumber, | |
77 | IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, | |
78 | IN VOID *ConfigData, OPTIONAL | |
79 | IN BOOLEAN State | |
80 | ) | |
81 | { | |
82 | CPU_REGISTER_TABLE_WRITE_FIELD ( | |
83 | ProcessorNumber, | |
84 | Msr, | |
85 | MSR_IA32_EFER, | |
86 | MSR_IA32_EFER_REGISTER, | |
87 | Bits.NXE, | |
88 | (State) ? 1 : 0 | |
89 | ); | |
90 | return RETURN_SUCCESS; | |
91 | } |