1/* PLT trampolines.  ARC version.
2   Copyright (C) 2020-2021 Free Software Foundation, Inc.
3   This file is part of the GNU C Library.
4
5   The GNU C Library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   The GNU C Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library.  If not, see
17   <https://www.gnu.org/licenses/>.  */
18
19#include <sysdep.h>
20#include <libc-symbols.h>
21
22#include <sysdep.h>
23#include <sys/syscall.h>
24
25/* resolver has atypical calling ABI (r11 and r12)
26        PLTn which lands us here, sets up
27	r11 = Module info (tpnt pointer as expected by resolver)
28	r12 = PC of the PLTn itself - needed by resolver to find
29	      corresponding .rela.plt entry.  */
30
31ENTRY (_dl_runtime_resolve)
32
33	/* save args to func being resolved before entering resolver.  */
34	push_s	r0
35	push_s	r1
36	push_s	r2
37	push_s	r3
38	st.a	r4, [sp, -4]
39	st.a	r5, [sp, -4]
40	st.a	r6, [sp, -4]
41	st.a	r7, [sp, -4]
42	st.a	r8, [sp, -4]
43	st.a	r9, [sp, -4]
44	cfi_adjust_cfa_offset (40)
45	push_s	blink
46	cfi_adjust_cfa_offset (4)
47	cfi_rel_offset (blink, 0)
48
49	mov_s 	r1, r12
50	bl.d  	_dl_fixup
51	mov   	r0, r11
52
53	/* restore regs back.  */
54	ld.ab	blink,[sp, 4]
55	cfi_adjust_cfa_offset (-4)
56	cfi_restore (blink)
57	ld.ab	r9, [sp, 4]
58	ld.ab	r8, [sp, 4]
59	ld.ab	r7, [sp, 4]
60	ld.ab	r6, [sp, 4]
61	ld.ab	r5, [sp, 4]
62	ld.ab	r4, [sp, 4]
63	pop_s   r3
64	pop_s   r2
65	pop_s   r1
66	cfi_adjust_cfa_offset (-36)
67
68	j_s.d   [r0]    /* r0 has resolved function addr.  */
69	pop_s   r0      /* restore first arg to resolved call.  */
70	cfi_adjust_cfa_offset (-4)
71	cfi_restore (r0)
72END (_dl_runtime_resolve)
73