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