1 use crate::smp::core::smp_get_processor_id; 2 3 use super::{process_init, ProcessManager, __PROCESS_MANAGEMENT_INIT_DONE}; 4 5 #[no_mangle] rs_process_init()6unsafe extern "C" fn rs_process_init() { 7 process_init(); 8 } 9 10 /// 临时用于获取空闲进程的栈顶的函数,这个函数是为了旧的smp模块的初始化而写在这的 11 #[no_mangle] rs_get_idle_stack_top(cpu_id: u32) -> usize12unsafe extern "C" fn rs_get_idle_stack_top(cpu_id: u32) -> usize { 13 return ProcessManager::idle_pcb()[cpu_id as usize] 14 .kernel_stack() 15 .stack_max_address() 16 .data(); 17 } 18 19 #[no_mangle] rs_current_pcb_cpuid() -> u3220unsafe extern "C" fn rs_current_pcb_cpuid() -> u32 { 21 return smp_get_processor_id().data(); 22 } 23 24 #[no_mangle] rs_current_pcb_pid() -> u3225unsafe extern "C" fn rs_current_pcb_pid() -> u32 { 26 if unsafe { __PROCESS_MANAGEMENT_INIT_DONE } { 27 return ProcessManager::current_pcb().pid().0 as u32; 28 } 29 return 0; 30 } 31 32 #[no_mangle] rs_current_pcb_preempt_count() -> u3233unsafe extern "C" fn rs_current_pcb_preempt_count() -> u32 { 34 if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } { 35 return 0; 36 } 37 return ProcessManager::current_pcb().preempt_count() as u32; 38 } 39 40 #[no_mangle] rs_current_pcb_flags() -> u3241unsafe extern "C" fn rs_current_pcb_flags() -> u32 { 42 if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } { 43 return 0; 44 } 45 return ProcessManager::current_pcb().flags().bits() as u32; 46 } 47 48 #[no_mangle] 49 #[cfg(target_arch = "x86_64")] rs_current_pcb_thread_rbp() -> u6450unsafe extern "C" fn rs_current_pcb_thread_rbp() -> u64 { 51 if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } { 52 return 0; 53 } 54 return ProcessManager::current_pcb().arch_info_irqsave().rbp() as u64; 55 } 56 57 #[no_mangle] 58 #[cfg(target_arch = "riscv64")] rs_current_pcb_thread_rbp() -> u6459unsafe extern "C" fn rs_current_pcb_thread_rbp() -> u64 { 60 // 不应该实现这个函数 61 unimplemented!("rs_current_pcb_thread_rbp") 62 } 63 64 #[no_mangle] rs_preempt_disable()65unsafe extern "C" fn rs_preempt_disable() { 66 return ProcessManager::preempt_disable(); 67 } 68 69 #[no_mangle] rs_preempt_enable()70unsafe extern "C" fn rs_preempt_enable() { 71 return ProcessManager::preempt_enable(); 72 } 73 74 #[no_mangle] rs_process_do_exit(exit_code: usize) -> usize75unsafe extern "C" fn rs_process_do_exit(exit_code: usize) -> usize { 76 if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } { 77 return 0; 78 } 79 ProcessManager::exit(exit_code); 80 } 81