implements PLN-0053

This commit is contained in:
2026-05-14 18:31:58 +01:00
parent ab825d3274
commit d1f4547e44
19 changed files with 295 additions and 163 deletions
@@ -5,11 +5,13 @@ use prometeu_hal::cartridge::Cartridge;
use prometeu_hal::log::{LogLevel, LogSource};
impl VirtualMachineRuntime {
pub fn new(cap_config: Option<CertificationConfig>) -> Self {
pub fn new_with_log_counter(
cap_config: Option<CertificationConfig>,
logs_count: Arc<AtomicU32>,
) -> Self {
let boot_time = Instant::now();
let log_service = LogService::new(4096);
let atomic_telemetry = Arc::new(AtomicTelemetry::new(Arc::clone(&log_service.logs_count)));
let mut os = Self {
let atomic_telemetry = Arc::new(AtomicTelemetry::new(logs_count));
Self {
tick_index: 0,
logical_frame_index: 0,
logical_frame_active: false,
@@ -20,7 +22,6 @@ impl VirtualMachineRuntime {
memcard: MemcardService::new(),
open_files: HashMap::new(),
next_handle: 1,
log_service,
current_app_id: 0,
current_cartridge_title: String::new(),
current_cartridge_app_version: String::new(),
@@ -36,25 +37,35 @@ impl VirtualMachineRuntime {
frame_start_string_materializations: 0,
needs_prepare_entry_call: false,
boot_time,
};
os.log(LogLevel::Info, LogSource::Pos, 0, "PrometeuOS starting...".to_string());
os
}
}
pub fn log(&mut self, level: LogLevel, source: LogSource, tag: u16, msg: String) {
pub fn log(
&self,
log_service: &mut LogService,
level: LogLevel,
source: LogSource,
tag: u16,
msg: String,
) {
let ts_ms = self.boot_time.elapsed().as_millis() as u64;
let frame = self.logical_frame_index;
self.log_service.log(ts_ms, frame, level, source, tag, msg);
log_service.log(ts_ms, frame, level, source, tag, msg);
}
pub fn mount_fs(&mut self, backend: Box<dyn FsBackend>) {
self.log(LogLevel::Info, LogSource::Fs, 0, "Attempting to mount filesystem".to_string());
pub fn mount_fs(&mut self, log_service: &mut LogService, backend: Box<dyn FsBackend>) {
self.log(
log_service,
LogLevel::Info,
LogSource::Fs,
0,
"Attempting to mount filesystem".to_string(),
);
match self.fs.mount(backend) {
Ok(_) => {
self.fs_state = FsState::Mounted;
self.log(
log_service,
LogLevel::Info,
LogSource::Fs,
0,
@@ -63,7 +74,7 @@ impl VirtualMachineRuntime {
}
Err(e) => {
let err_msg = format!("Failed to mount filesystem: {:?}", e);
self.log(LogLevel::Error, LogSource::Fs, 0, err_msg);
self.log(log_service, LogLevel::Error, LogSource::Fs, 0, err_msg);
self.fs_state = FsState::Error(e);
}
}
@@ -74,9 +85,10 @@ impl VirtualMachineRuntime {
self.fs_state = FsState::Unmounted;
}
pub(crate) fn update_fs(&mut self) {
pub(crate) fn update_fs(&mut self, log_service: &mut LogService) {
if self.fs_state == FsState::Mounted && !self.fs.is_healthy() {
self.log(
log_service,
LogLevel::Error,
LogSource::Fs,
0,
@@ -120,6 +132,7 @@ impl VirtualMachineRuntime {
pub fn initialize_vm(
&mut self,
log_service: &mut LogService,
vm: &mut VirtualMachine,
cartridge: &Cartridge,
) -> Result<(), CrashReport> {
@@ -138,6 +151,7 @@ impl VirtualMachineRuntime {
let report = CrashReport::VmInit { error: e };
self.last_crash_report = Some(report.clone());
self.log(
log_service,
LogLevel::Error,
LogSource::Vm,
report.log_tag(),