xref: /DragonOS/kernel/src/process/c_adapter.rs (revision 0dd8ff43325b494ea777dbe6e552fdc77b9dabc8)
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     return ProcessManager::current_pcb().preempt_count() as u32;
40 }
41 
42 #[no_mangle]
43 pub extern "C" fn rs_current_pcb_flags() -> u32 {
44     return ProcessManager::current_pcb().flags().bits() as u32;
45 }
46 
47 #[no_mangle]
48 pub extern "C" fn rs_current_pcb_thread_rbp() -> u64 {
49     return ProcessManager::current_pcb().arch_info_irqsave().rbp() as u64;
50 }
51 
52 #[no_mangle]
53 pub extern "C" fn rs_preempt_disable() {
54     return ProcessManager::preempt_disable();
55 }
56 
57 #[no_mangle]
58 pub extern "C" fn rs_preempt_enable() {
59     return ProcessManager::preempt_enable();
60 }
61 
62 #[no_mangle]
63 pub extern "C" fn rs_process_do_exit(exit_code: usize) -> usize {
64     ProcessManager::exit(exit_code);
65 }
66