127bd4146SNathan Whitehorn /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3e6209940SPedro F. Giffuni  *
427bd4146SNathan Whitehorn  * Copyright (c) 1999, 2000 John D. Polstra.
527bd4146SNathan Whitehorn  * All rights reserved.
627bd4146SNathan Whitehorn  *
727bd4146SNathan Whitehorn  * Redistribution and use in source and binary forms, with or without
827bd4146SNathan Whitehorn  * modification, are permitted provided that the following conditions
927bd4146SNathan Whitehorn  * are met:
1027bd4146SNathan Whitehorn  * 1. Redistributions of source code must retain the above copyright
1127bd4146SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer.
1227bd4146SNathan Whitehorn  * 2. Redistributions in binary form must reproduce the above copyright
1327bd4146SNathan Whitehorn  *    notice, this list of conditions and the following disclaimer in the
1427bd4146SNathan Whitehorn  *    documentation and/or other materials provided with the distribution.
1527bd4146SNathan Whitehorn  *
1627bd4146SNathan Whitehorn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1727bd4146SNathan Whitehorn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1827bd4146SNathan Whitehorn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1927bd4146SNathan Whitehorn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2027bd4146SNathan Whitehorn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2127bd4146SNathan Whitehorn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2227bd4146SNathan Whitehorn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2327bd4146SNathan Whitehorn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2427bd4146SNathan Whitehorn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2527bd4146SNathan Whitehorn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2627bd4146SNathan Whitehorn  * SUCH DAMAGE.
2727bd4146SNathan Whitehorn  */
2827bd4146SNathan Whitehorn 
2927bd4146SNathan Whitehorn #ifndef RTLD_MACHDEP_H
3027bd4146SNathan Whitehorn #define RTLD_MACHDEP_H	1
3127bd4146SNathan Whitehorn 
3227bd4146SNathan Whitehorn #include <sys/types.h>
3327bd4146SNathan Whitehorn #include <machine/atomic.h>
348bcdb144SJohn Baldwin #include <machine/tls.h>
3527bd4146SNathan Whitehorn 
3627bd4146SNathan Whitehorn struct Struct_Obj_Entry;
3727bd4146SNathan Whitehorn 
3827bd4146SNathan Whitehorn /* Return the address of the .dynamic section in the dynamic linker. */
3927bd4146SNathan Whitehorn #define rtld_dynamic(obj)    (&_DYNAMIC)
4027bd4146SNathan Whitehorn 
41d8925a5fSAndrew Turner /* No architecture specific notes */
42d8925a5fSAndrew Turner #define	arch_digest_note(obj, note)	false
43d8925a5fSAndrew Turner 
4427bd4146SNathan Whitehorn Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
45e35ddbe4SKonstantin Belousov     const struct Struct_Obj_Entry *defobj, const struct Struct_Obj_Entry *obj,
4627bd4146SNathan Whitehorn     const Elf_Rel *rel);
47903e0ffdSAlex Richardson void reloc_non_plt_self(Elf_Dyn *dynp, Elf_Addr relocbase);
4827bd4146SNathan Whitehorn 
4927bd4146SNathan Whitehorn #define make_function_pointer(def, defobj) \
5027bd4146SNathan Whitehorn 	((defobj)->relocbase + (def)->st_value)
5127bd4146SNathan Whitehorn 
5227bd4146SNathan Whitehorn #define call_initfini_pointer(obj, target) \
5327bd4146SNathan Whitehorn 	(((InitFunc)(target))())
5427bd4146SNathan Whitehorn 
5583aa9cc0SKonstantin Belousov #define call_init_pointer(obj, target) \
5683aa9cc0SKonstantin Belousov 	(((InitArrFunc)(target))(main_argc, main_argv, environ))
5783aa9cc0SKonstantin Belousov 
5841b4ec8aSBrandon Bergren extern u_long cpu_features; /* r3 */
5941b4ec8aSBrandon Bergren extern u_long cpu_features2; /* r4 */
6041b4ec8aSBrandon Bergren /* r5-r10: ifunc resolver parameters reserved for future assignment. */
614352999eSKonstantin Belousov #define	call_ifunc_resolver(ptr) \
6241b4ec8aSBrandon Bergren 	(((Elf_Addr (*)(uint32_t, uint32_t, uint64_t, uint64_t, uint64_t, \
6341b4ec8aSBrandon Bergren            uint64_t, uint64_t, uint64_t))ptr)((uint32_t)cpu_features, \
6441b4ec8aSBrandon Bergren            (uint32_t)cpu_features2, 0, 0, 0, 0, 0, 0))
654352999eSKonstantin Belousov 
6627bd4146SNathan Whitehorn /*
6727bd4146SNathan Whitehorn  * TLS
6827bd4146SNathan Whitehorn  */
6927bd4146SNathan Whitehorn 
7027bd4146SNathan Whitehorn #define round(size, align) \
7127bd4146SNathan Whitehorn     (((size) + (align) - 1) & ~((align) - 1))
72e5c3405cSKonstantin Belousov #define calculate_first_tls_offset(size, align, offset)	\
7317fb2856SBrooks Davis     TLS_TCB_SIZE
74e5c3405cSKonstantin Belousov #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \
7527bd4146SNathan Whitehorn     round(prev_offset + prev_size, align)
7617fb2856SBrooks Davis #define calculate_tls_post_size(align)  0
7727bd4146SNathan Whitehorn 
7827bd4146SNathan Whitehorn typedef struct {
7927bd4146SNathan Whitehorn 	unsigned long ti_module;
8027bd4146SNathan Whitehorn 	unsigned long ti_offset;
8127bd4146SNathan Whitehorn } tls_index;
8227bd4146SNathan Whitehorn 
8327bd4146SNathan Whitehorn extern void *__tls_get_addr(tls_index* ti);
8427bd4146SNathan Whitehorn 
8541b4ec8aSBrandon Bergren extern void powerpc64_abi_variant_hook(Elf_Auxinfo **);
8641b4ec8aSBrandon Bergren #define md_abi_variant_hook(x) powerpc64_abi_variant_hook(x)
878fd53f45SWarner Losh 
8827bd4146SNathan Whitehorn #endif
89