Skip to content

Commit

Permalink
fix(arch): migrate to naked_asm in naked functions
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Oct 23, 2024
1 parent 1daf8da commit 85a422f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloc::alloc::{alloc_zeroed, Layout};
use alloc::boxed::Box;
use core::arch::asm;
use core::arch::naked_asm;
use core::sync::atomic::Ordering;
use core::{mem, ptr, slice};

Expand Down Expand Up @@ -329,7 +329,7 @@ extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize) -> ! {
// `arg` is in the `x1` register

unsafe {
asm!(
naked_asm!(
"msr spsel, {l0}",
"mov x25, x0",
"mov x0, x1",
Expand All @@ -340,7 +340,6 @@ extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize) -> ! {
"br x4",
l0 = const 0,
exit = sym thread_exit,
options(noreturn)
)
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/arch/aarch64/kernel/start.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::{asm, naked_asm};

use hermit_entry::boot_info::RawBootInfo;
use hermit_entry::Entry;
Expand Down Expand Up @@ -28,7 +28,7 @@ pub unsafe extern "C" fn _start(boot_info: Option<&'static RawBootInfo>, cpu_id:
}

unsafe {
asm!(
naked_asm!(
"msr spsel, {l1}", // we want to use sp_el1
"adrp x8, {current_stack_address}",
"mov x4, sp",
Expand All @@ -45,7 +45,6 @@ pub unsafe extern "C" fn _start(boot_info: Option<&'static RawBootInfo>, cpu_id:
stack_top_offset = const KERNEL_STACK_SIZE - TaskStacks::MARKER_SIZE,
current_stack_address = sym super::CURRENT_STACK_ADDRESS,
pre_init = sym pre_init,
options(noreturn),
)
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/arch/riscv64/kernel/start.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::naked_asm;
use core::sync::atomic::Ordering;

use fdt::Fdt;
Expand Down Expand Up @@ -31,7 +31,7 @@ pub unsafe extern "C" fn _start(hart_id: usize, boot_info: Option<&'static RawBo
}

unsafe {
asm!(
naked_asm!(
// Use stack pointer from `CURRENT_STACK_ADDRESS` if set
"ld t0, {current_stack_pointer}",
"beqz t0, 2f",
Expand All @@ -44,7 +44,6 @@ pub unsafe extern "C" fn _start(hart_id: usize, boot_info: Option<&'static RawBo
current_stack_pointer = sym CURRENT_STACK_ADDRESS,
top_offset = const KERNEL_STACK_SIZE,
pre_init = sym pre_init,
options(noreturn),
)
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#[cfg(not(feature = "common-os"))]
use alloc::boxed::Box;
use core::arch::asm;
use core::arch::naked_asm;
#[cfg(not(feature = "common-os"))]
use core::mem::MaybeUninit;
#[cfg(not(feature = "common-os"))]
Expand Down Expand Up @@ -316,12 +316,11 @@ extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize, _user_stack: u64
// `user_stack` is in the `rdx` register

unsafe {
asm!(
naked_asm!(
"mov rsp, rdx",
"sti",
"jmp {task_entry}",
task_entry = sym task_entry,
options(noreturn)
)
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/arch/x86_64/kernel/start.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::naked_asm;

use hermit_entry::boot_info::RawBootInfo;
use hermit_entry::Entry;
Expand Down Expand Up @@ -26,7 +26,7 @@ pub unsafe extern "C" fn _start(_boot_info: Option<&'static RawBootInfo>, cpu_id
}

unsafe {
asm!(
naked_asm!(
// use core::sync::atomic::{AtomicU32, Ordering};
//
// pub static CPU_ONLINE: AtomicU32 = AtomicU32::new(0);
Expand Down Expand Up @@ -61,7 +61,6 @@ pub unsafe extern "C" fn _start(_boot_info: Option<&'static RawBootInfo>, cpu_id
current_stack_address = sym super::CURRENT_STACK_ADDRESS,
stack_top_offset = const KERNEL_STACK_SIZE - TaskStacks::MARKER_SIZE,
pre_init = sym pre_init,
options(noreturn)
)
}
}
8 changes: 3 additions & 5 deletions src/arch/x86_64/kernel/switch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::{asm, naked_asm};
use core::{mem, ptr};

use crate::core_local::CoreLocal;
Expand Down Expand Up @@ -173,7 +173,7 @@ pub(crate) unsafe extern "C" fn switch_to_task(_old_stack: *mut usize, _new_stac
// `new_stack` is in `rsi` register

unsafe {
asm!(
naked_asm!(
save_context!(),
// Store the old `rsp` behind `old_stack`
"mov [rdi], rsp",
Expand All @@ -187,7 +187,6 @@ pub(crate) unsafe extern "C" fn switch_to_task(_old_stack: *mut usize, _new_stac
"call {set_current_kernel_stack}",
restore_context!(),
set_current_kernel_stack = sym set_current_kernel_stack,
options(noreturn)
);
}
}
Expand All @@ -200,7 +199,7 @@ pub(crate) unsafe extern "C" fn switch_to_fpu_owner(_old_stack: *mut usize, _new
// `new_stack` is in `rsi` register

unsafe {
asm!(
naked_asm!(
save_context!(),
// Store the old `rsp` behind `old_stack`
"mov [rdi], rsp",
Expand All @@ -211,7 +210,6 @@ pub(crate) unsafe extern "C" fn switch_to_fpu_owner(_old_stack: *mut usize, _new
"call {set_current_kernel_stack}",
restore_context!(),
set_current_kernel_stack = sym set_current_kernel_stack,
options(noreturn),
);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/arch/x86_64/kernel/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::naked_asm;
use core::mem;

use super::core_local::CoreLocal;
Expand All @@ -8,7 +8,7 @@ use crate::syscalls::table::SYSHANDLER_TABLE;
#[naked]
pub(crate) unsafe extern "C" fn syscall_handler() -> ! {
unsafe {
asm!(
naked_asm!(
// save context, see x86_64 ABI
"push rcx",
"push rdx",
Expand Down Expand Up @@ -46,7 +46,6 @@ pub(crate) unsafe extern "C" fn syscall_handler() -> ! {
"sysretq",
core_local_kernel_stack = const mem::offset_of!(CoreLocal, kernel_stack),
table = sym SYSHANDLER_TABLE,
options(noreturn)
);
}
}
5 changes: 2 additions & 3 deletions src/syscalls/table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::arch::naked_asm;

use crate::syscalls::*;

Expand Down Expand Up @@ -42,11 +42,10 @@ extern "C" fn invalid_syscall(sys_no: u64) -> ! {
#[naked]
pub(crate) unsafe extern "C" fn sys_invalid() {
unsafe {
asm!(
naked_asm!(
"mov rdi, rax",
"call {}",
sym invalid_syscall,
options(noreturn)
);
}
}
Expand Down

0 comments on commit 85a422f

Please sign in to comment.