瀏覽代碼

内核:在lib.rs中,将arch模块的路径进行更改,使得其他模块使用arch的代码时,不需要指定arch::x86_64 (#128)

login 2 年之前
父節點
當前提交
adc1846b06

+ 0 - 3
kernel/src/arch/mod.rs

@@ -1,3 +0,0 @@
-#[cfg(target_arch="x86_64")]
-#[macro_use]
-pub mod x86_64;

+ 1 - 1
kernel/src/driver/timers/rtc/rtc.rs

@@ -8,7 +8,7 @@ pub struct rtc_time_t {
 }
 
 use crate::{
-    arch::x86_64::interrupt::{cli, sti},
+    arch::interrupt::{cli, sti},
     include::bindings::bindings::{io_in8, io_out8},
 };
 

+ 1 - 1
kernel/src/ipc/signal.rs

@@ -1,7 +1,7 @@
 use core::{ffi::c_void, intrinsics::size_of, ptr::read_volatile, sync::atomic::compiler_fence};
 
 use crate::{
-    arch::x86_64::{
+    arch::{
         asm::{bitops::ffz, current::current_pcb, ptrace::user_mode},
         interrupt::sti,
     },

+ 7 - 1
kernel/src/lib.rs

@@ -10,8 +10,12 @@
 #[allow(non_snake_case)]
 use core::panic::PanicInfo;
 
+/// 导出x86_64架构相关的代码,命名为arch模块
+#[cfg(target_arch = "x86_64")]
+#[path = "arch/x86_64/mod.rs"]
 #[macro_use]
 mod arch;
+
 #[macro_use]
 mod include;
 mod ipc;
@@ -25,13 +29,15 @@ mod sched;
 mod smp;
 mod time;
 
+
+
 extern crate alloc;
 
 use mm::allocator::KernelAllocator;
 
 // <3>
 use crate::{
-    arch::x86_64::asm::current::current_pcb,
+    arch::asm::current::current_pcb,
     include::bindings::bindings::{process_do_exit, BLACK, GREEN},
 };
 

+ 2 - 2
kernel/src/libs/spinlock.rs

@@ -3,8 +3,8 @@ use core::ptr::read_volatile;
 
 use core::sync::atomic::{AtomicBool, Ordering};
 
-use crate::arch::x86_64::asm::irqflags::{local_irq_restore, local_irq_save};
-use crate::arch::x86_64::interrupt::{cli, sti};
+use crate::arch::asm::irqflags::{local_irq_restore, local_irq_save};
+use crate::arch::interrupt::{cli, sti};
 use crate::include::bindings::bindings::{spin_lock, spin_unlock, spinlock_t};
 use crate::process::preempt::{preempt_disable, preempt_enable};
 

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

@@ -3,7 +3,7 @@ use core::{ffi::c_void, ptr::null_mut, sync::atomic::compiler_fence};
 use alloc::boxed::Box;
 
 use crate::{
-    arch::x86_64::asm::current::current_pcb,
+    arch::asm::current::current_pcb,
     include::bindings::bindings::{
         process_control_block, CLONE_CLEAR_SIGHAND, CLONE_SIGHAND, CLONE_THREAD, ENOMEM,
     },

+ 1 - 1
kernel/src/process/pid.rs

@@ -1,4 +1,4 @@
-use crate::{include::bindings::bindings::pt_regs, arch::x86_64::asm::current::current_pcb};
+use crate::{include::bindings::bindings::pt_regs, arch::asm::current::current_pcb};
 
 #[allow(dead_code)]
 #[derive(Debug, Clone, Copy)]

+ 1 - 1
kernel/src/process/preempt.rs

@@ -1,4 +1,4 @@
-use crate::arch::x86_64::asm::current::current_pcb;
+use crate::arch::asm::current::current_pcb;
 
 /// @brief 增加进程的锁持有计数
 #[inline]

+ 1 - 1
kernel/src/process/process.rs

@@ -1,7 +1,7 @@
 use core::ptr::{read_volatile, write_volatile};
 
 use crate::{
-    arch::x86_64::asm::current::current_pcb,
+    arch::asm::current::current_pcb,
     include::bindings::bindings::{
         process_control_block, sched_enqueue, PROC_RUNNING, PROC_STOPPED,
     },

+ 1 - 1
kernel/src/sched/core.rs

@@ -1,4 +1,4 @@
-use crate::{include::bindings::bindings::process_control_block, process::process::process_cpu, arch::x86_64::asm::current::current_pcb};
+use crate::{include::bindings::bindings::process_control_block, process::process::process_cpu, arch::asm::current::current_pcb};
 
 /// @brief 获取指定的cpu上正在执行的进程的pcb
 #[inline]

+ 1 - 1
kernel/src/smp/core.rs

@@ -2,7 +2,7 @@
 #[inline]
 pub fn smp_get_processor_id() -> u32 {
     if cfg!(x86_64) {
-        return crate::arch::x86_64::cpu::arch_current_apic_id() as u32;
+        return crate::arch::cpu::arch_current_apic_id() as u32;
     } else {
         255
     }