add process and task managers
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good

This commit is contained in:
2026-05-14 17:39:55 +01:00
parent 6694bd2dd1
commit be684ab0f9
32 changed files with 816 additions and 93 deletions
@@ -4,7 +4,7 @@ use crate::firmware::prometeu_context::PrometeuContext;
use prometeu_hal::cartridge::Cartridge;
use prometeu_hal::telemetry::CertificationConfig;
use prometeu_hal::{HardwareBridge, InputSignals};
use prometeu_system::{PrometeuHub, VirtualMachineRuntime};
use prometeu_system::{PrometeuHub, SystemOS};
use prometeu_vm::VirtualMachine;
/// PROMETEU Firmware.
@@ -26,7 +26,7 @@ pub struct Firmware {
/// The execution engine (PVM) for user applications.
pub vm: VirtualMachine,
/// The underlying OS services (Syscalls, Filesystem, Telemetry).
pub os: VirtualMachineRuntime,
pub os: SystemOS,
/// The internal state of the system launcher (Hub).
pub hub: PrometeuHub,
/// The current operational state (e.g., Reset, SplashScreen, GameRunning).
@@ -42,7 +42,7 @@ impl Firmware {
pub fn new(cap_config: Option<CertificationConfig>) -> Self {
Self {
vm: VirtualMachine::default(),
os: VirtualMachineRuntime::new(cap_config),
os: SystemOS::new(cap_config),
hub: PrometeuHub::new(),
state: FirmwareState::Reset(ResetStep),
boot_target: BootTarget::Hub,
@@ -335,7 +335,7 @@ mod tests {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
firmware.load_cartridge(valid_cartridge(AppMode::System));
firmware.load_cartridge(valid_cartridge(AppMode::Shell));
firmware.tick(&signals, &mut hardware);
assert!(matches!(firmware.state, FirmwareState::SystemRunning(_)));
@@ -349,14 +349,14 @@ mod tests {
let mut hardware = Hardware::new();
let signals = InputSignals::default();
firmware.load_cartridge(valid_cartridge(AppMode::System));
firmware.load_cartridge(valid_cartridge(AppMode::Shell));
firmware.tick(&signals, &mut hardware);
let tick_index_before_system_update = firmware.os.tick_index;
let tick_index_before_system_update = firmware.os.vm_runtime.tick_index;
firmware.tick(&signals, &mut hardware);
assert!(matches!(firmware.state, FirmwareState::SystemRunning(_)));
assert_eq!(firmware.os.tick_index, tick_index_before_system_update + 1);
assert_eq!(firmware.os.vm_runtime.tick_index, tick_index_before_system_update + 1);
}
#[test]
@@ -15,7 +15,12 @@ impl AppCrashesStep {
}
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(LogLevel::Error, LogSource::Pos, self.report.log_tag(), self.log_message());
ctx.os.vm_runtime.log(
LogLevel::Error,
LogSource::Pos,
self.report.log_tag(),
self.log_message(),
);
}
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
@@ -1,19 +1,48 @@
use crate::firmware::firmware_state::{AppCrashesStep, FirmwareState};
use crate::firmware::prometeu_context::PrometeuContext;
use prometeu_hal::log::{LogLevel, LogSource};
use prometeu_system::CrashReport;
use prometeu_system::task::{TaskId, TaskState};
#[derive(Debug, Clone)]
pub struct GameRunningStep;
pub struct GameRunningStep {
pub task_id: TaskId,
}
impl GameRunningStep {
pub fn new(task_id: TaskId) -> Self {
Self { task_id }
}
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Entering GameRunning".to_string());
ctx.os.vm_runtime.log(
LogLevel::Info,
LogSource::Pos,
0,
"Entering GameRunning".to_string(),
);
}
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
let result = ctx.os.tick(ctx.vm, ctx.signals, ctx.hw);
let Some(task) = ctx.os.task_manager.get(self.task_id) else {
// TODO: is it panic?
let report =
CrashReport::VmPanic { message: "task is gone, panic!".to_string(), pc: None };
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
};
if !ctx.os.logical_frame_active {
if task.state != TaskState::Foreground {
// TODO: is it panic?
let report = CrashReport::VmPanic {
message: "should be running as foreground, panic!".to_string(),
pc: None,
};
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
}
let result = ctx.os.vm_runtime.tick(ctx.vm, ctx.signals, ctx.hw);
if !ctx.os.vm_runtime.logical_frame_active {
ctx.hw.gfx_mut().present();
}
@@ -7,7 +7,7 @@ pub struct HubHomeStep;
impl HubHomeStep {
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(LogLevel::Info, LogSource::Hub, 0, "Entering HubHome".to_string());
ctx.os.vm_runtime.log(LogLevel::Info, LogSource::Hub, 0, "Entering HubHome".to_string());
}
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
@@ -9,7 +9,7 @@ pub struct LaunchHubStep;
impl LaunchHubStep {
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Launching Hub".to_string());
ctx.os.vm_runtime.log(LogLevel::Info, LogSource::Pos, 0, "Launching Hub".to_string());
ctx.hub.init();
}
@@ -22,7 +22,7 @@ impl LaunchHubStep {
return Some(FirmwareState::LoadCartridge(LoadCartridgeStep::new(cartridge)));
}
Err(e) => {
ctx.os.log(
ctx.os.vm_runtime.log(
LogLevel::Error,
LogSource::Pos,
0,
@@ -20,7 +20,7 @@ impl LoadCartridgeStep {
}
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(
ctx.os.vm_runtime.log(
LogLevel::Info,
LogSource::Pos,
0,
@@ -34,7 +34,7 @@ impl LoadCartridgeStep {
self.cartridge.assets.clone(),
);
self.init_error = ctx.os.initialize_vm(ctx.vm, &self.cartridge).err();
self.init_error = ctx.os.vm_runtime.initialize_vm(ctx.vm, &self.cartridge).err();
}
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
@@ -42,7 +42,7 @@ impl LoadCartridgeStep {
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
}
if self.cartridge.app_mode == AppMode::System {
if self.cartridge.app_mode == AppMode::Shell {
let id = ctx.hub.window_manager.add_window(
self.cartridge.title.clone(),
Rect { x: 40, y: 20, w: 240, h: 140 },
@@ -50,10 +50,14 @@ impl LoadCartridgeStep {
);
ctx.hub.window_manager.set_focus(id);
return Some(FirmwareState::SystemRunning(SystemRunningStep));
let task_id =
ctx.os.create_vm_shell_task(self.cartridge.app_id, self.cartridge.title.clone());
return Some(FirmwareState::SystemRunning(SystemRunningStep::new(task_id)));
}
Some(FirmwareState::GameRunning(GameRunningStep))
let task_id =
ctx.os.create_vm_game_task(self.cartridge.app_id, self.cartridge.title.clone());
Some(FirmwareState::GameRunning(GameRunningStep::new(task_id)))
}
pub fn on_exit(&mut self, _ctx: &mut PrometeuContext) {}
@@ -8,8 +8,8 @@ pub struct ResetStep;
impl ResetStep {
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Firmware Reset".to_string());
ctx.os.reset(ctx.vm);
ctx.os.vm_runtime.log(LogLevel::Info, LogSource::Pos, 0, "Firmware Reset".to_string());
ctx.os.vm_runtime.reset(ctx.vm);
}
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
@@ -10,7 +10,12 @@ pub struct SplashScreenStep {
impl SplashScreenStep {
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Showing SplashScreen".to_string());
ctx.os.vm_runtime.log(
LogLevel::Info,
LogSource::Pos,
0,
"Showing SplashScreen".to_string(),
);
// Play sound on enter
// ctx.hw.audio_mut().play(0, 0, 0, 255, 127, 1.0, 0, LoopMode::Off);
}
@@ -1,13 +1,25 @@
use crate::firmware::firmware_state::{AppCrashesStep, FirmwareState, HubHomeStep};
use crate::firmware::prometeu_context::PrometeuContext;
use prometeu_hal::log::{LogLevel, LogSource};
use prometeu_system::task::TaskId;
#[derive(Debug, Clone)]
pub struct SystemRunningStep;
pub struct SystemRunningStep {
pub task_id: TaskId,
}
impl SystemRunningStep {
pub fn new(task_id: TaskId) -> Self {
Self { task_id }
}
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
ctx.os.log(LogLevel::Info, LogSource::Hub, 0, "Entering SystemRunning".to_string());
ctx.os.vm_runtime.log(
LogLevel::Info,
LogSource::Hub,
0,
"Entering SystemRunning".to_string(),
);
}
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
@@ -1,11 +1,11 @@
use crate::firmware::boot_target::BootTarget;
use prometeu_hal::{HardwareBridge, InputSignals};
use prometeu_system::{PrometeuHub, VirtualMachineRuntime};
use prometeu_system::{PrometeuHub, SystemOS};
use prometeu_vm::VirtualMachine;
pub struct PrometeuContext<'a> {
pub vm: &'a mut VirtualMachine,
pub os: &'a mut VirtualMachineRuntime,
pub os: &'a mut SystemOS,
pub hub: &'a mut PrometeuHub,
pub boot_target: &'a BootTarget,
pub signals: &'a InputSignals,