Skip to content

Commit c5f2838

Browse files
committed
fix(x86_64): pseudo implementation
1 parent 922c163 commit c5f2838

File tree

3 files changed

+23
-44
lines changed

3 files changed

+23
-44
lines changed

src/x86_64/syscall.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ core::arch::global_asm!(
1717

1818
#[unsafe(no_mangle)]
1919
pub(super) fn handle_syscall(tf: &mut TrapFrame) {
20-
tf.rax = crate::trap::handle_syscall(tf, tf.rax as usize) as u64;
20+
// tf.rax = crate::trap::handle_syscall(tf, tf.rax as usize) as u64;
2121
}
2222

2323
#[unsafe(no_mangle)]
2424
fn x86_syscall_handler(tf: &mut TrapFrame) {
2525
super::uspace::switch_to_kernel_fs_base(tf);
26-
crate::trap::pre_trap_callback(tf, true);
2726
handle_syscall(tf);
28-
crate::trap::post_trap_callback(tf, true);
2927
super::uspace::switch_to_user_fs_base(tf);
3028
}
3129

src/x86_64/trap.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn handle_page_fault(tf: &TrapFrame) {
1616
let access_flags = err_code_to_flags(tf.error_code)
1717
.unwrap_or_else(|e| panic!("Invalid #PF error code: {:#x}", e));
1818
let vaddr = va!(unsafe { cr2() });
19-
if !handle_trap!(PAGE_FAULT, vaddr, access_flags, tf.is_user()) {
19+
if !handle_trap!(PAGE_FAULT, vaddr, access_flags) {
2020
panic!(
2121
"Unhandled {} #PF @ {:#x}, fault_vaddr={:#x}, error_code={:#x} ({:?}):\n{:#x?}\n{}",
2222
if tf.is_user() { "user" } else { "kernel" },
@@ -34,7 +34,6 @@ fn handle_page_fault(tf: &TrapFrame) {
3434
fn x86_trap_handler(tf: &mut TrapFrame) {
3535
#[cfg(feature = "uspace")]
3636
super::uspace::switch_to_kernel_fs_base(tf);
37-
crate::trap::pre_trap_callback(tf, tf.is_user());
3837
match tf.vector as u8 {
3938
PAGE_FAULT_VECTOR => handle_page_fault(tf),
4039
BREAKPOINT_VECTOR => debug!("#BP @ {:#x} ", tf.rip),
@@ -64,7 +63,6 @@ fn x86_trap_handler(tf: &mut TrapFrame) {
6463
);
6564
}
6665
}
67-
crate::trap::post_trap_callback(tf, tf.is_user());
6866
#[cfg(feature = "uspace")]
6967
super::uspace::switch_to_user_fs_base(tf);
7068
}

src/x86_64/uspace.rs

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
//! Structures and functions for user space.
22
3+
use core::ops::{Deref, DerefMut};
4+
35
use memory_addr::VirtAddr;
46

57
use crate::asm::{read_thread_pointer, write_thread_pointer};
8+
use crate::trap::{ExceptionKind, ReturnReason};
69
use crate::TrapFrame;
710

811
/// Context to enter user space.
9-
pub struct UspaceContext(TrapFrame);
12+
pub struct UserContext(TrapFrame);
1013

11-
impl UspaceContext {
14+
impl UserContext {
1215
/// Creates an empty context with all registers set to zero.
1316
pub const fn empty() -> Self {
1417
unsafe { core::mem::MaybeUninit::zeroed().assume_init() }
@@ -46,41 +49,11 @@ impl UspaceContext {
4649
///
4750
/// It restores the user registers and jumps to the user entry point
4851
/// (saved in `rip`).
49-
/// When an exception or syscall occurs, the kernel stack pointer is
50-
/// switched to `kstack_top`.
51-
///
52-
/// # Safety
5352
///
54-
/// This function is unsafe because it changes processor mode and the stack.
55-
pub unsafe fn enter_uspace(&self, kstack_top: VirtAddr) -> ! {
56-
crate::asm::disable_irqs();
57-
assert_eq!(super::gdt::read_tss_rsp0(), kstack_top);
58-
switch_to_user_fs_base(&self.0);
59-
unsafe {
60-
core::arch::asm!("
61-
mov rsp, {tf}
62-
pop rax
63-
pop rcx
64-
pop rdx
65-
pop rbx
66-
pop rbp
67-
pop rsi
68-
pop rdi
69-
pop r8
70-
pop r9
71-
pop r10
72-
pop r11
73-
pop r12
74-
pop r13
75-
pop r14
76-
pop r15
77-
add rsp, 32 // skip fs_base, vector, error_code
78-
swapgs
79-
iretq",
80-
tf = in(reg) &self.0,
81-
options(noreturn),
82-
)
83-
}
53+
/// This function returns when an exception or syscall occurs.
54+
pub fn run(&mut self) -> ReturnReason {
55+
// TODO: implement
56+
ReturnReason::Unknown
8457
}
8558
}
8659

@@ -109,16 +82,26 @@ pub fn switch_to_user_fs_base(tf: &TrapFrame) {
10982
}
11083
}
11184

112-
impl core::ops::Deref for UspaceContext {
85+
impl Deref for UserContext {
11386
type Target = TrapFrame;
11487

11588
fn deref(&self) -> &Self::Target {
11689
&self.0
11790
}
11891
}
11992

120-
impl core::ops::DerefMut for UspaceContext {
93+
impl DerefMut for UserContext {
12194
fn deref_mut(&mut self) -> &mut Self::Target {
12295
&mut self.0
12396
}
12497
}
98+
99+
#[derive(Debug, Clone, Copy)]
100+
pub struct ExceptionInfo {}
101+
102+
impl ExceptionInfo {
103+
pub fn kind(&self) -> ExceptionKind {
104+
// TODO: implement
105+
ExceptionKind::Other
106+
}
107+
}

0 commit comments

Comments
 (0)