2023-03-23 06:18:33 +01:00
|
|
|
; FXF launching routines
|
2023-01-25 02:08:27 +01:00
|
|
|
|
2023-07-11 02:59:21 +02:00
|
|
|
; launch an FXF binary from an already opened file
|
|
|
|
; inputs:
|
|
|
|
; r0: pointer to file struct
|
|
|
|
; r1: reserved
|
|
|
|
; r2: argument 0
|
|
|
|
; r3: argument 1
|
|
|
|
; r4: argument 2
|
|
|
|
; r5: argument 3
|
|
|
|
; r6: argument 4
|
|
|
|
; outputs:
|
|
|
|
; r0: task ID of the new task, or 0xFFFFFFFF if error
|
|
|
|
launch_fxf_from_open_file:
|
|
|
|
push r1
|
|
|
|
push r2
|
|
|
|
push r3
|
|
|
|
push r4
|
|
|
|
push r5
|
|
|
|
push r6
|
|
|
|
|
|
|
|
push r2
|
|
|
|
push r3
|
|
|
|
push r4
|
|
|
|
push r5
|
|
|
|
push r6
|
|
|
|
|
|
|
|
mov [launch_fxf_struct_ptr], r0
|
|
|
|
jmp launch_fxf_from_open_file_1
|
|
|
|
|
2023-03-23 06:18:33 +01:00
|
|
|
; launch an FXF binary from a file on disk
|
2023-01-25 02:08:27 +01:00
|
|
|
; inputs:
|
2023-03-23 06:18:33 +01:00
|
|
|
; r0: pointer to FXF binary name (8.3 format, for example "testfile.fxf" or "test.fxf")
|
2023-03-23 06:24:01 +01:00
|
|
|
; r1: disk ID
|
|
|
|
; r2: argument 0
|
|
|
|
; r3: argument 1
|
|
|
|
; r4: argument 2
|
|
|
|
; r5: argument 3
|
|
|
|
; r6: argument 4
|
2023-01-25 02:08:27 +01:00
|
|
|
; outputs:
|
2023-03-23 08:20:11 +01:00
|
|
|
; r0: task ID of the new task, or 0xFFFFFFFF if error
|
2023-03-23 06:18:33 +01:00
|
|
|
launch_fxf_from_disk:
|
2023-01-25 02:08:27 +01:00
|
|
|
push r1
|
|
|
|
push r2
|
|
|
|
push r3
|
|
|
|
push r4
|
2023-03-23 06:24:01 +01:00
|
|
|
push r5
|
|
|
|
push r6
|
|
|
|
|
|
|
|
push r2
|
|
|
|
push r3
|
|
|
|
push r4
|
|
|
|
push r5
|
|
|
|
push r6
|
2023-01-25 02:08:27 +01:00
|
|
|
|
|
|
|
; open the file
|
2023-07-11 02:59:21 +02:00
|
|
|
mov [launch_fxf_struct_ptr], launch_fxf_struct
|
|
|
|
mov r2, [launch_fxf_struct_ptr]
|
2023-01-25 02:08:27 +01:00
|
|
|
call open
|
|
|
|
cmp r0, 0
|
2023-03-23 08:16:53 +01:00
|
|
|
ifz jmp launch_fxf_from_disk_file_error
|
2023-07-11 02:59:21 +02:00
|
|
|
launch_fxf_from_open_file_1:
|
2023-01-25 02:08:27 +01:00
|
|
|
; allocate memory for the binary
|
2023-07-11 02:59:21 +02:00
|
|
|
mov r0, [launch_fxf_struct_ptr]
|
2023-03-31 07:16:31 +02:00
|
|
|
call get_size
|
2023-01-25 02:08:27 +01:00
|
|
|
call allocate_memory
|
|
|
|
cmp r0, 0
|
2023-03-23 08:16:53 +01:00
|
|
|
ifz jmp launch_fxf_from_disk_allocate_error
|
2023-01-25 02:08:27 +01:00
|
|
|
mov [launch_fxf_binary_ptr], r0
|
|
|
|
|
|
|
|
; read the file into memory
|
2023-07-11 02:59:21 +02:00
|
|
|
mov r0, [launch_fxf_struct_ptr]
|
2023-01-25 02:08:27 +01:00
|
|
|
mov r1, [launch_fxf_binary_ptr]
|
|
|
|
call ryfs_read_whole_file
|
|
|
|
|
|
|
|
; allocate a 64KiB stack
|
|
|
|
mov r0, 65536
|
|
|
|
call allocate_memory
|
|
|
|
cmp r0, 0
|
2023-03-23 08:16:53 +01:00
|
|
|
ifz jmp launch_fxf_from_disk_allocate_error
|
2023-01-25 02:08:27 +01:00
|
|
|
mov [launch_fxf_stack_ptr], r0
|
|
|
|
|
2023-03-23 06:18:33 +01:00
|
|
|
; push the arguments to the task's stack
|
2023-03-23 06:24:01 +01:00
|
|
|
pop r4
|
|
|
|
pop r3
|
|
|
|
pop r2
|
|
|
|
pop r1
|
|
|
|
pop r0
|
|
|
|
mov r5, rsp
|
2023-03-23 06:18:33 +01:00
|
|
|
mov rsp, [launch_fxf_stack_ptr]
|
|
|
|
add rsp, 65536 ; point to the end of the stack (stack grows down!!)
|
|
|
|
push r4
|
|
|
|
push r3
|
|
|
|
push r2
|
|
|
|
push r1
|
2023-03-23 06:24:01 +01:00
|
|
|
push r0
|
2023-03-23 06:18:33 +01:00
|
|
|
sub rsp, 65516
|
|
|
|
mov [launch_fxf_stack_ptr], rsp
|
2023-03-23 06:24:01 +01:00
|
|
|
mov rsp, r5
|
2023-03-23 06:18:33 +01:00
|
|
|
|
2023-01-25 02:08:27 +01:00
|
|
|
; relocate the binary
|
|
|
|
mov r0, [launch_fxf_binary_ptr]
|
|
|
|
call parse_fxf_binary
|
|
|
|
|
|
|
|
; create a new task
|
|
|
|
mov r1, r0
|
|
|
|
call get_unused_task_id
|
2023-03-23 08:16:53 +01:00
|
|
|
mov.8 [launch_fxf_task_id], r0
|
2023-01-25 02:08:27 +01:00
|
|
|
mov r2, [launch_fxf_stack_ptr]
|
|
|
|
add r2, 65516 ; point to the end of the stack (stack grows down!!)
|
|
|
|
mov r3, [launch_fxf_binary_ptr]
|
|
|
|
mov r4, [launch_fxf_stack_ptr]
|
|
|
|
call new_task
|
2023-03-23 08:20:11 +01:00
|
|
|
|
|
|
|
pop r6
|
|
|
|
pop r5
|
|
|
|
pop r4
|
|
|
|
pop r3
|
|
|
|
pop r2
|
|
|
|
pop r1
|
|
|
|
movz.8 r0, [launch_fxf_task_id]
|
|
|
|
ret
|
2023-03-23 08:16:53 +01:00
|
|
|
launch_fxf_from_disk_allocate_error:
|
2023-03-23 06:42:10 +01:00
|
|
|
mov r0, launch_fxf_allocate_error_string1
|
|
|
|
mov r1, launch_fxf_allocate_error_string2
|
|
|
|
mov r2, launch_fxf_allocate_error_string3
|
|
|
|
mov r3, 64
|
|
|
|
mov r4, 64
|
|
|
|
mov r5, 336
|
|
|
|
call new_messagebox
|
2023-03-23 08:16:53 +01:00
|
|
|
launch_fxf_from_disk_file_error:
|
2023-03-23 06:24:01 +01:00
|
|
|
pop r6
|
|
|
|
pop r5
|
2023-01-25 02:08:27 +01:00
|
|
|
pop r4
|
|
|
|
pop r3
|
|
|
|
pop r2
|
|
|
|
pop r1
|
2023-03-23 08:20:11 +01:00
|
|
|
mov r0, 0xFFFFFFFF
|
2023-01-25 02:08:27 +01:00
|
|
|
ret
|
|
|
|
|
2023-07-11 02:59:21 +02:00
|
|
|
launch_fxf_struct_ptr: data.32 0
|
2023-03-31 06:44:29 +02:00
|
|
|
launch_fxf_struct: data.fill 0, 32
|
2023-03-23 08:16:53 +01:00
|
|
|
launch_fxf_task_id: data.8 0
|
2023-01-25 02:08:27 +01:00
|
|
|
launch_fxf_binary_ptr: data.32 0
|
|
|
|
launch_fxf_stack_ptr: data.32 0
|
2023-03-23 06:42:10 +01:00
|
|
|
launch_fxf_allocate_error_string1: data.strz "Failed to allocate memory for a new task"
|
|
|
|
launch_fxf_allocate_error_string2: data.strz "The memory allocator seems to be in an"
|
|
|
|
launch_fxf_allocate_error_string3: data.strz "invalid state, a reboot is recommended"
|