Make catm work when no arguments are supplied.
This commit is contained in:
parent
74a5685102
commit
e14033b3d9
|
@ -29,6 +29,8 @@ DEFINE mov_rcx,r15 4C89F9
|
||||||
DEFINE mov_rdx,rax 4889C2
|
DEFINE mov_rdx,rax 4889C2
|
||||||
DEFINE mov_rdx,rbx 4889DA
|
DEFINE mov_rdx,rbx 4889DA
|
||||||
DEFINE mov_rdx,rsp 4889E2
|
DEFINE mov_rdx,rsp 4889E2
|
||||||
|
DEFINE mov_rbp,rsp 4889E5
|
||||||
|
DEFINE mov_rsp,rbp 4889EC
|
||||||
DEFINE mov_r8,rbx 4989D8
|
DEFINE mov_r8,rbx 4989D8
|
||||||
DEFINE mov_r8,rsp 4989E0
|
DEFINE mov_r8,rsp 4989E0
|
||||||
DEFINE mov_r8,r12 4D89E0
|
DEFINE mov_r8,r12 4D89E0
|
||||||
|
@ -61,10 +63,12 @@ DEFINE sub_rbx, 4883EB
|
||||||
DEFINE sub_rsp, 4883EC
|
DEFINE sub_rsp, 4883EC
|
||||||
DEFINE xor_eax,eax 31C0
|
DEFINE xor_eax,eax 31C0
|
||||||
DEFINE test_eax,eax 85C0
|
DEFINE test_eax,eax 85C0
|
||||||
|
DEFINE test_r8,r8 4D85C0
|
||||||
DEFINE xor_r9,r9 4D31C9
|
DEFINE xor_r9,r9 4D31C9
|
||||||
|
|
||||||
# efi_main(void *image_handle, struct efi_system_table *system)
|
# efi_main(void *image_handle, struct efi_system_table *system)
|
||||||
:_start
|
:_start
|
||||||
|
mov_rbp,rsp # save stack pointer
|
||||||
mov_r12,rcx # save image_handle
|
mov_r12,rcx # save image_handle
|
||||||
mov_r14,[rdx+BYTE] !96 # system->boot
|
mov_r14,[rdx+BYTE] !96 # system->boot
|
||||||
|
|
||||||
|
@ -84,21 +88,17 @@ DEFINE xor_r9,r9 4D31C9
|
||||||
mov_rcx,rax # get rootfs
|
mov_rcx,rax # get rootfs
|
||||||
|
|
||||||
# Get root directory
|
# Get root directory
|
||||||
push_rdx # allocate stack for rootdir
|
lea_rdx,[rip+DWORD] %rootdir # arg2 = &rootdir
|
||||||
mov_rdx,rsp # arg2 = &rootdir
|
|
||||||
push_rax # allocate shadow stack space for UEFI function
|
push_rax # allocate shadow stack space for UEFI function
|
||||||
push_rax # allocate shadow stack space for UEFI function
|
push_rax # allocate shadow stack space for UEFI function
|
||||||
call_[rcx+BYTE] !8 # rootfs->open_volume(rootfs, &rootdir)
|
call_[rcx+BYTE] !8 # rootfs->open_volume(rootfs, &rootdir)
|
||||||
pop_rax # deallocate stack
|
pop_rax # deallocate stack
|
||||||
pop_rax # deallocate stack
|
pop_rax # deallocate stack
|
||||||
pop_rax # get rootdir
|
|
||||||
mov_[rip+DWORD],rax %rootdir # save rootdir
|
|
||||||
|
|
||||||
# Push command line arguments onto stack
|
# Push command line arguments onto stack
|
||||||
mov_rbx,[rdi+BYTE] !56 # options = image->load_options
|
mov_rbx,[rdi+BYTE] !56 # options = image->load_options
|
||||||
mov_rdx,rbx # save beginning of load_options
|
mov_rdx,rbx # save beginning of load_options
|
||||||
add_rbx,[rdi+BYTE] !48 # go to the end of load_options
|
add_rbx,[rdi+BYTE] !48 # go to the end of load_options
|
||||||
|
|
||||||
push !0 # Save end of arguments (NULL) onto stack
|
push !0 # Save end of arguments (NULL) onto stack
|
||||||
:loop_options
|
:loop_options
|
||||||
cmp_rbx,rdx # Check if we are done
|
cmp_rbx,rdx # Check if we are done
|
||||||
|
@ -113,6 +113,8 @@ DEFINE xor_r9,r9 4D31C9
|
||||||
jmp !loop_options # next argument
|
jmp !loop_options # next argument
|
||||||
:loop_options_done
|
:loop_options_done
|
||||||
pop_r8 # get output file
|
pop_r8 # get output file
|
||||||
|
test_r8,r8 # if no output file
|
||||||
|
je !exit_early # then exit
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
push_rdx # allocate stack for fout
|
push_rdx # allocate stack for fout
|
||||||
|
@ -161,12 +163,12 @@ DEFINE xor_r9,r9 4D31C9
|
||||||
mov_rcx,r15 # Get output file
|
mov_rcx,r15 # Get output file
|
||||||
call %close_file # close it
|
call %close_file # close it
|
||||||
|
|
||||||
mov_rcx,[rip+DWORD] %rootdir # Get rootdir
|
|
||||||
call %close_file # close it
|
|
||||||
|
|
||||||
mov_rcx,rbx # Get buffer
|
mov_rcx,rbx # Get buffer
|
||||||
call %free_pool # release it
|
call %free_pool # release it
|
||||||
xor_eax,eax # Exit code 0
|
|
||||||
|
:exit_early
|
||||||
|
mov_rcx,[rip+DWORD] %rootdir # Get rootdir
|
||||||
|
call %close_file # close it
|
||||||
|
|
||||||
mov_r8,r12 # arg3 = image_handle
|
mov_r8,r12 # arg3 = image_handle
|
||||||
lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
||||||
|
@ -178,6 +180,7 @@ DEFINE xor_r9,r9 4D31C9
|
||||||
mov_rcx,r12 # arg1 = image_handle
|
mov_rcx,r12 # arg1 = image_handle
|
||||||
call %close_protocol # close protocol
|
call %close_protocol # close protocol
|
||||||
|
|
||||||
|
mov_rsp,rbp # restore stack pointer
|
||||||
ret # return to UEFI
|
ret # return to UEFI
|
||||||
|
|
||||||
# r8: input file name
|
# r8: input file name
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
# efi_main(void *image_handle, struct efi_system_table *system)
|
# efi_main(void *image_handle, struct efi_system_table *system)
|
||||||
_start:
|
_start:
|
||||||
|
mov rbp, rsp # save stack pointer
|
||||||
mov r12, rcx # save image_handle
|
mov r12, rcx # save image_handle
|
||||||
mov r14, [rdx+96] # system->boot
|
mov r14, [rdx+96] # system->boot
|
||||||
|
|
||||||
|
@ -27,21 +28,18 @@ _start:
|
||||||
call open_protocol # open protocol
|
call open_protocol # open protocol
|
||||||
mov rcx, rax # get rootfs
|
mov rcx, rax # get rootfs
|
||||||
|
|
||||||
push rdx # allocate stack for rootdir
|
# Get root directory
|
||||||
mov rdx, rsp # arg2 = &rootdir
|
lea rdx, [rip+rootdir] # arg2 = &rootdir
|
||||||
push rax # allocate shadow stack space for UEFI function
|
push rax # allocate shadow stack space for UEFI function
|
||||||
push rax # allocate shadow stack space for UEFI function
|
push rax # allocate shadow stack space for UEFI function
|
||||||
call [rcx+8] # rootfs->open_volume(rootfs, &rootdir)
|
call [rcx+8] # rootfs->open_volume(rootfs, &rootdir)
|
||||||
pop rax # deallocate stack
|
pop rax # deallocate stack
|
||||||
pop rax # deallocate stack
|
pop rax # deallocate stack
|
||||||
pop rax # get rootdir
|
|
||||||
mov [rip+rootdir], rax # save rootdir
|
|
||||||
|
|
||||||
# Push command line arguments onto stack
|
# Push command line arguments onto stack
|
||||||
mov rbx, [rdi+56] # options = image->load_options
|
mov rbx, [rdi+56] # options = image->load_options
|
||||||
mov rdx, rbx # save beginning of load_options
|
mov rdx, rbx # save beginning of load_options
|
||||||
add rbx, [rdi+48] # go to the end of load_options
|
add rbx, [rdi+48] # go to the end of load_options
|
||||||
|
|
||||||
push 0 # Save end of arguments (NULL) onto stack
|
push 0 # Save end of arguments (NULL) onto stack
|
||||||
loop_options:
|
loop_options:
|
||||||
cmp rbx, rdx # Check if we are done
|
cmp rbx, rdx # Check if we are done
|
||||||
|
@ -56,6 +54,8 @@ loop_options:
|
||||||
jmp loop_options # next argument
|
jmp loop_options # next argument
|
||||||
loop_options_done:
|
loop_options_done:
|
||||||
pop r8 # get output file
|
pop r8 # get output file
|
||||||
|
test r8, r8 # if no output file
|
||||||
|
je exit_early # then exit
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
push rdx # allocate stack for fout
|
push rdx # allocate stack for fout
|
||||||
|
@ -104,12 +104,12 @@ done:
|
||||||
mov rcx, r15 # Get output file
|
mov rcx, r15 # Get output file
|
||||||
call close_file # close it
|
call close_file # close it
|
||||||
|
|
||||||
mov rcx, [rip+rootdir] # Get rootdir
|
|
||||||
call close_file # close it
|
|
||||||
|
|
||||||
mov rcx, rbx # Get buffer
|
mov rcx, rbx # Get buffer
|
||||||
call free_pool # release it
|
call free_pool # release it
|
||||||
xor eax, eax # Exit code 0
|
|
||||||
|
exit_early:
|
||||||
|
mov rcx, [rip+rootdir] # Get rootdir
|
||||||
|
call close_file # close it
|
||||||
|
|
||||||
mov r8, r12 # arg3 = image_handle
|
mov r8, r12 # arg3 = image_handle
|
||||||
lea rdx, [rip+SIMPLE_FS_PROTOCOL] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
lea rdx, [rip+SIMPLE_FS_PROTOCOL] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
||||||
|
@ -121,6 +121,7 @@ done:
|
||||||
mov rcx, r12 # arg1 = image_handle
|
mov rcx, r12 # arg1 = image_handle
|
||||||
call close_protocol # close protocol
|
call close_protocol # close protocol
|
||||||
|
|
||||||
|
mov rsp, rbp # restore stack pointer
|
||||||
ret # return to UEFI
|
ret # return to UEFI
|
||||||
|
|
||||||
# r8: input file name
|
# r8: input file name
|
||||||
|
|
|
@ -136,7 +136,7 @@ F0 00 # SizeOfOptionalHeader
|
||||||
|
|
||||||
# efi_main(void *image_handle, struct efi_system_table *system)
|
# efi_main(void *image_handle, struct efi_system_table *system)
|
||||||
:_start
|
:_start
|
||||||
|
4889E5 ; mov_rbp,rsp # save stack pointer
|
||||||
4989CC ; mov_r12,rcx # save image_handle
|
4989CC ; mov_r12,rcx # save image_handle
|
||||||
4C8B72 60 ; mov_r14,[rdx+BYTE] !96 # system->boot
|
4C8B72 60 ; mov_r14,[rdx+BYTE] !96 # system->boot
|
||||||
|
|
||||||
|
@ -156,21 +156,17 @@ F0 00 # SizeOfOptionalHeader
|
||||||
4889C1 ; mov_rcx,rax # get rootfs
|
4889C1 ; mov_rcx,rax # get rootfs
|
||||||
|
|
||||||
# Get root directory
|
# Get root directory
|
||||||
52 ; push_rdx # allocate stack for rootdir
|
488D15 %rootdir ; lea_rdx,[rip+DWORD] %rootdir # arg2 = &rootdir
|
||||||
4889E2 ; mov_rdx,rsp # arg2 = &rootdir
|
|
||||||
50 ; push_rax # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
50 ; push_rax # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
FF51 08 ; call_[rcx+BYTE] !8 # rootfs->open_volume(rootfs, &rootdir)
|
FF51 08 ; call_[rcx+BYTE] !8 # rootfs->open_volume(rootfs, &rootdir)
|
||||||
58 ; pop_rax # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; pop_rax # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; pop_rax # get rootdir
|
|
||||||
488905 %rootdir ; mov_[rip+DWORD],rax %rootdir # save rootdir
|
|
||||||
|
|
||||||
# Push command line arguments onto stack
|
# Push command line arguments onto stack
|
||||||
488B5F 38 ; mov_rbx,[rdi+BYTE] !56 # options = image->load_options
|
488B5F 38 ; mov_rbx,[rdi+BYTE] !56 # options = image->load_options
|
||||||
4889DA ; mov_rdx,rbx # save beginning of load_options
|
4889DA ; mov_rdx,rbx # save beginning of load_options
|
||||||
48035F 30 ; add_rbx,[rdi+BYTE] !48 # go to the end of load_options
|
48035F 30 ; add_rbx,[rdi+BYTE] !48 # go to the end of load_options
|
||||||
|
|
||||||
6A 00 ; push !0 # Save end of arguments (NULL) onto stack
|
6A 00 ; push !0 # Save end of arguments (NULL) onto stack
|
||||||
:loop_options
|
:loop_options
|
||||||
4839D3 ; cmp_rbx,rdx # Check if we are done
|
4839D3 ; cmp_rbx,rdx # Check if we are done
|
||||||
|
@ -185,6 +181,8 @@ F0 00 # SizeOfOptionalHeader
|
||||||
EB !loop_options ; jmp !loop_options # next argument
|
EB !loop_options ; jmp !loop_options # next argument
|
||||||
:loop_options_done
|
:loop_options_done
|
||||||
4158 ; pop_r8 # get output file
|
4158 ; pop_r8 # get output file
|
||||||
|
4D85C0 ; test_r8,r8 # if no output file
|
||||||
|
74 !exit_early ; je !exit_early # then exit
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
52 ; push_rdx # allocate stack for fout
|
52 ; push_rdx # allocate stack for fout
|
||||||
|
@ -233,12 +231,12 @@ F0 00 # SizeOfOptionalHeader
|
||||||
4C89F9 ; mov_rcx,r15 # Get output file
|
4C89F9 ; mov_rcx,r15 # Get output file
|
||||||
E8 %close_file ; call %close_file # close it
|
E8 %close_file ; call %close_file # close it
|
||||||
|
|
||||||
488B0D %rootdir ; mov_rcx,[rip+DWORD] %rootdir # Get rootdir
|
|
||||||
E8 %close_file ; call %close_file # close it
|
|
||||||
|
|
||||||
4889D9 ; mov_rcx,rbx # Get buffer
|
4889D9 ; mov_rcx,rbx # Get buffer
|
||||||
E8 %free_pool ; call %free_pool # release it
|
E8 %free_pool ; call %free_pool # release it
|
||||||
31C0 ; xor_eax,eax # Exit code 0
|
|
||||||
|
:exit_early
|
||||||
|
488B0D %rootdir ; mov_rcx,[rip+DWORD] %rootdir # Get rootdir
|
||||||
|
E8 %close_file ; call %close_file # close it
|
||||||
|
|
||||||
4D89E0 ; mov_r8,r12 # arg3 = image_handle
|
4D89E0 ; mov_r8,r12 # arg3 = image_handle
|
||||||
488D15 %SIMPLE_FS_PROTOCOL ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
488D15 %SIMPLE_FS_PROTOCOL ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
||||||
|
@ -250,6 +248,7 @@ F0 00 # SizeOfOptionalHeader
|
||||||
4C89E1 ; mov_rcx,r12 # arg1 = image_handle
|
4C89E1 ; mov_rcx,r12 # arg1 = image_handle
|
||||||
E8 %close_protocol ; call %close_protocol # close protocol
|
E8 %close_protocol ; call %close_protocol # close protocol
|
||||||
|
|
||||||
|
4889EC ; mov_rsp,rbp # restore stack
|
||||||
C3 ; ret # return to UEFI
|
C3 ; ret # return to UEFI
|
||||||
|
|
||||||
# r8: input file name
|
# r8: input file name
|
||||||
|
|
Loading…
Reference in New Issue