Better virtual file system, keyboard through MMIO&VirtIO
This commit is contained in:
41
src/main.rs
41
src/main.rs
@@ -5,32 +5,29 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
// #![warn(clippy::pedantic)]
|
||||
#![feature(
|
||||
riscv_ext_intrinsics,
|
||||
const_trait_impl,
|
||||
iter_map_windows,
|
||||
str_from_raw_parts,
|
||||
macro_metavar_expr,
|
||||
macro_metavar_expr_concat,
|
||||
ptr_metadata
|
||||
)]
|
||||
#![allow(static_mut_refs)]
|
||||
#![feature(riscv_ext_intrinsics, str_from_raw_parts)]
|
||||
|
||||
use core::sync::atomic::AtomicBool;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use embedded_alloc::LlffHeap as Heap;
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
fs::FAT32_FILE_SYSTEM,
|
||||
io::init_log,
|
||||
riscv::enable_supervisor_interrupt,
|
||||
scheduler::{idle, SCHEDULER},
|
||||
scheduler::{SCHEDULER, idle},
|
||||
user::{proc2, test},
|
||||
vga::{Color, Vga},
|
||||
vga::Vga,
|
||||
virtio::{Virtqueue, input::{VirtioInputDriver, init_plic_m_mode}},
|
||||
virtual_fs::init_file_system,
|
||||
};
|
||||
|
||||
extern crate alloc;
|
||||
mod boot;
|
||||
mod critical_section;
|
||||
mod draw;
|
||||
mod fs;
|
||||
mod interrupt;
|
||||
mod io;
|
||||
@@ -41,30 +38,41 @@ mod scheduler;
|
||||
mod sync;
|
||||
mod syscall;
|
||||
mod time;
|
||||
mod tty;
|
||||
mod uart;
|
||||
mod user;
|
||||
mod vga;
|
||||
mod virtio;
|
||||
mod virtual_console;
|
||||
mod virtual_fs;
|
||||
|
||||
pub const HEAP_SIZE: usize = 1024 * 1024 * 32; // 32Mo RAM
|
||||
#[global_allocator]
|
||||
static HEAP: Heap = Heap::empty();
|
||||
|
||||
static HEAP_INITIALIZED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
// Usize is assumed to be an u64 in the whole kernel
|
||||
const _: () = assert!(core::mem::size_of::<usize>() == core::mem::size_of::<u64>());
|
||||
|
||||
// 1. Allouer de la mémoire statique alignée pour la queue
|
||||
static mut KBD_QUEUE: Virtqueue = unsafe { core::mem::zeroed() };
|
||||
// 2. Initialisation (adresse 0x10001000 typique pour QEMU virt machine)
|
||||
pub static mut KBD_DRIVER: VirtioInputDriver =
|
||||
unsafe { VirtioInputDriver::new(0x10001000, &mut KBD_QUEUE) };
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn supervisor_mode_entry() {
|
||||
unsafe {
|
||||
embedded_alloc::init!(HEAP, HEAP_SIZE);
|
||||
HEAP_INITIALIZED.store(true, core::sync::atomic::Ordering::Relaxed);
|
||||
init_log().unwrap();
|
||||
Vga::init();
|
||||
FAT32_FILE_SYSTEM.init();
|
||||
SCHEDULER.lock().init();
|
||||
init_file_system();
|
||||
}
|
||||
|
||||
info!("Hello World !");
|
||||
unsafe { Vga::draw_string(10, 10, "Hello World !", Color::WHITE, Color::BLACK) };
|
||||
// unsafe { Vga.draw_string(10, 10, "Hello World !", Color::WHITE, Color::BLACK) };
|
||||
|
||||
SCHEDULER.lock().create_process(Box::new(test), "proc1");
|
||||
SCHEDULER.lock().create_process(Box::new(proc2), "proc2");
|
||||
@@ -74,5 +82,10 @@ pub extern "C" fn supervisor_mode_entry() {
|
||||
.create_process_from_file("/usr/bin/test_pic");
|
||||
|
||||
enable_supervisor_interrupt();
|
||||
|
||||
unsafe {
|
||||
KBD_DRIVER.init();
|
||||
init_plic_m_mode();
|
||||
}
|
||||
idle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user