diff --git a/romdisk/misc.asm b/romdisk/misc.asm index 26fb9c8..aa2808d 100644 --- a/romdisk/misc.asm +++ b/romdisk/misc.asm @@ -61,10 +61,9 @@ _exec_main_merge: ; Execute the program stored in BC with the parameters in DE PUBLIC exec_main_bc_de exec_main_bc_de: - ld h, EXEC_PRESERVE_PROGRAM ; Keep the file name so that we can show it in case of error push bc - EXEC() + call try_exec_bc_de pop hl ; If an error occurred while executing, A will not be 0 or a @@ -92,6 +91,30 @@ exec_main_error: inc bc jp error_print + + ; Execute the program pointed by BC, this routien will automatically + ; determine whether to override or preserve the current program, depending + ; on the kernel configuration structure. + ; Parameters: + ; BC - Program path/name + ; DE - Parameter (optional) + PUBLIC try_exec_bc_de +try_exec_bc_de: + ; Check if the kernel has MMU support, if that's the case, this init program can be + ; preserved in memory while the subprogram executes. + KERNEL_CONFIG(hl) + inc hl ; point to MMU capability + ld a, (hl) + ; Prepare parameter before testing the MMU capability + ld h, EXEC_PRESERVE_PROGRAM + or a ; A = 0 <=> no MMU capability, cannot preserve + jr nz, _process_command_exec + ld h, EXEC_OVERRIDE_PROGRAM +_process_command_exec: + EXEC() + ret + + ; Reset the board PUBLIC reset_main reset_main: diff --git a/romdisk/parse.asm b/romdisk/parse.asm index 4004df4..1d9428f 100644 --- a/romdisk/parse.asm +++ b/romdisk/parse.asm @@ -27,6 +27,7 @@ EXTERN init_static_buffer EXTERN exec_main_bc_de EXTERN exec_main_ret_success + EXTERN try_exec_bc_de ; Parse and execute the command line passed as a parameter. ; Parameters: @@ -176,18 +177,8 @@ _process_command_not_path: ex de, hl push bc ld bc, init_static_buffer - ; Check if the kernel has MMU support, if that's the case, this init program can be - ; preserved in memory while the subprogram executes. - KERNEL_CONFIG(hl) - inc hl ; point to MMU capability - ld a, (hl) - ; Prepare parameter before testing the MMU capability - ld h, EXEC_PRESERVE_PROGRAM - or a ; A = 0 <=> no MMU capability, cannot preserve - jr nz, _process_command_exec - ld h, EXEC_OVERRIDE_PROGRAM -_process_command_exec: - EXEC() + ; Execute program whose name is pointed by BC + call try_exec_bc_de ; Pop the original command name and command length pop bc pop hl