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 pub extern "C" fn rs_process_init() { 7 process_init(); 8 } 9 10 #[no_mangle] 11 pub extern "C" fn rs_kthread_init() { 12 kthread_init(); 13 } 14 15 /// 临时用于获取空闲进程的栈顶的函数,这个函数是为了旧的smp模块的初始化而写在这的 16 #[no_mangle] 17 pub 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 pub extern "C" fn rs_current_pcb_cpuid() -> u32 { 26 return smp_get_processor_id(); 27 } 28 29 #[no_mangle] 30 pub 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 pub 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 pub 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 pub extern "C" fn rs_current_pcb_thread_rbp() -> u64 { 55 if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } { 56 return 0; 57 } 58 return ProcessManager::current_pcb().arch_info_irqsave().rbp() as u64; 59 } 60 61 #[no_mangle] 62 pub extern "C" fn rs_preempt_disable() { 63 return ProcessManager::preempt_disable(); 64 } 65 66 #[no_mangle] 67 pub extern "C" fn rs_preempt_enable() { 68 return ProcessManager::preempt_enable(); 69 } 70 71 #[no_mangle] 72 pub extern "C" fn rs_process_do_exit(exit_code: usize) -> usize { 73 if unsafe { !__PROCESS_MANAGEMENT_INIT_DONE } { 74 return 0; 75 } 76 ProcessManager::exit(exit_code); 77 } 78