Skip to content

Commit 81b705f

Browse files
katietheqt-oldjosephlr
authored andcommitted
Update to new asm! macro [Nightly Breaking]
1 parent 7fcea5d commit 81b705f

File tree

10 files changed

+43
-44
lines changed

10 files changed

+43
-44
lines changed

src/instructions/interrupts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn are_enabled() -> bool {
1515
pub fn enable() {
1616
#[cfg(feature = "inline_asm")]
1717
unsafe {
18-
llvm_asm!("sti" :::: "volatile");
18+
asm!("sti", options(nomem, nostack));
1919
}
2020
#[cfg(not(feature = "inline_asm"))]
2121
unsafe {
@@ -30,7 +30,7 @@ pub fn enable() {
3030
pub fn disable() {
3131
#[cfg(feature = "inline_asm")]
3232
unsafe {
33-
llvm_asm!("cli" :::: "volatile");
33+
asm!("cli", options(nomem, nostack));
3434
}
3535

3636
#[cfg(not(feature = "inline_asm"))]
@@ -131,7 +131,7 @@ where
131131
pub fn enable_interrupts_and_hlt() {
132132
#[cfg(feature = "inline_asm")]
133133
unsafe {
134-
llvm_asm!("sti; hlt" :::: "volatile");
134+
asm!("sti; hlt", options(nomem, nostack));
135135
}
136136
#[cfg(not(feature = "inline_asm"))]
137137
unsafe {
@@ -144,7 +144,7 @@ pub fn enable_interrupts_and_hlt() {
144144
pub fn int3() {
145145
#[cfg(feature = "inline_asm")]
146146
unsafe {
147-
llvm_asm!("int3" :::: "volatile");
147+
asm!("int3", options(nomem, nostack));
148148
}
149149

150150
#[cfg(not(feature = "inline_asm"))]
@@ -162,7 +162,7 @@ pub fn int3() {
162162
#[macro_export]
163163
macro_rules! software_interrupt {
164164
($x:expr) => {{
165-
llvm_asm!("int $0" :: "N" ($x) :: "volatile");
165+
asm!("int {}", in(reg) $x, options(nomem, nostack));
166166
}};
167167
}
168168

src/instructions/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub mod tlb;
1414
pub fn hlt() {
1515
#[cfg(feature = "inline_asm")]
1616
unsafe {
17-
llvm_asm!("hlt" :::: "volatile");
17+
asm!("hlt", options(nomem, nostack));
1818
}
1919

2020
#[cfg(not(feature = "inline_asm"))]
@@ -48,7 +48,7 @@ pub fn nop() {
4848
#[inline]
4949
pub fn bochs_breakpoint() {
5050
unsafe {
51-
llvm_asm!("xchgw %bx, %bx" :::: "volatile");
51+
asm!("xchgw bx, bx", options(nomem, nostack));
5252
}
5353
}
5454

@@ -59,9 +59,8 @@ pub fn bochs_breakpoint() {
5959
pub fn read_rip() -> u64 {
6060
let rip: u64;
6161
unsafe {
62-
llvm_asm!(
63-
"lea (%rip), $0"
64-
: "=r"(rip) ::: "volatile"
62+
asm!(
63+
"lea {}, rip", out(reg) rip, options(nostack, nomem)
6564
);
6665
}
6766
rip

src/instructions/port.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl PortRead for u8 {
99
#[inline]
1010
unsafe fn read_from_port(port: u16) -> u8 {
1111
let value: u8;
12-
llvm_asm!("inb $1, $0" : "={al}"(value) : "N{dx}"(port) :: "volatile");
12+
asm!("in al, dx", out("al") value, in("dx") port, options(nomem, nostack));
1313
value
1414
}
1515

@@ -25,7 +25,7 @@ impl PortRead for u16 {
2525
#[inline]
2626
unsafe fn read_from_port(port: u16) -> u16 {
2727
let value: u16;
28-
llvm_asm!("inw $1, $0" : "={ax}"(value) : "N{dx}"(port) :: "volatile");
28+
asm!("in ax, dx", out("ax") value, in("dx") port, options(nomem, nostack));
2929
value
3030
}
3131

@@ -41,7 +41,7 @@ impl PortRead for u32 {
4141
#[inline]
4242
unsafe fn read_from_port(port: u16) -> u32 {
4343
let value: u32;
44-
llvm_asm!("inl $1, $0" : "={eax}"(value) : "N{dx}"(port) :: "volatile");
44+
asm!("in eax, dx", out("eax") value, in("dx") port, options(nomem, nostack));
4545
value
4646
}
4747

@@ -56,7 +56,7 @@ impl PortWrite for u8 {
5656
#[cfg(feature = "inline_asm")]
5757
#[inline]
5858
unsafe fn write_to_port(port: u16, value: u8) {
59-
llvm_asm!("outb $1, $0" :: "N{dx}"(port), "{al}"(value) :: "volatile");
59+
asm!("out dx, al", in("dx") port, in("al") value, options(nomem, nostack));
6060
}
6161

6262
#[cfg(not(feature = "inline_asm"))]
@@ -70,7 +70,7 @@ impl PortWrite for u16 {
7070
#[cfg(feature = "inline_asm")]
7171
#[inline]
7272
unsafe fn write_to_port(port: u16, value: u16) {
73-
llvm_asm!("outw $1, $0" :: "N{dx}"(port), "{ax}"(value) :: "volatile");
73+
asm!("out dx, ax", in("dx") port, in("ax") value, options(nomem, nostack));
7474
}
7575

7676
#[cfg(not(feature = "inline_asm"))]
@@ -84,7 +84,7 @@ impl PortWrite for u32 {
8484
#[cfg(feature = "inline_asm")]
8585
#[inline]
8686
unsafe fn write_to_port(port: u16, value: u32) {
87-
llvm_asm!("outl $1, $0" :: "N{dx}"(port), "{eax}"(value) :: "volatile");
87+
asm!("out dx, eax", in("dx") port, in("eax") value, options(nomem, nostack));
8888
}
8989

9090
#[cfg(not(feature = "inline_asm"))]

src/instructions/segmentation.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
1818
#[cfg(feature = "inline_asm")]
1919
#[inline(always)]
2020
unsafe fn inner(sel: SegmentSelector) {
21-
llvm_asm!("pushq $0; \
22-
leaq 1f(%rip), %rax; \
23-
pushq %rax; \
24-
lretq; \
25-
1:" :: "ri" (u64::from(sel.0)) : "rax" "memory");
21+
// FIXME - Use intel syntax
22+
asm!("pushq {}; leaq 1f(%rip), %rax; pushq %rax; lretq; 1:", in(reg) u64::from(sel.0), out("rax") _, options(att_syntax));
2623
}
2724

2825
#[cfg(not(feature = "inline_asm"))]
@@ -43,7 +40,7 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
4340
#[inline]
4441
pub unsafe fn load_ss(sel: SegmentSelector) {
4542
#[cfg(feature = "inline_asm")]
46-
llvm_asm!("movw $0, %ss " :: "r" (sel.0) : "memory");
43+
asm!("mov ss, {0:x}", in(reg) sel.0, options(nostack));
4744

4845
#[cfg(not(feature = "inline_asm"))]
4946
crate::asm::x86_64_asm_load_ss(sel.0);
@@ -58,7 +55,7 @@ pub unsafe fn load_ss(sel: SegmentSelector) {
5855
#[inline]
5956
pub unsafe fn load_ds(sel: SegmentSelector) {
6057
#[cfg(feature = "inline_asm")]
61-
llvm_asm!("movw $0, %ds " :: "r" (sel.0) : "memory");
58+
asm!("mov ds, {0:x}", in(reg) sel.0, options(nostack));
6259

6360
#[cfg(not(feature = "inline_asm"))]
6461
crate::asm::x86_64_asm_load_ds(sel.0);
@@ -73,7 +70,7 @@ pub unsafe fn load_ds(sel: SegmentSelector) {
7370
#[inline]
7471
pub unsafe fn load_es(sel: SegmentSelector) {
7572
#[cfg(feature = "inline_asm")]
76-
llvm_asm!("movw $0, %es " :: "r" (sel.0) : "memory");
73+
asm!("mov es, {0:x}", in(reg) sel.0, options(nostack));
7774

7875
#[cfg(not(feature = "inline_asm"))]
7976
crate::asm::x86_64_asm_load_es(sel.0);
@@ -88,7 +85,7 @@ pub unsafe fn load_es(sel: SegmentSelector) {
8885
#[inline]
8986
pub unsafe fn load_fs(sel: SegmentSelector) {
9087
#[cfg(feature = "inline_asm")]
91-
llvm_asm!("movw $0, %fs " :: "r" (sel.0) : "memory");
88+
asm!("mov fs, {0:x}", in(reg) sel.0, options(nostack));
9289

9390
#[cfg(not(feature = "inline_asm"))]
9491
crate::asm::x86_64_asm_load_fs(sel.0);
@@ -103,7 +100,7 @@ pub unsafe fn load_fs(sel: SegmentSelector) {
103100
#[inline]
104101
pub unsafe fn load_gs(sel: SegmentSelector) {
105102
#[cfg(feature = "inline_asm")]
106-
llvm_asm!("movw $0, %gs " :: "r" (sel.0) : "memory");
103+
asm!("mov gs, {0:x}", in(reg) sel.0, options(nostack));
107104

108105
#[cfg(not(feature = "inline_asm"))]
109106
crate::asm::x86_64_asm_load_gs(sel.0);
@@ -118,7 +115,7 @@ pub unsafe fn load_gs(sel: SegmentSelector) {
118115
#[inline]
119116
pub unsafe fn swap_gs() {
120117
#[cfg(feature = "inline_asm")]
121-
llvm_asm!("swapgs" ::: "memory" : "volatile");
118+
asm!("swapgs", options(nostack));
122119

123120
#[cfg(not(feature = "inline_asm"))]
124121
crate::asm::x86_64_asm_swapgs();
@@ -130,7 +127,9 @@ pub fn cs() -> SegmentSelector {
130127
#[cfg(feature = "inline_asm")]
131128
{
132129
let segment: u16;
133-
unsafe { llvm_asm!("mov %cs, $0" : "=r" (segment) ) };
130+
unsafe {
131+
asm!("mov {0:x}, cs", out(reg) segment, options(nostack, nomem))
132+
};
134133
SegmentSelector(segment)
135134
}
136135

src/instructions/tables.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use crate::structures::DescriptorTablePointer;
1818
#[inline]
1919
pub unsafe fn lgdt(gdt: &DescriptorTablePointer) {
2020
#[cfg(feature = "inline_asm")]
21-
llvm_asm!("lgdt ($0)" :: "r" (gdt) : "memory");
21+
asm!("lgdt [{}]", in(reg) gdt, options(nostack));
2222

2323
#[cfg(not(feature = "inline_asm"))]
2424
crate::asm::x86_64_asm_lgdt(gdt as *const _);
@@ -38,7 +38,7 @@ pub unsafe fn lgdt(gdt: &DescriptorTablePointer) {
3838
#[inline]
3939
pub unsafe fn lidt(idt: &DescriptorTablePointer) {
4040
#[cfg(feature = "inline_asm")]
41-
llvm_asm!("lidt ($0)" :: "r" (idt) : "memory");
41+
asm!("lidt [{}]", in(reg) idt, options(nostack));
4242

4343
#[cfg(not(feature = "inline_asm"))]
4444
crate::asm::x86_64_asm_lidt(idt as *const _);
@@ -54,7 +54,7 @@ pub unsafe fn lidt(idt: &DescriptorTablePointer) {
5454
#[inline]
5555
pub unsafe fn load_tss(sel: SegmentSelector) {
5656
#[cfg(feature = "inline_asm")]
57-
llvm_asm!("ltr $0" :: "r" (sel.0));
57+
asm!("ltr {0:x}", in(reg) sel.0, options(nostack, nomem));
5858

5959
#[cfg(not(feature = "inline_asm"))]
6060
crate::asm::x86_64_asm_ltr(sel.0)

src/instructions/tlb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::VirtAddr;
77
pub fn flush(addr: VirtAddr) {
88
#[cfg(feature = "inline_asm")]
99
unsafe {
10-
llvm_asm!("invlpg ($0)" :: "r" (addr.as_u64()) : "memory")
10+
asm!("invlpg [{}]", in(reg) addr.as_u64(), options(nostack))
1111
};
1212

1313
#[cfg(not(feature = "inline_asm"))]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![cfg_attr(feature = "const_fn", feature(const_mut_refs))]
77
#![cfg_attr(feature = "const_fn", feature(const_fn_fn_ptr_basics))]
88
#![cfg_attr(feature = "const_fn", feature(const_in_array_repeat_expressions))]
9-
#![cfg_attr(feature = "inline_asm", feature(llvm_asm))]
9+
#![cfg_attr(feature = "inline_asm", feature(asm))]
1010
#![cfg_attr(feature = "abi_x86_interrupt", feature(abi_x86_interrupt))]
1111
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
1212
#![cfg_attr(feature = "deny-warnings", deny(missing_docs))]

src/registers/control.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ mod x86_64 {
145145

146146
#[cfg(feature = "inline_asm")]
147147
unsafe {
148-
llvm_asm!("mov %cr0, $0" : "=r" (value));
148+
asm!("mov {}, cr0", out(reg) value, options(nomem));
149149
}
150150

151151
#[cfg(not(feature = "inline_asm"))]
@@ -184,7 +184,7 @@ mod x86_64 {
184184
#[inline]
185185
pub unsafe fn write_raw(value: u64) {
186186
#[cfg(feature = "inline_asm")]
187-
llvm_asm!("mov $0, %cr0" :: "r" (value) : "memory");
187+
asm!("mov cr0, {}", in(reg) value, options(nostack));
188188

189189
#[cfg(not(feature = "inline_asm"))]
190190
crate::asm::x86_64_asm_write_cr0(value);
@@ -217,7 +217,7 @@ mod x86_64 {
217217

218218
#[cfg(feature = "inline_asm")]
219219
unsafe {
220-
llvm_asm!("mov %cr2, $0" : "=r" (value));
220+
asm!("mov {}, cr2", out(reg) value, options(nomem));
221221
}
222222

223223
#[cfg(not(feature = "inline_asm"))]
@@ -237,7 +237,7 @@ mod x86_64 {
237237

238238
#[cfg(feature = "inline_asm")]
239239
unsafe {
240-
llvm_asm!("mov %cr3, $0" : "=r" (value));
240+
asm!("mov {}, cr3", out(reg) value, options(nomem));
241241
}
242242

243243
#[cfg(not(feature = "inline_asm"))]
@@ -262,7 +262,7 @@ mod x86_64 {
262262
let value = addr.as_u64() | flags.bits();
263263

264264
#[cfg(feature = "inline_asm")]
265-
llvm_asm!("mov $0, %cr3" :: "r" (value) : "memory");
265+
asm!("mov cr3, {}", in(reg) value, options(nostack));
266266

267267
#[cfg(not(feature = "inline_asm"))]
268268
crate::asm::x86_64_asm_write_cr3(value)
@@ -283,7 +283,7 @@ mod x86_64 {
283283

284284
#[cfg(feature = "inline_asm")]
285285
unsafe {
286-
llvm_asm!("mov %cr4, $0" : "=r" (value));
286+
asm!("mov {}, cr4", out(reg) value, options(nostack));
287287
}
288288

289289
#[cfg(not(feature = "inline_asm"))]
@@ -324,7 +324,7 @@ mod x86_64 {
324324
#[inline]
325325
pub unsafe fn write_raw(value: u64) {
326326
#[cfg(feature = "inline_asm")]
327-
llvm_asm!("mov $0, %cr4" :: "r" (value) : "memory");
327+
asm!("mov cr4, {}", in(reg) value, options(nostack));
328328

329329
#[cfg(not(feature = "inline_asm"))]
330330
crate::asm::x86_64_asm_write_cr4(value);

src/registers/model_specific.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ mod x86_64 {
121121
#[cfg(feature = "inline_asm")]
122122
{
123123
let (high, low): (u32, u32);
124-
llvm_asm!("rdmsr" : "={eax}" (low), "={edx}" (high) : "{ecx}" (self.0) : "memory" : "volatile");
124+
asm!("rdmsr", out("eax") low, out("edx") high, in("ecx") self.0, options(nostack));
125125
((high as u64) << 32) | (low as u64)
126126
}
127127

@@ -141,7 +141,7 @@ mod x86_64 {
141141
{
142142
let low = value as u32;
143143
let high = (value >> 32) as u32;
144-
llvm_asm!("wrmsr" :: "{ecx}" (self.0), "{eax}" (low), "{edx}" (high) : "memory" : "volatile" );
144+
asm!("rdmsr", in("ecx") self.0, in("eax") low, in("edx") high, options(nostack))
145145
}
146146

147147
#[cfg(not(feature = "inline_asm"))]

src/registers/rflags.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ mod x86_64 {
8080
let r: u64;
8181
#[cfg(feature = "inline_asm")]
8282
unsafe {
83-
llvm_asm!("pushfq; popq $0" : "=r"(r) :: "memory")
83+
asm!("pushf; pop {}", out(reg) r)
8484
};
8585

8686
#[cfg(not(feature = "inline_asm"))]
@@ -108,7 +108,8 @@ mod x86_64 {
108108
pub fn write_raw(val: u64) {
109109
#[cfg(feature = "inline_asm")]
110110
unsafe {
111-
llvm_asm!("pushq $0; popfq" :: "r"(val) : "memory" "flags")
111+
// FIXME - There's probably a better way than saying we preserve the flags even though we actually don't
112+
asm!("push {}; popf", in(reg) val, options(preserves_flags))
112113
};
113114

114115
#[cfg(not(feature = "inline_asm"))]

0 commit comments

Comments
 (0)