Better user programs with a special std. Sleep and exit are calling scheduler instead of wfi.

This commit is contained in:
2026-02-21 18:29:27 +01:00
parent 235f17e7cf
commit 8a8034bd11
25 changed files with 263 additions and 210 deletions

View File

@@ -10,18 +10,15 @@
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,
fs::FILE_SYSTEM,
io::init_log,
process::create_process,
process::{create_process, create_process_from_file},
riscv::enable_supervisor_interrupt,
scheduler::{idle, scheduler_init},
tests_fat::MemoryDisk,
user::{proc2, test},
vga::{Color, Vga},
};
@@ -36,14 +33,12 @@ 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;
pub const HEAP_SIZE: usize = 1024 * 1024; // 1Mo RAM
#[global_allocator]
static HEAP: Heap = Heap::empty();
@@ -56,6 +51,7 @@ pub extern "C" fn supervisor_mode_entry() {
embedded_alloc::init!(HEAP, HEAP_SIZE);
init_log().unwrap();
Vga::init();
FILE_SYSTEM.init();
scheduler_init();
}
@@ -65,16 +61,7 @@ pub extern "C" fn supervisor_mode_entry() {
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");
create_process_from_file("/usr/bin/test_pic");
enable_supervisor_interrupt();
idle();