terminal: Use launch_fxf_from_disk

This commit is contained in:
Ry 2023-03-23 00:37:39 -07:00
parent 201336ad31
commit 861031ea6c
2 changed files with 21 additions and 76 deletions

View File

@ -17,10 +17,18 @@
call fill_window call fill_window
; start an instance of sh.fxf ; start an instance of sh.fxf
call get_unused_task_id call get_current_disk_id
mov r1, r0
mov r0, sh_fxf_name
mov r2, stream_struct
mov r3, 0
mov r4, 0
mov r5, 0
mov r6, 0
call launch_fxf_from_disk
cmp r0, 0xFFFFFFFF
ifz jmp sh_fxf_missing
mov.8 [shell_task_id], r0 mov.8 [shell_task_id], r0
mov r1, stream_struct
call new_shell_task
event_loop: event_loop:
mov r0, window_struct mov r0, window_struct
@ -99,9 +107,19 @@ close_window:
call end_current_task call end_current_task
jmp event_loop_end jmp event_loop_end
sh_fxf_missing:
mov r0, sh_fxf_missing_str
call print_str_to_terminal
sh_fxf_missing_yield_loop:
call yield_task
rjmp sh_fxf_missing_yield_loop
window_title: data.strz "Terminal" window_title: data.strz "Terminal"
window_struct: data.fill 0, 36 window_struct: data.fill 0, 36
sh_fxf_name: data.strz "sh.fxf"
sh_fxf_missing_str: data.str "sh could not be launched! hanging here" data.8 10 data.8 0
shell_task_id: data.8 0 shell_task_id: data.8 0
stream_struct: stream_struct:
@ -113,7 +131,6 @@ stream_struct:
data.32 stream_write_to_terminal data.32 stream_write_to_terminal
#include "stream.asm" #include "stream.asm"
#include "task.asm"
#include "text.asm" #include "text.asm"
; include system defs ; include system defs

View File

@ -1,72 +0,0 @@
; sh.fxf launching routines
; start an instance of sh.fxf
; inputs:
; r0: task ID
; r1: pointer to stream struct
; outputs:
; none
new_shell_task:
push r0
push r1
; open the file
call get_current_disk_id
mov r1, r0
mov r0, sh_fxf_name
mov r2, sh_fxf_struct
call open
cmp r0, 0
ifz jmp sh_fxf_missing
; allocate memory for the binary
mov r0, sh_fxf_struct
call ryfs_get_size
call allocate_memory
cmp r0, 0
ifz jmp sh_fxf_missing
mov [sh_fxf_binary_ptr], r0
; read the file into memory
mov r0, sh_fxf_struct
mov r1, [sh_fxf_binary_ptr]
call ryfs_read_whole_file
; allocate a 64KiB stack
mov r0, 65536
call allocate_memory
cmp r0, 0
ifz jmp sh_fxf_missing
mov [sh_fxf_stack_ptr], r0
; push the stream struct pointer to the shell's stack
add r0, 65532
pop r1
mov [r0], r1
mov r10, r0
; relocate the binary
mov r0, [sh_fxf_binary_ptr]
call parse_fxf_binary
; then start the task
mov r1, r0 ; initial instruction pointer
pop r0 ; task ID
mov r2, r10 ; initial stack pointer
mov r3, [sh_fxf_binary_ptr] ; pointer to task code block to free when task ends
mov r4, [sh_fxf_stack_ptr] ; pointer to task stack block to free when task ends
call new_task
ret
sh_fxf_missing:
mov r0, sh_fxf_missing_str
call print_str_to_terminal
sh_fxf_missing_yield_loop:
call yield_task
rjmp sh_fxf_missing_yield_loop
sh_fxf_name: data.strz "sh.fxf"
sh_fxf_struct: data.fill 0, 8
sh_fxf_missing_str: data.str "sh could not be launched! hanging here" data.8 10 data.8 0
sh_fxf_binary_ptr: data.32 0
sh_fxf_stack_ptr: data.32 0