Skip to content

Commit c4d88bb

Browse files
authored
use llvm_asm until real asm is ready (#151)
1 parent 1c18ad9 commit c4d88bb

File tree

11 files changed

+38
-38
lines changed

11 files changed

+38
-38
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-
asm!("sti" :::: "volatile");
18+
llvm_asm!("sti" :::: "volatile");
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-
asm!("cli" :::: "volatile");
33+
llvm_asm!("cli" :::: "volatile");
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-
asm!("sti; hlt" :::: "volatile");
134+
llvm_asm!("sti; hlt" :::: "volatile");
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-
asm!("int3" :::: "volatile");
147+
llvm_asm!("int3" :::: "volatile");
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-
asm!("int $0" :: "N" ($x) :: "volatile");
165+
llvm_asm!("int $0" :: "N" ($x) :: "volatile");
166166
}};
167167
}
168168

src/instructions/mod.rs

Lines changed: 2 additions & 2 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-
asm!("hlt" :::: "volatile");
17+
llvm_asm!("hlt" :::: "volatile");
1818
}
1919

2020
#[cfg(not(feature = "inline_asm"))]
@@ -29,6 +29,6 @@ pub fn hlt() {
2929
#[inline]
3030
pub fn bochs_breakpoint() {
3131
unsafe {
32-
asm!("xchgw %bx, %bx" :::: "volatile");
32+
llvm_asm!("xchgw %bx, %bx" :::: "volatile");
3333
}
3434
}

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-
asm!("inb $1, $0" : "={al}"(value) : "N{dx}"(port) :: "volatile");
12+
llvm_asm!("inb $1, $0" : "={al}"(value) : "N{dx}"(port) :: "volatile");
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-
asm!("inw $1, $0" : "={ax}"(value) : "N{dx}"(port) :: "volatile");
28+
llvm_asm!("inw $1, $0" : "={ax}"(value) : "N{dx}"(port) :: "volatile");
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-
asm!("inl $1, $0" : "={eax}"(value) : "N{dx}"(port) :: "volatile");
44+
llvm_asm!("inl $1, $0" : "={eax}"(value) : "N{dx}"(port) :: "volatile");
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-
asm!("outb $1, $0" :: "N{dx}"(port), "{al}"(value) :: "volatile");
59+
llvm_asm!("outb $1, $0" :: "N{dx}"(port), "{al}"(value) :: "volatile");
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-
asm!("outw $1, $0" :: "N{dx}"(port), "{ax}"(value) :: "volatile");
73+
llvm_asm!("outw $1, $0" :: "N{dx}"(port), "{ax}"(value) :: "volatile");
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-
asm!("outl $1, $0" :: "N{dx}"(port), "{eax}"(value) :: "volatile");
87+
llvm_asm!("outl $1, $0" :: "N{dx}"(port), "{eax}"(value) :: "volatile");
8888
}
8989

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

src/instructions/segmentation.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
1818
#[cfg(feature = "inline_asm")]
1919
#[inline(always)]
2020
unsafe fn inner(sel: SegmentSelector) {
21-
asm!("pushq $0; \
21+
llvm_asm!("pushq $0; \
2222
leaq 1f(%rip), %rax; \
2323
pushq %rax; \
2424
lretq; \
@@ -43,7 +43,7 @@ pub unsafe fn set_cs(sel: SegmentSelector) {
4343
#[inline]
4444
pub unsafe fn load_ss(sel: SegmentSelector) {
4545
#[cfg(feature = "inline_asm")]
46-
asm!("movw $0, %ss " :: "r" (sel.0) : "memory");
46+
llvm_asm!("movw $0, %ss " :: "r" (sel.0) : "memory");
4747

4848
#[cfg(not(feature = "inline_asm"))]
4949
crate::asm::x86_64_asm_load_ss(sel.0);
@@ -58,7 +58,7 @@ pub unsafe fn load_ss(sel: SegmentSelector) {
5858
#[inline]
5959
pub unsafe fn load_ds(sel: SegmentSelector) {
6060
#[cfg(feature = "inline_asm")]
61-
asm!("movw $0, %ds " :: "r" (sel.0) : "memory");
61+
llvm_asm!("movw $0, %ds " :: "r" (sel.0) : "memory");
6262

6363
#[cfg(not(feature = "inline_asm"))]
6464
crate::asm::x86_64_asm_load_ds(sel.0);
@@ -73,7 +73,7 @@ pub unsafe fn load_ds(sel: SegmentSelector) {
7373
#[inline]
7474
pub unsafe fn load_es(sel: SegmentSelector) {
7575
#[cfg(feature = "inline_asm")]
76-
asm!("movw $0, %es " :: "r" (sel.0) : "memory");
76+
llvm_asm!("movw $0, %es " :: "r" (sel.0) : "memory");
7777

7878
#[cfg(not(feature = "inline_asm"))]
7979
crate::asm::x86_64_asm_load_es(sel.0);
@@ -88,7 +88,7 @@ pub unsafe fn load_es(sel: SegmentSelector) {
8888
#[inline]
8989
pub unsafe fn load_fs(sel: SegmentSelector) {
9090
#[cfg(feature = "inline_asm")]
91-
asm!("movw $0, %fs " :: "r" (sel.0) : "memory");
91+
llvm_asm!("movw $0, %fs " :: "r" (sel.0) : "memory");
9292

9393
#[cfg(not(feature = "inline_asm"))]
9494
crate::asm::x86_64_asm_load_fs(sel.0);
@@ -103,7 +103,7 @@ pub unsafe fn load_fs(sel: SegmentSelector) {
103103
#[inline]
104104
pub unsafe fn load_gs(sel: SegmentSelector) {
105105
#[cfg(feature = "inline_asm")]
106-
asm!("movw $0, %gs " :: "r" (sel.0) : "memory");
106+
llvm_asm!("movw $0, %gs " :: "r" (sel.0) : "memory");
107107

108108
#[cfg(not(feature = "inline_asm"))]
109109
crate::asm::x86_64_asm_load_gs(sel.0);
@@ -118,7 +118,7 @@ pub unsafe fn load_gs(sel: SegmentSelector) {
118118
#[inline]
119119
pub unsafe fn swap_gs() {
120120
#[cfg(feature = "inline_asm")]
121-
asm!("swapgs" ::: "memory" : "volatile");
121+
llvm_asm!("swapgs" ::: "memory" : "volatile");
122122

123123
#[cfg(not(feature = "inline_asm"))]
124124
crate::asm::x86_64_asm_swapgs();
@@ -130,7 +130,7 @@ pub fn cs() -> SegmentSelector {
130130
#[cfg(feature = "inline_asm")]
131131
{
132132
let segment: u16;
133-
unsafe { asm!("mov %cs, $0" : "=r" (segment) ) };
133+
unsafe { llvm_asm!("mov %cs, $0" : "=r" (segment) ) };
134134
SegmentSelector(segment)
135135
}
136136

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-
asm!("lgdt ($0)" :: "r" (gdt) : "memory");
21+
llvm_asm!("lgdt ($0)" :: "r" (gdt) : "memory");
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-
asm!("lidt ($0)" :: "r" (idt) : "memory");
41+
llvm_asm!("lidt ($0)" :: "r" (idt) : "memory");
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-
asm!("ltr $0" :: "r" (sel.0));
57+
llvm_asm!("ltr $0" :: "r" (sel.0));
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-
asm!("invlpg ($0)" :: "r" (addr.as_u64()) : "memory")
10+
llvm_asm!("invlpg ($0)" :: "r" (addr.as_u64()) : "memory")
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
@@ -4,7 +4,7 @@
44
#![cfg_attr(not(test), no_std)]
55
#![cfg_attr(feature = "const_fn", feature(const_fn))]
66
#![cfg_attr(feature = "const_fn", feature(const_in_array_repeat_expressions))]
7-
#![cfg_attr(feature = "inline_asm", feature(asm))]
7+
#![cfg_attr(feature = "inline_asm", feature(llvm_asm))]
88
#![cfg_attr(feature = "abi_x86_interrupt", feature(abi_x86_interrupt))]
99
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
1010
#![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-
asm!("mov %cr0, $0" : "=r" (value));
148+
llvm_asm!("mov %cr0, $0" : "=r" (value));
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-
asm!("mov $0, %cr0" :: "r" (value) : "memory");
187+
llvm_asm!("mov $0, %cr0" :: "r" (value) : "memory");
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-
asm!("mov %cr2, $0" : "=r" (value));
220+
llvm_asm!("mov %cr2, $0" : "=r" (value));
221221
}
222222

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

238238
#[cfg(feature = "inline_asm")]
239239
unsafe {
240-
asm!("mov %cr3, $0" : "=r" (value));
240+
llvm_asm!("mov %cr3, $0" : "=r" (value));
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-
asm!("mov $0, %cr3" :: "r" (value) : "memory");
265+
llvm_asm!("mov $0, %cr3" :: "r" (value) : "memory");
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-
asm!("mov %cr4, $0" : "=r" (value));
286+
llvm_asm!("mov %cr4, $0" : "=r" (value));
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-
asm!("mov $0, %cr4" :: "r" (value) : "memory");
327+
llvm_asm!("mov $0, %cr4" :: "r" (value) : "memory");
328328

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

src/registers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod rflags;
1111
pub fn read_rip() -> u64 {
1212
let rip: u64;
1313
unsafe {
14-
asm!(
14+
llvm_asm!(
1515
"lea (%rip), $0"
1616
: "=r"(rip) ::: "volatile"
1717
);

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-
asm!("rdmsr" : "={eax}" (low), "={edx}" (high) : "{ecx}" (self.0) : "memory" : "volatile");
124+
llvm_asm!("rdmsr" : "={eax}" (low), "={edx}" (high) : "{ecx}" (self.0) : "memory" : "volatile");
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-
asm!("wrmsr" :: "{ecx}" (self.0), "{eax}" (low), "{edx}" (high) : "memory" : "volatile" );
144+
llvm_asm!("wrmsr" :: "{ecx}" (self.0), "{eax}" (low), "{edx}" (high) : "memory" : "volatile" );
145145
}
146146

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

src/registers/rflags.rs

Lines changed: 2 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-
asm!("pushfq; popq $0" : "=r"(r) :: "memory")
83+
llvm_asm!("pushfq; popq $0" : "=r"(r) :: "memory")
8484
};
8585

8686
#[cfg(not(feature = "inline_asm"))]
@@ -108,7 +108,7 @@ mod x86_64 {
108108
pub fn write_raw(val: u64) {
109109
#[cfg(feature = "inline_asm")]
110110
unsafe {
111-
asm!("pushq $0; popfq" :: "r"(val) : "memory" "flags")
111+
llvm_asm!("pushq $0; popfq" :: "r"(val) : "memory" "flags")
112112
};
113113

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

0 commit comments

Comments
 (0)