ObjFW  forwarding-x86_64-elf.S at [0b478d8138]

File src/forwarding/forwarding-x86_64-elf.S artifact 1d1fc641cf part of check-in 0b478d8138


/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include "platform.h"

.intel_syntax noprefix

.globl of_forward
.globl of_forward_stret

.section .text
of_forward:
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	call	object_getClass@PLT

	mov	rdi, rax
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	class_respondsToSelector@PLT

	test	rax, rax
	jz	short 0f

	mov	rdi, [rbp-0x10]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	objc_msg_lookup@PLT

	mov	rdi, [rbp-0x10]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x18]
	call	rax

	test	rax, rax
	jz	short 0f
	cmp	rax, [rbp-0x10]
	je	short 0f

	mov	[rbp-0x10], rax

	mov	rdi, rax
	mov	rsi, [rbp-0x18]
	call	objc_msg_lookup@PLT
	mov	r11, rax

	/* Restore all arguments */
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rsi,  [rbp-0x18]
	mov	rdi,  [rbp-0x10]
	mov	rax,  [rbp-0x08]

	mov	rsp, rbp
	pop	rbp

	jmp	r11

0:
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]

	mov	rsp, rbp
	pop	rbp

	jmp	of_method_not_found@PLT
.type of_forward, %function
.size of_forward, .-of_forward

of_forward_stret:
	push	rbp
	mov	rbp, rsp

	/* Save all arguments */
	sub	rsp, 0xC0	/* 16-byte alignment */
	mov	[rbp-0x08], rax
	mov	[rbp-0x10], rdi
	mov	[rbp-0x18], rsi
	mov	[rbp-0x20], rdx
	mov	[rbp-0x28], rcx
	mov	[rbp-0x30], r8
	mov	[rbp-0x38], r9
	movaps	[rbp-0x50], xmm0
	movaps	[rbp-0x60], xmm1
	movaps	[rbp-0x70], xmm2
	movaps	[rbp-0x80], xmm3
	movaps	[rbp-0x90], xmm4
	movaps	[rbp-0xA0], xmm5
	movaps	[rbp-0xB0], xmm6
	movaps	[rbp-0xC0], xmm7

	mov	rdi, rsi
	call	object_getClass@PLT

	mov	rdi, rax
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	class_respondsToSelector@PLT

	test	rax, rax
	jz	short 0f

	mov	rdi, [rbp-0x18]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	call	objc_msg_lookup@PLT

	mov	rdi, [rbp-0x18]
	lea	rsi, [rip+sel_forwardingTargetForSelector_]
	mov	rdx, [rbp-0x20]
	call	rax

	test	rax, rax
	jz	short 0f
	cmp	rax, [rbp-0x18]
	je	short 0f

	mov	[rbp-0x18], rax

	mov	rdi, rax
	mov	rsi, [rbp-0x20]
	call	objc_msg_lookup_stret@PLT
	mov	r11, rax

	/* Restore all arguments */
	movaps	xmm7, [rbp-0xC0]
	movaps	xmm6, [rbp-0xB0]
	movaps	xmm5, [rbp-0xA0]
	movaps	xmm4, [rbp-0x90]
	movaps	xmm3, [rbp-0x80]
	movaps	xmm2, [rbp-0x70]
	movaps	xmm1, [rbp-0x60]
	movaps	xmm0, [rbp-0x50]
	mov	r9,   [rbp-0x38]
	mov	r8,   [rbp-0x30]
	mov	rcx,  [rbp-0x28]
	mov	rdx,  [rbp-0x20]
	mov	rsi,  [rbp-0x18]
	mov	rdi,  [rbp-0x10]
	mov	rax,  [rbp-0x08]

	mov	rsp, rbp
	pop	rbp

	jmp	r11

0:
	mov	rdi, [rbp-0x10]
	mov	rsi, [rbp-0x18]
	mov	rdx, [rbp-0x20]

	mov	rsp, rbp
	pop	rbp

	jmp	of_method_not_found_stret@PLT
.type of_forward_stret, %function
.size of_forward_stret, .-of_forward_stret

init:
	lea	rdi, [rip+module]
	jmp	__objc_exec_class@PLT

#ifdef OF_SOLARIS
.section .init_array, "aw"
#else
.section .ctors, "aw", %progbits
#endif
	.quad init

.section .rodata
str_forwardingTargetForSelector_:
	.asciz "forwardingTargetForSelector:"

.section .data
sel_forwardingTargetForSelector_:
	.quad str_forwardingTargetForSelector_, 0
	.quad 0, 0
symtab:
	.quad 0, sel_forwardingTargetForSelector_
	.short 0, 0
	.long 0
	.quad 0
module:
	.quad 8, 32, 0, symtab

#ifdef OF_LINUX
.section .note.GNU-stack, "", %progbits
#endif