Skip to content

Commit 3ad17ea

Browse files
Update to use the new asm! macro
It's much easier to understand and has a simpler syntax. This breaks compatibility with nightlies older than 08/06/2020 (dd/mm/yyyy)
1 parent 1ec9e6c commit 3ad17ea

File tree

10 files changed

+50
-22
lines changed

10 files changed

+50
-22
lines changed

src/protected/stage_3/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![feature(llvm_asm)]
32

43
use shared::println;
54

@@ -9,5 +8,12 @@ mod panic;
98
pub extern "C" fn third_stage() -> ! {
109
println!("[Bootloader] [32] Stage 3");
1110

11+
unsafe {
12+
let ptr = 0x110000 as *mut u32;
13+
*ptr = 0xdeadbeef;
14+
}
15+
16+
println!("[Bootloader] [32] > 1MB");
17+
1218
loop {}
1319
}

src/real/bootsector/src/console.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub fn print(s: &[u8]) {
1717
pub fn print_char(c: u8) {
1818
let ax = u16::from(c) | 0x0e00;
1919
unsafe {
20-
llvm_asm!("int 0x10" :: "{ax}"(ax) :: "intel" );
20+
asm!("int 0x10",
21+
in("ax") ax,
22+
options(nostack)
23+
);
2124
}
2225
}

src/real/bootsector/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(llvm_asm, global_asm)]
1+
#![feature(asm, global_asm)]
22
#![no_std]
33
#![allow(dead_code)]
44

@@ -34,10 +34,13 @@ extern "C" fn rust_start(disk_number: u16) -> ! {
3434

3535
fn check_int13h_extensions(disk_number: u16) {
3636
unsafe {
37-
llvm_asm!("
38-
int 0x13
39-
jc no_int13h_extensions
40-
" :: "{ah}"(0x41), "{bx}"(0x55aa), "{dl}"(disk_number) :: "intel", "volatile");
37+
asm!("
38+
int 0x13
39+
jc no_int13h_extensions",
40+
41+
in("ax") 0x41, in("bx") 0x55aa, in("dx") disk_number,
42+
options(nostack)
43+
)
4144
}
4245
}
4346

src/real/stage_2/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(global_asm, llvm_asm)]
1+
#![feature(global_asm, asm)]
22
#![no_std]
33

44
use shared::linker_symbol;
@@ -52,8 +52,11 @@ pub fn second_stage() -> ! {
5252

5353
fn enable_a20() {
5454
unsafe {
55-
llvm_asm!("in al, 0x92
56-
or al, 2
57-
out 0x92, al" ::: "al" : "intel", "volatile");
55+
asm!("in {0}, 0x92
56+
or {0}, 2
57+
out 0x92, {0}",
58+
out(reg) _,
59+
options(nostack)
60+
);
5861
}
5962
}

src/shared/src/dap.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ impl DiskAddressPacket {
3131
#[inline(always)]
3232
pub unsafe fn perform_load(&self, disk_number: u16) {
3333
let self_addr = self as *const Self as u16;
34-
llvm_asm!("
34+
asm!("
3535
int 0x13
36-
jc dap_load_failed
37-
" :: "{si}"(self_addr), "{ax}"(0x4200), "{dx}"(disk_number) : "bx" : "intel", "volatile");
36+
jc dap_load_failed",
37+
in("si") self_addr, in("ax") 0x4200, in("dx") disk_number, out("bx") _,
38+
options(nostack)
39+
);
3840
}
3941
}

src/shared/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(abi_x86_interrupt)]
22
#![feature(const_fn)]
3-
#![feature(llvm_asm, global_asm)]
3+
#![feature(asm, global_asm)]
44
#![no_std]
55

66
pub mod console;

src/shared/src/macros.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ macro_rules! linker_symbol {
33
($symbol_name:ident) => {unsafe {
44
let symbol_value: u32;
55

6-
llvm_asm!(concat!("lea eax, ", stringify!($symbol_name))
7-
: "={eax}"(symbol_value)
8-
::: "intel", "volatile");
6+
asm!(
7+
concat!("lea {}, ", stringify!($symbol_name)),
8+
out(reg) symbol_value
9+
);
910

1011
symbol_value
1112
}};

src/shared/src/structures/gdt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ impl GlobalDescriptorTable {
5151
limit: (self.table.len() * size_of::<u64>() - 1) as u16,
5252
};
5353

54-
llvm_asm!("lgdt ($0)" :: "r" (&ptr) : "memory");
54+
asm!("lgdt [{}]",
55+
in(reg) &ptr,
56+
options(nostack)
57+
);
5558
}
5659

5760
#[inline]

src/shared/src/structures/idt.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ impl InterruptDescriptorTable {
8686
limit: (size_of::<Self>() - 1) as u16,
8787
};
8888

89-
llvm_asm!("lidt ($0)" :: "r" (&ptr) : "memory");
89+
asm!("lidt [{}]",
90+
in(reg) &ptr,
91+
options(nostack)
92+
);
9093
}
9194
}
9295

@@ -142,7 +145,11 @@ impl<F> Entry<F> {
142145
self.offset_high = (addr >> 16) as u16;
143146

144147
let segment: u16;
145-
unsafe { llvm_asm!("mov %cs, $0" : "=r" (segment) ) };
148+
149+
unsafe { asm!("mov {:x}, cs",
150+
out(reg) segment,
151+
options(nostack, nomem)
152+
) };
146153

147154
self.gdt_selector = segment;
148155

src/shared/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[inline(always)]
22
pub fn hlt() {
33
unsafe {
4-
llvm_asm!("hlt" :::: "intel","volatile");
4+
asm!("hlt");
55
}
66
}

0 commit comments

Comments
 (0)