From 41c25af2eab3405641cce7c8e0a2cbd78d5dced4 Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Thu, 16 Jul 2020 15:11:02 -0700 Subject: [PATCH 1/2] Switch to rust-lang/rust#72016 `asm!` syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per the bug report referenced in the above, `asm!` is back ― but it has a [brand-new syntax](https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html) associated with it that includes, among other things, `intel` and `volatile` by default. As if that's not enough, they're now deprecating `llvm_asm!` upstream in favor of this. --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 942a5bc..0cd9391 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ #![doc(html_root_url = "https://docs.rs/tinypci")] -#![feature(llvm_asm)] +#![feature(asm)] #![cfg_attr(not(feature="std"), no_std)] @@ -30,14 +30,14 @@ pub use enums::*; #[inline] unsafe fn read_from_port(port: u16) -> u32 { let value: u32; - llvm_asm!("inl %dx, %eax" : "={eax}"(value) : "{dx}"(port) :: "volatile"); + asm!("inl eax, dx", out("eax") value, in("dx") port); value } // extracted from the `x86_64` crate. #[inline] unsafe fn write_to_port(port: u16, value: u32) { - llvm_asm!("outl %eax, %dx" :: "{dx}"(port), "{eax}"(value) :: "volatile"); + asm!("outl eax, dx", out("dx") port, in("eax") value); } From 3a29eadf643c9b108fa96b250d9a77e740b1799c Mon Sep 17 00:00:00 2001 From: Kenny Strawn Date: Thu, 16 Jul 2020 15:28:41 -0700 Subject: [PATCH 2/2] Operand order is reversed Intel is the default syntax in the new `asm!` which means that one must reverse the operands when switching to it --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0cd9391..5c58df4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ unsafe fn read_from_port(port: u16) -> u32 { // extracted from the `x86_64` crate. #[inline] unsafe fn write_to_port(port: u16, value: u32) { - asm!("outl eax, dx", out("dx") port, in("eax") value); + asm!("outl dx, eax", out("dx") port, in("eax") value); }