extract device drivers into new module
This commit is contained in:
parent
9693d83bde
commit
49584f0f26
@ -45,7 +45,10 @@ pub mod mem {
|
||||
|
||||
pub mod virtual_memory {
|
||||
#[cfg(target_arch = "riscv64")]
|
||||
pub use super::riscv::virtual_memory::{kvminit as init, kvminithart as inithart, copyin, copyinstr, copyout, mappages, uvmalloc, uvmcopy, uvmcreate, uvmdealloc, uvmfree, uvmunmap};
|
||||
pub use super::riscv::virtual_memory::{
|
||||
copyin, copyinstr, copyout, kvminit as init, kvminithart as inithart, mappages, uvmalloc,
|
||||
uvmcopy, uvmcreate, uvmdealloc, uvmfree, uvmunmap,
|
||||
};
|
||||
}
|
||||
|
||||
pub mod power {
|
||||
|
@ -57,7 +57,7 @@ pub unsafe fn devintr() -> i32 {
|
||||
let irq = interrupt::handle_interrupt();
|
||||
|
||||
if irq == UART0_IRQ {
|
||||
crate::console::uart::UART0.interrupt();
|
||||
crate::hardware::uart::UART0.interrupt();
|
||||
} else if irq == VIRTIO0_IRQ {
|
||||
virtio_disk_intr();
|
||||
} else if irq > 0 {
|
||||
|
@ -1,4 +1,9 @@
|
||||
use super::{asm, mem::{make_satp, pte2pa}, plic::PLIC, power::QEMU_POWER};
|
||||
use super::{
|
||||
asm,
|
||||
mem::{make_satp, pte2pa},
|
||||
plic::PLIC,
|
||||
power::QEMU_POWER,
|
||||
};
|
||||
use crate::{
|
||||
arch::{
|
||||
self,
|
||||
|
@ -9,10 +9,10 @@
|
||||
// - ctrl-p: print process list
|
||||
|
||||
pub mod printf;
|
||||
pub mod uart;
|
||||
|
||||
use crate::{
|
||||
fs::file::{devsw, CONSOLE},
|
||||
hardware::uart::UART0,
|
||||
proc::{
|
||||
process::{procdump, Process},
|
||||
scheduler::wakeup,
|
||||
@ -20,7 +20,6 @@ use crate::{
|
||||
sync::mutex::Mutex,
|
||||
};
|
||||
use core::{ffi::c_void, ptr::addr_of_mut};
|
||||
use uart::UART0;
|
||||
|
||||
extern "C" {
|
||||
fn either_copyin(dst: *mut c_void, user_src: i32, src: u64, len: u64) -> i32;
|
||||
|
@ -30,13 +30,13 @@ pub(crate) use println;
|
||||
/// Does not use any locks.
|
||||
macro_rules! uprint {
|
||||
($($arg:tt)*) => {{
|
||||
use $crate::console::uart::Uart;
|
||||
use $crate::hardware::uart::Uart;
|
||||
use core::fmt::Write;
|
||||
|
||||
// Do some casts to get a mutable reference.
|
||||
// Safe because Uart's core::fmt::Write implementation
|
||||
// only uses the &mut reference immutably.
|
||||
let uart: *const Uart = &$crate::console::uart::UART0 as *const Uart;
|
||||
let uart: *const Uart = &$crate::hardware::uart::UART0 as *const Uart;
|
||||
let uart: &mut Uart = unsafe { &mut *uart.cast_mut() };
|
||||
|
||||
let _ = core::write!(uart, $($arg)*);
|
||||
|
@ -1,9 +1,9 @@
|
||||
//! Support functions for system calls that involve file descriptors.
|
||||
|
||||
use crate::{
|
||||
arch::virtual_memory::copyout,
|
||||
fs::{log, stat::Stat},
|
||||
io::pipe::Pipe,
|
||||
arch::virtual_memory::copyout,
|
||||
proc::process::Process,
|
||||
sync::{sleeplock::Sleeplock, spinlock::Spinlock},
|
||||
};
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
pub mod file;
|
||||
pub mod log;
|
||||
pub mod ramdisk;
|
||||
pub mod stat;
|
||||
pub mod virtio_disk;
|
||||
|
||||
use crate::fs::file::Inode;
|
||||
|
||||
|
5
kernel/rustkernel/src/hardware/mod.rs
Normal file
5
kernel/rustkernel/src/hardware/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
//! Device drivers and hardware implementations.
|
||||
|
||||
pub mod ramdisk;
|
||||
pub mod uart;
|
||||
pub mod virtio_disk;
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
arch::virtual_memory::{copyin, copyout},
|
||||
fs::file::{filealloc, fileclose, File, FileType},
|
||||
mem::kalloc::{kalloc, kfree},
|
||||
arch::virtual_memory::{copyin, copyout},
|
||||
proc::{process::Process, scheduler::wakeup},
|
||||
sync::spinlock::Spinlock,
|
||||
};
|
||||
|
@ -11,6 +11,7 @@ extern crate core;
|
||||
mod arch;
|
||||
mod console;
|
||||
mod fs;
|
||||
mod hardware;
|
||||
mod io;
|
||||
mod mem;
|
||||
mod proc;
|
||||
@ -68,7 +69,7 @@ pub unsafe fn main() -> ! {
|
||||
io::bio::binit();
|
||||
fs::iinit();
|
||||
fs::file::fileinit();
|
||||
fs::virtio_disk::virtio_disk_init();
|
||||
hardware::virtio_disk::virtio_disk_init();
|
||||
proc::process::userinit();
|
||||
STARTED = true;
|
||||
} else {
|
||||
|
@ -1,5 +1,9 @@
|
||||
use crate::{
|
||||
arch::{clock::CLOCK_TICKS, power::shutdown, virtual_memory::{copyin, copyinstr}},
|
||||
arch::{
|
||||
clock::CLOCK_TICKS,
|
||||
power::shutdown,
|
||||
virtual_memory::{copyin, copyinstr},
|
||||
},
|
||||
fs::{
|
||||
self,
|
||||
file::{self, File},
|
||||
|
Loading…
x
Reference in New Issue
Block a user