xref: /freebsd/libexec/rtld-elf/i386/rtld_machdep.h (revision 630df077ab61c69ad927873957c53efc22de140a)
1d5b537d0SJohn Polstra /*-
2630df077SJohn Polstra  * Copyright (c) 1999, 2000 John D. Polstra.
3d5b537d0SJohn Polstra  * All rights reserved.
4d5b537d0SJohn Polstra  *
5d5b537d0SJohn Polstra  * Redistribution and use in source and binary forms, with or without
6d5b537d0SJohn Polstra  * modification, are permitted provided that the following conditions
7d5b537d0SJohn Polstra  * are met:
8d5b537d0SJohn Polstra  * 1. Redistributions of source code must retain the above copyright
9d5b537d0SJohn Polstra  *    notice, this list of conditions and the following disclaimer.
10d5b537d0SJohn Polstra  * 2. Redistributions in binary form must reproduce the above copyright
11d5b537d0SJohn Polstra  *    notice, this list of conditions and the following disclaimer in the
12d5b537d0SJohn Polstra  *    documentation and/or other materials provided with the distribution.
13d5b537d0SJohn Polstra  *
14d5b537d0SJohn Polstra  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15d5b537d0SJohn Polstra  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16d5b537d0SJohn Polstra  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17d5b537d0SJohn Polstra  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18d5b537d0SJohn Polstra  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19d5b537d0SJohn Polstra  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20d5b537d0SJohn Polstra  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21d5b537d0SJohn Polstra  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22d5b537d0SJohn Polstra  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23d5b537d0SJohn Polstra  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24d5b537d0SJohn Polstra  * SUCH DAMAGE.
25d5b537d0SJohn Polstra  *
267f3dea24SPeter Wemm  * $FreeBSD$
27d5b537d0SJohn Polstra  */
28d5b537d0SJohn Polstra 
29d5b537d0SJohn Polstra #ifndef RTLD_MACHDEP_H
30d5b537d0SJohn Polstra #define RTLD_MACHDEP_H	1
31d5b537d0SJohn Polstra 
32d5b537d0SJohn Polstra /* Return the address of the .dynamic section in the dynamic linker. */
33d5b537d0SJohn Polstra #define rtld_dynamic(obj) \
34d5b537d0SJohn Polstra     ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
35d5b537d0SJohn Polstra 
36962fdc46SJohn Polstra /* Fixup the jump slot at "where" to transfer control to "target". */
37962fdc46SJohn Polstra #define reloc_jmpslot(where, target)			\
38962fdc46SJohn Polstra     do {						\
39962fdc46SJohn Polstra 	dbg("reloc_jmpslot: *%p = %p", (void *)(where),	\
40962fdc46SJohn Polstra 	  (void *)(target));				\
41962fdc46SJohn Polstra 	(*(Elf_Addr *)(where) = (Elf_Addr)(target));	\
42962fdc46SJohn Polstra     } while (0)
43962fdc46SJohn Polstra 
44630df077SJohn Polstra static inline void
45630df077SJohn Polstra atomic_decr_int(volatile int *p)
46630df077SJohn Polstra {
47630df077SJohn Polstra     __asm __volatile ("lock; decl %0" : "=m"(*p) : "0"(*p) : "cc");
48630df077SJohn Polstra }
49630df077SJohn Polstra 
50630df077SJohn Polstra static inline void
51630df077SJohn Polstra atomic_incr_int(volatile int *p)
52630df077SJohn Polstra {
53630df077SJohn Polstra     __asm __volatile ("lock; incl %0" : "=m"(*p) : "0"(*p) : "cc");
54630df077SJohn Polstra }
55630df077SJohn Polstra 
56630df077SJohn Polstra static inline void
57630df077SJohn Polstra atomic_add_int(volatile int *p, int val)
58630df077SJohn Polstra {
59630df077SJohn Polstra     __asm __volatile ("lock; addl %1, %0"
60630df077SJohn Polstra 	: "=m"(*p)
61630df077SJohn Polstra 	: "ri"(val), "0"(*p)
62630df077SJohn Polstra 	: "cc");
63630df077SJohn Polstra }
64630df077SJohn Polstra 
65d5b537d0SJohn Polstra #endif
66