Skip to content

Commit 2ab479b

Browse files
committed
segmentation: update docs on how we set CS
Signed-off-by: Joe Richey <[email protected]>
1 parent cd9d748 commit 2ab479b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/instructions/segmentation.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,14 @@ pub struct CS;
131131
impl Segment for CS {
132132
get_reg_impl!("cs", x86_64_asm_get_cs);
133133

134-
/// Note this is special since we cannot directly move to [`CS`]. Instead we
135-
/// push the new segment selector and return value on the stack and use
136-
/// `retfq` to reload [`CS`] and continue at the end of our function.
134+
/// Note this is special since we cannot directly move to [`CS`]; x86 requires the instruction
135+
/// pointer and [`CS`] to be set at the same time. To do this, we push the new segment selector
136+
/// and return value onto the stack and use a "far return" (`retfq`) to reload [`CS`] and
137+
/// continue at the end of our function.
138+
///
139+
/// Note we cannot use a "far call" (`lcall`) or "far jmp" (`ljmp`) to do this because then we
140+
/// would only be able to jump to 32-bit instruction pointers. Only Intel implements support
141+
/// for 64-bit far calls/jumps in long-mode, AMD does not.
137142
unsafe fn set_reg(sel: SegmentSelector) {
138143
#[cfg(feature = "inline_asm")]
139144
asm!(

0 commit comments

Comments
 (0)