Skip to content

Commit

Permalink
romdisk: fix a bug that prevented MMU-less targets to execute program…
Browse files Browse the repository at this point in the history
…s with `exec`
  • Loading branch information
Zeal8bit committed Mar 21, 2024
1 parent b62b51c commit 5931404
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
27 changes: 25 additions & 2 deletions romdisk/misc.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 3 additions & 12 deletions romdisk/parse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5931404

Please sign in to comment.