extract device drivers into new module

This commit is contained in:
Garen Tyler 2023-11-09 21:03:21 -07:00
parent 9693d83bde
commit 49584f0f26
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
14 changed files with 28 additions and 13 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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,

View File

@ -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;

View File

@ -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)*);

View File

@ -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},
};

View File

@ -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;

View File

@ -0,0 +1,5 @@
//! Device drivers and hardware implementations.
pub mod ramdisk;
pub mod uart;
pub mod virtio_disk;

View File

@ -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,
};

View File

@ -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 {

View File

@ -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},