Add hex1.M1 prototype.

This commit is contained in:
Andrius Štikonas 2022-08-07 23:15:34 +01:00
parent 368377191b
commit a4d36cc940
3 changed files with 513 additions and 65 deletions

View File

@ -24,69 +24,69 @@
# efi_main(void *image_handle, struct efi_system_table *system)
_start:
mov rbp, rsp # save stack pointer
mov r15, rcx # save image_handle
mov r14, [rdx+96] # system->boot
mov r14, [r14+280] # system->boot->open_protocol
mov rbp, rsp # save stack pointer
mov r15, rcx # save image_handle
mov r14, [rdx+96] # system->boot
mov r14, [r14+280] # system->boot->open_protocol
# 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)
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)
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
mov rdx, rsp # arg2 = &guid
push 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
push 0 # arg5 = NULL
mov r9, rcx # arg4 = image_handle
mov r9, rcx # arg4 = image_handle
# arg1 = ImageHandle (already set)
sub rsp, 32 # allocate shadow stack space for UEFI function
sub rsp, 32 # allocate shadow stack space for UEFI function
call r14 # 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
mov rax, [rsp+64] # get image
mov rcx, rax # save image
# Command line args
mov rbx, [rax+56] # options = image->load_options
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 al, [rbx] # *options
cmp al, 0x20 # if *options != ' '
jne loop_options1 # then jump
add rbx, 2 # ++options
mov r12, rbx # save input file
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
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
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)
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)
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
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
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 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
mov rcx, [rsp+64] # get rootfs
mov rcx, [rsp+64] # get rootfs
# Get root directory
push rdx # allocate stack for rootdir
mov rdx, rsp # 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
call [rcx+8] # rootfs->open_volume(rootfs, &rootdir)
@ -96,28 +96,28 @@ loop_options2: # Skip argv[1]
# Open file for writing
push rdx # allocate stack for fout
mov rdx, rsp # arg2 = &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
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 r13, [rsp+40] # get fout
mov r13, [rsp+40] # get fout
# Open file for reading
push rdx # allocate stack for fin
mov rdx, rsp # arg2 = &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
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 r12, [rsp+40] # get fin
mov r12, [rsp+40] # get fin
# Our flag for byte processing
push -1
@ -223,46 +223,46 @@ ascii_high:
# Writes byte stored in al
write_byte:
mov rcx, r13 # arg1 = fout
mov rcx, r13 # arg1 = fout
push 1 # size = 1
mov rdx, rsp # arg2 = &size
mov rdx, rsp # arg2 = &size
push rax # allocate stack
mov r8, rsp # 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
call [rcx+40] # fout->write()
add rsp, 40 # deallocate stack
add rsp, 40 # deallocate stack
ret # return
read_byte:
mov rcx, r12 # arg1 = fin
mov rcx, r12 # arg1 = fin
push 1 # size = 1
mov rdx, rsp # arg2 = &size
mov rdx, rsp # arg2 = &size
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
push rax # allocate shadow stack space for UEFI function
call [rcx+32] # fin->read()
pop rax # deallocate stack
pop rax # deallocate stack
pop rax # deallocate stack
pop rax # save input to rax
pop rsi # save size to rsi
pop rax # deallocate stack
pop rax # deallocate stack
pop rax # deallocate stack
pop rax # save input to rax
pop rsi # save size to rsi
# If the file ended (0 bytes read) terminate
test esi, esi # if size == 0
je terminate # then we are done
je terminate # then we are done
ret # return
terminate:
push rbx # allocate stack
mov rcx, r12 # arg1 = fin
mov rcx, r12 # arg1 = fin
call [rcx+16] # fin->close()
mov rcx, r13 # arg1 = fout
mov rcx, r13 # arg1 = fout
call [rcx+16] # fout->close()
abort: # used for debugging only
mov rsp, rbp # restore stack

448
amd64/Development/hex1.M1 Normal file
View File

@ -0,0 +1,448 @@
# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-FileCopyrightText: 2017 Jeremiah Orians <jeremiah@pdp10.guru>
#
# SPDX-License-Identifier: GPL-3.0-or-later
DEFINE ADDI32_to_RAX 4805
DEFINE ADDI32_to_R13 4981C5
DEFINE ADDI8_RBX 4883C3
DEFINE ADD_R14_to_RAX 4C01F0
DEFINE ADDI8_RSP 4883C4
DEFINE CALLI32 E8
DEFINE CALL_R14 41FFD6
DEFINE CALL_RCX_Immediate8 FF51
DEFINE CMPI8_AL 3C
DEFINE CMPI32_RAX 483D
DEFINE CMPI32_R15 4981FF
DEFINE COPY_RAX_to_R14 4989C6
DEFINE COPY_RBX_to_R12 4989DC
DEFINE COPY_RBX_to_R13 4989DD
DEFINE COPY_RCX_to_RAX 4889C1
DEFINE COPY_RSP_to_RBP 4889E5
DEFINE COPY_RSP_to_RDX 4889E2
DEFINE COPY_RSP_to_R8 4989E0
DEFINE COPY_RBP_to_RSP 4889EC
DEFINE COPY_RCX_to_R9 4989C9
DEFINE COPY_RDI_to_RCX 4889F9
DEFINE COPY_R12_to_R8 4D89E0
DEFINE COPY_RBX_to_RCX 4889D9
DEFINE COPY_R13_to_R8 4D89E8
DEFINE COPY_R14_to_RCX 4C89F1
DEFINE COPY_R15_to_RCX 4989CF
DEFINE COPY_R15_to_R9 4D89F9
DEFINE JE32 0F84
DEFINE JL32 0F8C
DEFINE JMP32 E9
DEFINE JNE8 75
DEFINE JNE32 0F85
DEFINE LOAD32_Address_in_RAX_into_RAX 678B00
DEFINE LOAD64_into_RBX_from_Address_RAX_Immediate8 488B58
DEFINE LOAD64_into_RAX_from_Address_RSP_Immediate8 488B4424
DEFINE LOAD64_into_RCX_from_Address_RSP_Immediate8 488B4C24
DEFINE LOAD64_into_RCX_from_Address_RCX_Immediate8 488B49
DEFINE LOAD64_into_RDI_from_Address_RSP_Immediate8 488B7C24
DEFINE LOAD64_into_RBX_from_Address_RSP_Immediate8 488B5C24
DEFINE LOAD64_into_R14_from_Address_RDX_Immediate8 4C8B72
DEFINE LOAD64_into_R14_from_Address_R14_Immediate32 4D8BB6
DEFINE LOAD8_AL_from_Address_RBX 8A03
DEFINE LOADI32_RAX 48C7C0
DEFINE LOADI32_RDX 48C7C2
DEFINE LOADI32_R13 49C7C5
DEFINE LOADI32_R14 49C7C6
DEFINE LOADI32_R15 49C7C7
DEFINE LOADI64_rel_RDX 488B15
DEFINE NOT_R15 49F7D7
DEFINE POP_RAX 58
DEFINE POP_RSI 5E
DEFINE POP_R9 4159
DEFINE POP_R14 415E
DEFINE PUSH 6A
DEFINE PUSH_RAX 50
DEFINE PUSH_RBX 53
DEFINE PUSH_RDX 52
DEFINE PUSH_RSI 56
DEFINE RET C3
DEFINE ROR_R9 49D1C9
DEFINE SHL8_R14 49C1E6
DEFINE SHL8_RAX 48C1E0
DEFINE STORE32_R13_to_Address_in_RAX 4C8928
DEFINE STOREI8_into_Address_RBX C603
DEFINE SUBI8_RSP 4883EC
DEFINE SUBI8_from_RAX 4883E8
DEFINE SUB_R13_from_RAX 4C29E8
DEFINE XOR_EDX_EDX 31D2
DEFINE TEST_ESI_ESI 85F6
# efi_main(void *image_handle, struct efi_system_table *system)
:_start
COPY_RSP_to_RBP # save stack pointer
COPY_R15_to_RCX # save image_handle
LOAD64_into_R14_from_Address_RDX_Immediate8 !96 # system->boot
LOAD64_into_R14_from_Address_R14_Immediate32 %280 # system->boot->open_protocol
# Open Loaded Image protocol
PUSH_RAX # allocate stack for image
COPY_RSP_to_R8 # arg3 = &image
LOADI64_rel_RDX %LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
PUSH_RDX # push last 64 bits onto stack
LOADI64_rel_RDX %LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
PUSH_RDX # push first 64 bits onto stack
COPY_RSP_to_RDX # arg2 = &guid
PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
PUSH !0 # arg5 = NULL
COPY_RCX_to_R9 # arg4 = image_handle
# arg1 = ImageHandle (already set)
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
CALL_R14 # 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
PUSH_RAX # allocate stack for rootfs
COPY_RSP_to_R8 # arg3 = &rootfs
LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
PUSH_RDX # push last 64 bits onto stack
LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
PUSH_RDX # push first 64 bits onto stack
COPY_RSP_to_RDX # arg2 = &guid
PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
PUSH !0 # arg5 = NULL
COPY_R15_to_R9 # arg4 = image_handle
LOAD64_into_RCX_from_Address_RCX_Immediate8 !24 # arg1 = root_device = image->device
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
CALL_R14 # 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
PUSH_RDX # allocate stack for rootdir
COPY_RSP_to_RDX # arg2 = &rootdir
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)
POP_RAX # deallocate stack
POP_RAX # deallocate stack
POP_R14 # save &rootdir
# Open file for reading
PUSH_RDX # allocate stack for fin
COPY_RSP_to_RDX # 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
COPY_R12_to_R8 # arg3 = in
COPY_R14_to_RCX # arg1 = rootdir
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
CALL_RCX_Immediate8 !8 # rootdir->open()
LOAD64_into_RDI_from_Address_RSP_Immediate8 !40 # get fin
# Open file for writing
PUSH_RDX # allocate stack for fout
COPY_RSP_to_RDX # 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
COPY_R13_to_R8 # arg3 = out
COPY_R14_to_RCX # arg1 = rootdir
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
CALL_RCX_Immediate8 !8 # rootdir->open()
LOAD64_into_RBX_from_Address_RSP_Immediate8 !40 # get fout
LOADI32_R15 %-1 # Our flag for byte processing
LOADI32_R14 %0 # temp storage for the sum
LOADI32_R13 %0 # Our starting IP
CALLI32 %First_pass # Process it
# rewind input file
COPY_RDI_to_RCX # Using our input file
XOR_EDX_EDX # Offset Zero
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)
POP_RAX # deallocate stack
POP_RAX # deallocate stack
LOADI32_R15 %-1 # Our flag for byte processing
LOADI32_R14 %0 # temp storage for the sum
LOADI32_R13 %0 # Our starting IP
CALLI32 %Second_pass # Process it
JMP32 %Done
:First_pass
CALLI32 %Read_byte
# Deal with EOF
CMPI32_RAX %-4
JE32 %First_pass_done
# Check for :
CMPI32_RAX %0x3a
JNE32 %First_pass_0
# Deal with label
CALLI32 %StoreLabel
:First_pass_0
# Check for %
CMPI32_RAX %0x25
JE32 %First_pass_pointer
# Deal with everything else
CALLI32 %hex # Process our char
# Deal with EOF
CMPI32_RAX %-4
JE32 %First_pass_done
# deal with -1 values
CMPI32_RAX %0
JL32 %First_pass
# deal with toggle
CMPI32_R15 %0
JE32 %First_pass_1
ADDI32_to_R13 %1 # Increment IP
:First_pass_1
NOT_R15
JMP32 %First_pass
:First_pass_pointer
# Deal with Pointer to label
CALLI32 %Read_byte # Drop the char
ADDI32_to_R13 %4 # Increment IP
JMP32 %First_pass # Loop again
:First_pass_done
RET
:hex
# deal with EOF
CMPI32_RAX %-4
JE32 %EOF
# deal with line comments starting with #
CMPI32_RAX %0x23
JE32 %ascii_comment
# deal with line comments starting with ;
CMPI32_RAX %0x3b
JE32 %ascii_comment
# deal all ascii less than 0
CMPI32_RAX %0x30
JL32 %ascii_other
# deal with 0-9
CMPI32_RAX %0x3a
JL32 %ascii_num
# deal with all ascii less than A
CMPI32_RAX %0x41
JL32 %ascii_other
# deal with A-F
CMPI32_RAX %0x47
JL32 %ascii_high
#deal with all ascii less than a
CMPI32_RAX %0x61
JL32 %ascii_other
#deal with a-f
CMPI32_RAX %0x67
JL32 %ascii_low
# The rest that remains needs to be ignored
JMP32 %ascii_other
:Second_pass
CALLI32 %Read_byte
# Deal with EOF
CMPI32_RAX %-4
JE32 %Second_pass_done
# Simply drop the label
CMPI32_RAX %0x3a
JNE32 %Second_pass_0
CALLI32 %Read_byte
JMP32 %Second_pass
:Second_pass_0
# Deal with % pointer
CMPI32_RAX %0x25
JNE32 %Second_pass_1
CALLI32 %StorePointer
JMP32 %Second_pass
:Second_pass_1
# Deal with everything else
CALLI32 %hex # Process our char
# Deal with EOF
CMPI32_RAX %-4
JE32 %Second_pass_done
# deal with -1 values
CMPI32_RAX %0
JL32 %Second_pass
# deal with toggle
CMPI32_R15 %0
JE32 %print
# process first byte of pair
COPY_RAX_to_R14
LOADI32_R15 %0
JMP32 %Second_pass
:Second_pass_done
RET
:EOF
RET
:ascii_num
SUBI8_from_RAX !0x30
RET
:ascii_low
SUBI8_from_RAX !0x57
RET
:ascii_high
SUBI8_from_RAX !0x37
RET
:ascii_other
LOADI32_RAX %-1
RET
:ascii_comment
CALLI32 %Read_byte
CMPI32_RAX %0xd
JE32 %ascii_comment_cr
CMPI32_RAX %0xa
JNE32 %ascii_comment
:ascii_comment_cr
LOADI32_RAX %-1
RET
# process second byte of pair
:print
# update the sum and store in output
SHL8_R14 !4
ADD_R14_to_RAX
# flip the toggle
NOT_R15
# Print our first Hex
LOADI32_RDX %1 # set the size of chars we want
CALLI32 %print_chars
ADDI32_to_R13 %1 # Increment IP
JMP32 %Second_pass
:Read_byte
COPY_RDI_to_RCX # arg1 = fin
PUSH !1 # size = 1
COPY_RSP_to_RDX # arg2 = &size
PUSH_RSI # allocate stack
COPY_RSP_to_R8 # 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
CALL_RCX_Immediate8 !32 # fin->read()
POP_RAX # deallocate stack
POP_RAX # deallocate stack
POP_RAX # deallocate stack
POP_RAX # save input to rax
POP_RSI # save size to rsi
# If the file ended (0 bytes read) return EOF
TEST_ESI_ESI # if size = 0
JNE8 !Read_byte_1
LOADI32_RAX %-4 # Put EOF in rax
:Read_byte_1
RET # return
# Writes bytes stored in rax
:print_chars
COPY_RBX_to_RCX # arg1 = fout
PUSH_RDX # set size
COPY_RSP_to_RDX # arg2 = &size
PUSH_RAX # allocate stack
COPY_RSP_to_R8 # 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
CALL_RCX_Immediate8 !40 # fout->write()
ADDI8_RSP !40 # deallocate stack
RET # return
:Get_table_target
CALLI32 %Read_byte # Get single char label
SHL8_RAX !3 # Each label in table takes 8 bytes to store
ADDI32_to_RAX &table # Calculate offset
RET
:StoreLabel
CALLI32 %Get_table_target
STORE32_R13_to_Address_in_RAX # Write out pointer to table
RET
:StorePointer
ADDI32_to_R13 %4 # Increment IP
CALLI32 %Get_table_target # Get address of pointer
LOAD32_Address_in_RAX_into_RAX # Get pointer
SUB_R13_from_RAX # target - ip
LOADI32_RDX %4 # set the size of chars we want
CALLI32 %print_chars
RET
:Done
PUSH_RBX # allocate stack
COPY_RDI_to_RCX # arg1 = fin
CALL_RCX_Immediate8 !16 # fin->close()
COPY_RBX_to_RCX # arg1 = fout
CALL_RCX_Immediate8 !16 # fout->close()
COPY_RBP_to_RSP # restore stack
RET # return to UEFI
# Protocol GUIDs
:LOADED_IMAGE_PROTOCOL
%0x5b1b31a1
@0x9562
@0x11d2
:LOADED_IMAGE_PROTOCOL_8
!0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
:SIMPLE_FS_PROTOCOL
%0x0964e5b22
@0x6459
@0x11d2
:SIMPLE_FS_PROTOCOL_8
!0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
:table
%0 %0
:PE32_end

View File

@ -66,7 +66,7 @@ loop_options2: # Skip argv[1]
mov rcx, [rcx+24] # arg1 = root_device = image->device
sub rsp, 32 # allocate shadow stack space for UEFI function
call r14 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
mov rcx, [rsp+64] # get rootfs
mov rcx, [rsp+64] # get rootfs
# Get root directory
push rdx # allocate stack for rootdir
@ -281,7 +281,7 @@ print:
add rax, r14
# flip the toggle
dec r15 # rbx = -1
not r15 # rbx = -1
mov rdx, 1 # set the size of chars we want
call print_chars
@ -314,10 +314,10 @@ Read_byte:
Read_byte_1:
ret # return
# Writes byte stored in al
# Writes bytes stored in rax
print_chars:
mov rcx, rbx # arg1 = fout
push rdx # size = 1
push rdx # set size
mov rdx, rsp # arg2 = &size
push rax # allocate stack
mov r8, rsp # arg3 = &output