Adds syscall for sleep and print and makes process work in user mode

This commit is contained in:
2026-02-12 11:36:04 +01:00
parent 8a5c17482c
commit 369ff5fef4
9 changed files with 210 additions and 75 deletions

View File

@@ -1,18 +1,22 @@
#![no_std]
#![no_main]
#![allow(static_mut_refs)]
#![feature(riscv_ext_intrinsics, const_trait_impl, iter_map_windows)]
use core::{arch::riscv64::wfi, time::Duration};
#![feature(
riscv_ext_intrinsics,
const_trait_impl,
iter_map_windows,
str_from_raw_parts
)]
use embedded_alloc::LlffHeap as Heap;
use log::info;
use crate::{
io::init_log,
process::{create_processus, sleep},
process::create_processus,
riscv::enable_supervisor_interrupt,
scheduler::{idle, scheduler_init},
user::{proc2, test},
vga::{Color, Vga},
};
@@ -26,31 +30,18 @@ mod panic_handler;
mod process;
mod riscv;
mod scheduler;
mod syscall;
mod time;
mod uart;
mod user;
mod vga;
pub const HEAP_SIZE: usize = 4096;
#[global_allocator]
static HEAP: Heap = Heap::empty();
extern "C" fn test() {
loop {
info!("test");
enable_supervisor_interrupt();
sleep(Duration::new(2, 0));
unsafe { wfi() };
}
}
extern "C" fn proc2() {
loop {
info!("proc2");
enable_supervisor_interrupt();
sleep(Duration::new(3, 0));
unsafe { wfi() };
}
}
// 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() {
@@ -59,7 +50,7 @@ pub extern "C" fn supervisor_mode_entry() {
init_log().unwrap();
Vga::init();
scheduler_init();
enable_supervisor_interrupt();
// enable_supervisor_interrupt();
}
info!("Hello World !");
@@ -68,5 +59,6 @@ pub extern "C" fn supervisor_mode_entry() {
create_processus(test, "proc1");
create_processus(proc2, "proc2");
enable_supervisor_interrupt();
idle();
}