#[cfg(any(target_os = "linux", target_os = "macos"))]
mod fncall;
#[cfg(any(target_os = "none", target_os = "uefi"))]
mod gdt;
#[cfg(any(target_os = "none", target_os = "uefi"))]
mod idt;
#[cfg(feature = "ioport_bitmap")]
#[cfg(any(target_os = "none", target_os = "uefi"))]
pub mod ioport;
#[cfg(any(target_os = "none", target_os = "uefi"))]
mod syscall;
#[cfg(any(target_os = "none", target_os = "uefi"))]
mod trap;
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub use fncall::syscall_fn_entry;
#[cfg(any(target_os = "none", target_os = "uefi"))]
pub use trap::TrapFrame;
#[cfg(any(target_os = "none", target_os = "uefi"))]
pub unsafe fn init() {
use log::info;
info!("Initializing trapframe...");
x86_64::instructions::interrupts::disable();
gdt::init();
info!("GDT initialization completed");
idt::init();
info!("IDT initialization completed");
syscall::init();
info!("Syscall related register initialization completed");
}
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
#[repr(C)]
pub struct UserContext {
pub general: GeneralRegs,
pub trap_num: usize,
pub error_code: usize,
}
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
#[repr(C)]
pub struct GeneralRegs {
pub rax: usize,
pub rbx: usize,
pub rcx: usize,
pub rdx: usize,
pub rsi: usize,
pub rdi: usize,
pub rbp: usize,
pub rsp: usize,
pub r8: usize,
pub r9: usize,
pub r10: usize,
pub r11: usize,
pub r12: usize,
pub r13: usize,
pub r14: usize,
pub r15: usize,
pub rip: usize,
pub rflags: usize,
pub fsbase: usize,
pub gsbase: usize,
}
unsafe impl pod::Pod for GeneralRegs {}
unsafe impl pod::Pod for UserContext {}
impl UserContext {
pub fn get_syscall_num(&self) -> usize {
self.general.rax
}
pub fn get_syscall_ret(&self) -> usize {
self.general.rax
}
pub fn set_syscall_ret(&mut self, ret: usize) {
self.general.rax = ret;
}
pub fn get_syscall_args(&self) -> [usize; 6] {
[
self.general.rdi,
self.general.rsi,
self.general.rdx,
self.general.r10,
self.general.r8,
self.general.r9,
]
}
pub fn set_ip(&mut self, ip: usize) {
self.general.rip = ip;
}
pub fn set_sp(&mut self, sp: usize) {
self.general.rsp = sp;
}
pub fn get_sp(&self) -> usize {
self.general.rsp
}
pub fn set_tls(&mut self, tls: usize) {
self.general.fsbase = tls;
}
}