catm: Switch to M1 defines that are closer to intel syntax.
This commit is contained in:
parent
01fae8cd06
commit
3528be5b2b
|
@ -3,266 +3,265 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
DEFINE ADD_RBX_from_Address_RDI_Immediate8 48035F
|
DEFINE add_rbx,[rdi+BYTE] 48035F
|
||||||
DEFINE ADDI8_RBX 4883C3
|
DEFINE add_rbx, 4883C3
|
||||||
DEFINE ADDI8_RSP 4883C4
|
DEFINE add_rsp, 4883C4
|
||||||
DEFINE ADDI32_to_RDX 48C7C2
|
DEFINE call E8
|
||||||
DEFINE CALLI32 E8
|
DEFINE call_[rcx+BYTE] FF51
|
||||||
DEFINE CALL_RCX_Immediate8 FF51
|
DEFINE call_[r14+BYTE] 41FF56
|
||||||
DEFINE CALL_R14_Immediate8 41FF56
|
DEFINE call_[r14+QWORD] 41FF96
|
||||||
DEFINE CALL_R14_Immediate32 41FF96
|
DEFINE cmp_al, 3C
|
||||||
DEFINE CMPI8_AL 3C
|
DEFINE cmp_rax, 483D
|
||||||
DEFINE CMPI32_RAX 483D
|
DEFINE cmp_rbx,rdx 4839D3
|
||||||
DEFINE CMP_RBX_RDX 4839D3
|
DEFINE cmp_r8, 4983F8
|
||||||
DEFINE CMP_R8_Immediate8 4983F8
|
DEFINE je 74
|
||||||
DEFINE COPY_RAX_to_RBX 4889C3
|
DEFINE jmp EB
|
||||||
DEFINE COPY_RAX_to_RDX 4889C2
|
DEFINE jne 75
|
||||||
DEFINE COPY_RBX_to_RCX 4889D9
|
DEFINE mov_rdx, 48C7C2
|
||||||
DEFINE COPY_RBX_to_RDX 4889DA
|
DEFINE mov_rax,rdi 4889C7
|
||||||
DEFINE COPY_RBP_to_RSP 4889EC
|
DEFINE mov_rbx,rax 4889C3
|
||||||
DEFINE COPY_RBX_to_R8 4989D8
|
DEFINE mov_rcx,rbx 4889D9
|
||||||
DEFINE COPY_RCX_to_R15 4989CF
|
DEFINE mov_rcx,r13 4C89E9
|
||||||
DEFINE COPY_RDI_to_RAX 4889C7
|
DEFINE mov_rcx,r15 4C89F9
|
||||||
DEFINE COPY_RSI_to_R13 4989F5
|
DEFINE mov_rdx,rax 4889C2
|
||||||
DEFINE COPY_RSP_to_RBP 4889E5
|
DEFINE mov_rdx,rbx 4889DA
|
||||||
DEFINE COPY_RSP_to_RDX 4889E2
|
DEFINE mov_rdx,rsp 4889E2
|
||||||
DEFINE COPY_RSP_to_R8 4989E0
|
DEFINE mov_rbp,rsp 4889E5
|
||||||
DEFINE COPY_R13_to_RCX 4C89E9
|
DEFINE mov_rsp,rbp 4889EC
|
||||||
DEFINE COPY_R15_to_RCX 4C89F9
|
DEFINE mov_r8,rbx 4989D8
|
||||||
DEFINE COPY_R15_to_R9 4D89F9
|
DEFINE mov_r8,rsp 4989E0
|
||||||
DEFINE JE8 74
|
DEFINE mov_r9,r15 4D89F9
|
||||||
DEFINE JMP8 EB
|
DEFINE mov_r13,rsi 4989F5
|
||||||
DEFINE JNE8 75
|
DEFINE mov_r15,rcx 4989CF
|
||||||
DEFINE LOAD8_AL_from_Address_RBX 8A03
|
DEFINE mov_al,[rbx] 8A03
|
||||||
DEFINE LOAD64_into_RAX_from_Address_RSP_Immediate8 488B4424
|
DEFINE mov_rax,[rsp+BYTE] 488B4424
|
||||||
DEFINE LOAD64_into_RBX_from_Address_RDI_Immediate8 488B5F
|
DEFINE mov_rbx,[rdi+BYTE] 488B5F
|
||||||
DEFINE LOAD64_into_RCX_from_Address_RDI_Immediate8 488B4F
|
DEFINE mov_rcx,[rdi+BYTE] 488B4F
|
||||||
DEFINE LOAD64_into_RCX_from_Address_RSP_Immediate8 488B4C24
|
DEFINE mov_rcx,[rsp+BYTE] 488B4C24
|
||||||
DEFINE LOAD64_into_R14_from_Address_RDX_Immediate8 4C8B72
|
DEFINE mov_r14,[rdx+BYTE] 4C8B72
|
||||||
DEFINE LOAD64_rel_RCX 488B0D
|
DEFINE mov_rcx,[rip+QWORD] 488B0D
|
||||||
DEFINE LOAD64_rel_RDX 488B15
|
DEFINE mov_rdx,[rip+QWORD] 488B15
|
||||||
DEFINE POP_RAX 58
|
DEFINE mov_[rip+QWORD],rax 488905
|
||||||
DEFINE POP_RBX 5B
|
DEFINE mov_[rbx], C603
|
||||||
DEFINE POP_RCX 59
|
DEFINE pop_rax 58
|
||||||
DEFINE POP_RSI 5E
|
DEFINE pop_rcx 59
|
||||||
DEFINE POP_R8 4158
|
DEFINE pop_rsi 5E
|
||||||
DEFINE POP_R9 4159
|
DEFINE pop_r8 4158
|
||||||
DEFINE POP_R15 415F
|
DEFINE pop_r9 4159
|
||||||
DEFINE PUSH 6A
|
DEFINE pop_r15 415F
|
||||||
DEFINE PUSH_RAX 50
|
DEFINE push 6A
|
||||||
DEFINE PUSH_RBX 53
|
DEFINE push_rax 50
|
||||||
DEFINE PUSH_RDX 52
|
DEFINE push_rbx 53
|
||||||
DEFINE RET C3
|
DEFINE push_rdx 52
|
||||||
DEFINE ROR_R9 49D1C9
|
DEFINE ret C3
|
||||||
DEFINE STOREI8_into_Address_RBX C603
|
DEFINE ror_r9 49D1C9
|
||||||
DEFINE STORE64_rel_RAX 488905
|
DEFINE sub_rbx, 4883EB
|
||||||
DEFINE SUBI8_RBX 4883EB
|
DEFINE sub_rsp, 4883EC
|
||||||
DEFINE SUBI8_RSP 4883EC
|
DEFINE test_eax,eax 85C0
|
||||||
DEFINE TEST_EAX_EAX 85C0
|
DEFINE xor_eax,eax 31C0
|
||||||
DEFINE XOR_EAX_EAX 31C0
|
|
||||||
|
|
||||||
# efi_main(void *image_handle, struct efi_system_table *system)
|
# efi_main(void *image_handle, struct efi_system_table *system)
|
||||||
:_start
|
:_start
|
||||||
|
|
||||||
COPY_RSP_to_RBP # save stack pointer
|
mov_rbp,rsp # save stack pointer
|
||||||
COPY_RCX_to_R15 # save image_handle
|
mov_r15,rcx # save image_handle
|
||||||
LOAD64_into_R14_from_Address_RDX_Immediate8 !96 # system->boot
|
mov_r14,[rdx+BYTE] !96 # system->boot
|
||||||
|
|
||||||
# Open Loaded Image protocol
|
# Open Loaded Image protocol
|
||||||
PUSH_RAX # allocate stack for image
|
push_rax # allocate stack for image
|
||||||
COPY_RSP_to_R8 # arg3 = &image
|
mov_r8,rsp # arg3 = &image
|
||||||
LOAD64_rel_RDX %LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
mov_rdx,[rip+QWORD] %LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||||
PUSH_RDX # push last 64 bits onto stack
|
push_rdx # push last 64 bits onto stack
|
||||||
LOAD64_rel_RDX %LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
mov_rdx,[rip+QWORD] %LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||||
PUSH_RDX # push first 64 bits onto stack
|
push_rdx # push first 64 bits onto stack
|
||||||
COPY_RSP_to_RDX # arg2 = &guid
|
mov_rdx,rsp # arg2 = &guid
|
||||||
PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
PUSH !0 # arg5 = NULL
|
push !0 # arg5 = NULL
|
||||||
COPY_R15_to_R9 # arg4 = image_handle
|
mov_r9,r15 # arg4 = image_handle
|
||||||
COPY_R15_to_RCX # arg1 = image_handle
|
mov_rcx,r15 # arg1 = image_handle
|
||||||
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
CALL_R14_Immediate32 %280 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
call_[r14+QWORD] %280 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
LOAD64_into_RAX_from_Address_RSP_Immediate8 !64 # get_image
|
mov_rax,[rsp+BYTE] !64 # get_image
|
||||||
COPY_RDI_to_RAX # save image
|
mov_rax,rdi # save image
|
||||||
|
|
||||||
# Get root file system
|
# Get root file system
|
||||||
PUSH_RAX # allocate stack for rootfs
|
push_rax # allocate stack for rootfs
|
||||||
COPY_RSP_to_R8 # arg3 = &rootfs
|
mov_r8,rsp # arg3 = &rootfs
|
||||||
LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
mov_rdx,[rip+QWORD] %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||||
PUSH_RDX # push last 64 bits onto stack
|
push_rdx # push last 64 bits onto stack
|
||||||
LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
mov_rdx,[rip+QWORD] %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||||
PUSH_RDX # push first 64 bits onto stack
|
push_rdx # push first 64 bits onto stack
|
||||||
COPY_RSP_to_RDX # arg2 = &guid
|
mov_rdx,rsp # arg2 = &guid
|
||||||
PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
PUSH !0 # arg5 = NULL
|
push !0 # arg5 = NULL
|
||||||
COPY_R15_to_R9 # arg4 = image_handle
|
mov_r9,r15 # arg4 = image_handle
|
||||||
LOAD64_into_RCX_from_Address_RDI_Immediate8 !24 # arg1 = root_device = image->device
|
mov_rcx,[rdi+BYTE] !24 # arg1 = root_device = image->device
|
||||||
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
CALL_R14_Immediate32 %280 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
call_[r14+QWORD] %280 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
LOAD64_into_RCX_from_Address_RSP_Immediate8 !64 # get rootfs
|
mov_rcx,[rsp+BYTE] !64 # get rootfs
|
||||||
|
|
||||||
# Get root directory
|
# Get root directory
|
||||||
PUSH_RDX # allocate stack for rootdir
|
push_rdx # allocate stack for rootdir
|
||||||
COPY_RSP_to_RDX # 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_Immediate8 !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
|
pop_rax # get rootdir
|
||||||
STORE64_rel_RAX %rootdir # save rootdir
|
mov_[rip+QWORD],rax %rootdir # save rootdir
|
||||||
|
|
||||||
# Push command line arguments onto stack
|
# Push command line arguments onto stack
|
||||||
LOAD64_into_RBX_from_Address_RDI_Immediate8 !56 # options = image->load_options
|
mov_rbx,[rdi+BYTE] !56 # options = image->load_options
|
||||||
COPY_RBX_to_RDX # save beginning of load_options
|
mov_rdx,rbx # save beginning of load_options
|
||||||
ADD_RBX_from_Address_RDI_Immediate8 !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
|
||||||
JE8 !loop_options_done # We are done
|
je !loop_options_done # We are done
|
||||||
SUBI8_RBX !2 # --options
|
sub_rbx, !2 # --options
|
||||||
LOAD8_AL_from_Address_RBX # *options
|
mov_al,[rbx] # *options
|
||||||
CMPI8_AL !0x20 # if *options != ' '
|
cmp_al, !0x20 # if *options != ' '
|
||||||
JNE8 !loop_options # then continue looping
|
jne !loop_options # then continue looping
|
||||||
STOREI8_into_Address_RBX !0 # zero it
|
mov_[rbx], !0 # zero it
|
||||||
ADDI8_RBX !2 # ++options
|
add_rbx, !2 # ++options
|
||||||
PUSH_RBX # push another argument onto stack
|
push_rbx # push another argument onto stack
|
||||||
JMP8 !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
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
PUSH_RDX # allocate stack for fout
|
push_rdx # allocate stack for fout
|
||||||
COPY_RSP_to_RDX # arg2 = &fout
|
mov_rdx,rsp # arg2 = &fout
|
||||||
PUSH !0 # arg5 = 0
|
push !0 # arg5 = 0
|
||||||
PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
push !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||||
POP_R9 # and then do right rotation by 1
|
pop_r9 # and then do right rotation by 1
|
||||||
ROR_R9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
ror_r9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
||||||
LOAD64_rel_RCX %rootdir # arg1 = rootdir
|
mov_rcx,[rip+QWORD] %rootdir # arg1 = rootdir
|
||||||
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
CALL_RCX_Immediate8 !8 # rootdir->open()
|
call_[rcx+BYTE] !8 # rootdir->open()
|
||||||
ADDI8_RSP !40 # deallocate stack
|
add_rsp, !40 # deallocate stack
|
||||||
POP_R15 # get fout
|
pop_r15 # get fout
|
||||||
|
|
||||||
ADDI32_to_RDX %0x100000 # Allocate 1MB
|
mov_rdx, %0x100000 # Allocate 1MB
|
||||||
CALLI32 %allocate_pool # Get memory pool
|
call %allocate_pool # Get memory pool
|
||||||
COPY_RAX_to_RBX # Save it
|
mov_rbx,rax # Save it
|
||||||
|
|
||||||
:core
|
:core
|
||||||
POP_R8 # Get the actual input name
|
pop_r8 # Get the actual input name
|
||||||
CMP_R8_Immediate8 !0 # Check for null string
|
cmp_r8, !0 # Check for null string
|
||||||
JE8 !done # We are done if null string
|
je !done # We are done if null string
|
||||||
|
|
||||||
CALLI32 %open_file # Open file as read only
|
call %open_file # Open file as read only
|
||||||
TEST_EAX_EAX # check if successfully opened
|
test_eax,eax # check if successfully opened
|
||||||
JNE8 !core # Else go to another file
|
jne !core # Else go to another file
|
||||||
COPY_RSI_to_R13 # Protect fin
|
mov_r13,rsi # Protect fin
|
||||||
|
|
||||||
:keep
|
:keep
|
||||||
ADDI32_to_RDX %0x100000 # set the size of chars we want
|
mov_rdx, %0x100000 # set the size of chars we want
|
||||||
CALLI32 %read # read them
|
call %read # read them
|
||||||
PUSH_RAX # Protect the number of bytes read
|
push_rax # Protect the number of bytes read
|
||||||
|
|
||||||
COPY_RAX_to_RDX # number of bytes to write
|
mov_rdx,rax # number of bytes to write
|
||||||
CALLI32 %write # write them
|
call %write # write them
|
||||||
|
|
||||||
POP_RAX # Get bytes read
|
pop_rax # Get bytes read
|
||||||
CMPI32_RAX %0x100000 # Check if buffer was fully used
|
cmp_rax, %0x100000 # Check if buffer was fully used
|
||||||
JE8 !keep # Keep looping if it was full
|
je !keep # Keep looping if it was full
|
||||||
|
|
||||||
COPY_R13_to_RCX # fin
|
mov_rcx,r13 # fin
|
||||||
CALLI32 %close_file # close file
|
call %close_file # close file
|
||||||
JMP8 !core # Move to next file
|
jmp !core # Move to next file
|
||||||
|
|
||||||
:done
|
:done
|
||||||
COPY_R15_to_RCX # Get output file
|
mov_rcx,r15 # Get output file
|
||||||
CALLI32 %close_file # close it
|
call %close_file # close it
|
||||||
|
|
||||||
LOAD64_rel_RCX %rootdir # Get rootdir
|
mov_rcx,[rip+QWORD] %rootdir # Get rootdir
|
||||||
CALLI32 %rootdir # close it
|
call %rootdir # close it
|
||||||
|
|
||||||
COPY_RBX_to_RCX # Get buffer
|
mov_rcx,rbx # Get buffer
|
||||||
CALLI32 %free_pool # release it
|
call %free_pool # release it
|
||||||
XOR_EAX_EAX # Exit code 0
|
xor_eax,eax # Exit code 0
|
||||||
|
|
||||||
COPY_RBP_to_RSP # restore stack
|
mov_rsp,rbp # restore stack
|
||||||
RET # return to UEFI
|
ret # return to UEFI
|
||||||
|
|
||||||
# r8: input file name
|
# r8: input file name
|
||||||
# returns input file handle in rsi, status in rax
|
# returns input file handle in rsi, status in rax
|
||||||
:open_file
|
:open_file
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
PUSH_RDX # allocate stack for fin
|
push_rdx # allocate stack for fin
|
||||||
COPY_RSP_to_RDX # arg2 = &fin
|
mov_rdx,rsp # arg2 = &fin
|
||||||
PUSH !1 # arg5 = EFI_FILE_READ_ONLY
|
push !1 # arg5 = EFI_FILE_READ_ONLY
|
||||||
PUSH !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
push !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
||||||
POP_R9 # arg4 = EFI_FILE_MODE_READ
|
pop_r9 # arg4 = EFI_FILE_MODE_READ
|
||||||
LOAD64_rel_RCX %rootdir # arg1 = rootdir
|
mov_rcx,[rip+QWORD] %rootdir # arg1 = rootdir
|
||||||
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
CALL_RCX_Immediate8 !8 # rootdir->open()
|
call_[rcx+BYTE] !8 # rootdir->open()
|
||||||
ADDI8_RSP !40 # deallocate stack
|
add_rsp, !40 # deallocate stack
|
||||||
POP_RSI # get fin
|
pop_rsi # get fin
|
||||||
RET
|
ret
|
||||||
|
|
||||||
# rcx: file handle
|
# rcx: file handle
|
||||||
:close_file
|
:close_file
|
||||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
push_rax # allocate shadow stack space for UEFI function
|
||||||
CALL_RCX_Immediate8 !16 # file_handle->close(file_handle)
|
call_[rcx+BYTE] !16 # file_handle->close(file_handle)
|
||||||
POP_RAX # deallocate stack
|
pop_rax # deallocate stack
|
||||||
RET
|
ret
|
||||||
|
|
||||||
# rdx: number of bytes to allocate
|
# rdx: number of bytes to allocate
|
||||||
# r14: system->boot
|
# r14: system->boot
|
||||||
# returns pointer in rax
|
# returns pointer in rax
|
||||||
:allocate_pool
|
:allocate_pool
|
||||||
PUSH_RDX # allocate stack for pool pointer
|
push_rdx # allocate stack for pool pointer
|
||||||
COPY_RSP_to_R8 # arg3 = &pool
|
mov_r8,rsp # arg3 = &pool
|
||||||
PUSH !2
|
push !2
|
||||||
POP_RCX # arg1 = EFI_LOADER_DATA
|
pop_rcx # arg1 = EFI_LOADER_DATA
|
||||||
SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
CALL_R14_Immediate8 !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &pool)
|
call_[r14+BYTE] !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &pool)
|
||||||
ADDI8_RSP !24 # deallocate stack
|
add_rsp, !24 # deallocate stack
|
||||||
POP_RAX # get pool
|
pop_rax # get pool
|
||||||
RET
|
ret
|
||||||
|
|
||||||
# rcx: memory pool
|
# rcx: memory pool
|
||||||
# r14: system->boot
|
# r14: system->boot
|
||||||
:free_pool
|
:free_pool
|
||||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
push_rax # allocate shadow stack space for UEFI function
|
||||||
CALL_R14_Immediate8 !72 # system->boot->free_pool(pool)
|
call_[r14+BYTE] !72 # system->boot->free_pool(pool)
|
||||||
POP_RAX # deallocate stack
|
pop_rax # deallocate stack
|
||||||
RET
|
ret
|
||||||
|
|
||||||
# rdx: number of bytes to read
|
# rdx: number of bytes to read
|
||||||
# rbx: buffer
|
# rbx: buffer
|
||||||
# r13: input file handle
|
# r13: input file handle
|
||||||
# returns number of bytes read in rax
|
# returns number of bytes read in rax
|
||||||
:read
|
:read
|
||||||
COPY_R13_to_RCX # arg1 = fin
|
mov_rcx,r13 # arg1 = fin
|
||||||
PUSH_RDX # set size
|
push_rdx # set size
|
||||||
COPY_RSP_to_RDX # arg2 = &size
|
mov_rdx,rsp # arg2 = &size
|
||||||
COPY_RBX_to_R8 # arg3 = buffer
|
mov_r8,rbx # arg3 = buffer
|
||||||
SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
CALL_RCX_Immediate8 !32 # fin->read()
|
call_[rcx+BYTE] !32 # fin->read()
|
||||||
ADDI8_RSP !24 # deallocate stack
|
add_rsp, !24 # deallocate stack
|
||||||
POP_RAX # save size to rax
|
pop_rax # save size to rax
|
||||||
RET
|
ret
|
||||||
|
|
||||||
# rdx: number of bytes to write
|
# rdx: number of bytes to write
|
||||||
# rbx: buffer
|
# rbx: buffer
|
||||||
# r14: output file handle
|
# r14: output file handle
|
||||||
# returns number of bytes written in rax
|
# returns number of bytes written in rax
|
||||||
:write
|
:write
|
||||||
COPY_R15_to_RCX # arg1 = fout
|
mov_rcx,r15 # arg1 = fout
|
||||||
PUSH_RDX # set size
|
push_rdx # set size
|
||||||
COPY_RSP_to_RDX # arg2 = &size
|
mov_rdx,rsp # arg2 = &size
|
||||||
COPY_RBX_to_R8 # arg3 = buffer
|
mov_r8,rbx # arg3 = buffer
|
||||||
SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
CALL_RCX_Immediate8 !40 # fin->write()
|
call_[rcx+BYTE] !40 # fin->write()
|
||||||
ADDI8_RSP !24 # deallocate stack
|
add_rsp, !24 # deallocate stack
|
||||||
POP_RAX # save size to rax
|
pop_rax # save size to rax
|
||||||
RET
|
ret
|
||||||
|
|
||||||
|
|
||||||
# Protocol GUIDs
|
# Protocol GUIDs
|
||||||
|
|
286
amd64/catm.hex2
286
amd64/catm.hex2
|
@ -137,205 +137,205 @@ 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 ; COPY_RSP_to_RBP # save stack pointer
|
4889E5 ; mov_rbp,rsp # save stack pointer
|
||||||
4989CF ; COPY_RCX_to_R15 # save image_handle
|
4989CF ; mov_r15,rcx # save image_handle
|
||||||
4C8B72 60 ; LOAD64_into_R14_from_Address_RDX_Immediate8 !96 # system->boot
|
4C8B72 60 ; mov_r14,[rdx+BYTE] !96 # system->boot
|
||||||
|
|
||||||
# Open Loaded Image protocol
|
# Open Loaded Image protocol
|
||||||
50 ; PUSH_RAX # allocate stack for image
|
50 ; push_rax # allocate stack for image
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &image
|
4989E0 ; mov_r8,rsp # arg3 = &image
|
||||||
488B15 %LOADED_IMAGE_PROTOCOL_8 ; LOAD64_rel_RDX %LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
488B15 %LOADED_IMAGE_PROTOCOL_8 ; mov_rdx,[rip+QWORD] %LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
52 ; push_rdx # push last 64 bits onto stack
|
||||||
488B15 %LOADED_IMAGE_PROTOCOL ; LOAD64_rel_RDX %LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
488B15 %LOADED_IMAGE_PROTOCOL ; mov_rdx,[rip+QWORD] %LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
52 ; push_rdx # push first 64 bits onto stack
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
4889E2 ; mov_rdx,rsp # arg2 = &guid
|
||||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
6A 01 ; push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
6A 00 ; PUSH !0 # arg5 = NULL
|
6A 00 ; push !0 # arg5 = NULL
|
||||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
4D89F9 ; mov_r9,r15 # arg4 = image_handle
|
||||||
4C89F9 ; COPY_R15_to_RCX # arg1 = image_handle
|
4C89F9 ; mov_rcx,r15 # arg1 = image_handle
|
||||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
41FF96 18010000 ; CALL_R14_Immediate32 %280 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
41FF96 18010000 ; call_[r14+QWORD] %280 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
488B4424 40 ; LOAD64_into_RAX_from_Address_RSP_Immediate8 !64 # get_image
|
488B4424 40 ; mov_rax,[rsp+BYTE] !64 # get_image
|
||||||
4889C7 ; COPY_RDI_to_RAX # save image
|
4889C7 ; mov_rax,rdi # save image
|
||||||
|
|
||||||
# Get root file system
|
# Get root file system
|
||||||
50 ; PUSH_RAX # allocate stack for rootfs
|
50 ; push_rax # allocate stack for rootfs
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &rootfs
|
4989E0 ; mov_r8,rsp # arg3 = &rootfs
|
||||||
488B15 %SIMPLE_FS_PROTOCOL_8 ; LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
488B15 %SIMPLE_FS_PROTOCOL_8 ; mov_rdx,[rip+QWORD] %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
52 ; push_rdx # push last 64 bits onto stack
|
||||||
488B15 %SIMPLE_FS_PROTOCOL ; LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
488B15 %SIMPLE_FS_PROTOCOL ; mov_rdx,[rip+QWORD] %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
52 ; push_rdx # push first 64 bits onto stack
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
4889E2 ; mov_rdx,rsp # arg2 = &guid
|
||||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
6A 01 ; push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
6A 00 ; PUSH !0 # arg5 = NULL
|
6A 00 ; push !0 # arg5 = NULL
|
||||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
4D89F9 ; mov_r9,r15 # arg4 = image_handle
|
||||||
488B4F 18 ; LOAD64_into_RCX_from_Address_RDI_Immediate8 !24 # arg1 = root_device = image->device
|
488B4F 18 ; mov_rcx,[rdi+BYTE] !24 # arg1 = root_device = image->device
|
||||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
41FF96 18010000 ; CALL_R14_Immediate32 %280 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
41FF96 18010000 ; call_[r14+QWORD] %280 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
488B4C24 40 ; LOAD64_into_RCX_from_Address_RSP_Immediate8 !64 # get rootfs
|
488B4C24 40 ; mov_rcx,[rsp+BYTE] !64 # get rootfs
|
||||||
|
|
||||||
# Get root directory
|
# Get root directory
|
||||||
52 ; PUSH_RDX # allocate stack for rootdir
|
52 ; push_rdx # allocate stack for rootdir
|
||||||
4889E2 ; COPY_RSP_to_RDX # 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_Immediate8 !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
|
58 ; pop_rax # get rootdir
|
||||||
488905 %rootdir ; STORE64_rel_RAX %rootdir # save rootdir
|
488905 %rootdir ; mov_[rip+QWORD],rax %rootdir # save rootdir
|
||||||
|
|
||||||
# Push command line arguments onto stack
|
# Push command line arguments onto stack
|
||||||
488B5F 38 ; LOAD64_into_RBX_from_Address_RDI_Immediate8 !56 # options = image->load_options
|
488B5F 38 ; mov_rbx,[rdi+BYTE] !56 # options = image->load_options
|
||||||
4889DA ; COPY_RBX_to_RDX # save beginning of load_options
|
4889DA ; mov_rdx,rbx # save beginning of load_options
|
||||||
48035F 30 ; ADD_RBX_from_Address_RDI_Immediate8 !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
|
||||||
74 !loop_options_done ; JE8 !loop_options_done # We are done
|
74 !loop_options_done ; je !loop_options_done # We are done
|
||||||
4883EB 02 ; SUBI8_RBX !2 # --options
|
4883EB 02 ; sub_rbx, !2 # --options
|
||||||
8A03 ; LOAD8_AL_from_Address_RBX # *options
|
8A03 ; mov_al,[rbx] # *options
|
||||||
3C 20 ; CMPI8_AL !0x20 # if *options != ' '
|
3C 20 ; cmp_al, !0x20 # if *options != ' '
|
||||||
75 !loop_options ; JNE8 !loop_options # then continue looping
|
75 !loop_options ; jne !loop_options # then continue looping
|
||||||
C603 00 ; STOREI8_into_Address_RBX !0 # zero it
|
C603 00 ; mov_[rbx], !0 # zero it
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
4883C3 02 ; add_rbx, !2 # ++options
|
||||||
53 ; PUSH_RBX # push another argument onto stack
|
53 ; push_rbx # push another argument onto stack
|
||||||
EB !loop_options ; JMP8 !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
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
52 ; PUSH_RDX # allocate stack for fout
|
52 ; push_rdx # allocate stack for fout
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fout
|
4889E2 ; mov_rdx,rsp # arg2 = &fout
|
||||||
6A 00 ; PUSH !0 # arg5 = 0
|
6A 00 ; push !0 # arg5 = 0
|
||||||
6A 07 ; PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
6A 07 ; push !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||||
4159 ; POP_R9 # and then do right rotation by 1
|
4159 ; pop_r9 # and then do right rotation by 1
|
||||||
49D1C9 ; ROR_R9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
49D1C9 ; ror_r9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
||||||
488B0D %rootdir ; LOAD64_rel_RCX %rootdir # arg1 = rootdir
|
488B0D %rootdir ; mov_rcx,[rip+QWORD] %rootdir # arg1 = rootdir
|
||||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
FF51 08 ; CALL_RCX_Immediate8 !8 # rootdir->open()
|
FF51 08 ; call_[rcx+BYTE] !8 # rootdir->open()
|
||||||
4883C4 28 ; ADDI8_RSP !40 # deallocate stack
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
415F ; POP_R15 # get fout
|
415F ; pop_r15 # get fout
|
||||||
|
|
||||||
48C7C2 00001000 ; ADDI32_to_RDX %0x100000 # Allocate 1MB
|
48C7C2 00001000 ; mov_rdx, %0x100000 # Allocate 1MB
|
||||||
E8 %allocate_pool ; CALLI32 %allocate_pool # Get memory pool
|
E8 %allocate_pool ; call %allocate_pool # Get memory pool
|
||||||
4889C3 ; COPY_RAX_to_RBX # Save it
|
4889C3 ; mov_rbx,rax # Save it
|
||||||
|
|
||||||
:core
|
:core
|
||||||
4158 ; POP_R8 # Get the actual input name
|
4158 ; pop_r8 # Get the actual input name
|
||||||
4983F8 00 ; CMP_R8_Immediate8 !0 # Check for null string
|
4983F8 00 ; cmp_r8, !0 # Check for null string
|
||||||
74 !done ; JE8 !done # We are done if null string
|
74 !done ; je !done # We are done if null string
|
||||||
|
|
||||||
E8 %open_file ; CALLI32 %open_file # Open file as read only
|
E8 %open_file ; call %open_file # Open file as read only
|
||||||
85C0 ; TEST_EAX_EAX # check if successfully opened
|
85C0 ; test_eax,eax # check if successfully opened
|
||||||
75 !core ; JNE8 !core # Else go to another file
|
75 !core ; jne !core # Else go to another file
|
||||||
4989F5 ; COPY_RSI_to_R13 # Protect fin
|
4989F5 ; mov_r13,rsi # Protect fin
|
||||||
|
|
||||||
:keep
|
:keep
|
||||||
48C7C2 00001000 ; ADDI32_to_RDX %0x100000 # set the size of chars we want
|
48C7C2 00001000 ; mov_rdx, %0x100000 # set the size of chars we want
|
||||||
E8 %read ; CALLI32 %read # read them
|
E8 %read ; call %read # read them
|
||||||
50 ; PUSH_RAX # Protect the number of bytes read
|
50 ; push_rax # Protect the number of bytes read
|
||||||
|
|
||||||
4889C2 ; COPY_RAX_to_RDX # number of bytes to write
|
4889C2 ; mov_rdx,rax # number of bytes to write
|
||||||
E8 %write ; CALLI32 %write # write them
|
E8 %write ; call %write # write them
|
||||||
|
|
||||||
58 ; POP_RAX # Get bytes read
|
58 ; pop_rax # Get bytes read
|
||||||
483D 00001000 ; CMPI32_RAX %0x100000 # Check if buffer was fully used
|
483D 00001000 ; cmp_rax, %0x100000 # Check if buffer was fully used
|
||||||
74 !keep ; JE8 !keep # Keep looping if it was full
|
74 !keep ; je !keep # Keep looping if it was full
|
||||||
|
|
||||||
4C89E9 ; COPY_R13_to_RCX # fin
|
4C89E9 ; mov_rcx,r13 # fin
|
||||||
E8 %close_file ; CALLI32 %close_file # close file
|
E8 %close_file ; call %close_file # close file
|
||||||
EB !core ; JMP8 !core # Move to next file
|
EB !core ; jmp !core # Move to next file
|
||||||
|
|
||||||
:done
|
:done
|
||||||
4C89F9 ; COPY_R15_to_RCX # Get output file
|
4C89F9 ; mov_rcx,r15 # Get output file
|
||||||
E8 %close_file ; CALLI32 %close_file # close it
|
E8 %close_file ; call %close_file # close it
|
||||||
|
|
||||||
488B0D %rootdir ; LOAD64_rel_RCX %rootdir # Get rootdir
|
488B0D %rootdir ; mov_rcx,[rip+QWORD] %rootdir # Get rootdir
|
||||||
E8 %close_file ; CALLI32 %rootdir # close it
|
E8 %close_file ; call %rootdir # close it
|
||||||
|
|
||||||
4889D9 ; COPY_RBX_to_RCX # Get buffer
|
4889D9 ; mov_rcx,rbx # Get buffer
|
||||||
E8 %free_pool ; CALLI32 %free_pool # release it
|
E8 %free_pool ; call %free_pool # release it
|
||||||
31C0 ; XOR_EAX_EAX # Exit code 0
|
31C0 ; xor_eax,eax # Exit code 0
|
||||||
|
|
||||||
4889EC ; COPY_RBP_to_RSP # restore stack
|
4889EC ; mov_rsp,rbp # restore stack
|
||||||
C3 ; RET # return to UEFI
|
C3 ; ret # return to UEFI
|
||||||
|
|
||||||
# r8: input file name
|
# r8: input file name
|
||||||
# returns input file handle in rsi, status in rax
|
# returns input file handle in rsi, status in rax
|
||||||
:open_file
|
:open_file
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
52 ; PUSH_RDX # allocate stack for fin
|
52 ; push_rdx # allocate stack for fin
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fin
|
4889E2 ; mov_rdx,rsp # arg2 = &fin
|
||||||
6A 01 ; PUSH !1 # arg5 = EFI_FILE_READ_ONLY
|
6A 01 ; push !1 # arg5 = EFI_FILE_READ_ONLY
|
||||||
6A 01 ; PUSH !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
6A 01 ; push !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
||||||
4159 ; POP_R9 # arg4 = EFI_FILE_MODE_READ
|
4159 ; pop_r9 # arg4 = EFI_FILE_MODE_READ
|
||||||
488B0D %rootdir ; LOAD64_rel_RCX %rootdir # arg1 = rootdir
|
488B0D %rootdir ; mov_rcx,[rip+QWORD] %rootdir # arg1 = rootdir
|
||||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
FF51 08 ; CALL_RCX_Immediate8 !8 # rootdir->open()
|
FF51 08 ; call_[rcx+BYTE] !8 # rootdir->open()
|
||||||
4883C4 28 ; ADDI8_RSP !40 # deallocate stack
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
5E ; POP_RSI # get fin
|
5E ; pop_rsi # get fin
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# rcx: file handle
|
# rcx: file handle
|
||||||
:close_file
|
:close_file
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
FF51 10 ; CALL_RCX_Immediate8 !16 # file_handle->close(file_handle)
|
FF51 10 ; call_[rcx+BYTE] !16 # file_handle->close(file_handle)
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# rdx: number of bytes to allocate
|
# rdx: number of bytes to allocate
|
||||||
# r14: system->boot
|
# r14: system->boot
|
||||||
# returns pointer in rax
|
# returns pointer in rax
|
||||||
:allocate_pool
|
:allocate_pool
|
||||||
52 ; PUSH_RDX # allocate stack for pool pointer
|
52 ; push_rdx # allocate stack for pool pointer
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &pool
|
4989E0 ; mov_r8,rsp # arg3 = &pool
|
||||||
6A 02 ; PUSH !2
|
6A 02 ; push !2
|
||||||
59 ; POP_RCX # arg1 = EFI_LOADER_DATA
|
59 ; pop_rcx # arg1 = EFI_LOADER_DATA
|
||||||
4883EC 18 ; SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
4883EC 18 ; sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
41FF56 40 ; CALL_R14_Immediate8 !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &pool)
|
41FF56 40 ; call_[r14+BYTE] !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &pool)
|
||||||
4883C4 18 ; ADDI8_RSP !24 # deallocate stack
|
4883C4 18 ; add_rsp, !24 # deallocate stack
|
||||||
58 ; POP_RAX # get pool
|
58 ; pop_rax # get pool
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# rcx: memory pool
|
# rcx: memory pool
|
||||||
# r14: system->boot
|
# r14: system->boot
|
||||||
:free_pool
|
:free_pool
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
41FF56 48 ; CALL_R14_Immediate8 !72 # system->boot->free_pool(pool)
|
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(pool)
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# rdx: number of bytes to read
|
# rdx: number of bytes to read
|
||||||
# rbx: buffer
|
# rbx: buffer
|
||||||
# r13: input file handle
|
# r13: input file handle
|
||||||
# returns number of bytes read in rax
|
# returns number of bytes read in rax
|
||||||
:read
|
:read
|
||||||
4C89E9 ; COPY_R13_to_RCX # arg1 = fin
|
4C89E9 ; mov_rcx,r13 # arg1 = fin
|
||||||
52 ; PUSH_RDX # set size
|
52 ; push_rdx # set size
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
4889E2 ; mov_rdx,rsp # arg2 = &size
|
||||||
4989D8 ; COPY_RBX_to_R8 # arg3 = buffer
|
4989D8 ; mov_r8,rbx # arg3 = buffer
|
||||||
4883EC 18 ; SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
4883EC 18 ; sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
FF51 20 ; CALL_RCX_Immediate8 !32 # fin->read()
|
FF51 20 ; call_[rcx+BYTE] !32 # fin->read()
|
||||||
4883C4 18 ; ADDI8_RSP !24 # deallocate stack
|
4883C4 18 ; add_rsp, !24 # deallocate stack
|
||||||
58 ; POP_RAX # save size to rax
|
58 ; pop_rax # save size to rax
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# rdx: number of bytes to write
|
# rdx: number of bytes to write
|
||||||
# rbx: buffer
|
# rbx: buffer
|
||||||
# r14: output file handle
|
# r14: output file handle
|
||||||
# returns number of bytes written in rax
|
# returns number of bytes written in rax
|
||||||
:write
|
:write
|
||||||
4C89F9 ; COPY_R15_to_RCX # arg1 = fout
|
4C89F9 ; mov_rcx,r15 # arg1 = fout
|
||||||
52 ; PUSH_RDX # set size
|
52 ; push_rdx # set size
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
4889E2 ; mov_rdx,rsp # arg2 = &size
|
||||||
4989D8 ; COPY_RBX_to_R8 # arg3 = buffer
|
4989D8 ; mov_r8,rbx # arg3 = buffer
|
||||||
4883EC 18 ; SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
4883EC 18 ; sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
FF51 28 ; CALL_RCX_Immediate8 !40 # fin->write()
|
FF51 28 ; call_[rcx+BYTE] !40 # fin->write()
|
||||||
4883C4 18 ; ADDI8_RSP !24 # deallocate stack
|
4883C4 18 ; add_rsp, !24 # deallocate stack
|
||||||
58 ; POP_RAX # save size to rax
|
58 ; pop_rax # save size to rax
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
|
|
||||||
# Protocol GUIDs
|
# Protocol GUIDs
|
||||||
|
|
Loading…
Reference in New Issue