From 5708227a613f9ae2693d8187b21fe226b74b750b Mon Sep 17 00:00:00 2001 From: Ry Date: Wed, 1 Feb 2023 15:43:21 -0800 Subject: [PATCH] kernel/main: Detect if disk 1 is a valid FXF binary before running it --- kernel/main.asm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kernel/main.asm b/kernel/main.asm index 3d5b3a4..6685d5e 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -153,14 +153,14 @@ draw_bottom_bar_loop: in r31, 0x80001001 cmp r31, 0 ifnz jmp boot_disk_1 - +try_startup: ; open startup.cfg mov r0, startup_cfg mov r1, 0 mov r2, startup_cfg_struct call ryfs_open cmp r0, 0 - ifz jmp boot_disk_1 + ifz jmp startup_error ; load a startup task load_startup_task: @@ -242,7 +242,7 @@ no_other_tasks: ; this does not return. call end_current_task_no_mark_no_free -; if startup.cfg is invalid, try loading the raw contents of disk 1 as an FXF binary +; try loading the raw contents of disk 1 as an FXF binary ; if disk 1 is not inserted, then fail boot_disk_1: ; check if a disk is inserted as disk 1 @@ -277,6 +277,8 @@ boot_disk_1_loop: mov r1, r5 mov r0, r5 call parse_fxf_binary + cmp r0, 0 + ifz jmp disk_1_is_not_fxf mov r3, r1 mov r1, r0 movz.8 r0, [next_task_id] @@ -286,6 +288,13 @@ boot_disk_1_loop: call new_task jmp no_other_tasks +; disk 1 was found to not be a valid FXF binary +; free the memory allocated for it and instead just keep it mounted as a disk +disk_1_is_not_fxf: + mov r0, r5 + call free_memory + jmp try_startup + startup_error: mov r0, BACKGROUND_COLOR call fill_background