aboutsummaryrefslogtreecommitdiff
path: root/src/bits64/segmentation.rs
blob: f43828a713e3b7246856dd7f415a20d3c1bea180 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#[allow(unused_imports)]
use segmentation::SegmentSelector;

/// Reload code segment register.
/// Note this is special since we can not directly move
/// to %cs. Instead we push the new segment selector
/// and return value on the stack and use lretq
/// to reload cs and continue at 1:.
#[cfg(target_arch="x86_64")]
pub unsafe fn set_cs(sel: SegmentSelector) {
    asm!("pushq $0; \
          leaq  1f(%rip), %rax; \
          pushq %rax; \
          lretq; \
          1:" :: "ri" (sel.bits() as usize) : "rax" "memory");
}