Skip to content

Commit 9056715

Browse files
committed
remove global_asm support
using "Rust assembly" to jump in the user space
1 parent a1103d1 commit 9056715

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

src/arch/x86_64/kernel/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ pub mod task;
1818
pub use crate::arch::x86_64::kernel::syscall::syscall_handler;
1919
use core::ptr::read_volatile;
2020

21-
global_asm!(include_str!("user_land.s"), options(att_syntax));
22-
2321
#[repr(C)]
2422
struct KernelHeader {
2523
magic_number: u32,
@@ -49,8 +47,27 @@ pub fn register_task() {
4947
}
5048
}
5149

52-
extern "C" {
53-
pub fn jump_to_user_land(func: extern "C" fn()) -> !;
50+
pub unsafe fn jump_to_user_land(func: extern "C" fn()) -> ! {
51+
let ds = 0x23u64;
52+
let cs = 0x2bu64;
53+
54+
asm!(
55+
"push {0}",
56+
"push rsp",
57+
"add QWORD PTR [rsp], 16",
58+
"pushf",
59+
"push {1}",
60+
"push {2}",
61+
"iretq",
62+
in(reg) ds,
63+
in(reg) cs,
64+
in(reg) func as u64,
65+
options(nostack)
66+
);
67+
68+
loop {
69+
processor::halt();
70+
}
5471
}
5572

5673
/// This macro can be used to call system functions from user-space

src/arch/x86_64/kernel/user_land.s

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(const_ptr_offset, asm, lang_items)]
22
#![feature(allocator_api)]
3-
#![feature(global_asm)]
43
#![feature(panic_info_message)]
54
#![feature(naked_functions)]
65
#![feature(abi_x86_interrupt)]

0 commit comments

Comments
 (0)