14b1859c0SRuslan Bukin /*-
24b1859c0SRuslan Bukin  * Copyright (c) 1999, 2000 John D. Polstra.
34b1859c0SRuslan Bukin  * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
44b1859c0SRuslan Bukin  * All rights reserved.
54b1859c0SRuslan Bukin  *
64b1859c0SRuslan Bukin  * Portions of this software were developed by SRI International and the
74b1859c0SRuslan Bukin  * University of Cambridge Computer Laboratory under DARPA/AFRL contract
84b1859c0SRuslan Bukin  * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
94b1859c0SRuslan Bukin  *
104b1859c0SRuslan Bukin  * Portions of this software were developed by the University of Cambridge
114b1859c0SRuslan Bukin  * Computer Laboratory as part of the CTSRD Project, with support from the
124b1859c0SRuslan Bukin  * UK Higher Education Innovation Fund (HEIF).
134b1859c0SRuslan Bukin  *
144b1859c0SRuslan Bukin  * Redistribution and use in source and binary forms, with or without
154b1859c0SRuslan Bukin  * modification, are permitted provided that the following conditions
164b1859c0SRuslan Bukin  * are met:
174b1859c0SRuslan Bukin  * 1. Redistributions of source code must retain the above copyright
184b1859c0SRuslan Bukin  *    notice, this list of conditions and the following disclaimer.
194b1859c0SRuslan Bukin  * 2. Redistributions in binary form must reproduce the above copyright
204b1859c0SRuslan Bukin  *    notice, this list of conditions and the following disclaimer in the
214b1859c0SRuslan Bukin  *    documentation and/or other materials provided with the distribution.
224b1859c0SRuslan Bukin  *
234b1859c0SRuslan Bukin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
244b1859c0SRuslan Bukin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
254b1859c0SRuslan Bukin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
264b1859c0SRuslan Bukin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
274b1859c0SRuslan Bukin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
284b1859c0SRuslan Bukin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
294b1859c0SRuslan Bukin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
304b1859c0SRuslan Bukin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
314b1859c0SRuslan Bukin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
324b1859c0SRuslan Bukin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
334b1859c0SRuslan Bukin  * SUCH DAMAGE.
344b1859c0SRuslan Bukin  */
354b1859c0SRuslan Bukin 
364b1859c0SRuslan Bukin #ifndef RTLD_MACHDEP_H
374b1859c0SRuslan Bukin #define RTLD_MACHDEP_H	1
384b1859c0SRuslan Bukin 
394b1859c0SRuslan Bukin #include <sys/types.h>
404b1859c0SRuslan Bukin #include <machine/atomic.h>
418bcdb144SJohn Baldwin #include <machine/tls.h>
424b1859c0SRuslan Bukin 
434b1859c0SRuslan Bukin struct Struct_Obj_Entry;
444b1859c0SRuslan Bukin 
454b1859c0SRuslan Bukin uint64_t set_gp(struct Struct_Obj_Entry *obj);
464b1859c0SRuslan Bukin 
474b1859c0SRuslan Bukin /* Return the address of the .dynamic section in the dynamic linker. */
484b1859c0SRuslan Bukin #define rtld_dynamic(obj)                                               \
494b1859c0SRuslan Bukin ({                                                                      \
504b1859c0SRuslan Bukin 	Elf_Addr _dynamic_addr;                                         \
514b1859c0SRuslan Bukin 	__asm __volatile("lla       %0, _DYNAMIC" : "=r"(_dynamic_addr));   \
524b1859c0SRuslan Bukin 	(const Elf_Dyn *)_dynamic_addr;                                 \
534b1859c0SRuslan Bukin })
544b1859c0SRuslan Bukin 
55d8925a5fSAndrew Turner /* No architecture specific notes */
56d8925a5fSAndrew Turner #define	arch_digest_note(obj, note)	false
57d8925a5fSAndrew Turner 
584b1859c0SRuslan Bukin Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
59e35ddbe4SKonstantin Belousov     const struct Struct_Obj_Entry *defobj, const struct Struct_Obj_Entry *obj,
604b1859c0SRuslan Bukin     const Elf_Rel *rel);
614b1859c0SRuslan Bukin 
624b1859c0SRuslan Bukin #define make_function_pointer(def, defobj) \
634b1859c0SRuslan Bukin 	((defobj)->relocbase + (def)->st_value)
644b1859c0SRuslan Bukin 
654b1859c0SRuslan Bukin #define call_initfini_pointer(obj, target)				\
664b1859c0SRuslan Bukin ({									\
674b1859c0SRuslan Bukin 	uint64_t old0;							\
684b1859c0SRuslan Bukin 	old0 = set_gp(obj);						\
694b1859c0SRuslan Bukin 	(((InitFunc)(target))());					\
704b1859c0SRuslan Bukin 	__asm __volatile("mv    gp, %0" :: "r"(old0));			\
714b1859c0SRuslan Bukin })
724b1859c0SRuslan Bukin 
734b1859c0SRuslan Bukin #define call_init_pointer(obj, target)					\
744b1859c0SRuslan Bukin ({									\
754b1859c0SRuslan Bukin 	uint64_t old1;							\
764b1859c0SRuslan Bukin 	old1 = set_gp(obj);						\
774b1859c0SRuslan Bukin 	(((InitArrFunc)(target))(main_argc, main_argv, environ));	\
784b1859c0SRuslan Bukin 	__asm __volatile("mv    gp, %0" :: "r"(old1));			\
794b1859c0SRuslan Bukin })
804b1859c0SRuslan Bukin 
814352999eSKonstantin Belousov #define	call_ifunc_resolver(ptr) \
824352999eSKonstantin Belousov 	(((Elf_Addr (*)(void))ptr)())
834352999eSKonstantin Belousov 
844b1859c0SRuslan Bukin /*
854b1859c0SRuslan Bukin  * TLS
864b1859c0SRuslan Bukin  */
874b1859c0SRuslan Bukin 
884b1859c0SRuslan Bukin #define round(size, align) \
894b1859c0SRuslan Bukin     (((size) + (align) - 1) & ~((align) - 1))
90e5c3405cSKonstantin Belousov #define calculate_first_tls_offset(size, align, offset)	\
9117fb2856SBrooks Davis     TLS_TCB_SIZE
92e5c3405cSKonstantin Belousov #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
934b1859c0SRuslan Bukin     round(prev_offset + prev_size, align)
9417fb2856SBrooks Davis #define calculate_tls_post_size(align)  0
954b1859c0SRuslan Bukin 
964b1859c0SRuslan Bukin typedef struct {
974b1859c0SRuslan Bukin 	unsigned long ti_module;
984b1859c0SRuslan Bukin 	unsigned long ti_offset;
994b1859c0SRuslan Bukin } tls_index;
1004b1859c0SRuslan Bukin 
1014b1859c0SRuslan Bukin extern void *__tls_get_addr(tls_index* ti);
1024b1859c0SRuslan Bukin 
103e0752870SRuslan Bukin #define	md_abi_variant_hook(x)
104e0752870SRuslan Bukin 
1054b1859c0SRuslan Bukin #endif
106