Browse Source

将include目录下的rust代码转移到他们应当属于的模块中 (#96)

* 将include目录下的rust代码转移到他们应当属于的模块下。
login 2 years ago
parent
commit
6cb769c423

+ 0 - 3
kernel/src/include/DragonOS/mod.rs

@@ -1,3 +0,0 @@
-pub mod gfp;
-pub mod printk;
-pub mod signal;

+ 0 - 86
kernel/src/include/DragonOS/printk.rs

@@ -1,86 +0,0 @@
-#![allow(unused)]
-// ====== 定义颜色 ======
-/// 白色
-pub const COLOR_WHITE: u32 = 0x00ffffff;
-/// 黑色
-pub const COLOR_BLACK: u32 = 0x00000000;
-/// 红色
-pub const COLOR_RED: u32 = 0x00ff0000;
-/// 橙色
-pub const COLOR_ORANGE: u32 = 0x00ff8000;
-/// 黄色
-pub const COLOR_YELLOW: u32 = 0x00ffff00;
-/// 绿色
-pub const COLOR_GREEN: u32 = 0x0000ff00;
-/// 蓝色
-pub const COLOR_BLUE: u32 = 0x000000ff;
-/// 靛色
-pub const COLOR_INDIGO: u32 = 0x0000ffff;
-/// 紫色
-pub const COLOR_PURPLE: u32 = 0x008000ff;
-
-#[macro_export]
-macro_rules! print {
-    ($($arg:tt)*) => ($crate::libs::printk::__printk(format_args!($($arg)*)));
-}
-
-#[macro_export]
-macro_rules! println {
-    () => {
-        $crate::print!("\n");
-    };
-    ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
-}
-
-/// 指定颜色,彩色输出
-/// @param FRcolor 前景色
-/// @param BKcolor 背景色
-#[macro_export]
-macro_rules! printk_color {
-
-    ($FRcolor:expr, $BKcolor:expr, $($arg:tt)*) => {
-        use alloc;
-        $crate::libs::printk::PrintkWriter.__write_string_color($FRcolor, $BKcolor, alloc::fmt::format(format_args!($($arg)*)).as_str())
-    };
-}
-
-#[macro_export]
-macro_rules! kdebug {
-    ($($arg:tt)*) => {
-        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("[ DEBUG ] ({}:{})\t", file!(), line!()))+
-                                                                alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
-    }
-}
-
-#[macro_export]
-macro_rules! kinfo {
-    ($($arg:tt)*) => {
-        $crate::libs::printk::PrintkWriter.__write_string((alloc::string::String::from("[ INFO ] ")+ alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
-    }
-}
-
-#[macro_export]
-macro_rules! kwarn {
-    ($($arg:tt)*) => {
-        $crate::libs::printk::PrintkWriter.__write_string_color($crate::include::DragonOS::printk::COLOR_YELLOW, $crate::include::DragonOS::printk::COLOR_BLACK, "[ WARN ] ");
-        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!($($arg)*)) + "\n").as_str())
-    }
-}
-
-#[macro_export]
-macro_rules! kerror {
-    ($($arg:tt)*) => {
-        $crate::libs::printk::PrintkWriter.__write_string_color($crate::include::DragonOS::printk::COLOR_RED, $crate::include::DragonOS::printk::COLOR_BLACK, "[ ERROR ] ");
-        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
-                                                                alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
-    }
-}
-
-#[macro_export]
-macro_rules! kBUG {
-    ($($arg:tt)*) => {
-        $crate::libs::printk::PrintkWriter.__write_string_color($crate::include::DragonOS::printk::COLOR_RED, $crate::include::DragonOS::printk::COLOR_BLACK, "[ BUG ] ");
-        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
-                                                                alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
-    }
-}

+ 1 - 2
kernel/src/include/mod.rs

@@ -1,3 +1,2 @@
 #![allow(non_snake_case)]
-pub mod bindings;
-pub mod DragonOS;
+pub mod bindings;

+ 2 - 1
kernel/src/ipc/mod.rs

@@ -1 +1,2 @@
-pub mod signal;
+pub mod signal;
+pub mod signal_types;

+ 11 - 7
kernel/src/ipc/signal.rs

@@ -6,10 +6,7 @@ use crate::{
             pid_t, process_control_block, process_find_pcb_by_pid, pt_regs, spinlock_t, EINVAL,
             ENOTSUP, ESRCH, PF_EXITING, PF_KTHREAD, PF_WAKEKILL, PROC_INTERRUPTIBLE,
         },
-        DragonOS::signal::{
-            si_code_val, sigaction, sigaction__union_u, sighand_struct, siginfo, signal_struct,
-            sigpending, sigset_t, SignalNumber, MAX_SIG_NUM,
-        },
+        
     },
     kBUG, kdebug, kwarn,
     libs::{
@@ -23,7 +20,14 @@ use crate::{
     },
 };
 
-use crate::include::DragonOS::signal::{__siginfo_union, __siginfo_union_data};
+use super::signal_types::{
+    si_code_val, sigaction, sigaction__union_u, sighand_struct, siginfo, signal_struct,
+    sigpending, sigset_t, SignalNumber, MAX_SIG_NUM,
+};
+
+
+
+use super::signal_types::{__siginfo_union, __siginfo_union_data};
 
 /// 默认信号处理程序占位符(用于在sighand结构体中的action数组中占位)
 pub static DEFAULT_SIGACTION: sigaction = sigaction {
@@ -61,8 +65,8 @@ pub extern "C" fn sys_kill(regs: &pt_regs) -> u64 {
                 si_code: si_code_val::SI_USER as i32,
                 si_errno: 0,
                 reserved: 0,
-                _sifields: crate::include::DragonOS::signal::__sifields {
-                    _kill: crate::include::DragonOS::signal::__sifields__kill { _pid: pid },
+                _sifields: super::signal_types::__sifields {
+                    _kill: super::signal_types::__sifields__kill { _pid: pid },
                 },
             },
         },

+ 0 - 0
kernel/src/include/DragonOS/signal.rs → kernel/src/ipc/signal_types.rs


+ 88 - 0
kernel/src/libs/printk.rs

@@ -1,7 +1,95 @@
+#![allow(unused)]
 use crate::include::bindings::bindings::{printk_color, BLACK, WHITE};
 use ::core::ffi::c_char;
 use alloc::vec::Vec;
 use core::fmt;
+
+// ====== 定义颜色 ======
+/// 白色
+pub const COLOR_WHITE: u32 = 0x00ffffff;
+/// 黑色
+pub const COLOR_BLACK: u32 = 0x00000000;
+/// 红色
+pub const COLOR_RED: u32 = 0x00ff0000;
+/// 橙色
+pub const COLOR_ORANGE: u32 = 0x00ff8000;
+/// 黄色
+pub const COLOR_YELLOW: u32 = 0x00ffff00;
+/// 绿色
+pub const COLOR_GREEN: u32 = 0x0000ff00;
+/// 蓝色
+pub const COLOR_BLUE: u32 = 0x000000ff;
+/// 靛色
+pub const COLOR_INDIGO: u32 = 0x0000ffff;
+/// 紫色
+pub const COLOR_PURPLE: u32 = 0x008000ff;
+
+#[macro_export]
+macro_rules! print {
+    ($($arg:tt)*) => ($crate::libs::printk::__printk(format_args!($($arg)*)));
+}
+
+#[macro_export]
+macro_rules! println {
+    () => {
+        $crate::print!("\n");
+    };
+    ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
+}
+
+/// 指定颜色,彩色输出
+/// @param FRcolor 前景色
+/// @param BKcolor 背景色
+#[macro_export]
+macro_rules! printk_color {
+
+    ($FRcolor:expr, $BKcolor:expr, $($arg:tt)*) => {
+        use alloc;
+        $crate::libs::printk::PrintkWriter.__write_string_color($FRcolor, $BKcolor, alloc::fmt::format(format_args!($($arg)*)).as_str())
+    };
+}
+
+#[macro_export]
+macro_rules! kdebug {
+    ($($arg:tt)*) => {
+        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("[ DEBUG ] ({}:{})\t", file!(), line!()))+
+                                                                alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
+    }
+}
+
+#[macro_export]
+macro_rules! kinfo {
+    ($($arg:tt)*) => {
+        $crate::libs::printk::PrintkWriter.__write_string((alloc::string::String::from("[ INFO ] ")+ alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
+    }
+}
+
+#[macro_export]
+macro_rules! kwarn {
+    ($($arg:tt)*) => {
+        $crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::printk::COLOR_YELLOW, $crate::libs::printk::COLOR_BLACK, "[ WARN ] ");
+        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!($($arg)*)) + "\n").as_str())
+    }
+}
+
+#[macro_export]
+macro_rules! kerror {
+    ($($arg:tt)*) => {
+        $crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::printk::COLOR_RED, $crate::libs::printk::COLOR_BLACK, "[ ERROR ] ");
+        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
+                                                                alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
+    }
+}
+
+#[macro_export]
+macro_rules! kBUG {
+    ($($arg:tt)*) => {
+        $crate::libs::printk::PrintkWriter.__write_string_color($crate::libs::printk::COLOR_RED, $crate::libs::printk::COLOR_BLACK, "[ BUG ] ");
+        $crate::libs::printk::PrintkWriter.__write_string((alloc::fmt::format(format_args!("({}:{})\t", file!(), line!())) +
+                                                                alloc::fmt::format(format_args!($($arg)*)).as_str() + "\n").as_str())
+    }
+}
+
 pub struct PrintkWriter;
 
 impl PrintkWriter {

+ 1 - 1
kernel/src/mm/allocator.rs

@@ -1,5 +1,5 @@
 use crate::include::bindings::bindings::{gfp_t, kfree, kmalloc, PAGE_2M_SIZE};
-use crate::include::DragonOS::gfp::__GFP_ZERO;
+use super::gfp::__GFP_ZERO;
 
 use core::alloc::{GlobalAlloc, Layout};
 

+ 0 - 0
kernel/src/include/DragonOS/gfp.rs → kernel/src/mm/gfp.rs


+ 2 - 1
kernel/src/mm/mod.rs

@@ -1 +1,2 @@
-pub mod allocator;
+pub mod allocator;
+pub mod gfp;

+ 6 - 6
kernel/src/process/fork.rs

@@ -4,13 +4,13 @@ use alloc::boxed::Box;
 
 use crate::{
     arch::x86_64::asm::current::current_pcb,
-    include::{
-        bindings::bindings::{
-            process_control_block, CLONE_CLEAR_SIGHAND, CLONE_SIGHAND, CLONE_THREAD, ENOMEM,
-        },
-        DragonOS::signal::{sigaction, sighand_struct, signal_struct},
+    include::bindings::bindings::{
+        process_control_block, CLONE_CLEAR_SIGHAND, CLONE_SIGHAND, CLONE_THREAD, ENOMEM,
+    },
+    ipc::{
+        signal::DEFAULT_SIGACTION,
+        signal_types::{sigaction, sighand_struct, signal_struct},
     },
-    ipc::signal::DEFAULT_SIGACTION,
     kdebug,
     libs::{
         atomic::atomic_set,

+ 3 - 4
kernel/src/process/initial_proc.rs

@@ -1,11 +1,10 @@
 use crate::{
-    include::{
-        bindings::bindings::{atomic_t, spinlock_t},
-        DragonOS::signal::{sighand_struct, signal_struct, MAX_SIG_NUM},
-    },
+    include::bindings::bindings::{atomic_t, spinlock_t},
     ipc::signal::DEFAULT_SIGACTION,
 };
 
+use crate::ipc::signal_types::{sighand_struct, signal_struct, MAX_SIG_NUM};
+
 /// @brief 初始进程的signal结构体
 #[no_mangle]
 pub static INITIAL_SIGNALS: signal_struct = signal_struct {