Load dynamic programs using FAT32
This commit is contained in:
81
src/main.rs
Normal file
81
src/main.rs
Normal file
@@ -0,0 +1,81 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![allow(static_mut_refs)]
|
||||
#![feature(
|
||||
riscv_ext_intrinsics,
|
||||
const_trait_impl,
|
||||
iter_map_windows,
|
||||
str_from_raw_parts,
|
||||
macro_metavar_expr,
|
||||
macro_metavar_expr_concat
|
||||
)]
|
||||
|
||||
use alloc::{boxed::Box, vec::Vec};
|
||||
use bffs::{io::Read, Fat32FileSystem};
|
||||
use embedded_alloc::LlffHeap as Heap;
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
fs::Disk,
|
||||
io::init_log,
|
||||
process::create_process,
|
||||
riscv::enable_supervisor_interrupt,
|
||||
scheduler::{idle, scheduler_init},
|
||||
tests_fat::MemoryDisk,
|
||||
user::{proc2, test},
|
||||
vga::{Color, Vga},
|
||||
};
|
||||
|
||||
extern crate alloc;
|
||||
mod boot;
|
||||
mod critical_section;
|
||||
mod fs;
|
||||
mod interrupt;
|
||||
mod io;
|
||||
mod panic_handler;
|
||||
mod process;
|
||||
mod riscv;
|
||||
mod scheduler;
|
||||
mod syscall;
|
||||
mod tests_fat;
|
||||
mod time;
|
||||
mod uart;
|
||||
mod user;
|
||||
mod vga;
|
||||
|
||||
pub const HEAP_SIZE: usize = 40960;
|
||||
#[global_allocator]
|
||||
static HEAP: Heap = Heap::empty();
|
||||
|
||||
// Usize is assumed to be an u64 in the whole kernel
|
||||
const _: () = assert!(size_of::<usize>() == size_of::<u64>());
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn supervisor_mode_entry() {
|
||||
unsafe {
|
||||
embedded_alloc::init!(HEAP, HEAP_SIZE);
|
||||
init_log().unwrap();
|
||||
Vga::init();
|
||||
scheduler_init();
|
||||
}
|
||||
|
||||
info!("Hello World !");
|
||||
unsafe { Vga::draw_string(10, 10, "Hello World !", Color::WHITE, Color::BLACK) };
|
||||
|
||||
create_process(&test, "proc1");
|
||||
create_process(&proc2, "proc2");
|
||||
|
||||
let fs = Fat32FileSystem::new(Disk::new(1024 * 1024 * 16)).unwrap();
|
||||
let mut bin = fs.open_file("/usr/bin/test").unwrap();
|
||||
let mut content: Vec<u8> = Vec::new();
|
||||
bin.read_to_end(&mut content).unwrap();
|
||||
let test = unsafe { core::mem::transmute::<*const u8, extern "C" fn()>(content.as_ptr()) };
|
||||
|
||||
let test = Box::leak(Box::new(move || {
|
||||
test();
|
||||
}));
|
||||
create_process(test, "dyn_proc");
|
||||
|
||||
enable_supervisor_interrupt();
|
||||
idle();
|
||||
}
|
||||
Reference in New Issue
Block a user