hex0.S: more stack optimizations.
Pass function arguments with push opcodes which are shorter than using e.g. "mov qword ptr [rsp+40], 1"
This commit is contained in:
parent
555caea6c7
commit
f5bae9d646
|
@ -21,28 +21,27 @@
|
||||||
.text
|
.text
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
mov rbp, rsp # save stack
|
mov rbp, rsp # save stack pointer
|
||||||
mov r15, rcx # image_handle
|
mov r15, rcx # save image_handle
|
||||||
mov rax, [rdx+96] # system->boot
|
mov r14, [rdx+96] # save system->boot
|
||||||
mov r14, rax # save system->boot
|
|
||||||
|
|
||||||
# Open Loaded Image protocol
|
# Open Loaded Image protocol
|
||||||
sub rsp, 72 # allocate stack
|
push rax # allocate stack for image
|
||||||
# arg1 = ImageHandle
|
mov r8, rsp # arg3 = &image
|
||||||
mov rdx, [LOADED_IMAGE_PROTOCOL] # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
|
||||||
mov [rsp+48], rdx # save onto stack
|
|
||||||
mov rdx, [LOADED_IMAGE_PROTOCOL+8]# EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
mov rdx, [LOADED_IMAGE_PROTOCOL+8]# EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||||
mov [rsp+56], rdx # save onto stack
|
push rdx # push last 64 bits onto stack
|
||||||
lea rdx, [rsp+48] # arg2 = &EFI_LOADED_IMAGE_PROTOCOL_GUID
|
mov rdx, [LOADED_IMAGE_PROTOCOL] # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||||
lea r8, [rsp+64] # arg3 = &image
|
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, rcx # arg4 = image_handle
|
mov r9, rcx # arg4 = image_handle
|
||||||
mov qword ptr [rsp+32], 0 # arg5 = NULL
|
# arg1 = ImageHandle (already set)
|
||||||
mov qword ptr [rsp+40], 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
sub rsp, 32 # allocate stack
|
||||||
|
call [r14+280] # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
|
||||||
call [rax+280] # system->boot->open_protocol();
|
mov rax, [rsp+64] # get image
|
||||||
|
|
||||||
# Command line args
|
# Command line args
|
||||||
mov rax, [rsp+64] # get image
|
|
||||||
mov rcx, rax # save image
|
mov rcx, rax # save image
|
||||||
mov rax, [rax+56] # options = image->load_options
|
mov rax, [rax+56] # options = image->load_options
|
||||||
|
|
||||||
|
@ -53,7 +52,6 @@ loop_options1: # Skip application name
|
||||||
jne loop_options1 # then jump
|
jne loop_options1 # then jump
|
||||||
|
|
||||||
add rax, 2 # ++options
|
add rax, 2 # ++options
|
||||||
#push rax # in = options
|
|
||||||
mov r12, rax
|
mov r12, rax
|
||||||
|
|
||||||
loop_options2: # Skip argv[1]
|
loop_options2: # Skip argv[1]
|
||||||
|
@ -64,49 +62,50 @@ loop_options2: # Skip argv[1]
|
||||||
|
|
||||||
mov byte ptr [rax], 0 # *options = 0;
|
mov byte ptr [rax], 0 # *options = 0;
|
||||||
add rax, 2 # ++options
|
add rax, 2 # ++options
|
||||||
#push rax # out = options
|
|
||||||
mov r13, rax
|
mov r13, rax
|
||||||
|
|
||||||
# Get root device
|
# Get root device
|
||||||
sub rsp, 72 # allocate stack
|
push rax # allocate stack for rootfs
|
||||||
mov rcx, [rcx+24] # arg1 = root_device = image->device
|
mov r8, rsp # arg3 = &rootfs
|
||||||
mov rdx, [SIMPLE_FS_PROTOCOL] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
|
||||||
mov [rsp+48], rdx # save onto stack
|
|
||||||
mov rdx, [SIMPLE_FS_PROTOCOL+8] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
mov rdx, [SIMPLE_FS_PROTOCOL+8] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||||
mov [rsp+56], rdx # save onto stack
|
push rdx # push last 64 bits onto stack
|
||||||
lea rdx, [rsp+48] # arg2 = &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
|
mov rdx, [SIMPLE_FS_PROTOCOL] # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||||
lea r8, [rsp+64] # arg3 = &rootfs
|
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 r9, r15 # arg4 = image_handle
|
||||||
mov qword ptr [rsp+32], 0 # arg5 = NULL
|
mov rcx, [rcx+24] # arg1 = root_device = image->device
|
||||||
mov qword ptr [rsp+40], 1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
sub rsp, 32 # allocate stack
|
||||||
|
call [r14+280] # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
|
||||||
mov rax, r14 # system->boot
|
|
||||||
call [rax+280] # system->boot->open_protocol();
|
|
||||||
mov rcx, [rsp+64] # get rootfs
|
mov rcx, [rsp+64] # get rootfs
|
||||||
|
|
||||||
# Get root fs
|
# Get rootfs
|
||||||
sub rsp, 24 # allocate stack
|
push rdx # allocate stack for rootdir
|
||||||
lea rdx, [rsp+16] # arg2 = &rootdir
|
mov rdx, rsp # arg2 = &rootdir
|
||||||
|
sub rsp, 16 # allocate stack
|
||||||
call [rcx+8] # rootfs->open_volume(rootfs, &rootdir)
|
call [rcx+8] # rootfs->open_volume(rootfs, &rootdir)
|
||||||
mov rsi, [rsp+16] # save &rootdir
|
mov rsi, [rsp+16] # save &rootdir
|
||||||
|
|
||||||
# Open file for writing
|
# Open file for writing
|
||||||
sub rsp, 48 # allocate stack
|
push rdx # allocate stack for fout
|
||||||
mov rcx, rsi # arg1 = rootdir
|
mov rdx, rsp # arg2 = &fout
|
||||||
lea rdx, [rsp+40] # arg2 = &fout
|
push 0 # arg5 = 0
|
||||||
mov r8, r13 # arg3 = out
|
|
||||||
mov r9, 0x8000000000000003 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
mov r9, 0x8000000000000003 # arg4 = EFI_FILE_MODE_CREATE| EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ
|
||||||
mov qword ptr [rsp+32], 0 # arg5 = 0
|
mov r8, r13 # arg3 = out
|
||||||
|
mov rcx, rsi # arg1 = rootdir
|
||||||
|
sub rsp, 32 # allocate stack
|
||||||
call [rcx+8] # rootdir->open()
|
call [rcx+8] # rootdir->open()
|
||||||
mov r13, [rsp+40] # get fout
|
mov r13, [rsp+40] # get fout
|
||||||
|
|
||||||
# Open file for reading
|
# Open file for reading
|
||||||
mov rcx, rsi # arg1 = rootdir
|
push rdx # allocate stack for fin
|
||||||
mov r8, r12 # arg3 = in
|
mov rdx, rsp # arg2 = &fin
|
||||||
sub rsp, 48 # allocate stack
|
push 1 # arg5 = EFI_FILE_READ_ONLY
|
||||||
lea rdx, [rsp+40] # arg2 = &fin
|
|
||||||
mov r9, 1 # arg4 = EFI_FILE_MODE_READ
|
mov r9, 1 # arg4 = EFI_FILE_MODE_READ
|
||||||
mov qword ptr [rsp+32], 1 # arg5 = EFI_FILE_READ_ONLY
|
mov r8, r12 # arg3 = in
|
||||||
|
mov rcx, rsi # arg1 = rootdir
|
||||||
|
sub rsp, 32 # allocate stack
|
||||||
call [rcx+8] # rootdir->open()
|
call [rcx+8] # rootdir->open()
|
||||||
mov r12, [rsp+40] # get fin
|
mov r12, [rsp+40] # get fin
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue