@@ -6,13 +6,15 @@ use bit_field::BitField;
6
6
use core:: fmt;
7
7
// imports for intra doc links
8
8
#[ cfg( doc) ]
9
- use crate :: registers:: control:: Cr4Flags ;
9
+ use crate :: {
10
+ registers:: control:: Cr4Flags ,
11
+ structures:: gdt:: { Descriptor , DescriptorFlags , GlobalDescriptorTable } ,
12
+ } ;
10
13
11
14
/// An x86 segment
12
15
///
13
16
/// Segment registers on x86 are 16-bit [`SegmentSelector`]s, which index into
14
- /// the [`GlobalDescriptorTable`](crate::structures::gdt::GlobalDescriptorTable). The
15
- /// corresponding GDT entry is used to
17
+ /// the [`GlobalDescriptorTable`]. The corresponding GDT entry is used to
16
18
/// configure the segment itself. Note that most segmentation functionality is
17
19
/// disabled in 64-bit mode. See the individual segments for more information.
18
20
pub trait Segment {
@@ -111,18 +113,27 @@ impl fmt::Debug for SegmentSelector {
111
113
112
114
/// Code Segment
113
115
///
114
- /// The segment base and limit are unused in 64-bit mode. Only the L (long), D
115
- /// (default operation size), and DPL (descriptor privilege-level) fields of the
116
- /// descriptor are recognized. So changing the segment register can be used to
117
- /// change privilege level or enable/disable long mode.
116
+ /// While most fields in the Code-Segment [`Descriptor`] are unused in 64-bit
117
+ /// long mode, some of them must be set to a specific value. The
118
+ /// [`EXECUTABLE`](DescriptorFlags::EXECUTABLE),
119
+ /// [`USER_SEGMENT`](DescriptorFlags::USER_SEGMENT), and
120
+ /// [`LONG_MODE`](DescriptorFlags::LONG_MODE) bits must be set, while the
121
+ /// [`DEFAULT_SIZE`](DescriptorFlags::DEFAULT_SIZE) bit must be unset.
122
+ ///
123
+ /// The [`DPL_RING_3`](DescriptorFlags::DPL_RING_3) field can be used to change
124
+ /// privilege level. The [`PRESENT`](DescriptorFlags::PRESENT) bit can be used
125
+ /// to make a segment present or not present.
126
+ ///
127
+ /// All other fields (like the segment base and limit) are ignored by the
128
+ /// processor and setting them has no effect.
118
129
#[ derive( Debug ) ]
119
130
pub struct CS ;
120
131
121
132
/// Stack Segment
122
133
///
123
134
/// Entirely unused in 64-bit mode; setting the segment register does nothing.
124
135
/// However, in ring 3, the SS register still has to point to a valid
125
- /// [`Descriptor`](crate::structures::gdt::Descriptor) (it cannot be zero). This
136
+ /// [`Descriptor`] (it cannot be zero). This
126
137
/// means a user-mode read/write segment descriptor must be present in the GDT.
127
138
///
128
139
/// This register is also set by the `syscall`/`sysret` and
0 commit comments