hermit/arch/x86_64/
mod.rs

1pub mod kernel;
2pub mod mm;
3
4#[cfg(feature = "common-os")]
5use x86_64::registers::segmentation::SegmentSelector;
6
7use crate::arch::mm::paging::ExceptionStackFrame;
8
9/// Helper function to swap the GS register, if the user-space is
10/// is interrupted.
11#[cfg(feature = "common-os")]
12#[inline(always)]
13pub(crate) fn swapgs(stack_frame: &ExceptionStackFrame) {
14	use core::arch::asm;
15	if stack_frame.code_segment != SegmentSelector(8) {
16		unsafe {
17			asm!("swapgs", options(nomem, nostack, preserves_flags));
18		}
19	}
20}
21
22#[cfg(not(feature = "common-os"))]
23#[inline(always)]
24pub(crate) fn swapgs(_stack_frame: &ExceptionStackFrame) {}
25
26/// Force strict CPU ordering, serializes load and store operations.
27#[allow(dead_code)]
28#[inline(always)]
29pub(crate) fn memory_barrier() {
30	use core::arch::asm;
31	unsafe {
32		asm!("mfence", options(nostack, nomem, preserves_flags),);
33	}
34}