Skip to content

Commit b1549d9

Browse files
committed
convert inline assmebly to the new assembly format
1 parent 27b5a5c commit b1549d9

File tree

5 files changed

+79
-19
lines changed

5 files changed

+79
-19
lines changed

src/arch/x86_64/kernel/mod.rs

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8-
mod gdt;
8+
pub mod gdt;
99
pub mod irq;
1010
mod pit;
1111
pub mod processor;
@@ -17,8 +17,8 @@ pub mod task;
1717
pub use crate::arch::x86_64::kernel::syscall::syscall_handler;
1818
use core::ptr::read_volatile;
1919

20-
global_asm!(include_str!("user_land.s"));
21-
global_asm!(include_str!("switch.s"));
20+
global_asm!(include_str!("user_land.s"), options(att_syntax));
21+
global_asm!(include_str!("switch.s"), options(att_syntax));
2222

2323
#[repr(C)]
2424
struct KernelHeader {
@@ -61,7 +61,7 @@ pub fn register_task() {
6161
let sel: u16 = 6u16 << 3;
6262

6363
unsafe {
64-
asm!("ltr ax", in("ax") sel, options(nostack));
64+
asm!("ltr ax", in("ax") sel, options(nostack, nomem));
6565
}
6666
}
6767

@@ -140,7 +140,12 @@ macro_rules! syscall {
140140
pub fn syscall0(arg0: u64) -> u64 {
141141
let mut ret: u64;
142142
unsafe {
143-
asm!("syscall", lateout("rax") ret, in("rax") arg0, lateout("rcx") _, lateout("r11") _);
143+
asm!("syscall",
144+
inlateout("rax") arg0 => ret,
145+
lateout("rcx") _,
146+
lateout("r11") _,
147+
options(preserves_flags, nostack)
148+
);
144149
}
145150
ret
146151
}
@@ -150,7 +155,13 @@ pub fn syscall0(arg0: u64) -> u64 {
150155
pub fn syscall1(arg0: u64, arg1: u64) -> u64 {
151156
let mut ret: u64;
152157
unsafe {
153-
asm!("syscall", lateout("rax") ret, in("rax") arg0, in("rdi") arg1, lateout("rcx") _, lateout("r11") _);
158+
asm!("syscall",
159+
inlateout("rax") arg0 => ret,
160+
in("rdi") arg1,
161+
lateout("rcx") _,
162+
lateout("r11") _,
163+
options(preserves_flags, nostack)
164+
);
154165
}
155166
ret
156167
}
@@ -160,7 +171,14 @@ pub fn syscall1(arg0: u64, arg1: u64) -> u64 {
160171
pub fn syscall2(arg0: u64, arg1: u64, arg2: u64) -> u64 {
161172
let mut ret: u64;
162173
unsafe {
163-
asm!("syscall", lateout("rax") ret, in("rax") arg0, in("rdi") arg1, in("rsi") arg2, lateout("rcx") _, lateout("r11") _);
174+
asm!("syscall",
175+
inlateout("rax") arg0 => ret,
176+
in("rdi") arg1,
177+
in("rsi") arg2,
178+
lateout("rcx") _,
179+
lateout("r11") _,
180+
options(preserves_flags, nostack)
181+
);
164182
}
165183
ret
166184
}
@@ -170,7 +188,15 @@ pub fn syscall2(arg0: u64, arg1: u64, arg2: u64) -> u64 {
170188
pub fn syscall3(arg0: u64, arg1: u64, arg2: u64, arg3: u64) -> u64 {
171189
let mut ret: u64;
172190
unsafe {
173-
asm!("syscall", lateout("rax") ret, in("rax") arg0, in("rdi") arg1, in("rsi") arg2, in("rdx") arg3, lateout("rcx") _, lateout("r11") _);
191+
asm!("syscall",
192+
inlateout("rax") arg0 => ret,
193+
in("rdi") arg1,
194+
in("rsi") arg2,
195+
in("rdx") arg3,
196+
lateout("rcx") _,
197+
lateout("r11") _,
198+
options(preserves_flags, nostack)
199+
);
174200
}
175201
ret
176202
}
@@ -180,7 +206,16 @@ pub fn syscall3(arg0: u64, arg1: u64, arg2: u64, arg3: u64) -> u64 {
180206
pub fn syscall4(arg0: u64, arg1: u64, arg2: u64, arg3: u64, arg4: u64) -> u64 {
181207
let mut ret: u64;
182208
unsafe {
183-
asm!("syscall", lateout("rax") ret, in("rax") arg0, in("rdi") arg1, in("rsi") arg2, in("rdx") arg3, in("r10") arg4, lateout("rcx") _, lateout("r11") _);
209+
asm!("syscall",
210+
inlateout("rax") arg0 => ret,
211+
in("rdi") arg1,
212+
in("rsi") arg2,
213+
in("rdx") arg3,
214+
in("r10") arg4,
215+
lateout("rcx") _,
216+
lateout("r11") _,
217+
options(preserves_flags, nostack)
218+
);
184219
}
185220
ret
186221
}
@@ -190,7 +225,17 @@ pub fn syscall4(arg0: u64, arg1: u64, arg2: u64, arg3: u64, arg4: u64) -> u64 {
190225
pub fn syscall5(arg0: u64, arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64) -> u64 {
191226
let mut ret: u64;
192227
unsafe {
193-
asm!("syscall", lateout("rax") ret, in("rax") arg0, in("rdi") arg1, in("rsi") arg2, in("rdx") arg3, in("r10") arg4, in("r8") arg5, lateout("rcx") _, lateout("r11") _);
228+
asm!("syscall",
229+
inlateout("rax") arg0 => ret,
230+
in("rdi") arg1,
231+
in("rsi") arg2,
232+
in("rdx") arg3,
233+
in("r10") arg4,
234+
in("r8") arg5,
235+
lateout("rcx") _,
236+
lateout("r11") _,
237+
options(preserves_flags, nostack)
238+
);
194239
}
195240
ret
196241
}
@@ -208,7 +253,18 @@ pub fn syscall6(
208253
) -> u64 {
209254
let mut ret: u64;
210255
unsafe {
211-
asm!("syscall", lateout("rax") ret, in("rax") arg0, in("rdi") arg1, in("rsi") arg2, in("rdx") arg3, in("r10") arg4, in("r8") arg5, in("r9") arg6, lateout("rcx") _, lateout("r11") _);
256+
asm!("syscall",
257+
inlateout("rax") arg0 => ret,
258+
in("rdi") arg1,
259+
in("rsi") arg2,
260+
in("rdx") arg3,
261+
in("r10") arg4,
262+
in("r8") arg5,
263+
in("r9") arg6,
264+
lateout("rcx") _,
265+
lateout("r11") _,
266+
options(preserves_flags, nostack)
267+
);
212268
}
213269
ret
214270
}

src/arch/x86_64/kernel/processor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static mut SUPPORTS_1GIB_PAGES: bool = false;
2626
#[inline(always)]
2727
pub fn mb() {
2828
unsafe {
29-
asm!("mfence", options(nostack));
29+
asm!("mfence", options(preserves_flags, nostack));
3030
}
3131
}
3232

@@ -37,9 +37,9 @@ pub fn msb(value: u64) -> Option<u64> {
3737
let ret: u64;
3838
unsafe {
3939
asm!("bsr {0}, {1}",
40-
out(reg) ret,
40+
out(reg) ret,
4141
in(reg) value,
42-
options(nomem, nostack)
42+
options(nomem, nostack)
4343
);
4444
}
4545
Some(ret)
@@ -55,9 +55,9 @@ pub fn lsb(value: u64) -> Option<u64> {
5555
let ret: u64;
5656
unsafe {
5757
asm!("bsf {0}, {1}",
58-
out(reg) ret,
58+
out(reg) ret,
5959
in(reg) value,
60-
options(nomem, nostack)
60+
options(nomem, nostack)
6161
);
6262
}
6363
Some(ret)
@@ -179,7 +179,7 @@ pub fn init() {
179179

180180
// reset GS registers
181181
wrmsr(IA32_GS_BASE, 0);
182-
asm!("wrgsbase {}", in(reg) BOOT_STACK.top());
182+
asm!("wrgsbase {}", in(reg) BOOT_STACK.top(), options(preserves_flags, nomem, nostack));
183183
}
184184

185185
// determin processor features

src/arch/x86_64/kernel/switch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8-
use crate::arch::x86_64::gdt::set_current_kernel_stack;
8+
use crate::arch::x86_64::kernel::gdt::set_current_kernel_stack;
99

1010
macro_rules! save_context {
1111
() => {

src/arch/x86_64/mm/paging.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ impl<S: PageSize> Page<S> {
238238
#[inline(always)]
239239
fn flush_from_tlb(&self) {
240240
unsafe {
241+
<<<<<<< HEAD
241242
asm!("invlpg [{0}]", in(reg) self.virtual_address, options(nostack));
243+
=======
244+
asm!("invlpg [{}]", in(reg) self.virtual_address, options(preserves_flags, nostack));
245+
>>>>>>> 7d66029... convert inline assmebly to the new assembly format
242246
}
243247
}
244248

src/arch/x86_64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2018 Stefan Lankes, RWTH Aachen University
1+
// Copyright (c) 2017-2021 Stefan Lankes, RWTH Aachen University
22
//
33
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
44
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or

0 commit comments

Comments
 (0)