diff options
author | 2021-09-29 23:34:39 -0700 | |
---|---|---|
committer | 2021-09-29 23:34:39 -0700 | |
commit | b0dcf8dd08b0a817510d2f55e8bc25edcc4f8809 (patch) | |
tree | 83d6ec011b36fc033eb12c2f4bdc78613a26a385 | |
parent | 4cdaaa20c5e07c4fd90414581de06c3a469784f2 (diff) | |
download | rust-x86-b0dcf8dd08b0a817510d2f55e8bc25edcc4f8809.tar.gz rust-x86-b0dcf8dd08b0a817510d2f55e8bc25edcc4f8809.tar.zst rust-x86-b0dcf8dd08b0a817510d2f55e8bc25edcc4f8809.zip |
Convert some things to asm! syntax.
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/task.rs | 13 | ||||
-rw-r--r-- | src/tlb.rs | 2 |
4 files changed, 14 insertions, 7 deletions
@@ -1,6 +1,6 @@ [package] name = "x86" -version = "0.42.1" +version = "0.43.0" authors = [ "Gerd Zellweger <mail@gerdzellweger.com>", "Eric Kidd <git@randomhacks.net>", @@ -90,7 +90,7 @@ pub enum Ring { /// Will cause a general protection fault if used outside of ring 0. #[inline(always)] pub unsafe fn halt() { - llvm_asm!("hlt" :::: "volatile"); + asm!("hlt", options(att_syntax, nomem, nostack)); // check if preserves_flags } #[cfg(all(test, feature = "vmtest"))] @@ -117,7 +117,7 @@ mod x86testing { #[inline(always)] pub unsafe fn rdpid() -> u64 { let mut pid: u64; - llvm_asm!("rdpid $0" : "=r"(pid)); + asm!("rdpid {pid}", pid = out(reg) pid, options(att_syntax)); pid } diff --git a/src/task.rs b/src/task.rs index a7b3423..d819e2d 100644 --- a/src/task.rs +++ b/src/task.rs @@ -4,9 +4,14 @@ pub use crate::segmentation; /// Returns the current value of the task register. -pub fn tr() -> segmentation::SegmentSelector { +/// +/// # Safety +/// Needs CPL 0. +pub unsafe fn tr() -> segmentation::SegmentSelector { let segment: u16; - unsafe { llvm_asm!("str $0" : "=r" (segment) ) }; + asm!("str {0:x}", + out(reg) segment, + options(att_syntax, nostack, nomem, preserves_flags)); segmentation::SegmentSelector::from_raw(segment) } @@ -15,5 +20,7 @@ pub fn tr() -> segmentation::SegmentSelector { /// # Safety /// Needs CPL 0. pub unsafe fn load_tr(sel: segmentation::SegmentSelector) { - llvm_asm!("ltr $0" :: "r" (sel.bits())); + asm!("ltr {0:x}", + in(reg) sel.bits(), + options(att_syntax, nostack, nomem, preserves_flags)); } @@ -6,7 +6,7 @@ /// This function is unsafe as it causes a general protection fault (GP) if the current privilege /// level is not 0. pub unsafe fn flush(addr: usize) { - llvm_asm!("invlpg ($0)" :: "r" (addr) : "memory"); + asm!("invlpg ({})", in(reg) addr, options(att_syntax, nostack, preserves_flags)); } /// Invalidate the TLB completely by reloading the CR3 register. |