hex1: Implement various improvements:
* Make sure to close all protocols before exit. * Use more sophisticated command line argument processing that pushes command line arguments onto stack. * Switch to more readable M1 defines.
This commit is contained in:
parent
7020101bd7
commit
9b9ff9ac52
|
@ -3,474 +3,487 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
DEFINE ADDI32_to_R13 4981C5
|
DEFINE add_rbx, 4883C3
|
||||||
DEFINE ADDI8_RBX 4883C3
|
DEFINE add_rsp, 4883C4
|
||||||
DEFINE ADD_RCX_to_RAX 4801C8
|
DEFINE add_r13, 4981C5
|
||||||
DEFINE ADD_R14_to_RAX 4C01F0
|
DEFINE add_rax,rcx 4801C8
|
||||||
DEFINE ADDI8_RSP 4883C4
|
DEFINE add_rax,r14 4C01F0
|
||||||
DEFINE CALLI32 E8
|
DEFINE add_rbx,[rdi+BYTE] 48035F
|
||||||
DEFINE CALL_RCX_Immediate8 FF51
|
DEFINE call E8
|
||||||
DEFINE CALL_R14_Immediate8 41FF56
|
DEFINE call_[rcx+BYTE] FF51
|
||||||
DEFINE CALL_R14_Immediate32 41FF96
|
DEFINE call_[r14+BYTE] 41FF56
|
||||||
DEFINE CMPI8_AL 3C
|
DEFINE call_[r14+DWORD] 41FF96
|
||||||
DEFINE CMPI32_RAX 483D
|
DEFINE cmp_al, 3C
|
||||||
DEFINE CMPI32_R15 4981FF
|
DEFINE cmp_rax, 483D
|
||||||
DEFINE COPY_RAX_to_R14 4989C6
|
DEFINE cmp_r15, 4981FF
|
||||||
DEFINE COPY_RBX_to_R12 4989DC
|
DEFINE cmp_rbx,rdx 4839D3
|
||||||
DEFINE COPY_RBX_to_R13 4989DD
|
DEFINE je 0F84
|
||||||
DEFINE COPY_RCX_to_RAX 4889C1
|
DEFINE je8 74
|
||||||
DEFINE COPY_RCX_to_R15 4989CF
|
DEFINE jl 0F8C
|
||||||
DEFINE COPY_RSP_to_RBP 4889E5
|
DEFINE jmp E9
|
||||||
DEFINE COPY_RSP_to_RDX 4889E2
|
DEFINE jmp8 EB
|
||||||
DEFINE COPY_RSP_to_R8 4989E0
|
DEFINE jne 0F85
|
||||||
DEFINE COPY_RBP_to_RSP 4889EC
|
DEFINE jne8 75
|
||||||
DEFINE COPY_RDI_to_RCX 4889F9
|
DEFINE lea_rdx,[rip+DWORD] 488D15
|
||||||
DEFINE COPY_R12_to_R8 4D89E0
|
DEFINE mov_dh, B6
|
||||||
DEFINE COPY_RBX_to_RCX 4889D9
|
DEFINE mov_rax, 48C7C0
|
||||||
DEFINE COPY_R13_to_R8 4D89E8
|
DEFINE mov_rdx, 48C7C2
|
||||||
DEFINE COPY_R14_to_RCX 4C89F1
|
DEFINE mov_r13, 49C7C5
|
||||||
DEFINE COPY_R15_to_RCX 4C89F9
|
DEFINE mov_r14, 49C7C6
|
||||||
DEFINE COPY_R15_to_R9 4D89F9
|
DEFINE mov_r15, 49C7C7
|
||||||
DEFINE JE32 0F84
|
DEFINE mov_rbp,rsp 4889E5
|
||||||
DEFINE JL32 0F8C
|
DEFINE mov_rcx,rbx 4889D9
|
||||||
DEFINE JMP32 E9
|
DEFINE mov_rcx,rdi 4889F9
|
||||||
DEFINE JNE8 75
|
DEFINE mov_rcx,rsi 4889F1
|
||||||
DEFINE JNE32 0F85
|
DEFINE mov_rcx,r8 4C89C1
|
||||||
DEFINE LOAD32_Address_in_RAX_into_RAX 678B00
|
DEFINE mov_rcx,r9 4C89C9
|
||||||
DEFINE LOAD64_into_RBX_from_Address_RAX_Immediate8 488B58
|
DEFINE mov_rcx,r13 4C89E9
|
||||||
DEFINE LOAD64_into_RAX_from_Address_RSP_Immediate8 488B4424
|
DEFINE mov_rdx,rbx 4889DA
|
||||||
DEFINE LOAD64_into_RCX_from_Address_RSP_Immediate8 488B4C24
|
DEFINE mov_rdx,rsp 4889E2
|
||||||
DEFINE LOAD64_into_RCX_from_Address_RCX_Immediate8 488B49
|
DEFINE mov_rsp,rbp 4889EC
|
||||||
DEFINE LOAD64_into_RDI_from_Address_RSP_Immediate8 488B7C24
|
DEFINE mov_r8,rsp 4989E0
|
||||||
DEFINE LOAD64_into_RBX_from_Address_RSP_Immediate8 488B5C24
|
DEFINE mov_r8,r15 4D89F8
|
||||||
DEFINE LOAD64_into_R14_from_Address_RDX_Immediate8 4C8B72
|
DEFINE mov_r9,r15 4D89F9
|
||||||
DEFINE LOAD64_into_R14_from_Address_R14_Immediate32 4D8BB6
|
DEFINE mov_r13,rcx 4989CD
|
||||||
DEFINE LOAD8_AL_from_Address_RBX 8A03
|
DEFINE mov_r14,rax 4989C6
|
||||||
DEFINE LOADI8_DH B6
|
DEFINE mov_r15,rcx 4989CF
|
||||||
DEFINE LOADI32_RAX 48C7C0
|
DEFINE mov_al,[rbx] 8A03
|
||||||
DEFINE LOADI32_RDX 48C7C2
|
DEFINE mov_rax,[rax] 488B00
|
||||||
DEFINE LOADI32_R13 49C7C5
|
DEFINE mov_[rbx], C603
|
||||||
DEFINE LOADI32_R14 49C7C6
|
DEFINE mov_rbx,[rdi+BYTE] 488B5F
|
||||||
DEFINE LOADI32_R15 49C7C7
|
DEFINE mov_rcx,[rdi+BYTE] 488B4F
|
||||||
DEFINE LOAD64_rel_RCX 488B0D
|
DEFINE mov_rcx,[rsp+BYTE] 488B4C24
|
||||||
DEFINE LOAD64_rel_RDX 488B15
|
DEFINE mov_rdi,[rsp+BYTE] 488B7C24
|
||||||
DEFINE LOAD64_rel_R14 4C8B35
|
DEFINE mov_r14,[rdx+BYTE] 4C8B72
|
||||||
DEFINE NOT_R15 49F7D7
|
DEFINE mov_[rax],r13 4C8928
|
||||||
DEFINE POP_RAX 58
|
DEFINE not_r15 49F7D7
|
||||||
DEFINE POP_RCX 59
|
DEFINE pop_rax 58
|
||||||
DEFINE POP_RSI 5E
|
DEFINE pop_rbx 5B
|
||||||
DEFINE POP_R9 4159
|
DEFINE pop_rcx 59
|
||||||
DEFINE POP_R14 415E
|
DEFINE pop_rdi 5F
|
||||||
DEFINE PUSH 6A
|
DEFINE pop_rsi 5E
|
||||||
DEFINE PUSH_RAX 50
|
DEFINE pop_r8 4158
|
||||||
DEFINE PUSH_RBX 53
|
DEFINE pop_r9 4159
|
||||||
DEFINE PUSH_RDX 52
|
DEFINE pop_r13 415D
|
||||||
DEFINE PUSH_RSI 56
|
DEFINE pop_r14 415E
|
||||||
DEFINE RET C3
|
DEFINE pop_r15 415F
|
||||||
DEFINE ROR_R9 49D1C9
|
DEFINE push 6A
|
||||||
DEFINE SHL8_R14 49C1E6
|
DEFINE push_rax 50
|
||||||
DEFINE SHL8_RAX 48C1E0
|
DEFINE push_rbx 53
|
||||||
DEFINE STORE32_R13_to_Address_in_RAX 4C8928
|
DEFINE push_rdx 52
|
||||||
DEFINE STORE64_rel_R14 4C8935
|
DEFINE push_rsi 56
|
||||||
DEFINE STORE64_rel_RAX 488905
|
DEFINE push_r13 4155
|
||||||
DEFINE STOREI8_into_Address_RBX C603
|
DEFINE push_r14 4156
|
||||||
DEFINE SUBI8_RSP 4883EC
|
DEFINE push_r15 4157
|
||||||
DEFINE SUBI8_from_RAX 4883E8
|
DEFINE ret C3
|
||||||
DEFINE SUB_R13_from_RAX 4C29E8
|
DEFINE ror_r9 49D1C9
|
||||||
DEFINE XOR_EDX_EDX 31D2
|
DEFINE shl_rax, 48C1E0
|
||||||
DEFINE TEST_ESI_ESI 85F6
|
DEFINE shl_r14, 49C1E6
|
||||||
|
DEFINE sub_rax, 4883E8
|
||||||
|
DEFINE sub_rbx, 4883EB
|
||||||
|
DEFINE sub_rsp, 4883EC
|
||||||
|
DEFINE sub_rax,r13 4C29E8
|
||||||
|
DEFINE test_esi,esi 85F6
|
||||||
|
DEFINE xor_edx,edx 31D2
|
||||||
|
DEFINE xor_esi,esi 31F6
|
||||||
|
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
|
||||||
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
|
||||||
STORE64_rel_R14 %SystemBoot # save system->boot
|
|
||||||
|
|
||||||
# Allocate pool for single-character label table
|
|
||||||
PUSH_RDX # allocate stack for table
|
|
||||||
COPY_RSP_to_R8 # arg3 = &table
|
|
||||||
XOR_EDX_EDX # zero rdx
|
|
||||||
LOADI8_DH !0x8 # arg2 = 256 * 8 = 2048 = 0x800
|
|
||||||
PUSH !2
|
|
||||||
POP_RCX # arg1 = EFI_LOADER_DATA
|
|
||||||
SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
|
||||||
CALL_R14_Immediate8 !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
|
||||||
ADDI8_RSP !24 # deallocate stack
|
|
||||||
POP_RAX # get table
|
|
||||||
STORE64_rel_RAX %table # save table
|
|
||||||
|
|
||||||
# Open Loaded Image protocol
|
# Open Loaded Image protocol
|
||||||
PUSH_RAX # allocate stack for image
|
mov_r9,r15 # arg4 = image_handle
|
||||||
COPY_RSP_to_R8 # arg3 = &image
|
lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
LOAD64_rel_RDX %LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
mov_rcx,r9 # arg1 = image_handle
|
||||||
PUSH_RDX # push last 64 bits onto stack
|
push_rax # allocate stack for image
|
||||||
LOAD64_rel_RDX %LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
mov_r8,rsp # arg3 = &image
|
||||||
PUSH_RDX # push first 64 bits onto stack
|
push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
COPY_RSP_to_RDX # arg2 = &guid
|
push !0 # arg5 = NULL
|
||||||
PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
PUSH !0 # arg5 = NULL
|
call_[r14+DWORD] %280 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
COPY_R15_to_R9 # arg4 = image_handle
|
mov_rdi,[rsp+BYTE] !48 # save image
|
||||||
COPY_R15_to_RCX # arg1 = image_handle
|
|
||||||
SUBI8_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)
|
|
||||||
LOAD64_into_RAX_from_Address_RSP_Immediate8 !64 # get_image
|
|
||||||
COPY_RCX_to_RAX # save image
|
|
||||||
|
|
||||||
# Command line args
|
|
||||||
LOAD64_into_RBX_from_Address_RAX_Immediate8 !56 # options = image->load_options
|
|
||||||
|
|
||||||
:loop_options1 # Skip application name
|
|
||||||
ADDI8_RBX !2 # ++options
|
|
||||||
LOAD8_AL_from_Address_RBX # *options
|
|
||||||
CMPI8_AL !0x20 # if *options != ' '
|
|
||||||
JNE8 !loop_options1 # then jump
|
|
||||||
|
|
||||||
ADDI8_RBX !2 # ++options
|
|
||||||
COPY_RBX_to_R12 # save input file
|
|
||||||
|
|
||||||
:loop_options2 # Skip argv[1]
|
|
||||||
ADDI8_RBX !2 # ++options
|
|
||||||
LOAD8_AL_from_Address_RBX # *options
|
|
||||||
CMPI8_AL !0x20 # if *options != ' '
|
|
||||||
JNE8 !loop_options2 # then jump
|
|
||||||
|
|
||||||
STOREI8_into_Address_RBX !0 # *options = 0;
|
|
||||||
ADDI8_RBX !2 # ++options
|
|
||||||
COPY_RBX_to_R13 # save output file
|
|
||||||
|
|
||||||
# Get root file system
|
# Get root file system
|
||||||
PUSH_RAX # allocate stack for rootfs
|
mov_r9,r15 # arg4 = image_handle
|
||||||
COPY_RSP_to_R8 # arg3 = &rootfs
|
lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
|
||||||
LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
mov_rcx,[rdi+BYTE] !24 # arg1 = root_device = image->device
|
||||||
PUSH_RDX # push last 64 bits onto stack
|
mov_r13,rcx # save root_device
|
||||||
LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
push_rax # allocate stack for rootfs
|
||||||
PUSH_RDX # push first 64 bits onto stack
|
mov_r8,rsp # arg3 = &rootfs
|
||||||
COPY_RSP_to_RDX # 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
|
sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
COPY_R15_to_R9 # arg4 = image_handle
|
call_[r14+DWORD] %280 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
LOAD64_into_RCX_from_Address_RCX_Immediate8 !24 # arg1 = root_device = image->device
|
mov_rcx,[rsp+BYTE] !48 # get rootfs
|
||||||
SUBI8_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)
|
|
||||||
LOAD64_into_RCX_from_Address_RSP_Immediate8 !64 # get rootfs
|
|
||||||
|
|
||||||
# Get root directory
|
# Get root directory
|
||||||
PUSH_RDX # allocate stack for rootdir
|
push_rax # 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_R14 # save rootdir
|
pop_rsi # get rootdir
|
||||||
|
|
||||||
|
# Push command line arguments onto stack
|
||||||
|
mov_rbx,[rdi+BYTE] !56 # options = image->load_options
|
||||||
|
mov_rdx,rbx # save beginning of load_options
|
||||||
|
add_rbx,[rdi+BYTE] !48 # go to the end of load_options
|
||||||
|
push !0 # Save end of arguments (NULL) onto stack
|
||||||
|
:loop_options
|
||||||
|
cmp_rbx,rdx # Check if we are done
|
||||||
|
je8 !loop_options_done # We are done
|
||||||
|
sub_rbx, !2 # --options
|
||||||
|
mov_al,[rbx] # *options
|
||||||
|
cmp_al, !0x20 # if *options != ' '
|
||||||
|
jne8 !loop_options # then continue looping
|
||||||
|
mov_[rbx], !0 # zero it
|
||||||
|
add_rbx, !2 # ++options
|
||||||
|
push_rbx # push another argument onto stack
|
||||||
|
jmp8 !loop_options # next argument
|
||||||
|
:loop_options_done
|
||||||
|
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
PUSH_RDX # allocate stack for fin
|
pop_r8 # arg3 = in
|
||||||
COPY_RSP_to_RDX # arg2 = &fin
|
push_rdx # allocate stack for fin
|
||||||
PUSH !1 # arg5 = EFI_FILE_READ_ONLY
|
mov_rdx,rsp # arg2 = &fin
|
||||||
PUSH !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
push !1 # arg5 = EFI_FILE_READ_ONLY
|
||||||
POP_R9 # arg4 = EFI_FILE_MODE_READ
|
push !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
||||||
COPY_R12_to_R8 # arg3 = in
|
pop_r9 # arg4 = EFI_FILE_MODE_READ
|
||||||
COPY_R14_to_RCX # arg1 = rootdir
|
mov_rcx,rsi # 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()
|
||||||
LOAD64_into_RDI_from_Address_RSP_Immediate8 !40 # get fin
|
add_rsp, !40 # deallocate stack
|
||||||
|
pop_rdi # get fin
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
PUSH_RDX # allocate stack for fout
|
pop_r8 # arg3 = out
|
||||||
COPY_RSP_to_RDX # arg2 = &fout
|
push_rdx # allocate stack for fout
|
||||||
PUSH !0 # arg5 = 0
|
mov_rdx,rsp # arg2 = &fout
|
||||||
PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
push !0 # arg5 = 0
|
||||||
POP_R9 # and then do right rotation by 1
|
push !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||||
ROR_R9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
pop_r9 # and then do right rotation by 1
|
||||||
COPY_R13_to_R8 # arg3 = out
|
ror_r9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
||||||
COPY_R14_to_RCX # arg1 = rootdir
|
mov_rcx,rsi # 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()
|
||||||
LOAD64_into_RBX_from_Address_RSP_Immediate8 !40 # get fout
|
add_rsp, !40 # deallocate stack
|
||||||
|
pop_rbx # get fout
|
||||||
|
|
||||||
LOADI32_R15 %-1 # Our flag for byte processing
|
# Save variables that are needed for cleanup
|
||||||
LOADI32_R14 %0 # temp storage for the sum
|
push_r13 # save root_device
|
||||||
LOADI32_R13 %0 # Our starting IP
|
push_r14 # save system->boot
|
||||||
CALLI32 %First_pass # Process it
|
push_r15 # save image_handle
|
||||||
|
push_rsi # save rootdir
|
||||||
|
|
||||||
|
# Allocate pool for single-character label table
|
||||||
|
# pointer to table will be stored at the top of the stack
|
||||||
|
push_rdx # allocate stack for table
|
||||||
|
mov_r8,rsp # arg3 = &table
|
||||||
|
xor_edx,edx # zero rdx
|
||||||
|
mov_dh, !0x8 # arg2 = 256 * 8 = 2048 = 0x800
|
||||||
|
push !2
|
||||||
|
pop_rcx # arg1 = EFI_LOADER_DATA
|
||||||
|
sub_rsp, !24 # allocate shadow stack space for UEFI function
|
||||||
|
call_[r14+BYTE] !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
||||||
|
add_rsp, !24 # deallocate stack
|
||||||
|
|
||||||
|
mov_r15, %-1 # Our flag for byte processing
|
||||||
|
mov_r14, %0 # temp storage for the sum
|
||||||
|
mov_r13, %0 # Our starting IP
|
||||||
|
call %First_pass # Process it
|
||||||
|
|
||||||
# rewind input file
|
# rewind input file
|
||||||
COPY_RDI_to_RCX # Using our input file
|
mov_rcx,rdi # Using our input file
|
||||||
XOR_EDX_EDX # Offset Zero
|
xor_edx,edx # Offset Zero
|
||||||
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 !56 # fin->set_position(fin, 0)
|
call_[rcx+BYTE] !56 # fin->set_position(fin, 0)
|
||||||
POP_RAX # deallocate stack
|
pop_rax # deallocate stack
|
||||||
POP_RAX # deallocate stack
|
pop_rax # deallocate stack
|
||||||
|
|
||||||
LOADI32_R15 %-1 # Our flag for byte processing
|
mov_r15, %-1 # Our flag for byte processing
|
||||||
LOADI32_R14 %0 # temp storage for the sum
|
mov_r14, %0 # temp storage for the sum
|
||||||
LOADI32_R13 %0 # Our starting IP
|
mov_r13, %0 # Our starting IP
|
||||||
CALLI32 %Second_pass # Process it
|
call %Second_pass # Process it
|
||||||
|
|
||||||
JMP32 %Done
|
jmp %Done
|
||||||
|
|
||||||
:First_pass
|
:First_pass
|
||||||
CALLI32 %Read_byte
|
call %Read_byte
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
CMPI32_RAX %-4
|
cmp_rax, %-4
|
||||||
JE32 %First_pass_done
|
je %First_pass_done
|
||||||
|
|
||||||
# Check for :
|
# Check for :
|
||||||
CMPI32_RAX %0x3a
|
cmp_rax, %0x3a
|
||||||
JNE32 %First_pass_0
|
jne %First_pass_0
|
||||||
|
|
||||||
# Deal with label
|
# Deal with label
|
||||||
CALLI32 %StoreLabel
|
call %StoreLabel
|
||||||
|
|
||||||
:First_pass_0
|
:First_pass_0
|
||||||
# Check for %
|
# Check for %
|
||||||
CMPI32_RAX %0x25
|
cmp_rax, %0x25
|
||||||
JE32 %First_pass_pointer
|
je %First_pass_pointer
|
||||||
|
|
||||||
# Deal with everything else
|
# Deal with everything else
|
||||||
CALLI32 %hex # Process our char
|
call %hex # Process our char
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
CMPI32_RAX %-4
|
cmp_rax, %-4
|
||||||
JE32 %First_pass_done
|
je %First_pass_done
|
||||||
|
|
||||||
# deal with -1 values
|
# deal with -1 values
|
||||||
CMPI32_RAX %0
|
cmp_rax, %0
|
||||||
JL32 %First_pass
|
jl %First_pass
|
||||||
|
|
||||||
# deal with toggle
|
# deal with toggle
|
||||||
CMPI32_R15 %0
|
cmp_r15, %0
|
||||||
JE32 %First_pass_1
|
je %First_pass_1
|
||||||
ADDI32_to_R13 %1 # Increment IP
|
add_r13, %1 # Increment IP
|
||||||
|
|
||||||
:First_pass_1
|
:First_pass_1
|
||||||
NOT_R15
|
not_r15
|
||||||
JMP32 %First_pass
|
jmp %First_pass
|
||||||
|
|
||||||
:First_pass_pointer
|
:First_pass_pointer
|
||||||
# Deal with Pointer to label
|
# Deal with Pointer to label
|
||||||
CALLI32 %Read_byte # Drop the char
|
call %Read_byte # Drop the char
|
||||||
ADDI32_to_R13 %4 # Increment IP
|
add_r13, %4 # Increment IP
|
||||||
JMP32 %First_pass # Loop again
|
jmp %First_pass # Loop again
|
||||||
|
|
||||||
:First_pass_done
|
:First_pass_done
|
||||||
RET
|
ret
|
||||||
|
|
||||||
:hex
|
:hex
|
||||||
# deal with EOF
|
# deal with EOF
|
||||||
CMPI32_RAX %-4
|
cmp_rax, %-4
|
||||||
JE32 %EOF
|
je %EOF
|
||||||
# deal with line comments starting with #
|
# deal with line comments starting with #
|
||||||
CMPI32_RAX %0x23
|
cmp_rax, %0x23
|
||||||
JE32 %ascii_comment
|
je %ascii_comment
|
||||||
# deal with line comments starting with ;
|
# deal with line comments starting with ;
|
||||||
CMPI32_RAX %0x3b
|
cmp_rax, %0x3b
|
||||||
JE32 %ascii_comment
|
je %ascii_comment
|
||||||
# deal all ascii less than 0
|
# deal all ascii less than 0
|
||||||
CMPI32_RAX %0x30
|
cmp_rax, %0x30
|
||||||
JL32 %ascii_other
|
jl %ascii_other
|
||||||
# deal with 0-9
|
# deal with 0-9
|
||||||
CMPI32_RAX %0x3a
|
cmp_rax, %0x3a
|
||||||
JL32 %ascii_num
|
jl %ascii_num
|
||||||
# deal with all ascii less than A
|
# deal with all ascii less than A
|
||||||
CMPI32_RAX %0x41
|
cmp_rax, %0x41
|
||||||
JL32 %ascii_other
|
jl %ascii_other
|
||||||
# deal with A-F
|
# deal with A-F
|
||||||
CMPI32_RAX %0x47
|
cmp_rax, %0x47
|
||||||
JL32 %ascii_high
|
jl %ascii_high
|
||||||
# deal with all ascii less than a
|
# deal with all ascii less than a
|
||||||
CMPI32_RAX %0x61
|
cmp_rax, %0x61
|
||||||
JL32 %ascii_other
|
jl %ascii_other
|
||||||
# deal with a-f
|
# deal with a-f
|
||||||
CMPI32_RAX %0x67
|
cmp_rax, %0x67
|
||||||
JL32 %ascii_low
|
jl %ascii_low
|
||||||
# The rest that remains needs to be ignored
|
# The rest that remains needs to be ignored
|
||||||
JMP32 %ascii_other
|
jmp %ascii_other
|
||||||
|
|
||||||
:Second_pass
|
:Second_pass
|
||||||
CALLI32 %Read_byte
|
call %Read_byte
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
CMPI32_RAX %-4
|
cmp_rax, %-4
|
||||||
JE32 %Second_pass_done
|
je %Second_pass_done
|
||||||
|
|
||||||
# Simply drop the label
|
# Simply drop the label
|
||||||
CMPI32_RAX %0x3a
|
cmp_rax, %0x3a
|
||||||
JNE32 %Second_pass_0
|
jne %Second_pass_0
|
||||||
|
|
||||||
CALLI32 %Read_byte
|
call %Read_byte
|
||||||
JMP32 %Second_pass
|
jmp %Second_pass
|
||||||
|
|
||||||
:Second_pass_0
|
:Second_pass_0
|
||||||
# Deal with % pointer
|
# Deal with % pointer
|
||||||
CMPI32_RAX %0x25
|
cmp_rax, %0x25
|
||||||
JNE32 %Second_pass_1
|
jne %Second_pass_1
|
||||||
|
|
||||||
CALLI32 %StorePointer
|
call %StorePointer
|
||||||
JMP32 %Second_pass
|
jmp %Second_pass
|
||||||
|
|
||||||
:Second_pass_1
|
:Second_pass_1
|
||||||
# Deal with everything else
|
# Deal with everything else
|
||||||
CALLI32 %hex # Process our char
|
call %hex # Process our char
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
CMPI32_RAX %-4
|
cmp_rax, %-4
|
||||||
JE32 %Second_pass_done
|
je %Second_pass_done
|
||||||
|
|
||||||
# deal with -1 values
|
# deal with -1 values
|
||||||
CMPI32_RAX %0
|
cmp_rax, %0
|
||||||
JL32 %Second_pass
|
jl %Second_pass
|
||||||
|
|
||||||
# deal with toggle
|
# deal with toggle
|
||||||
CMPI32_R15 %0
|
cmp_r15, %0
|
||||||
JE32 %print
|
je %print
|
||||||
|
|
||||||
# process first byte of pair
|
# process first byte of pair
|
||||||
COPY_RAX_to_R14
|
mov_r14,rax
|
||||||
LOADI32_R15 %0
|
mov_r15, %0
|
||||||
JMP32 %Second_pass
|
jmp %Second_pass
|
||||||
|
|
||||||
:Second_pass_done
|
:Second_pass_done
|
||||||
RET
|
|
||||||
|
|
||||||
:EOF
|
:EOF
|
||||||
RET
|
ret
|
||||||
:ascii_num
|
:ascii_num
|
||||||
SUBI8_from_RAX !0x30
|
sub_rax, !0x30
|
||||||
RET
|
ret
|
||||||
:ascii_low
|
:ascii_low
|
||||||
SUBI8_from_RAX !0x57
|
sub_rax, !0x57
|
||||||
RET
|
ret
|
||||||
:ascii_high
|
:ascii_high
|
||||||
SUBI8_from_RAX !0x37
|
sub_rax, !0x37
|
||||||
RET
|
ret
|
||||||
:ascii_other
|
:ascii_other
|
||||||
LOADI32_RAX %-1
|
mov_rax, %-1
|
||||||
RET
|
ret
|
||||||
:ascii_comment
|
:ascii_comment
|
||||||
CALLI32 %Read_byte
|
call %Read_byte
|
||||||
CMPI32_RAX %0xd
|
cmp_rax, %0xd
|
||||||
JE32 %ascii_comment_cr
|
je %ascii_comment_cr
|
||||||
CMPI32_RAX %0xa
|
cmp_rax, %0xa
|
||||||
JNE32 %ascii_comment
|
jne %ascii_comment
|
||||||
:ascii_comment_cr
|
:ascii_comment_cr
|
||||||
LOADI32_RAX %-1
|
mov_rax, %-1
|
||||||
RET
|
ret
|
||||||
|
|
||||||
# process second byte of pair
|
# process second byte of pair
|
||||||
:print
|
:print
|
||||||
# update the sum and store in output
|
# update the sum and store in output
|
||||||
SHL8_R14 !4
|
shl_r14, !4
|
||||||
ADD_R14_to_RAX
|
add_rax,r14
|
||||||
|
|
||||||
# flip the toggle
|
# flip the toggle
|
||||||
NOT_R15 # R15 = -1
|
not_r15 # R15 = -1
|
||||||
|
|
||||||
LOADI32_RDX %1 # set the size of chars we want
|
mov_rdx, %1 # set the size of chars we want
|
||||||
CALLI32 %print_chars
|
call %print_chars
|
||||||
|
|
||||||
ADDI32_to_R13 %1 # Increment IP
|
add_r13, %1 # Increment IP
|
||||||
JMP32 %Second_pass
|
jmp %Second_pass
|
||||||
|
|
||||||
|
|
||||||
:Read_byte
|
:Read_byte
|
||||||
COPY_RDI_to_RCX # arg1 = fin
|
mov_rcx,rdi # arg1 = fin
|
||||||
PUSH !1 # size = 1
|
push !1 # size = 1
|
||||||
COPY_RSP_to_RDX # arg2 = &size
|
mov_rdx,rsp # arg2 = &size
|
||||||
PUSH_RSI # allocate stack
|
xor_esi,esi # zero rsi
|
||||||
COPY_RSP_to_R8 # arg3 = &input
|
push_rsi # allocate stack
|
||||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
mov_r8,rsp # arg3 = &input
|
||||||
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 !32 # fin->read()
|
push_rax # allocate shadow stack space for UEFI function
|
||||||
POP_RAX # deallocate stack
|
call_[rcx+BYTE] !32 # fin->read()
|
||||||
POP_RAX # deallocate stack
|
pop_rax # deallocate stack
|
||||||
POP_RAX # deallocate stack
|
pop_rax # deallocate stack
|
||||||
POP_RAX # save input to rax
|
pop_rax # deallocate stack
|
||||||
POP_RSI # save size to rsi
|
pop_rax # save input to rax
|
||||||
|
pop_rsi # save size to rsi
|
||||||
|
|
||||||
# If the file ended (0 bytes read) return EOF
|
# If the file ended (0 bytes read) return EOF
|
||||||
TEST_ESI_ESI # if size = 0
|
test_esi,esi # if size = 0
|
||||||
JNE8 !Read_byte_1
|
jne8 !Read_byte_1
|
||||||
LOADI32_RAX %-4 # Put EOF in rax
|
mov_rax, %-4 # Put EOF in rax
|
||||||
|
|
||||||
:Read_byte_1
|
:Read_byte_1
|
||||||
RET # return
|
ret # return
|
||||||
|
|
||||||
# Writes bytes stored in rax
|
# Writes bytes stored in rax
|
||||||
:print_chars
|
:print_chars
|
||||||
COPY_RBX_to_RCX # arg1 = fout
|
mov_rcx,rbx # arg1 = fout
|
||||||
PUSH_RDX # set size
|
push_rdx # set size
|
||||||
COPY_RSP_to_RDX # arg2 = &size
|
mov_rdx,rsp # arg2 = &size
|
||||||
PUSH_RAX # allocate stack
|
push_rax # allocate stack
|
||||||
COPY_RSP_to_R8 # arg3 = &output
|
mov_r8,rsp # arg3 = &output
|
||||||
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
|
||||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
push_rax # allocate shadow stack space for UEFI function
|
||||||
CALL_RCX_Immediate8 !40 # fout->write()
|
call_[rcx+BYTE] !40 # fout->write()
|
||||||
ADDI8_RSP !40 # deallocate stack
|
add_rsp, !40 # deallocate stack
|
||||||
|
|
||||||
RET # return
|
ret # return
|
||||||
|
|
||||||
:Get_table_target
|
:Get_table_target
|
||||||
CALLI32 %Read_byte # Get single char label
|
call %Read_byte # Get single char label
|
||||||
SHL8_RAX !3 # Each label in table takes 8 bytes to store
|
shl_rax, !3 # Each label in table takes 8 bytes to store
|
||||||
LOAD64_rel_RCX %table # Get table
|
mov_rcx,[rsp+BYTE] !24 # Get table
|
||||||
ADD_RCX_to_RAX # Calculate offset
|
add_rax,rcx # Calculate offset
|
||||||
RET
|
ret
|
||||||
|
|
||||||
:StoreLabel
|
:StoreLabel
|
||||||
CALLI32 %Get_table_target
|
call %Get_table_target
|
||||||
STORE32_R13_to_Address_in_RAX # Write out pointer to table
|
mov_[rax],r13 # Write out pointer to table
|
||||||
RET
|
ret
|
||||||
|
|
||||||
:StorePointer
|
:StorePointer
|
||||||
ADDI32_to_R13 %4 # Increment IP
|
add_r13, %4 # Increment IP
|
||||||
CALLI32 %Get_table_target # Get address of pointer
|
call %Get_table_target # Get address of pointer
|
||||||
LOAD32_Address_in_RAX_into_RAX # Get pointer
|
mov_rax,[rax] # Get pointer
|
||||||
SUB_R13_from_RAX # target - ip
|
sub_rax,r13 # target - ip
|
||||||
LOADI32_RDX %4 # set the size of chars we want
|
mov_rdx, %4 # set the size of chars we want
|
||||||
CALLI32 %print_chars
|
call %print_chars
|
||||||
RET
|
ret
|
||||||
|
|
||||||
:Done
|
:Done
|
||||||
|
pop_rcx # restore table
|
||||||
|
pop_rsi # restore rootdir
|
||||||
|
pop_r15 # restore image_handle
|
||||||
|
pop_r14 # restore system->boot
|
||||||
|
pop_r13 # restore root_device
|
||||||
|
|
||||||
# Free pool
|
# Free pool
|
||||||
LOAD64_rel_RCX %table # arg1 = table
|
# arg1 = table
|
||||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
push_rax # allocate shadow stack space for UEFI function
|
||||||
LOAD64_rel_R14 %SystemBoot # get system->boot
|
call_[r14+BYTE] !72 # system->boot->free_pool(table)
|
||||||
CALL_R14_Immediate8 !72 # system->boot->free_pool(table)
|
|
||||||
|
|
||||||
COPY_RDI_to_RCX # arg1 = fin
|
mov_rcx,rdi # arg1 = fin
|
||||||
CALL_RCX_Immediate8 !16 # fin->close()
|
call_[rcx+BYTE] !16 # fin->close()
|
||||||
COPY_RBX_to_RCX # arg1 = fout
|
mov_rcx,rbx # arg1 = fout
|
||||||
CALL_RCX_Immediate8 !16 # fout->close()
|
call_[rcx+BYTE] !16 # fout->close()
|
||||||
|
mov_rcx,rsi # arg1 = rootdir
|
||||||
|
call_[rcx+BYTE] !16 # rootdir->close()
|
||||||
|
|
||||||
COPY_RBP_to_RSP # restore stack
|
mov_r8,r15 # arg3 = image_handle
|
||||||
RET # return to UEFI
|
lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
|
||||||
|
mov_rcx,r13 # arg1 = root_device
|
||||||
|
xor_r9,r9 # arg4 = NULL
|
||||||
|
sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
|
call_[r14+DWORD] %288 # system->boot->close_protocol(root_device, &guid, image_handle, 0)
|
||||||
|
|
||||||
|
mov_r8,r15 # arg3 = image_handle
|
||||||
|
lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
|
mov_rcx,r8 # arg1 = image_handle
|
||||||
|
xor_r9,r9 # arg4 = NULL
|
||||||
|
call_[r14+DWORD] %288 # system->boot->close_protocol(image_handle, &guid, image_handle, 0)
|
||||||
|
|
||||||
|
mov_rsp,rbp # restore stack
|
||||||
|
ret # return to UEFI
|
||||||
|
|
||||||
# Protocol GUIDs
|
# Protocol GUIDs
|
||||||
:LOADED_IMAGE_PROTOCOL
|
:LOADED_IMAGE_PROTOCOL
|
||||||
%0x5b1b31a1
|
%0x5b1b31a1
|
||||||
@0x9562
|
@0x9562
|
||||||
@0x11d2
|
@0x11d2
|
||||||
:LOADED_IMAGE_PROTOCOL_8
|
|
||||||
!0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
!0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||||
|
|
||||||
:SIMPLE_FS_PROTOCOL
|
:SIMPLE_FS_PROTOCOL
|
||||||
%0x0964e5b22
|
%0x0964e5b22
|
||||||
@0x6459
|
@0x6459
|
||||||
@0x11d2
|
@0x11d2
|
||||||
:SIMPLE_FS_PROTOCOL_8
|
|
||||||
!0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
!0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||||
|
|
||||||
:table
|
|
||||||
%0 %0
|
|
||||||
|
|
||||||
:SystemBoot
|
|
||||||
%0 %0
|
|
||||||
|
|
||||||
:PE32_end
|
:PE32_end
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# Some of the functions are deliberately inlined at the slight expense of
|
||||||
|
# binary size to avoid tricky jump calculations in hex0 code.
|
||||||
|
|
||||||
.global _start
|
.global _start
|
||||||
.text
|
.text
|
||||||
|
|
||||||
|
@ -11,9 +14,95 @@ _start:
|
||||||
mov rbp, rsp # save stack pointer
|
mov rbp, rsp # save stack pointer
|
||||||
mov r15, rcx # save image_handle
|
mov r15, rcx # save image_handle
|
||||||
mov r14, [rdx+96] # system->boot
|
mov r14, [rdx+96] # system->boot
|
||||||
mov [rip+SystemBoot], r14 # save system->boot
|
|
||||||
|
# Open Loaded Image protocol
|
||||||
|
mov r9, r15 # arg4 = image_handle
|
||||||
|
lea rdx, [rip+LOADED_IMAGE_PROTOCOL] # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
|
mov rcx, r9 # arg1 = image_handle
|
||||||
|
push rax # allocate stack for image
|
||||||
|
mov r8, rsp # arg3 = &image
|
||||||
|
push 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
|
push 0 # arg5 = NULL
|
||||||
|
sub rsp, 32 # allocate shadow stack space for UEFI function
|
||||||
|
call [r14+280] # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
|
mov rdi, [rsp+48] # save image
|
||||||
|
|
||||||
|
# Get root file system
|
||||||
|
mov r9, r15 # arg4 = image_handle
|
||||||
|
lea rdx, [rip+SIMPLE_FS_PROTOCOL] # guid = &SIMPLE_FS_PROTOCOL
|
||||||
|
mov rcx, [rdi+24] # arg1 = root_device = image->device
|
||||||
|
mov r13, rcx # save root_device
|
||||||
|
push rax # allocate stack for rootfs
|
||||||
|
mov r8, rsp # arg3 = &rootfs
|
||||||
|
push 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
|
push 0 # arg5 = NULL
|
||||||
|
sub rsp, 32 # allocate shadow stack space for UEFI function
|
||||||
|
call [r14+280] # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
|
mov rcx, [rsp+48] # get rootfs
|
||||||
|
|
||||||
|
# Get root directory
|
||||||
|
push rax # allocate stack for rootdir
|
||||||
|
mov rdx, rsp # arg2 = &rootdir
|
||||||
|
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)
|
||||||
|
pop rax # deallocate stack
|
||||||
|
pop rax # deallocate stack
|
||||||
|
pop rsi # get rootdir
|
||||||
|
|
||||||
|
# Push command line arguments onto stack
|
||||||
|
mov rbx, [rdi+56] # options = image->load_options
|
||||||
|
mov rdx, rbx # save beginning of load_options
|
||||||
|
add rbx, [rdi+48] # go to the end of load_options
|
||||||
|
push 0 # Save end of arguments (NULL) onto stack
|
||||||
|
loop_options:
|
||||||
|
cmp rbx, rdx # Check if we are done
|
||||||
|
je loop_options_done # We are done
|
||||||
|
sub rbx, 2 # --options
|
||||||
|
mov al, [rbx] # *options
|
||||||
|
cmp al, 0x20 # if *options != ' '
|
||||||
|
jne loop_options # then continue looping
|
||||||
|
mov BYTE PTR [rbx], 0 # zero it
|
||||||
|
add rbx, 2 # ++options
|
||||||
|
push rbx # push another argument onto stack
|
||||||
|
jmp loop_options # next argument
|
||||||
|
loop_options_done:
|
||||||
|
|
||||||
|
# Open file for reading
|
||||||
|
pop r8 # arg3 = in
|
||||||
|
push rdx # allocate stack for fin
|
||||||
|
mov rdx, rsp # arg2 = &fin
|
||||||
|
push 1 # arg5 = EFI_FILE_READ_ONLY
|
||||||
|
push 1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
||||||
|
pop r9 # arg4 = EFI_FILE_MODE_READ
|
||||||
|
mov rcx, rsi # arg1 = rootdir
|
||||||
|
sub rsp, 32 # allocate shadow stack space for UEFI function
|
||||||
|
call [rcx+8] # rootdir->open()
|
||||||
|
add rsp, 40 # deallocate stack
|
||||||
|
pop rdi # get fin
|
||||||
|
|
||||||
|
# Open file for writing
|
||||||
|
pop r8 # arg3 = out
|
||||||
|
push rdx # allocate stack for fout
|
||||||
|
mov rdx, rsp # arg2 = &fout
|
||||||
|
push 0 # arg5 = 0
|
||||||
|
push 7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||||
|
pop r9 # and then do right rotation by 1
|
||||||
|
ror r9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
||||||
|
mov rcx, rsi # arg1 = rootdir
|
||||||
|
sub rsp, 32 # allocate shadow stack space for UEFI function
|
||||||
|
call [rcx+8] # rootdir->open()
|
||||||
|
add rsp, 40 # deallocate stack
|
||||||
|
pop rbx # get fout
|
||||||
|
|
||||||
|
# Save variables that are needed for cleanup
|
||||||
|
push r13 # save root_device
|
||||||
|
push r14 # save system->boot
|
||||||
|
push r15 # save image_handle
|
||||||
|
push rsi # save rootdir
|
||||||
|
|
||||||
# Allocate pool for single-character label table
|
# Allocate pool for single-character label table
|
||||||
|
# pointer to table will be stored at the top of the stack
|
||||||
push rdx # allocate stack for table
|
push rdx # allocate stack for table
|
||||||
mov r8, rsp # arg3 = &table
|
mov r8, rsp # arg3 = &table
|
||||||
xor edx, edx # zero rdx
|
xor edx, edx # zero rdx
|
||||||
|
@ -23,98 +112,6 @@ _start:
|
||||||
sub rsp, 24 # allocate shadow stack space for UEFI
|
sub rsp, 24 # allocate shadow stack space for UEFI
|
||||||
call [r14+64] # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
call [r14+64] # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
||||||
add rsp, 24 # deallocate stack
|
add rsp, 24 # deallocate stack
|
||||||
pop rax # get table
|
|
||||||
mov [rip+table], rax # save table
|
|
||||||
|
|
||||||
# Open Loaded Image protocol
|
|
||||||
push rax # allocate stack for image
|
|
||||||
mov r8, rsp # arg3 = &image
|
|
||||||
mov rdx, [rip+LOADED_IMAGE_PROTOCOL+8] # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
|
||||||
push rdx # push last 64 bits onto stack
|
|
||||||
mov rdx, [rip+LOADED_IMAGE_PROTOCOL] # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
|
||||||
push rdx # push first 64 bits onto stack
|
|
||||||
mov rdx, rsp # arg2 = &guid
|
|
||||||
push 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
|
||||||
push 0 # arg5 = NULL
|
|
||||||
mov r9, r15 # arg4 = image_handle
|
|
||||||
mov rcx, r15 # arg1 = image_handle
|
|
||||||
sub rsp, 32 # allocate shadow stack space for UEFI function
|
|
||||||
call [r14+280] # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
|
||||||
mov rax, [rsp+64] # get image
|
|
||||||
mov rcx, rax # save image
|
|
||||||
|
|
||||||
# Command line args
|
|
||||||
mov rbx, [rax+56] # options = image->load_options
|
|
||||||
|
|
||||||
loop_options1: # Skip application name
|
|
||||||
add rbx, 2 # ++options
|
|
||||||
mov al, [rbx] # *options
|
|
||||||
cmp al, 0x20 # if *options != ' '
|
|
||||||
jne loop_options1 # then jump
|
|
||||||
|
|
||||||
add rbx, 2 # ++options
|
|
||||||
mov r12, rbx # save input file
|
|
||||||
|
|
||||||
loop_options2: # Skip argv[1]
|
|
||||||
add rbx, 2 # ++options
|
|
||||||
mov al, [rbx] # *options
|
|
||||||
cmp al, 0x20 # if *options != ' '
|
|
||||||
jne loop_options2 # then jump
|
|
||||||
|
|
||||||
mov byte ptr [rbx], 0 # *options = 0
|
|
||||||
add rbx, 2 # ++options
|
|
||||||
mov r13, rbx # save output file
|
|
||||||
|
|
||||||
# Get root file system
|
|
||||||
push rax # allocate stack for rootfs
|
|
||||||
mov r8, rsp # arg3 = &rootfs
|
|
||||||
mov rdx, [rip+SIMPLE_FS_PROTOCOL+8] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
|
||||||
push rdx # push last 64 bits onto stack
|
|
||||||
mov rdx, [rip+SIMPLE_FS_PROTOCOL] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
|
||||||
push rdx # push first 64 bits onto stack
|
|
||||||
mov rdx, rsp # arg2 = &guid
|
|
||||||
push 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
|
||||||
push 0 # arg5 = NULL
|
|
||||||
mov r9, r15 # arg4 = image_handle
|
|
||||||
mov rcx, [rcx+24] # arg1 = root_device = image->device
|
|
||||||
sub rsp, 32 # allocate shadow stack space for UEFI function
|
|
||||||
call [r14+280] # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
|
||||||
mov rcx, [rsp+64] # get rootfs
|
|
||||||
|
|
||||||
# Get root directory
|
|
||||||
push rdx # allocate stack for rootdir
|
|
||||||
mov rdx, rsp # arg2 = &rootdir
|
|
||||||
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)
|
|
||||||
pop rax # deallocate stack
|
|
||||||
pop rax # deallocate stack
|
|
||||||
pop r14 # save rootdir
|
|
||||||
|
|
||||||
# Open file for reading
|
|
||||||
push rdx # allocate stack for fin
|
|
||||||
mov rdx, rsp # arg2 = &fin
|
|
||||||
push 1 # arg5 = EFI_FILE_READ_ONLY
|
|
||||||
push 1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
|
||||||
pop r9 # arg4 = EFI_FILE_MODE_READ
|
|
||||||
mov r8, r12 # arg3 = in
|
|
||||||
mov rcx, r14 # arg1 = rootdir
|
|
||||||
sub rsp, 32 # allocate shadow stack space for UEFI function
|
|
||||||
call [rcx+8] # rootdir->open()
|
|
||||||
mov rdi, [rsp+40] # get fin
|
|
||||||
|
|
||||||
# Open file for writing
|
|
||||||
push rdx # allocate stack for fout
|
|
||||||
mov rdx, rsp # arg2 = &fout
|
|
||||||
push 0 # arg5 = 0
|
|
||||||
push 7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
|
||||||
pop r9 # and then do right rotation by 1
|
|
||||||
ror r9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
|
||||||
mov r8, r13 # arg3 = out
|
|
||||||
mov rcx, r14 # arg1 = rootdir
|
|
||||||
sub rsp, 32 # allocate shadow stack space for UEFI function
|
|
||||||
call [rcx+8] # rootdir->open()
|
|
||||||
mov rbx, [rsp+40] # get fout
|
|
||||||
|
|
||||||
mov r15, -1 # Our flag for byte processing
|
mov r15, -1 # Our flag for byte processing
|
||||||
mov r14, 0 # temp storage for the sum
|
mov r14, 0 # temp storage for the sum
|
||||||
|
@ -261,8 +258,6 @@ Second_pass_1:
|
||||||
jmp Second_pass
|
jmp Second_pass
|
||||||
|
|
||||||
Second_pass_done:
|
Second_pass_done:
|
||||||
ret
|
|
||||||
|
|
||||||
EOF:
|
EOF:
|
||||||
ret
|
ret
|
||||||
ascii_num:
|
ascii_num:
|
||||||
|
@ -307,6 +302,7 @@ Read_byte:
|
||||||
mov rcx, rdi # arg1 = fin
|
mov rcx, rdi # arg1 = fin
|
||||||
push 1 # size = 1
|
push 1 # size = 1
|
||||||
mov rdx, rsp # arg2 = &size
|
mov rdx, rsp # arg2 = &size
|
||||||
|
xor esi, esi # zero rsi
|
||||||
push rsi # allocate stack
|
push rsi # allocate stack
|
||||||
mov r8, rsp # arg3 = &input
|
mov r8, rsp # arg3 = &input
|
||||||
push rax # allocate shadow stack space for UEFI function
|
push rax # allocate shadow stack space for UEFI function
|
||||||
|
@ -345,7 +341,7 @@ print_chars:
|
||||||
Get_table_target:
|
Get_table_target:
|
||||||
call Read_byte # Get single char label
|
call Read_byte # Get single char label
|
||||||
shl rax, 3 # Each label in table takes 8 bytes to store
|
shl rax, 3 # Each label in table takes 8 bytes to store
|
||||||
mov rcx, [rip+table] # Get table
|
mov rcx, [rsp+24] # Get table
|
||||||
add rax, rcx # Calculate offset
|
add rax, rcx # Calculate offset
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -364,16 +360,37 @@ StorePointer:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
|
pop rcx # restore table
|
||||||
|
pop rsi # restore rootdir
|
||||||
|
pop r15 # restore image_handle
|
||||||
|
pop r14 # restore system->boot
|
||||||
|
pop r13 # restore root_device
|
||||||
|
|
||||||
# Free pool
|
# Free pool
|
||||||
mov rcx, [rip+table] # arg1 = table
|
# arg1 = table
|
||||||
push rax # allocate shadow stack space for UEFI function
|
push rax # allocate shadow stack space for UEFI function
|
||||||
mov r14, [rip+SystemBoot] # get system->boot
|
|
||||||
call [r14+72] # system->boot->free_pool(table)
|
call [r14+72] # system->boot->free_pool(table)
|
||||||
|
|
||||||
mov rcx, rdi # arg1 = fin
|
mov rcx, rdi # arg1 = fin
|
||||||
call [rcx+16] # fin->close()
|
call [rcx+16] # fin->close()
|
||||||
mov rcx, rbx # arg1 = fout
|
mov rcx, rbx # arg1 = fout
|
||||||
call [rcx+16] # fout->close()
|
call [rcx+16] # fout->close()
|
||||||
|
mov rcx, rsi # arg1 = rootdir
|
||||||
|
call [rcx+16] # rootdir->close()
|
||||||
|
|
||||||
|
mov r8, r15 # arg3 = image_handle
|
||||||
|
lea rdx, [rip+SIMPLE_FS_PROTOCOL] # guid = &SIMPLE_FS_PROTOCOL
|
||||||
|
mov rcx, r13 # arg1 = root_device
|
||||||
|
xor r9, r9 # arg4 = NULL
|
||||||
|
sub rsp, 32 # allocate shadow stack space for UEFI function
|
||||||
|
call [r14+288] # system->boot->close_protocol(root_device, &guid, image_handle, 0)
|
||||||
|
|
||||||
|
mov r8, r15 # arg3 = image_handle
|
||||||
|
lea rdx, [rip+LOADED_IMAGE_PROTOCOL] # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
|
mov rcx, r8 # arg1 = image_handle
|
||||||
|
xor r9, r9 # arg4 = NULL
|
||||||
|
call [r14+288] # system->boot->close_protocol(image_handle, &guid, image_handle, 0)
|
||||||
|
|
||||||
abort: # used for debugging only
|
abort: # used for debugging only
|
||||||
mov rsp, rbp # restore stack
|
mov rsp, rbp # restore stack
|
||||||
ret # return to UEFI
|
ret # return to UEFI
|
||||||
|
@ -391,9 +408,3 @@ SIMPLE_FS_PROTOCOL:
|
||||||
.short 0x6459
|
.short 0x6459
|
||||||
.short 0x11d2
|
.short 0x11d2
|
||||||
.byte 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b
|
.byte 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b
|
||||||
|
|
||||||
table:
|
|
||||||
.long 0, 0
|
|
||||||
|
|
||||||
SystemBoot:
|
|
||||||
.long 0, 0
|
|
||||||
|
|
|
@ -6,374 +6,387 @@
|
||||||
|
|
||||||
# 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
|
||||||
4C8935 %SystemBoot ; STORE64_rel_R14 %SystemBoot # save system->boot
|
|
||||||
|
|
||||||
# Allocate pool for single-character label table
|
|
||||||
52 ; PUSH_RDX # allocate stack for table
|
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &table
|
|
||||||
31D2 ; XOR_EDX_EDX # zero rdx
|
|
||||||
B6 08 ; LOADI8_DH !0x8 # arg2 = 256 * 8 = 2048 = 0x800
|
|
||||||
6A 02 ; PUSH !2
|
|
||||||
59 ; POP_RCX # arg1 = EFI_LOADER_DATA
|
|
||||||
4883EC 18 ; SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
|
||||||
41FF56 40 ; CALL_R14_Immediate8 !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
|
||||||
4883C4 18 ; ADDI8_RSP !24 # deallocate stack
|
|
||||||
58 ; POP_RAX # get table
|
|
||||||
488905 %table ; STORE64_rel_RAX %table # save table
|
|
||||||
|
|
||||||
# Open Loaded Image protocol
|
# Open Loaded Image protocol
|
||||||
50 ; PUSH_RAX # allocate stack for image
|
4D89F9 ; mov_r9,r15 # arg4 = image_handle
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &image
|
488D15 %LOADED_IMAGE_PROTOCOL ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
488B15 %LOADED_IMAGE_PROTOCOL_8 ; LOAD64_rel_RDX !LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
4C89C9 ; mov_rcx,r9 # arg1 = image_handle
|
||||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
50 ; push_rax # allocate stack for image
|
||||||
488B15 %LOADED_IMAGE_PROTOCOL ; LOAD64_rel_RDX !LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
4989E0 ; mov_r8,rsp # arg3 = &image
|
||||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
6A 01 ; push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
6A 00 ; push !0 # arg5 = NULL
|
||||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
6A 00 ; PUSH !0 # arg5 = NULL
|
41FF96 18010000 ; call_[r14+DWORD] %280 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
488B7C24 30 ; mov_rdi,[rsp+BYTE] !48 # save image
|
||||||
4C89F9 ; COPY_R15_to_RCX # arg1 = image_handle
|
|
||||||
4883EC 20 ; SUBI8_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)
|
|
||||||
488B4424 40 ; LOAD64_into_RAX_from_Address_RSP_Immediate8 !64 # get_image
|
|
||||||
4889C1 ; COPY_RCX_to_RAX # save image
|
|
||||||
|
|
||||||
# Command line args
|
|
||||||
488B58 38 ; LOAD64_into_RBX_from_Address_RAX_Immediate8 !56 # options = image->load_options
|
|
||||||
|
|
||||||
:loop_options1 # Skip application name
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
8A03 ; LOAD8_AL_from_Address_RBX # *options
|
|
||||||
3C 20 ; CMPI8_AL !0x20 # if *options != ' '
|
|
||||||
75 !loop_options1 ; JNE8 !loop_options1 # then jump
|
|
||||||
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
4989DC ; COPY_RBX_to_R12 # save input file
|
|
||||||
|
|
||||||
:loop_options2 # Skip argv[1]
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
8A03 ; LOAD8_AL_from_Address_RBX # *options
|
|
||||||
3C 20 ; CMPI8_AL !0x20 # if *options != ' '
|
|
||||||
75 !loop_options2 ; JNE8 !loop_options2 # then jump
|
|
||||||
|
|
||||||
C603 00 ; STOREI8_into_Address_RBX !0 # *options = 0;
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
4989DD ; COPY_RBX_to_R13 # save output file
|
|
||||||
|
|
||||||
# Get root file system
|
# Get root file system
|
||||||
50 ; PUSH_RAX # allocate stack for rootfs
|
4D89F9 ; mov_r9,r15 # arg4 = image_handle
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &rootfs
|
488D15 %SIMPLE_FS_PROTOCOL ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
|
||||||
488B15 %SIMPLE_FS_PROTOCOL_8 ; LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
488B4F 18 ; mov_rcx,[rdi+BYTE] !24 # arg1 = root_device = image->device
|
||||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
4989CD ; mov_r13,rcx # save root_device
|
||||||
488B15 %SIMPLE_FS_PROTOCOL ; LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
50 ; push_rax # allocate stack for rootfs
|
||||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
4989E0 ; mov_r8,rsp # arg3 = &rootfs
|
||||||
4889E2 ; COPY_RSP_to_RDX # 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
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
41FF96 18010000 ; call_[r14+DWORD] %280 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
488B49 18 ; LOAD64_into_RCX_from_Address_RCX_Immediate8 !24 # arg1 = root_device = image->device
|
488B4C24 30 ; mov_rcx,[rsp+BYTE] !48 # get rootfs
|
||||||
4883EC 20 ; SUBI8_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)
|
|
||||||
488B4C24 40 ; LOAD64_into_RCX_from_Address_RSP_Immediate8 !64 # get rootfs
|
|
||||||
|
|
||||||
# Get root directory
|
# Get root directory
|
||||||
52 ; PUSH_RDX # allocate stack for rootdir
|
50 ; push_rax # 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
|
||||||
415E ; POP_R14 # save rootdir
|
5E ; pop_rsi # save rootdir
|
||||||
|
|
||||||
|
# Push command line arguments onto stack
|
||||||
|
488B5F 38 ; mov_rbx,[rdi+BYTE] !56 # options = image->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
|
||||||
|
6A 00 ; push !0 # Save end of arguments (NULL) onto stack
|
||||||
|
:loop_options
|
||||||
|
4839D3 ; cmp_rbx,rdx # Check if we are done
|
||||||
|
74 !loop_options_done ; je8 !loop_options_done # We are done
|
||||||
|
4883EB 02 ; sub_rbx, !2 # --options
|
||||||
|
8A03 ; mov_al,[rbx] # *options
|
||||||
|
3C 20 ; cmp_al, !0x20 # if *options != ' '
|
||||||
|
75 !loop_options ; jne8 !loop_options # then continue looping
|
||||||
|
C603 00 ; mov_[rbx], !0 # zero it
|
||||||
|
4883C3 02 ; add_rbx, !2 # ++options
|
||||||
|
53 ; push_rbx # push another argument onto stack
|
||||||
|
EB !loop_options ; jmp8 !loop_options # next argument
|
||||||
|
:loop_options_done
|
||||||
|
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
52 ; PUSH_RDX # allocate stack for fin
|
4158 ; pop_r8 # arg3 = in
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fin
|
52 ; push_rdx # allocate stack for fin
|
||||||
6A 01 ; PUSH !1 # arg5 = EFI_FILE_READ_ONLY
|
4889E2 ; mov_rdx,rsp # arg2 = &fin
|
||||||
6A 01 ; PUSH !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
6A 01 ; push !1 # arg5 = EFI_FILE_READ_ONLY
|
||||||
4159 ; POP_R9 # arg4 = EFI_FILE_MODE_READ
|
6A 01 ; push !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
||||||
4D89E0 ; COPY_R12_to_R8 # arg3 = in
|
4159 ; pop_r9 # arg4 = EFI_FILE_MODE_READ
|
||||||
4C89F1 ; COPY_R14_to_RCX # arg1 = rootdir
|
4889F1 ; mov_rcx,rsi # 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()
|
||||||
488B7C24 28 ; LOAD64_into_RDI_from_Address_RSP_Immediate8 !40 # get fin
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
|
5F ; pop_rdi # get fin
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
52 ; PUSH_RDX # allocate stack for fout
|
4158 ; pop_r8 # arg3 = out
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fout
|
52 ; push_rdx # allocate stack for fout
|
||||||
6A 00 ; PUSH !0 # arg5 = 0
|
4889E2 ; mov_rdx,rsp # arg2 = &fout
|
||||||
6A 07 ; PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
6A 00 ; push !0 # arg5 = 0
|
||||||
4159 ; POP_R9 # and then do right rotation by 1
|
6A 07 ; push !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||||
49D1C9 ; ROR_R9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
4159 ; pop_r9 # and then do right rotation by 1
|
||||||
4D89E8 ; COPY_R13_to_R8 # arg3 = out
|
49D1C9 ; ror_r9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
||||||
4C89F1 ; COPY_R14_to_RCX # arg1 = rootdir
|
4889F1 ; mov_rcx,rsi # 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()
|
||||||
488B5C24 28 ; LOAD64_into_RBX_from_Address_RSP_Immediate8 !40 # get fout
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
|
5B ; pop_rbx # get fout
|
||||||
|
|
||||||
49C7C7 FFFFFFFF ; LOADI32_R15 %-1 # Our flag for byte processing
|
# Save variables that are needed for cleanup
|
||||||
49C7C6 00000000 ; LOADI32_R14 %0 # temp storage for the sum
|
4155 ; push_r13 # save root_device
|
||||||
49C7C5 00000000 ; LOADI32_R13 %0 # Our starting IP
|
4156 ; push_r14 # save system->boot
|
||||||
E8 %First_pass ; CALLI32 %First_pass # Process it
|
4157 ; push_r15 # save image_handle
|
||||||
|
56 ; push_rsi # save rootdir
|
||||||
|
|
||||||
|
# Allocate pool for single-character label table
|
||||||
|
# pointer to table will be stored at the top of the stack
|
||||||
|
52 ; push_rdx # allocate stack for table
|
||||||
|
4989E0 ; mov_r8,rsp # arg3 = &table
|
||||||
|
31D2 ; xor_edx,edx # zero rdx
|
||||||
|
B6 08 ; mov_dh, !0x8 # arg2 = 256 * 8 = 2048 = 0x800
|
||||||
|
6A 02 ; push !2
|
||||||
|
59 ; pop_rcx # arg1 = EFI_LOADER_DATA
|
||||||
|
4883EC 18 ; sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
|
41FF56 40 ; call_[r14+BYTE] !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
||||||
|
4883C4 18 ; add_rsp, !24 # deallocate stack
|
||||||
|
|
||||||
|
49C7C7 FFFFFFFF ; mov_r15, %-1 # Our flag for byte processing
|
||||||
|
49C7C6 00000000 ; mov_r14, %0 # temp storage for the sum
|
||||||
|
49C7C5 00000000 ; mov_r13, %0 # Our starting IP
|
||||||
|
E8 %First_pass ; call %First_pass # Process it
|
||||||
|
|
||||||
# rewind input file
|
# rewind input file
|
||||||
4889F9 ; COPY_RDI_to_RCX # Using our input file
|
4889F9 ; mov_rcx,rdi # Using our input file
|
||||||
31D2 ; XOR_EDX_EDX # Offset Zero
|
31D2 ; xor_edx,edx # Offset Zero
|
||||||
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 38 ; CALL_RCX_Immediate8 !56 # fin->set_position(fin, 0)
|
FF51 38 ; call_[rcx+BYTE] !56 # fin->set_position(fin, 0)
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
|
|
||||||
49C7C7 FFFFFFFF ; LOADI32_R15 %-1 # Our flag for byte processing
|
49C7C7 FFFFFFFF ; mov_r15, %-1 # Our flag for byte processing
|
||||||
49C7C6 00000000 ; LOADI32_R14 %0 # temp storage for the sum
|
49C7C6 00000000 ; mov_r14, %0 # temp storage for the sum
|
||||||
49C7C5 00000000 ; LOADI32_R13 %0 # Our starting IP
|
49C7C5 00000000 ; mov_r13, %0 # Our starting IP
|
||||||
E8 %Second_pass ; CALLI32 %Second_pass # Process it
|
E8 %Second_pass ; call %Second_pass # Process it
|
||||||
|
|
||||||
E9 %Done ; JMP32 %Done
|
E9 %Done ; jmp %Done
|
||||||
|
|
||||||
:First_pass
|
:First_pass
|
||||||
E8 %Read_byte ; CALLI32 %Read_byte
|
E8 %Read_byte ; call %Read_byte
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 %First_pass_done ; JE32 %First_pass_done
|
0F84 %First_pass_done ; je %First_pass_done
|
||||||
|
|
||||||
# Check for :
|
# Check for :
|
||||||
483D 3A000000 ; CMPI32_RAX %0x3a
|
483D 3A000000 ; cmp_rax, %0x3a
|
||||||
0F85 %First_pass_0 ; JNE32 %First_pass_0
|
0F85 %First_pass_0 ; jne %First_pass_0
|
||||||
|
|
||||||
# Deal with label
|
# Deal with label
|
||||||
E8 %StoreLabel ; CALLI32 %StoreLabel
|
E8 %StoreLabel ; call %StoreLabel
|
||||||
|
|
||||||
:First_pass_0
|
:First_pass_0
|
||||||
# Check for %
|
# Check for %
|
||||||
483D 25000000 ; CMPI32_RAX %0x25
|
483D 25000000 ; cmp_rax, %0x25
|
||||||
0F84 %First_pass_pointer ; JE32 %First_pass_pointer
|
0F84 %First_pass_pointer ; je %First_pass_pointer
|
||||||
|
|
||||||
# Deal with everything else
|
# Deal with everything else
|
||||||
E8 %hex ; CALLI32 %hex # Process our char
|
E8 %hex ; call %hex # Process our char
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 %First_pass_done ; JE32 %First_pass_done
|
0F84 %First_pass_done ; je %First_pass_done
|
||||||
|
|
||||||
# deal with -1 values
|
# deal with -1 values
|
||||||
483D 00000000 ; CMPI32_RAX %0
|
483D 00000000 ; cmp_rax, %0
|
||||||
0F8C %First_pass ; JL32 %First_pass
|
0F8C %First_pass ; jl %First_pass
|
||||||
|
|
||||||
# deal with toggle
|
# deal with toggle
|
||||||
4981FF 00000000 ; CMPI32_R15 %0
|
4981FF 00000000 ; cmp_r15, %0
|
||||||
0F84 %First_pass_1 ; JE32 %First_pass_1
|
0F84 %First_pass_1 ; je %First_pass_1
|
||||||
4981C5 01000000 ; ADDI32_to_R13 %1 # Increment IP
|
4981C5 01000000 ; add_r13, %1 # Increment IP
|
||||||
|
|
||||||
:First_pass_1
|
:First_pass_1
|
||||||
49F7D7 ; NOT_R15
|
49F7D7 ; not_r15
|
||||||
E9 %First_pass ; JMP32 %First_pass
|
E9 %First_pass ; jmp %First_pass
|
||||||
|
|
||||||
:First_pass_pointer
|
:First_pass_pointer
|
||||||
# Deal with Pointer to label
|
# Deal with Pointer to label
|
||||||
E8 %Read_byte ; CALLI32 %Read_byte # Drop the char
|
E8 %Read_byte ; call %Read_byte # Drop the char
|
||||||
4981C5 04000000 ; ADDI32_to_R13 %4 # Increment IP
|
4981C5 04000000 ; add_r13, %4 # Increment IP
|
||||||
E9 %First_pass ; JMP32 %First_pass # Loop again
|
E9 %First_pass ; jmp %First_pass # Loop again
|
||||||
|
|
||||||
:First_pass_done
|
:First_pass_done
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
:hex
|
:hex
|
||||||
# deal with EOF
|
# deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 %EOF ; JE32 %EOF
|
0F84 %EOF ; je %EOF
|
||||||
# deal with line comments starting with #
|
# deal with line comments starting with #
|
||||||
483D 23000000 ; CMPI32_RAX %0x23
|
483D 23000000 ; cmp_rax, %0x23
|
||||||
0F84 %ascii_comment ; JE32 %ascii_comment
|
0F84 %ascii_comment ; je %ascii_comment
|
||||||
# deal with line comments starting with ;
|
# deal with line comments starting with ;
|
||||||
483D 3B000000 ; CMPI32_RAX %0x3b
|
483D 3B000000 ; cmp_rax, %0x3b
|
||||||
0F84 %ascii_comment ; JE32 %ascii_comment
|
0F84 %ascii_comment ; je %ascii_comment
|
||||||
# deal all ascii less than 0
|
# deal all ascii less than 0
|
||||||
483D 30000000 ; CMPI32_RAX %0x30
|
483D 30000000 ; cmp_rax, %0x30
|
||||||
0F8C %ascii_other ; JL32 %ascii_other
|
0F8C %ascii_other ; jl %ascii_other
|
||||||
# deal with 0-9
|
# deal with 0-9
|
||||||
483D 3A000000 ; CMPI32_RAX %0x3a
|
483D 3A000000 ; cmp_rax, %0x3a
|
||||||
0F8C %ascii_num ; JL32 %ascii_num
|
0F8C %ascii_num ; jl %ascii_num
|
||||||
# deal with all ascii less than A
|
# deal with all ascii less than A
|
||||||
483D 41000000 ; CMPI32_RAX %0x41
|
483D 41000000 ; cmp_rax, %0x41
|
||||||
0F8C %ascii_other ; JL32 %ascii_other
|
0F8C %ascii_other ; jl %ascii_other
|
||||||
# deal with A-F
|
# deal with A-F
|
||||||
483D 47000000 ; CMPI32_RAX %0x47
|
483D 47000000 ; cmp_rax, %0x47
|
||||||
0F8C %ascii_high ; JL32 %ascii_high
|
0F8C %ascii_high ; jl %ascii_high
|
||||||
# deal with all ascii less than a
|
# deal with all ascii less than a
|
||||||
483D 61000000 ; CMPI32_RAX %0x61
|
483D 61000000 ; cmp_rax, %0x61
|
||||||
0F8C %ascii_other ; JL32 %ascii_other
|
0F8C %ascii_other ; jl %ascii_other
|
||||||
# deal with a-f
|
# deal with a-f
|
||||||
483D 67000000 ; CMPI32_RAX %0x67
|
483D 67000000 ; cmp_rax, %0x67
|
||||||
0F8C %ascii_low ; JL32 %ascii_low
|
0F8C %ascii_low ; jl %ascii_low
|
||||||
# The rest that remains needs to be ignored
|
# The rest that remains needs to be ignored
|
||||||
E9 %ascii_other ; JMP32 %ascii_other
|
E9 %ascii_other ; jmp %ascii_other
|
||||||
|
|
||||||
:Second_pass
|
:Second_pass
|
||||||
E8 %Read_byte ; CALLI32 %Read_byte
|
E8 %Read_byte ; call %Read_byte
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 %Second_pass_done ; JE32 %Second_pass_done
|
0F84 %Second_pass_done ; je %Second_pass_done
|
||||||
|
|
||||||
# Simply drop the label
|
# Simply drop the label
|
||||||
483D 3A000000 ; CMPI32_RAX %0x3a
|
483D 3A000000 ; cmp_rax, %0x3a
|
||||||
0F85 %Second_pass_0 ; JNE32 %Second_pass_0
|
0F85 %Second_pass_0 ; jne %Second_pass_0
|
||||||
|
|
||||||
E8 %Read_byte ; CALLI32 %Read_byte
|
E8 %Read_byte ; call %Read_byte
|
||||||
E9 %Second_pass ; JMP32 %Second_pass
|
E9 %Second_pass ; jmp %Second_pass
|
||||||
|
|
||||||
:Second_pass_0
|
:Second_pass_0
|
||||||
# Deal with % pointer
|
# Deal with % pointer
|
||||||
483D 25000000 ; CMPI32_RAX %0x25
|
483D 25000000 ; cmp_rax, %0x25
|
||||||
0F85 %Second_pass_1 ; JNE32 %Second_pass_1
|
0F85 %Second_pass_1 ; jne %Second_pass_1
|
||||||
|
|
||||||
E8 %StorePointer ; CALLI32 %StorePointer
|
E8 %StorePointer ; call %StorePointer
|
||||||
E9 %Second_pass ; JMP32 %Second_pass
|
E9 %Second_pass ; jmp %Second_pass
|
||||||
|
|
||||||
:Second_pass_1
|
:Second_pass_1
|
||||||
# Deal with everything else
|
# Deal with everything else
|
||||||
E8 %hex ; CALLI32 %hex # Process our char
|
E8 %hex ; call %hex # Process our char
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 %Second_pass_done ; JE32 %Second_pass_done
|
0F84 %Second_pass_done ; je %Second_pass_done
|
||||||
|
|
||||||
# deal with -1 values
|
# deal with -1 values
|
||||||
483D 00000000 ; CMPI32_RAX %0
|
483D 00000000 ; cmp_rax, %0
|
||||||
0F8C %Second_pass ; JL32 %Second_pass
|
0F8C %Second_pass ; jl %Second_pass
|
||||||
|
|
||||||
# deal with toggle
|
# deal with toggle
|
||||||
4981FF 00000000 ; CMPI32_R15 %0
|
4981FF 00000000 ; cmp_r15, %0
|
||||||
0F84 %print ; JE32 %print
|
0F84 %print ; je %print
|
||||||
|
|
||||||
# process first byte of pair
|
# process first byte of pair
|
||||||
4989C6 ; COPY_RAX_to_R14
|
4989C6 ; mov_r14,rax
|
||||||
49C7C7 00000000 ; LOADI32_R15 %0
|
49C7C7 00000000 ; mov_r15, %0
|
||||||
E9 %Second_pass ; JMP32 %Second_pass
|
E9 %Second_pass ; jmp %Second_pass
|
||||||
|
|
||||||
:Second_pass_done
|
:Second_pass_done
|
||||||
C3 ; RET
|
|
||||||
|
|
||||||
:EOF
|
:EOF
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
:ascii_num
|
:ascii_num
|
||||||
4883E8 30 ; SUBI8_from_RAX !0x30
|
4883E8 30 ; sub_rax, !0x30
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
:ascii_low
|
:ascii_low
|
||||||
4883E8 57 ; SUBI8_from_RAX !0x57
|
4883E8 57 ; sub_rax, !0x57
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
:ascii_high
|
:ascii_high
|
||||||
4883E8 37 ; SUBI8_from_RAX !0x37
|
4883E8 37 ; sub_rax, !0x37
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
:ascii_other
|
:ascii_other
|
||||||
48C7C0 FFFFFFFF ; LOADI32_RAX %-1
|
48C7C0 FFFFFFFF ; mov_rax, %-1
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
:ascii_comment
|
:ascii_comment
|
||||||
E8 %Read_byte ; CALLI32 %Read_byte
|
E8 %Read_byte ; call %Read_byte
|
||||||
483D 0D000000 ; CMPI32_RAX %0xd
|
483D 0D000000 ; cmp_rax, %0xd
|
||||||
0F84 %ascii_comment_cr ; JE32 %ascii_comment_cr
|
0F84 %ascii_comment_cr ; je %ascii_comment_cr
|
||||||
483D 0A000000 ; CMPI32_RAX %0xa
|
483D 0A000000 ; cmp_rax, %0xa
|
||||||
0F85 %ascii_comment ; JNE32 %ascii_comment
|
0F85 %ascii_comment ; jne %ascii_comment
|
||||||
:ascii_comment_cr
|
:ascii_comment_cr
|
||||||
48C7C0 FFFFFFFF ; LOADI32_RAX %-1
|
48C7C0 FFFFFFFF ; mov_rax, %-1
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# process second byte of pair
|
# process second byte of pair
|
||||||
:print
|
:print
|
||||||
# update the sum and store in output
|
# update the sum and store in output
|
||||||
49C1E6 04 ; SHL8_R14 !4
|
49C1E6 04 ; shl_r14, !4
|
||||||
4C01F0 ; ADD_R14_to_RAX
|
4C01F0 ; add_rax,r14
|
||||||
|
|
||||||
# flip the toggle
|
# flip the toggle
|
||||||
49F7D7 ; NOT_R15 # R15 = -1
|
49F7D7 ; not_r15 # R15 = -1
|
||||||
|
|
||||||
48C7C2 01000000 ; LOADI32_RDX %1 # set the size of chars we want
|
48C7C2 01000000 ; mov_rdx, %1 # set the size of chars we want
|
||||||
E8 %print_chars ; CALLI32 %print_chars
|
E8 %print_chars ; call %print_chars
|
||||||
|
|
||||||
4981C5 01000000 ; ADDI32_to_R13 %1 # Increment IP
|
4981C5 01000000 ; add_r13, %1 # Increment IP
|
||||||
E9 %Second_pass ; JMP32 %Second_pass
|
E9 %Second_pass ; jmp %Second_pass
|
||||||
|
|
||||||
|
|
||||||
:Read_byte
|
:Read_byte
|
||||||
4889F9 ; COPY_RDI_to_RCX # arg1 = fin
|
4889F9 ; mov_rcx,rdi # arg1 = fin
|
||||||
6A 01 ; PUSH !1 # size = 1
|
6A 01 ; push !1 # size = 1
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
4889E2 ; mov_rdx,rsp # arg2 = &size
|
||||||
56 ; PUSH_RSI # allocate stack
|
31F6 ; xor_esi,esi # zero rsi
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &input
|
56 ; push_rsi # allocate stack
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
4989E0 ; mov_r8,rsp # arg3 = &input
|
||||||
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 20 ; CALL_RCX_Immediate8 !32 # fin->read()
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
58 ; POP_RAX # deallocate stack
|
FF51 20 ; call_[rcx+BYTE] !32 # fin->read()
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; POP_RAX # save input to rax
|
58 ; pop_rax # deallocate stack
|
||||||
5E ; POP_RSI # save size to rsi
|
58 ; pop_rax # save input to rax
|
||||||
|
5E ; pop_rsi # save size to rsi
|
||||||
|
|
||||||
# If the file ended (0 bytes read) return EOF
|
# If the file ended (0 bytes read) return EOF
|
||||||
85F6 ; TEST_ESI_ESI # if size = 0
|
85F6 ; test_esi,esi # if size = 0
|
||||||
75 !Read_byte_1 ; JNE8 !Read_byte_1
|
75 !Read_byte_1 ; jne8 !Read_byte_1
|
||||||
48C7C0 FCFFFFFF ; LOADI32_RAX %-4 # Put EOF in rax
|
48C7C0 FCFFFFFF ; mov_rax, %-4 # Put EOF in rax
|
||||||
|
|
||||||
:Read_byte_1
|
:Read_byte_1
|
||||||
C3 ; RET # return
|
C3 ; ret # return
|
||||||
|
|
||||||
# Writes bytes stored in rax
|
# Writes bytes stored in rax
|
||||||
:print_chars
|
:print_chars
|
||||||
4889D9 ; COPY_RBX_to_RCX # arg1 = fout
|
4889D9 ; mov_rcx,rbx # 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
|
||||||
50 ; PUSH_RAX # allocate stack
|
50 ; push_rax # allocate stack
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &output
|
4989E0 ; mov_r8,rsp # arg3 = &output
|
||||||
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
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
FF51 28 ; CALL_RCX_Immediate8 !40 # fout->write()
|
FF51 28 ; call_[rcx+BYTE] !40 # fout->write()
|
||||||
4883C4 28 ; ADDI8_RSP !40 # deallocate stack
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
|
|
||||||
C3 ; RET # return
|
C3 ; ret # return
|
||||||
|
|
||||||
:Get_table_target
|
:Get_table_target
|
||||||
E8 %Read_byte ; CALLI32 %Read_byte # Get single char label
|
E8 %Read_byte ; call %Read_byte # Get single char label
|
||||||
48C1E0 03 ; SHL8_RAX !3 # Each label in table takes 8 bytes to store
|
48C1E0 03 ; shl_rax, !3 # Each label in table takes 8 bytes to store
|
||||||
488B0D %table ; LOAD64_rel_RCX %table # Get table
|
488B4C24 18 ; mov_rcx,[rsp+BYTE] !24 # Get table
|
||||||
4801C8 ; ADD_RCX_to_RAX # Calculate offset
|
4801C8 ; add_rax,rcx # Calculate offset
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
:StoreLabel
|
:StoreLabel
|
||||||
E8 %Get_table_target ; CALLI32 %Get_table_target
|
E8 %Get_table_target ; call %Get_table_target
|
||||||
4C8928 ; STORE32_R13_to_Address_in_RAX # Write out pointer to table
|
4C8928 ; mov_[rax],r13 # Write out pointer to table
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
:StorePointer
|
:StorePointer
|
||||||
4981C5 04000000 ; ADDI32_to_R13 %4 # Increment IP
|
4981C5 04000000 ; add_r13, %4 # Increment IP
|
||||||
E8 %Get_table_target ; CALLI32 %Get_table_target # Get address of pointer
|
E8 %Get_table_target ; call %Get_table_target # Get address of pointer
|
||||||
678B00 ; LOAD32_Address_in_RAX_into_RAX # Get pointer
|
488B00 ; mov_rax,[rax] # Get pointer
|
||||||
4C29E8 ; SUB_R13_from_RAX # target - ip
|
4C29E8 ; sub_rax,r13 # target - ip
|
||||||
48C7C2 04000000 ; LOADI32_RDX %4 # set the size of chars we want
|
48C7C2 04000000 ; mov_rdx, %4 # set the size of chars we want
|
||||||
E8 %print_chars ; CALLI32 %print_chars
|
E8 %print_chars ; call %print_chars
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
:Done
|
:Done
|
||||||
|
59 ; pop_rcx # restore table
|
||||||
|
5E ; pop_rsi # restore rootdir
|
||||||
|
415F ; pop_r15 # restore image_handle
|
||||||
|
415E ; pop_r14 # restore system->boot
|
||||||
|
415D ; pop_r13 # restore root_device
|
||||||
|
|
||||||
# Free pool
|
# Free pool
|
||||||
488B0D %table ; LOAD64_rel_RCX %table # arg1 = table
|
# arg1 = table
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
4C8B35 %SystemBoot ; LOAD64_rel_R14 %SystemBoot # get system->boot
|
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(table)
|
||||||
41FF56 48 ; CALL_R14_Immediate8 !72 # system->boot->free_pool(table)
|
|
||||||
|
|
||||||
4889F9 ; COPY_RDI_to_RCX # arg1 = fin
|
4889F9 ; mov_rcx,rdi # arg1 = fin
|
||||||
FF51 10 ; CALL_RCX_Immediate8 !16 # fin->close()
|
FF51 10 ; call_[rcx+BYTE] !16 # fin->close()
|
||||||
4889D9 ; COPY_RBX_to_RCX # arg1 = fout
|
4889D9 ; mov_rcx,rbx # arg1 = fout
|
||||||
FF51 10 ; CALL_RCX_Immediate8 !16 # fout->close()
|
FF51 10 ; call_[rcx+BYTE] !16 # fout->close()
|
||||||
|
4889F1 ; mov_rcx,rsi # arg1 = rootdir
|
||||||
|
FF51 10 ; call_[rcx+BYTE] !16 # rootdir->close()
|
||||||
|
|
||||||
4889EC ; COPY_RBP_to_RSP # restore stack
|
4D89F8 ; mov_r8,r15 # arg3 = image_handle
|
||||||
C3 ; RET # return to UEFI
|
488D15 %SIMPLE_FS_PROTOCOL ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
|
||||||
|
4C89E9 ; mov_rcx,r13 # arg1 = root_device
|
||||||
|
4D31C9 ; xor_r9,r9 # arg4 = NULL
|
||||||
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
|
41FF96 20010000 ; call_[r14+DWORD] %288 # system->boot->close_protocol(root_device, &guid, image_handle, 0)
|
||||||
|
|
||||||
|
4D89F8 ; mov_r8,r15 # arg3 = image_handle
|
||||||
|
488D15 %LOADED_IMAGE_PROTOCOL ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
|
4C89C1 ; mov_rcx,r8 # arg1 = image_handle
|
||||||
|
4D31C9 ; xor_r9,r9 # arg4 = NULL
|
||||||
|
41FF96 20010000 ; call_[r14+DWORD] %288 # system->boot->close_protocol(image_handle, &guid, image_handle, 0)
|
||||||
|
|
||||||
|
4889EC ; mov_rsp,rbp # restore stack
|
||||||
|
C3 ; ret # return to UEFI
|
||||||
|
|
||||||
|
|
||||||
# Protocol GUIDs
|
# Protocol GUIDs
|
||||||
|
@ -381,20 +394,12 @@
|
||||||
A1 31 1B 5B ; %0x5b1b31a1
|
A1 31 1B 5B ; %0x5b1b31a1
|
||||||
62 95 ; @0x9562
|
62 95 ; @0x9562
|
||||||
D2 11 ; @0x11d2
|
D2 11 ; @0x11d2
|
||||||
:LOADED_IMAGE_PROTOCOL_8
|
|
||||||
8E 3F 00 A0 C9 69 72 3B ; !0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
8E 3F 00 A0 C9 69 72 3B ; !0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||||
|
|
||||||
:SIMPLE_FS_PROTOCOL
|
:SIMPLE_FS_PROTOCOL
|
||||||
22 5B 4E 96 ; %0x0964e5b22
|
22 5B 4E 96 ; %0x0964e5b22
|
||||||
59 64 ; @0x6459
|
59 64 ; @0x6459
|
||||||
D2 11 ; @0x11d2
|
D2 11 ; @0x11d2
|
||||||
:SIMPLE_FS_PROTOCOL_8
|
|
||||||
8E 39 00 A0 C9 69 72 3B ; !0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
8E 39 00 A0 C9 69 72 3B ; !0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||||
|
|
||||||
:table
|
|
||||||
00000000 00000000
|
|
||||||
|
|
||||||
:SystemBoot
|
|
||||||
00000000 00000000
|
|
||||||
|
|
||||||
:PE32_end
|
:PE32_end
|
||||||
|
|
|
@ -63,6 +63,10 @@ DEFINE mov_al,[rsi] 8A06
|
||||||
DEFINE mov_bl,[rdi] 8A1F
|
DEFINE mov_bl,[rdi] 8A1F
|
||||||
DEFINE mov_rcx,[rbx] 488B0B
|
DEFINE mov_rcx,[rbx] 488B0B
|
||||||
DEFINE mov_rcx,[rcx] 488B09
|
DEFINE mov_rcx,[rcx] 488B09
|
||||||
|
DEFINE mov_[rax],r11 4C8918
|
||||||
|
DEFINE mov_[rbx], C603
|
||||||
|
DEFINE mov_[rbx],al 8803
|
||||||
|
DEFINE mov_[rbx],rcx 48890B
|
||||||
DEFINE mov_rax,[rcx+BYTE] 488B41
|
DEFINE mov_rax,[rcx+BYTE] 488B41
|
||||||
DEFINE mov_rbx,[rdi+BYTE] 488B5F
|
DEFINE mov_rbx,[rdi+BYTE] 488B5F
|
||||||
DEFINE mov_rcx,[rdi+BYTE] 488B4F
|
DEFINE mov_rcx,[rdi+BYTE] 488B4F
|
||||||
|
@ -80,10 +84,6 @@ DEFINE mov_[r11+BYTE],r12 4D8963
|
||||||
DEFINE mov_[rip+DWORD],rax 488905
|
DEFINE mov_[rip+DWORD],rax 488905
|
||||||
DEFINE mov_[rip+DWORD],rcx 48890D
|
DEFINE mov_[rip+DWORD],rcx 48890D
|
||||||
DEFINE mov_[rip+DWORD],r14 4C8935
|
DEFINE mov_[rip+DWORD],r14 4C8935
|
||||||
DEFINE mov_[rax],r11 4C8918
|
|
||||||
DEFINE mov_[rbx], C603
|
|
||||||
DEFINE mov_[rbx],al 8803
|
|
||||||
DEFINE mov_[rbx],rcx 48890B
|
|
||||||
DEFINE movzx_rax,al 480FB6C0
|
DEFINE movzx_rax,al 480FB6C0
|
||||||
DEFINE movzx_rbx,bl 480FB6DB
|
DEFINE movzx_rbx,bl 480FB6DB
|
||||||
DEFINE not_r15 49F7D7
|
DEFINE not_r15 49F7D7
|
||||||
|
|
|
@ -36,7 +36,7 @@ _start:
|
||||||
mov r9, [rip+image_handle] # arg4 = image_handle
|
mov r9, [rip+image_handle] # arg4 = image_handle
|
||||||
lea rdx, [rip+SIMPLE_FS_PROTOCOL] # guid = &SIMPLE_FS_PROTOCOL
|
lea rdx, [rip+SIMPLE_FS_PROTOCOL] # guid = &SIMPLE_FS_PROTOCOL
|
||||||
mov rcx, [rdi+24] # arg1 = root_device = image->device
|
mov rcx, [rdi+24] # arg1 = root_device = image->device
|
||||||
mov [rip+root_device], rdi # save root_device
|
mov [rip+root_device], rcx # save root_device
|
||||||
call open_protocol # open protocol
|
call open_protocol # open protocol
|
||||||
mov rcx, rax # get rootfs
|
mov rcx, rax # get rootfs
|
||||||
|
|
||||||
|
|
589
amd64/hex1.hex0
589
amd64/hex1.hex0
|
@ -120,9 +120,9 @@ F0 00 # SizeOfOptionalHeader
|
||||||
# [0x148]
|
# [0x148]
|
||||||
# Start of section headers
|
# Start of section headers
|
||||||
00 00 00 00 00 00 00 00 ; Name of the section (empty) but could set to ".text"
|
00 00 00 00 00 00 00 00 ; Name of the section (empty) but could set to ".text"
|
||||||
D4 03 00 00 ; VirtualSize
|
CF 03 00 00 ; VirtualSize
|
||||||
00 10 00 00 ; VirtualAddress
|
00 10 00 00 ; VirtualAddress
|
||||||
D4 03 00 00 ; SizeOfRawData
|
CF 03 00 00 ; SizeOfRawData
|
||||||
70 01 00 00 ; PointerToRawData
|
70 01 00 00 ; PointerToRawData
|
||||||
00 00 00 00 ; PointerToRelocations
|
00 00 00 00 ; PointerToRelocations
|
||||||
00 00 00 00 ; PointerToLinenumbers
|
00 00 00 00 ; PointerToLinenumbers
|
||||||
|
@ -134,396 +134,401 @@ D4 03 00 00 ; SizeOfRawData
|
||||||
|
|
||||||
# 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
|
||||||
4C8935 BB030000 ; STORE64_rel_R14 %SystemBoot # save system->boot
|
|
||||||
|
|
||||||
# Allocate pool for single-character label table
|
|
||||||
52 ; PUSH_RDX # allocate stack for table
|
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &table
|
|
||||||
31D2 ; XOR_EDX_EDX # zero rdx
|
|
||||||
B6 08 ; LOADI8_DH !0x8 # arg2 = 256 * 8 = 2048 = 0x800
|
|
||||||
6A 02 ; PUSH !2
|
|
||||||
59 ; POP_RCX # arg1 = EFI_LOADER_DATA
|
|
||||||
4883EC 18 ; SUBI8_RSP !24 # allocate shadow stack space for UEFI
|
|
||||||
41FF56 40 ; CALL_R14_Immediate8 !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
|
||||||
4883C4 18 ; ADDI8_RSP !24 # deallocate stack
|
|
||||||
58 ; POP_RAX # get table
|
|
||||||
488905 94030000 ; STORE64_rel_RAX %table # save table
|
|
||||||
|
|
||||||
# Open Loaded Image protocol
|
# Open Loaded Image protocol
|
||||||
50 ; PUSH_RAX # allocate stack for image
|
4D89F9 ; mov_r9,r15 # arg4 = image_handle
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &image
|
488D15 9B030000 ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
488B15 71030000 ; LOAD64_rel_RDX !LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
4C89C9 ; mov_rcx,r9 # arg1 = image_handle
|
||||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
50 ; push_rax # allocate stack for image
|
||||||
488B15 61030000 ; LOAD64_rel_RDX !LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
4989E0 ; mov_r8,rsp # arg3 = &image
|
||||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
6A 01 ; push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
6A 00 ; push !0 # arg5 = NULL
|
||||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
6A 00 ; PUSH !0 # arg5 = NULL
|
41FF96 18010000 ; call_[r14+DWORD] %280 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
488B7C24 30 ; mov_rdi,[rsp+BYTE] !48 # save image
|
||||||
4C89F9 ; COPY_R15_to_RCX # arg1 = image_handle
|
|
||||||
4883EC 20 ; SUBI8_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)
|
|
||||||
488B4424 40 ; LOAD64_into_RAX_from_Address_RSP_Immediate8 !64 # get_image
|
|
||||||
4889C1 ; COPY_RCX_to_RAX # save image
|
|
||||||
|
|
||||||
# Command line args
|
|
||||||
488B58 38 ; LOAD64_into_RBX_from_Address_RAX_Immediate8 !56 # options = image->load_options
|
|
||||||
|
|
||||||
# :loop_options1 [_start+0x68] # Skip application name
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
8A03 ; LOAD8_AL_from_Address_RBX # *options
|
|
||||||
3C 20 ; CMPI8_AL !0x20 # if *options != ' '
|
|
||||||
75 F6 ; JNE8 !loop_options1 # then jump
|
|
||||||
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
4989DC ; COPY_RBX_to_R12 # save input file
|
|
||||||
|
|
||||||
# :loop_options2 [_start+0x79] # Skip argv[1]
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
8A03 ; LOAD8_AL_from_Address_RBX # *options
|
|
||||||
3C 20 ; CMPI8_AL !0x20 # if *options != ' '
|
|
||||||
75 F6 ; JNE8 !loop_options2 # then jump
|
|
||||||
|
|
||||||
C603 00 ; STOREI8_into_Address_RBX !0 # *options = 0;
|
|
||||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
|
||||||
4989DD ; COPY_RBX_to_R13 # save output file
|
|
||||||
|
|
||||||
# Get root file system
|
# Get root file system
|
||||||
50 ; PUSH_RAX # allocate stack for rootfs
|
4D89F9 ; mov_r9,r15 # arg4 = image_handle
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &rootfs
|
488D15 86030000 ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
|
||||||
488B15 24030000 ; LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
488B4F 18 ; mov_rcx,[rdi+BYTE] !24 # arg1 = root_device = image->device
|
||||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
4989CD ; mov_r13,rcx # save root_device
|
||||||
488B15 14030000 ; LOAD64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
50 ; push_rax # allocate stack for rootfs
|
||||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
4989E0 ; mov_r8,rsp # arg3 = &rootfs
|
||||||
4889E2 ; COPY_RSP_to_RDX # 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
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
41FF96 18010000 ; call_[r14+DWORD] %280 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||||
488B49 18 ; LOAD64_into_RCX_from_Address_RCX_Immediate8 !24 # arg1 = root_device = image->device
|
488B4C24 30 ; mov_rcx,[rsp+BYTE] !48 # get rootfs
|
||||||
4883EC 20 ; SUBI8_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)
|
|
||||||
488B4C24 40 ; LOAD64_into_RCX_from_Address_RSP_Immediate8 !64 # get rootfs
|
|
||||||
|
|
||||||
# Get root directory
|
# Get root directory
|
||||||
52 ; PUSH_RDX # allocate stack for rootdir
|
50 ; push_rax # 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
|
||||||
415E ; POP_R14 # save rootdir
|
5E ; pop_rsi # save rootdir
|
||||||
|
|
||||||
|
# Push command line arguments onto stack
|
||||||
|
488B5F 38 ; mov_rbx,[rdi+BYTE] !56 # options = image->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
|
||||||
|
6A 00 ; push !0 # Save end of arguments (NULL) onto stack
|
||||||
|
# :loop_options
|
||||||
|
4839D3 ; cmp_rbx,rdx # Check if we are done
|
||||||
|
74 14 ; je8 !loop_options_done # We are done
|
||||||
|
4883EB 02 ; sub_rbx, !2 # --options
|
||||||
|
8A03 ; mov_al,[rbx] # *options
|
||||||
|
3C 20 ; cmp_al, !0x20 # if *options != ' '
|
||||||
|
75 F1 ; jne8 !loop_options # then continue looping
|
||||||
|
C603 00 ; mov_[rbx], !0 # zero it
|
||||||
|
4883C3 02 ; add_rbx, !2 # ++options
|
||||||
|
53 ; push_rbx # push another argument onto stack
|
||||||
|
EB E7 ; jmp8 !loop_options # next argument
|
||||||
|
# :loop_options_done
|
||||||
|
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
52 ; PUSH_RDX # allocate stack for fin
|
4158 ; pop_r8 # arg3 = in
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fin
|
52 ; push_rdx # allocate stack for fin
|
||||||
6A 01 ; PUSH !1 # arg5 = EFI_FILE_READ_ONLY
|
4889E2 ; mov_rdx,rsp # arg2 = &fin
|
||||||
6A 01 ; PUSH !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
6A 01 ; push !1 # arg5 = EFI_FILE_READ_ONLY
|
||||||
4159 ; POP_R9 # arg4 = EFI_FILE_MODE_READ
|
6A 01 ; push !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
||||||
4D89E0 ; COPY_R12_to_R8 # arg3 = in
|
4159 ; pop_r9 # arg4 = EFI_FILE_MODE_READ
|
||||||
4C89F1 ; COPY_R14_to_RCX # arg1 = rootdir
|
4889F1 ; mov_rcx,rsi # 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()
|
||||||
488B7C24 28 ; LOAD64_into_RDI_from_Address_RSP_Immediate8 !40 # get fin
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
|
5F ; pop_rdi # get fin
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
52 ; PUSH_RDX # allocate stack for fout
|
4158 ; pop_r8 # arg3 = out
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fout
|
52 ; push_rdx # allocate stack for fout
|
||||||
6A 00 ; PUSH !0 # arg5 = 0
|
4889E2 ; mov_rdx,rsp # arg2 = &fout
|
||||||
6A 07 ; PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
6A 00 ; push !0 # arg5 = 0
|
||||||
4159 ; POP_R9 # and then do right rotation by 1
|
6A 07 ; push !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||||
49D1C9 ; ROR_R9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
4159 ; pop_r9 # and then do right rotation by 1
|
||||||
4D89E8 ; COPY_R13_to_R8 # arg3 = out
|
49D1C9 ; ror_r9 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
||||||
4C89F1 ; COPY_R14_to_RCX # arg1 = rootdir
|
4889F1 ; mov_rcx,rsi # 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()
|
||||||
488B5C24 28 ; LOAD64_into_RBX_from_Address_RSP_Immediate8 !40 # get fout
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
|
5B ; pop_rbx # get fout
|
||||||
|
|
||||||
# [_start+0x107]
|
# Save variables that are needed for cleanup
|
||||||
49C7C7 FFFFFFFF ; LOADI32_R15 %-1 # Our flag for byte processing
|
4155 ; push_r13 # save root_device
|
||||||
49C7C6 00000000 ; LOADI32_R14 %0 # temp storage for the sum
|
4156 ; push_r14 # save system->boot
|
||||||
49C7C5 00000000 ; LOADI32_R13 %0 # Our starting IP
|
4157 ; push_r15 # save image_handle
|
||||||
E8 2B000000 ; CALLI32 %First_pass # Process it
|
56 ; push_rsi # save rootdir
|
||||||
|
|
||||||
|
# Allocate pool for single-character label table
|
||||||
|
# pointer to table will be stored at the top of the stack
|
||||||
|
52 ; push_rdx # allocate stack for table
|
||||||
|
4989E0 ; mov_r8,rsp # arg3 = &table
|
||||||
|
31D2 ; xor_edx,edx # zero rdx
|
||||||
|
B6 08 ; mov_dh, !0x8 # arg2 = 256 * 8 = 2048 = 0x800
|
||||||
|
6A 02 ; push !2
|
||||||
|
59 ; pop_rcx # arg1 = EFI_LOADER_DATA
|
||||||
|
4883EC 18 ; sub_rsp, !24 # allocate shadow stack space for UEFI
|
||||||
|
41FF56 40 ; call_[r14+BYTE] !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &table)
|
||||||
|
4883C4 18 ; add_rsp, !24 # deallocate stack
|
||||||
|
|
||||||
|
# [_start+0xe1]
|
||||||
|
49C7C7 FFFFFFFF ; mov_r15, %-1 # Our flag for byte processing
|
||||||
|
49C7C6 00000000 ; mov_r14, %0 # temp storage for the sum
|
||||||
|
49C7C5 00000000 ; mov_r13, %0 # Our starting IP
|
||||||
|
E8 2B000000 ; call %First_pass # Process it
|
||||||
|
|
||||||
# rewind input file
|
# rewind input file
|
||||||
4889F9 ; COPY_RDI_to_RCX # Using our input file
|
4889F9 ; mov_rcx,rdi # Using our input file
|
||||||
31D2 ; XOR_EDX_EDX # Offset Zero
|
31D2 ; xor_edx,edx # Offset Zero
|
||||||
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 38 ; CALL_RCX_Immediate8 !56 # fin->set_position(fin, 0)
|
FF51 38 ; call_[rcx+BYTE] !56 # fin->set_position(fin, 0)
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
|
|
||||||
49C7C7 FFFFFFFF ; LOADI32_R15 %-1 # Our flag for byte processing
|
49C7C7 FFFFFFFF ; mov_r15, %-1 # Our flag for byte processing
|
||||||
49C7C6 00000000 ; LOADI32_R14 %0 # temp storage for the sum
|
49C7C6 00000000 ; mov_r14, %0 # temp storage for the sum
|
||||||
49C7C5 00000000 ; LOADI32_R13 %0 # Our starting IP
|
49C7C5 00000000 ; mov_r13, %0 # Our starting IP
|
||||||
E8 EF000000 ; CALLI32 %Second_pass # Process it
|
E8 EF000000 ; call %Second_pass # Process it
|
||||||
|
|
||||||
E9 35020000 ; JMP32 %Done
|
E9 34020000 ; jmp %Done
|
||||||
|
|
||||||
# :First_pass [_start+0x14C]
|
# :First_pass [_start+0x126]
|
||||||
E8 BB010000 ; CALLI32 %Read_byte
|
E8 BA010000 ; call %Read_byte
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 67000000 ; JE32 %First_pass_done
|
0F84 67000000 ; je %First_pass_done
|
||||||
|
|
||||||
# Check for :
|
# Check for :
|
||||||
483D 3A000000 ; CMPI32_RAX %0x3a
|
483D 3A000000 ; cmp_rax, %0x3a
|
||||||
0F85 05000000 ; JNE32 %First_pass_0
|
0F85 05000000 ; jne %First_pass_0
|
||||||
|
|
||||||
# Deal with label
|
# Deal with label
|
||||||
E8 EB010000 ; CALLI32 %StoreLabel
|
E8 EA010000 ; call %StoreLabel
|
||||||
|
|
||||||
# :First_pass_0 [_start+0x16E]
|
# :First_pass_0 [_start+0x148]
|
||||||
# Check for %
|
# Check for %
|
||||||
483D 25000000 ; CMPI32_RAX %0x25
|
483D 25000000 ; cmp_rax, %0x25
|
||||||
0F84 39000000 ; JE32 %First_pass_pointer
|
0F84 39000000 ; je %First_pass_pointer
|
||||||
|
|
||||||
# Deal with everything else
|
# Deal with everything else
|
||||||
E8 46000000 ; CALLI32 %hex # Process our char
|
E8 46000000 ; call %hex # Process our char
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 39000000 ; JE32 %First_pass_done
|
0F84 39000000 ; je %First_pass_done
|
||||||
|
|
||||||
# deal with -1 values
|
# deal with -1 values
|
||||||
483D 00000000 ; CMPI32_RAX %0
|
483D 00000000 ; cmp_rax, %0
|
||||||
0F8C B5FFFFFF ; JL32 %First_pass
|
0F8C B5FFFFFF ; jl %First_pass
|
||||||
|
|
||||||
# deal with toggle
|
# deal with toggle
|
||||||
4981FF 00000000 ; CMPI32_R15 %0
|
4981FF 00000000 ; cmp_r15, %0
|
||||||
0F84 07000000 ; JE32 %First_pass_1
|
0F84 07000000 ; je %First_pass_1
|
||||||
4981C5 01000000 ; ADDI32_to_R13 %1 # Increment IP
|
4981C5 01000000 ; add_r13, %1 # Increment IP
|
||||||
|
|
||||||
# :First_pass_1 [_start+0xAB]
|
# :First_pass_1 [_start+0x185]
|
||||||
49F7D7 ; NOT_R15
|
49F7D7 ; not_r15
|
||||||
E9 99FFFFFF ; JMP32 %First_pass
|
E9 99FFFFFF ; jmp %First_pass
|
||||||
|
|
||||||
# :First_pass_pointer [_start+0x1B3]
|
# :First_pass_pointer [_start+0x18D]
|
||||||
# Deal with Pointer to label
|
# Deal with Pointer to label
|
||||||
E8 54010000 ; CALLI32 %Read_byte # Drop the char
|
E8 53010000 ; call %Read_byte # Drop the char
|
||||||
4981C5 04000000 ; ADDI32_to_R13 %4 # Increment IP
|
4981C5 04000000 ; add_r13, %4 # Increment IP
|
||||||
E9 88FFFFFF ; JMP32 %First_pass # Loop again
|
E9 88FFFFFF ; jmp %First_pass # Loop again
|
||||||
|
|
||||||
# :First_pass_done [_start+0x1C4]
|
# :First_pass_done [_start+0x19E]
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# :hex [_start+0x1C5]
|
# :hex [_start+0x19F]
|
||||||
# deal with EOF
|
# deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 DC000000 ; JE32 %EOF
|
0F84 DB000000 ; je %EOF
|
||||||
# deal with line comments starting with #
|
# deal with line comments starting with #
|
||||||
483D 23000000 ; CMPI32_RAX %0x23
|
483D 23000000 ; cmp_rax, %0x23
|
||||||
0F84 E8000000 ; JE32 %ascii_comment
|
0F84 E7000000 ; je %ascii_comment
|
||||||
# deal with line comments starting with ;
|
# deal with line comments starting with ;
|
||||||
483D 3B000000 ; CMPI32_RAX %0x3b
|
483D 3B000000 ; cmp_rax, %0x3b
|
||||||
0F84 DC000000 ; JE32 %ascii_comment
|
0F84 DB000000 ; je %ascii_comment
|
||||||
# deal all ascii less than 0
|
# deal all ascii less than 0
|
||||||
483D 30000000 ; CMPI32_RAX %0x30
|
483D 30000000 ; cmp_rax, %0x30
|
||||||
0F8C C8000000 ; JL32 %ascii_other
|
0F8C C7000000 ; jl %ascii_other
|
||||||
# deal with 0-9
|
# deal with 0-9
|
||||||
483D 3A000000 ; CMPI32_RAX %0x3a
|
483D 3A000000 ; cmp_rax, %0x3a
|
||||||
0F8C AD000000 ; JL32 %ascii_num
|
0F8C AC000000 ; jl %ascii_num
|
||||||
# deal with all ascii less than A
|
# deal with all ascii less than A
|
||||||
483D 41000000 ; CMPI32_RAX %0x41
|
483D 41000000 ; cmp_rax, %0x41
|
||||||
0F8C B0000000 ; JL32 %ascii_other
|
0F8C AF000000 ; jl %ascii_other
|
||||||
# deal with A-F
|
# deal with A-F
|
||||||
483D 47000000 ; CMPI32_RAX %0x47
|
483D 47000000 ; cmp_rax, %0x47
|
||||||
0F8C 9F000000 ; JL32 %ascii_high
|
0F8C 9E000000 ; jl %ascii_high
|
||||||
# deal with all ascii less than a
|
# deal with all ascii less than a
|
||||||
483D 61000000 ; CMPI32_RAX %0x61
|
483D 61000000 ; cmp_rax, %0x61
|
||||||
0F8C 98000000 ; JL32 %ascii_other
|
0F8C 97000000 ; jl %ascii_other
|
||||||
# deal with a-f
|
# deal with a-f
|
||||||
483D 67000000 ; CMPI32_RAX %0x67
|
483D 67000000 ; cmp_rax, %0x67
|
||||||
0F8C 82000000 ; JL32 %ascii_low
|
0F8C 81000000 ; jl %ascii_low
|
||||||
# The rest that remains needs to be ignored
|
# The rest that remains needs to be ignored
|
||||||
E9 87000000 ; JMP32 %ascii_other
|
E9 86000000 ; jmp %ascii_other
|
||||||
|
|
||||||
# :Second_pass [_start+0x236]
|
# :Second_pass [_start+0x210]
|
||||||
E8 D1000000 ; CALLI32 %Read_byte
|
E8 D0000000 ; call %Read_byte
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 65000000 ; JE32 %Second_pass_done
|
0F84 65000000 ; je %Second_pass_done
|
||||||
|
|
||||||
# Simply drop the label
|
# Simply drop the label
|
||||||
483D 3A000000 ; CMPI32_RAX %0x3a
|
483D 3A000000 ; cmp_rax, %0x3a
|
||||||
0F85 0A000000 ; JNE32 %Second_pass_0
|
0F85 0A000000 ; jne %Second_pass_0
|
||||||
|
|
||||||
E8 B4000000 ; CALLI32 %Read_byte
|
E8 B3000000 ; call %Read_byte
|
||||||
E9 D9FFFFFF ; JMP32 %Second_pass
|
E9 D9FFFFFF ; jmp %Second_pass
|
||||||
|
|
||||||
# :Second_pass_0 [_start+0x25D]
|
# :Second_pass_0 [_start+0x237]
|
||||||
# Deal with % pointer
|
# Deal with % pointer
|
||||||
483D 25000000 ; CMPI32_RAX %0x25
|
483D 25000000 ; cmp_rax, %0x25
|
||||||
0F85 0A000000 ; JNE32 %Second_pass_1
|
0F85 0A000000 ; jne %Second_pass_1
|
||||||
|
|
||||||
E8 F4000000 ; CALLI32 %StorePointer
|
E8 F3000000 ; call %StorePointer
|
||||||
E9 C3FFFFFF ; JMP32 %Second_pass
|
E9 C3FFFFFF ; jmp %Second_pass
|
||||||
|
|
||||||
# :Second_pass_1 [_start+0x273]
|
# :Second_pass_1 [_start+0x24D]
|
||||||
# Deal with everything else
|
# Deal with everything else
|
||||||
E8 4DFFFFFF ; CALLI32 %hex # Process our char
|
E8 4DFFFFFF ; call %hex # Process our char
|
||||||
|
|
||||||
# Deal with EOF
|
# Deal with EOF
|
||||||
483D FCFFFFFF ; CMPI32_RAX %-4
|
483D FCFFFFFF ; cmp_rax, %-4
|
||||||
0F84 28000000 ; JE32 %Second_pass_done
|
0F84 28000000 ; je %Second_pass_done
|
||||||
|
|
||||||
# deal with -1 values
|
# deal with -1 values
|
||||||
483D 00000000 ; CMPI32_RAX %0
|
483D 00000000 ; cmp_rax, %0
|
||||||
0F8C A6FFFFFF ; JL32 %Second_pass
|
0F8C A6FFFFFF ; jl %Second_pass
|
||||||
|
|
||||||
# deal with toggle
|
# deal with toggle
|
||||||
4981FF 00000000 ; CMPI32_R15 %0
|
4981FF 00000000 ; cmp_r15, %0
|
||||||
0F84 4D000000 ; JE32 %print
|
0F84 4C000000 ; je %print
|
||||||
|
|
||||||
# process first byte of pair
|
# process first byte of pair
|
||||||
4989C6 ; COPY_RAX_to_R14
|
4989C6 ; mov_r14,rax
|
||||||
49C7C7 00000000 ; LOADI32_R15 %0
|
49C7C7 00000000 ; mov_r15, %0
|
||||||
E9 8AFFFFFF ; JMP32 %Second_pass
|
E9 8AFFFFFF ; JMP32 %Second_pass
|
||||||
|
|
||||||
# :Second_pass_done [_start+0x2AC]
|
# :Second_pass_done [_start+0x286]
|
||||||
C3 ; RET
|
# :EOF
|
||||||
|
C3 ; ret
|
||||||
# :EOF [_start+0x2AD]
|
# :ascii_num [_start+0x287]
|
||||||
C3 ; RET
|
4883E8 30 ; sub_rax, !0x30
|
||||||
# :ascii_num [_start+0x2AE]
|
C3 ; ret
|
||||||
4883E8 30 ; SUBI8_from_RAX !0x30
|
# :ascii_low [_start+0x28C]
|
||||||
C3 ; RET
|
4883E8 57 ; sub_rax, !0x57
|
||||||
# :ascii_low [_start+0x2B3]
|
C3 ; ret
|
||||||
4883E8 57 ; SUBI8_from_RAX !0x57
|
# :ascii_high [_start+0x291]
|
||||||
C3 ; RET
|
4883E8 37 ; sub_rax, !0x37
|
||||||
# :ascii_high [_start+0x2B8]
|
C3 ; ret
|
||||||
4883E8 37 ; SUBI8_from_RAX !0x37
|
# :ascii_other [_start+0x296]
|
||||||
C3 ; RET
|
48C7C0 FFFFFFFF ; mov_rax, %-1
|
||||||
# :ascii_other [_start+0x2BD]
|
C3 ; ret
|
||||||
48C7C0 FFFFFFFF ; LOADI32_RAX %-1
|
# :ascii_comment [_start+0x29E]
|
||||||
C3 ; RET
|
E8 42000000 ; call %Read_byte
|
||||||
# :ascii_comment [_start+0x2C5]
|
483D 0D000000 ; cmp_rax, %0xd
|
||||||
E8 42000000 ; CALLI32 %Read_byte
|
0F84 0C000000 ; je %ascii_comment_cr
|
||||||
483D 0D000000 ; CMPI32_RAX %0xd
|
483D 0A000000 ; cmp_rax, %0xa
|
||||||
0F84 0C000000 ; JE32 %ascii_comment_cr
|
0F85 E3FFFFFF ; jne %ascii_comment
|
||||||
483D 0A000000 ; CMPI32_RAX %0xa
|
# :ascii_comment_cr [_start+0x2BB]
|
||||||
0F85 E3FFFFFF ; JNE32 %ascii_comment
|
48C7C0 FFFFFFFF ; mov_rax, %-1
|
||||||
# :ascii_comment_cr [_start+0x2E2]
|
C3 ; ret
|
||||||
48C7C0 FFFFFFFF ; LOADI32_RAX %-1
|
|
||||||
C3 ; RET
|
|
||||||
|
|
||||||
# process second byte of pair
|
# process second byte of pair
|
||||||
# :print [_start+0x2EA]
|
# :print [_start+0x2C3]
|
||||||
# update the sum and store in output
|
# update the sum and store in output
|
||||||
49C1E6 04 ; SHL8_R14 !4
|
49C1E6 04 ; shl_r14, !4
|
||||||
4C01F0 ; ADD_R14_to_RAX
|
4C01F0 ; add_rax,r14
|
||||||
|
|
||||||
# flip the toggle
|
# flip the toggle
|
||||||
49F7D7 ; NOT_R15 # R15 = -1
|
49F7D7 ; not_r15 # R15 = -1
|
||||||
|
|
||||||
48C7C2 01000000 ; LOADI32_RDX %1 # set the size of chars we want
|
48C7C2 01000000 ; mov_rdx, %1 # set the size of chars we want
|
||||||
E8 2F000000 ; CALLI32 %print_chars
|
E8 31000000 ; call %print_chars
|
||||||
|
|
||||||
4981C5 01000000 ; ADDI32_to_R13 %1 # Increment IP
|
4981C5 01000000 ; add_r13, %1 # Increment IP
|
||||||
E9 2AFFFFFF ; JMP32 %Second_pass
|
E9 2BFFFFFF ; jmp %Second_pass
|
||||||
|
|
||||||
|
|
||||||
# :Read_byte [_start+0x30C]
|
# :Read_byte [_start+0x2E5]
|
||||||
4889F9 ; COPY_RDI_to_RCX # arg1 = fin
|
4889F9 ; mov_rcx,rdi # arg1 = fin
|
||||||
6A 01 ; PUSH !1 # size = 1
|
6A 01 ; push !1 # size = 1
|
||||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
4889E2 ; mov_rdx,rsp # arg2 = &size
|
||||||
56 ; PUSH_RSI # allocate stack
|
31F6 ; xor_esi,esi # zero rsi
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &input
|
56 ; push_rsi # allocate stack
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
4989E0 ; mov_r8,rsp # arg3 = &input
|
||||||
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 20 ; CALL_RCX_Immediate8 !32 # fin->read()
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
58 ; POP_RAX # deallocate stack
|
FF51 20 ; call_[rcx+BYTE] !32 # fin->read()
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; POP_RAX # deallocate stack
|
58 ; pop_rax # deallocate stack
|
||||||
58 ; POP_RAX # save input to rax
|
58 ; pop_rax # deallocate stack
|
||||||
5E ; POP_RSI # save size to rsi
|
58 ; pop_rax # save input to rax
|
||||||
|
5E ; pop_rsi # save size to rsi
|
||||||
|
|
||||||
# If the file ended (0 bytes read) return EOF
|
# If the file ended (0 bytes read) return EOF
|
||||||
85F6 ; TEST_ESI_ESI # if size = 0
|
85F6 ; test_esi,esi # if size = 0
|
||||||
75 07 ; JNE8 !Read_byte_1
|
75 07 ; jne8 !Read_byte_1
|
||||||
48C7C0 FCFFFFFF ; LOADI32_RAX %-4 # Put EOF in rax
|
48C7C0 FCFFFFFF ; mov_rax, %-4 # Put EOF in rax
|
||||||
|
|
||||||
# :Read_byte_1 [_start+0x32E]
|
# :Read_byte_1 [_start+0x309]
|
||||||
C3 ; RET # return
|
C3 ; ret # return
|
||||||
|
|
||||||
# Writes bytes stored in rax
|
# Writes bytes stored in rax
|
||||||
# :print_chars [_start+0x32F]
|
# :print_chars [_start+0x30A]
|
||||||
4889D9 ; COPY_RBX_to_RCX # arg1 = fout
|
4889D9 ; mov_rcx,rbx # 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
|
||||||
50 ; PUSH_RAX # allocate stack
|
50 ; push_rax # allocate stack
|
||||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &output
|
4989E0 ; mov_r8,rsp # arg3 = &output
|
||||||
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
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
FF51 28 ; CALL_RCX_Immediate8 !40 # fout->write()
|
FF51 28 ; call_[rcx+BYTE] !40 # fout->write()
|
||||||
4883C4 28 ; ADDI8_RSP !40 # deallocate stack
|
4883C4 28 ; add_rsp, !40 # deallocate stack
|
||||||
|
|
||||||
C3 ; RET # return
|
C3 ; ret # return
|
||||||
|
|
||||||
# :Get_table_target [_start+0x345]
|
# :Get_table_target [_start+0x320]
|
||||||
E8 C2FFFFFF ; CALLI32 %Read_byte # Get single char label
|
E8 C0FFFFFF ; call %Read_byte # Get single char label
|
||||||
48C1E0 03 ; SHL8_RAX !3 # Each label in table takes 8 bytes to store
|
48C1E0 03 ; shl_rax, !3 # Each label in table takes 8 bytes to store
|
||||||
488B0D 6F000000 ; LOAD64_rel_RCX %table # Get table
|
488B4C24 18 ; mov_rcx,[rsp+BYTE] !24 # Get table
|
||||||
4801C8 ; ADD_RCX_to_RAX # Calculate offset
|
4801C8 ; add_rax,rcx # Calculate offset
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# :StoreLabel [_start+0x359]
|
# :StoreLabel [_start+0x332]
|
||||||
E8 E7FFFFFF ; CALLI32 %Get_table_target
|
E8 E9FFFFFF ; call %Get_table_target
|
||||||
4C8928 ; STORE32_R13_to_Address_in_RAX # Write out pointer to table
|
4C8928 ; mov_[rax],r13 # Write out pointer to table
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
# :StorePointer [_start+0x362]
|
# :StorePointer [_start+0x33B]
|
||||||
4981C5 04000000 ; ADDI32_to_R13 %4 # Increment IP
|
4981C5 04000000 ; add_r13, %4 # Increment IP
|
||||||
E8 D7FFFFFF ; CALLI32 %Get_table_target # Get address of pointer
|
E8 D9FFFFFF ; call %Get_table_target # Get address of pointer
|
||||||
678B00 ; LOAD32_Address_in_RAX_into_RAX # Get pointer
|
488B00 ; mov_rax,[rax] # Get pointer
|
||||||
4C29E8 ; SUB_R13_from_RAX # target - ip
|
4C29E8 ; sub_rax,r13 # target - ip
|
||||||
48C7C2 04000000 ; LOADI32_RDX %4 # set the size of chars we want
|
48C7C2 04000000 ; mov_rdx, %4 # set the size of chars we want
|
||||||
E8 AFFFFFFF ; CALLI32 %print_chars
|
E8 B1FFFFFF ; call %print_chars
|
||||||
C3 ; RET
|
C3 ; ret
|
||||||
|
|
||||||
|
# :Done [_start+0x35A]
|
||||||
|
59 ; pop_rcx # restore table
|
||||||
|
5E ; pop_rsi # restore rootdir
|
||||||
|
415F ; pop_r15 # restore image_handle
|
||||||
|
415E ; pop_r14 # restore system->boot
|
||||||
|
415D ; pop_r13 # restore root_device
|
||||||
|
|
||||||
# :Done [_start+0x381]
|
|
||||||
# Free pool
|
# Free pool
|
||||||
488B0D 3C000000 ; LOAD64_rel_RCX %table # arg1 = table
|
# arg1 = table
|
||||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
50 ; push_rax # allocate shadow stack space for UEFI function
|
||||||
4C8B35 3C000000 ; LOAD64_rel_R14 %SystemBoot # get system->boot
|
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(table)
|
||||||
41FF56 48 ; CALL_R14_Immediate8 !72 # system->boot->free_pool(table)
|
|
||||||
|
|
||||||
4889F9 ; COPY_RDI_to_RCX # arg1 = fin
|
4889F9 ; mov_rcx,rdi # arg1 = fin
|
||||||
FF51 10 ; CALL_RCX_Immediate8 !16 # fin->close()
|
FF51 10 ; call_[rcx+BYTE] !16 # fin->close()
|
||||||
4889D9 ; COPY_RBX_to_RCX # arg1 = fout
|
4889D9 ; mov_rcx,rbx # arg1 = fout
|
||||||
FF51 10 ; CALL_RCX_Immediate8 !16 # fout->close()
|
FF51 10 ; call_[rcx+BYTE] !16 # fout->close()
|
||||||
|
4889F1 ; mov_rcx,rsi # arg1 = rootdir
|
||||||
|
FF51 10 ; call_[rcx+BYTE] !16 # rootdir->close()
|
||||||
|
|
||||||
4889EC ; COPY_RBP_to_RSP # restore stack
|
4D89F8 ; mov_r8,r15 # arg3 = image_handle
|
||||||
C3 ; RET # return to UEFI
|
488D15 3C000000 ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
|
||||||
|
4C89E9 ; mov_rcx,r13 # arg1 = root_device
|
||||||
|
4D31C9 ; xor_r9,r9 # arg4 = NULL
|
||||||
|
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
|
||||||
|
41FF96 20010000 ; call_[r14+DWORD] %288 # system->boot->close_protocol(root_device, &guid, image_handle, 0)
|
||||||
|
|
||||||
|
4D89F8 ; mov_r8,r15 # arg3 = image_handle
|
||||||
|
488D15 11000000 ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
|
||||||
|
4C89C1 ; mov_rcx,r8 # arg1 = image_handle
|
||||||
|
4D31C9 ; xor_r9,r9 # arg4 = NULL
|
||||||
|
41FF96 20010000 ; call_[r14+DWORD] %288 # system->boot->close_protocol(image_handle, &guid, image_handle, 0)
|
||||||
|
|
||||||
|
4889EC ; mov_rsp,rbp # restore stack
|
||||||
|
C3 ; ret # return to UEFI
|
||||||
|
|
||||||
|
|
||||||
# Protocol GUIDs
|
# Protocol GUIDs
|
||||||
# :LOADED_IMAGE_PROTOCOL [_start+0x3A4]
|
# :LOADED_IMAGE_PROTOCOL [_start+0x3AF]
|
||||||
A1 31 1B 5B ; %0x5b1b31a1
|
A1 31 1B 5B ; %0x5b1b31a1
|
||||||
62 95 ; @0x9562
|
62 95 ; @0x9562
|
||||||
D2 11 ; @0x11d2
|
D2 11 ; @0x11d2
|
||||||
# :LOADED_IMAGE_PROTOCOL_8 [_start+0x3AC]
|
|
||||||
8E 3F 00 A0 C9 69 72 3B ; !0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
8E 3F 00 A0 C9 69 72 3B ; !0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||||
|
|
||||||
# :SIMPLE_FS_PROTOCOL [_start+0x3B4]
|
# :SIMPLE_FS_PROTOCOL [_start+0x3BF]
|
||||||
22 5B 4E 96 ; %0x0964e5b22
|
22 5B 4E 96 ; %0x0964e5b22
|
||||||
59 64 ; @0x6459
|
59 64 ; @0x6459
|
||||||
D2 11 ; @0x11d2
|
D2 11 ; @0x11d2
|
||||||
# :SIMPLE_FS_PROTOCOL_8 [_start+0x3BC]
|
|
||||||
8E 39 00 A0 C9 69 72 3B ; !0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
8E 39 00 A0 C9 69 72 3B ; !0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||||
|
|
||||||
# :table [_start+0x3C4]
|
# :PE32_end [_start+0x3CF]
|
||||||
00000000 00000000
|
|
||||||
|
|
||||||
# :SystemBoot [_start+0x3CC]
|
|
||||||
00000000 00000000
|
|
||||||
|
|
||||||
# :PE32_end [_start+0x3D4]
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ amd64\artifact\hex0.efi amd64\hex1.hex0 amd64\artifact\hex1.efi
|
||||||
#################################
|
#################################
|
||||||
# Phase-2 Build hex2 from hex1 #
|
# Phase-2 Build hex2 from hex1 #
|
||||||
#################################
|
#################################
|
||||||
amd64\artifact\hex1.efi amd64\hex2.hex1 amd64\artifact\hex2-0.efi
|
amd64\artifact\hex1.efi amd64\hex2.hex1 amd64\artifact\hex2-0.efi
|
||||||
# hex2 adds support for long labels and absolute addresses thus allowing it
|
# hex2 adds support for long labels and absolute addresses thus allowing it
|
||||||
# to function as an effective linker for later stages of the bootstrap
|
# to function as an effective linker for later stages of the bootstrap
|
||||||
# This is a minimal version which will be used to bootstrap a much more advanced
|
# This is a minimal version which will be used to bootstrap a much more advanced
|
||||||
|
|
Loading…
Reference in New Issue