Skip to content

Commit d4cb7bf

Browse files
committed
registers: Update documentation for control flags
Signed-off-by: Joe Richey <[email protected]>
1 parent cb2728a commit d4cb7bf

File tree

2 files changed

+83
-44
lines changed

2 files changed

+83
-44
lines changed

src/registers/control.rs

+56-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Functions to read and write control registers.
22
33
pub use super::model_specific::{Efer, EferFlags};
4+
#[cfg(docsrs)]
5+
use crate::{registers::rflags::RFlags, structures::paging::PageTableFlags};
46

57
use bitflags::bitflags;
68

@@ -15,30 +17,37 @@ bitflags! {
1517
const PROTECTED_MODE_ENABLE = 1;
1618
/// Enables monitoring of the coprocessor, typical for x87 instructions.
1719
///
18-
/// Controls together with the `TASK_SWITCHED` flag whether a `wait` or `fwait`
19-
/// instruction should cause a device-not-available exception.
20+
/// Controls together with the [`TASK_SWITCHED`](Cr0Flags::TASK_SWITCHED)
21+
/// flag whether a `wait` or `fwait` instruction should cause an `#NE` exception.
2022
const MONITOR_COPROCESSOR = 1 << 1;
21-
/// Force all x87 and MMX instructions to cause an exception.
23+
/// Force all x87 and MMX instructions to cause an `#NE` exception.
2224
const EMULATE_COPROCESSOR = 1 << 2;
2325
/// Automatically set to 1 on _hardware_ task switch.
2426
///
2527
/// This flags allows lazily saving x87/MMX/SSE instructions on hardware context switches.
2628
const TASK_SWITCHED = 1 << 3;
27-
/// Indicates support of 387DX math coprocessor instructions when set
29+
/// Indicates support of 387DX math coprocessor instructions.
30+
///
31+
/// Always set on all recent x86 processors, cannot be cleared.
2832
const EXTENSION_TYPE = 1 << 4;
29-
/// Enables the native error reporting mechanism for x87 FPU errors.
33+
/// Enables the native (internal) error reporting mechanism for x87 FPU errors.
3034
const NUMERIC_ERROR = 1 << 5;
3135
/// Controls whether supervisor-level writes to read-only pages are inhibited.
3236
///
3337
/// When set, it is not possible to write to read-only pages from ring 0.
3438
const WRITE_PROTECT = 1 << 16;
35-
/// Enables automatic alignment checking.
39+
/// Enables automatic usermode alignment checking if [`RFlags::ALIGNMENT_CHECK`] is also set.
3640
const ALIGNMENT_MASK = 1 << 18;
37-
/// Ignored. Used to control write-back/write-through cache strategy on older CPUs.
41+
/// Ignored, should always be unset.
42+
///
43+
/// Must be unset if [`CACHE_DISABLE`](Cr0Flags::CACHE_DISABLE) is unset.
44+
/// Older CPUs used this to control write-back/write-through cache strategy.
3845
const NOT_WRITE_THROUGH = 1 << 29;
39-
/// Disables internal caches (only for some cases).
46+
/// Disables some processor caches, specifics are model-dependent.
4047
const CACHE_DISABLE = 1 << 30;
41-
/// Enables page translation.
48+
/// Enables paging.
49+
///
50+
/// If this bit is set, [`PROTECTED_MODE_ENABLE`](Cr0Flags::PROTECTED_MODE_ENABLE) must be set.
4251
const PAGING = 1 << 31;
4352
}
4453
}
@@ -49,16 +58,18 @@ bitflags! {
4958
#[derive(Debug)]
5059
pub struct Cr2;
5160

52-
/// Contains the physical address of the level 4 page table.
61+
/// Contains the physical address of the highest-level page table.
5362
#[derive(Debug)]
5463
pub struct Cr3;
5564

5665
bitflags! {
57-
/// Controls cache settings for the level 4 page table.
66+
/// Controls cache settings for the highest-level page table.
67+
///
68+
/// Unused if paging is disabled or if [`PCID`](Cr4Flags::PCID) is enabled.
5869
pub struct Cr3Flags: u64 {
59-
/// Use a writethrough cache policy for the P4 table (else a writeback policy is used).
70+
/// Use a writethrough cache policy for the table (else a writeback policy is used).
6071
const PAGE_LEVEL_WRITETHROUGH = 1 << 3;
61-
/// Disable caching for the P4 table.
72+
/// Disable caching for the table.
6273
const PAGE_LEVEL_CACHE_DISABLE = 1 << 4;
6374
}
6475
}
@@ -78,57 +89,71 @@ bitflags! {
7889
const VIRTUAL_8086_MODE_EXTENSIONS = 1;
7990
/// Enables support for protected-mode virtual interrupts.
8091
const PROTECTED_MODE_VIRTUAL_INTERRUPTS = 1 << 1;
81-
/// When set, only privilege-level 0 can execute the RDTSC or RDTSCP instructions.
92+
/// When set, only privilege-level 0 can execute the `RDTSC` or `RDTSCP` instructions.
8293
const TIMESTAMP_DISABLE = 1 << 2;
83-
/// Enables I/O breakpoint capability and enforces treatment of DR4 and DR5 registers
94+
/// Enables I/O breakpoint capability and enforces treatment of `DR4` and `DR5` registers
8495
/// as reserved.
8596
const DEBUGGING_EXTENSIONS = 1 << 3;
86-
/// Enables the use of 4MB physical frames; ignored in long mode.
97+
/// Enables the use of 4MB physical frames; ignored if
98+
/// [`PHYSICAL_ADDRESS_EXTENSION`](Cr4Flags::PHYSICAL_ADDRESS_EXTENSION)
99+
/// is set (so always ignored in long mode).
87100
const PAGE_SIZE_EXTENSION = 1 << 4;
88-
/// Enables physical address extension and 2MB physical frames; required in long mode.
101+
/// Enables physical address extensions and 2MB physical frames; required in long mode.
89102
const PHYSICAL_ADDRESS_EXTENSION = 1 << 5;
90103
/// Enables the machine-check exception mechanism.
91104
const MACHINE_CHECK_EXCEPTION = 1 << 6;
92-
/// Enables the global-page mechanism, which allows to make page translations global
93-
/// to all processes.
105+
/// Enables the global page feature, allowing some page translations to
106+
/// be marked as global (see [`PageTableFlags::GLOBAL`]).
94107
const PAGE_GLOBAL = 1 << 7;
95-
/// Allows software running at any privilege level to use the RDPMC instruction.
108+
/// Allows software running at any privilege level to use the `RDPMC` instruction.
96109
const PERFORMANCE_MONITOR_COUNTER = 1 << 8;
97-
/// Enable the use of legacy SSE instructions; allows using FXSAVE/FXRSTOR for saving
110+
/// Enable the use of legacy SSE instructions; allows using `FXSAVE`/`FXRSTOR` for saving
98111
/// processor state of 128-bit media instructions.
99112
const OSFXSR = 1 << 9;
100-
/// Enables the SIMD floating-point exception (#XF) for handling unmasked 256-bit and
113+
/// Enables the SIMD floating-point exception (`#XF`) for handling unmasked 256-bit and
101114
/// 128-bit media floating-point errors.
102115
const OSXMMEXCPT_ENABLE = 1 << 10;
103-
/// Prevents the execution of the SGDT, SIDT, SLDT, SMSW, and STR instructions by
116+
/// Prevents the execution of the `SGDT`, `SIDT`, `SLDT`, `SMSW`, and `STR` instructions by
104117
/// user-mode software.
105118
const USER_MODE_INSTRUCTION_PREVENTION = 1 << 11;
106-
/// Enables 5-level paging on supported CPUs.
119+
/// Enables 5-level paging on supported CPUs (Intel Only).
107120
const L5_PAGING = 1 << 12;
108-
/// Enables VMX insturctions.
121+
/// Enables VMX insturctions (Intel Only).
109122
const VIRTUAL_MACHINE_EXTENSIONS = 1 << 13;
110-
/// Enables SMX instructions.
123+
/// Enables SMX instructions (Intel Only).
111124
const SAFER_MODE_EXTENSIONS = 1 << 14;
112125
/// Enables software running in 64-bit mode at any privilege level to read and write
113126
/// the FS.base and GS.base hidden segment register state.
114127
const FSGSBASE = 1 << 16;
115128
/// Enables process-context identifiers (PCIDs).
116129
const PCID = 1 << 17;
117-
/// Enables extendet processor state management instructions, including XGETBV and XSAVE.
130+
/// Enables extended processor state management instructions, including `XGETBV` and `XSAVE`.
118131
const OSXSAVE = 1 << 18;
119-
/// When set, the `LOADIWKEY` instruction is available; additionally, if system firmware has activated the AES key locker instructions, register EBX of CPUID leaf 0x19, bit 0 (AESKLE) is set and the AES key locker instructions are enabled. See the [Intel Key Locker Specification](https://software.intel.com/content/www/us/en/develop/download/intel-key-locker-specification.html) for information on this feature.
132+
/// Enables the Key Locker feature (Intel Only).
133+
///
134+
/// This enables creation/use opaque AES key handles; see the
135+
/// [Intel Key Locker Specification](https://software.intel.com/content/www/us/en/develop/download/intel-key-locker-specification.html)
136+
/// for more information.
120137
const KEY_LOCKER = 1 << 19;
121138
/// Prevents the execution of instructions that reside in pages accessible by user-mode
122139
/// software when the processor is in supervisor-mode.
123140
const SUPERVISOR_MODE_EXECUTION_PROTECTION = 1 << 20;
124141
/// Enables restrictions for supervisor-mode software when reading data from user-mode
125142
/// pages.
126143
const SUPERVISOR_MODE_ACCESS_PREVENTION = 1 << 21;
127-
/// Enables 4-level and 5-level paging to associate each linear address with a protection key in user mode.
144+
/// Enables protection keys for user-mode pages.
145+
///
146+
/// Also enables access to the PKRU register (via the `RDPKRU`/`WRPKRU`
147+
/// instructions) to set protection key access controls.
128148
const PROTECTION_KEY = 1 << 22;
129-
/// When set, enables intel control-flow enforcement technology. See chapter 18 of the Intel software developer manuals, volume 1, for more information.
149+
/// Enables Control-flow Enforcement Technology (CET)
150+
///
151+
/// This enables the shadow stack feature, ensuring return addresses read
152+
/// via `RET` and `IRET` have not been corrupted.
130153
const CONTROL_FLOW_ENFORCEMENT = 1 << 23;
131-
/// When set, allows 4-level and 5-level paging implementations to use the `IA32_PKRS` MSR to specify, for each protection key, whether supervisor-mode linear addresses with a particular protection key can be read or written.
154+
/// Enables protection keys for supervisor-mode pages (Intel Only).
155+
///
156+
/// Also enables the `IA32_PKRS` MSR to set protection key access controls.
132157
const PROTECTION_KEY_SUPERVISOR = 1 << 24;
133158
}
134159
}

src/registers/xcontrol.rs

+27-13
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,43 @@ pub struct XCr0;
77

88
bitflags! {
99
/// Configuration flags of the XCr0 register.
10+
///
11+
/// For MPX, [`BNDREG`](XCr0Flags::BNDREG) and [`BNDCSR`](XCr0Flags::BNDCSR) must be set/unset simultaneously.
12+
/// For AVX-512, [`OPMASK`](XCr0Flags::OPMASK), [`ZMM_HI256`](XCr0Flags::ZMM_HI256), and [`HI16_ZMM`](XCr0Flags::HI16_ZMM) must be set/unset simultaneously.
1013
pub struct XCr0Flags: u64 {
11-
/// Enables x87 FPU
14+
/// Enables using the x87 FPU state
15+
/// with `XSAVE`/`XRSTOR`.
16+
///
17+
/// Must be set.
1218
const X87 = 1;
13-
/// Enables 128-bit (legacy) SSE
14-
/// Must be set to enable AVX and YMM
19+
/// Enables using MXCSR and the XMM registers
20+
/// with `XSAVE`/`XRSTOR`.
21+
///
22+
/// Must be set if [`YMM`](XCr0Flags::YMM) is set.
1523
const SSE = 1<<1;
16-
/// Enables 256-bit SSE
17-
/// Must be set to enable AVX
24+
/// Enables AVX instructions and using the upper halves of the YMM registers
25+
/// with `XSAVE`/`XRSTOR`.
1826
const YMM = 1<<2;
19-
/// When set, MPX instructions are enabled and the bound registers BND0-BND3 can be managed by XSAVE.
27+
/// Enables MPX instructions and using the BND0-BND3 bound registers
28+
/// with `XSAVE`/`XRSTOR` (Intel Only).
2029
const BNDREG = 1 << 3;
21-
/// When set, MPX instructions can be executed and XSAVE can manage the BNDCFGU and BNDSTATUS registers.
30+
/// Enables MPX instructions and using the BNDCFGU and BNDSTATUS registers
31+
/// with `XSAVE`/`XRSTOR` (Intel Only).
2232
const BNDCSR = 1 << 4;
23-
/// If set, AVX-512 instructions can be executed and XSAVE can manage the K0-K7 mask registers.
33+
/// Enables AVX-512 instructions and using the K0-K7 mask registers
34+
/// with `XSAVE`/`XRSTOR` (Intel Only).
2435
const OPMASK = 1 << 5;
25-
/// If set, AVX-512 instructions can be executed and XSAVE can be used to manage the upper halves of the lower ZMM registers.
36+
/// Enables AVX-512 instructions and using the upper halves of the lower ZMM registers
37+
/// with `XSAVE`/`XRSTOR` (Intel Only).
2638
const ZMM_HI256 = 1 << 6;
27-
/// If set, AVX-512 instructions can be executed and XSAVE can manage the upper ZMM registers.
39+
/// Enables AVX-512 instructions and using the upper ZMM registers
40+
/// with `XSAVE`/`XRSTOR` (Intel Only).
2841
const HI16_ZMM = 1 << 7;
29-
/// When set, PKRU state management is supported by
30-
/// XSAVE/XRSTOR
42+
/// Enables using the PKRU register
43+
/// with `XSAVE`/`XRSTOR`.
3144
const MPK = 1<<9;
32-
/// When set the Lightweight Profiling extensions are enabled
45+
/// Enables Lightweight Profiling extensions and managing LWP state
46+
/// with `XSAVE` (AMD Only).
3347
const LWP = 1<<62;
3448
}
3549
}

0 commit comments

Comments
 (0)