1 /* Used by the elf ifunc tests. */
2 #ifndef ELF_IFUNC_SEL_H
3 #define ELF_IFUNC_SEL_H 1
4
5 extern int global;
6
7 static inline __attribute__ ((always_inline)) void *
8 inhibit_stack_protector
ifunc_sel(int (* f1)(void),int (* f2)(void),int (* f3)(void))9 ifunc_sel (int (*f1) (void), int (*f2) (void), int (*f3) (void))
10 {
11 register void *ret __asm__ ("r3");
12 __asm__ ("mflr 12\n\t"
13 "bcl 20,31,1f\n"
14 "1:\tmflr 11\n\t"
15 "mtlr 12\n\t"
16 "addis 12,11,global-1b@ha\n\t"
17 "lwz 12,global-1b@l(12)\n\t"
18 "addis %0,11,%2-1b@ha\n\t"
19 "addi %0,%0,%2-1b@l\n\t"
20 "cmpwi 12,1\n\t"
21 "beq 2f\n\t"
22 "addis %0,11,%3-1b@ha\n\t"
23 "addi %0,%0,%3-1b@l\n\t"
24 "cmpwi 12,-1\n\t"
25 "beq 2f\n\t"
26 "addis %0,11,%4-1b@ha\n\t"
27 "addi %0,%0,%4-1b@l\n\t"
28 "2:"
29 : "=r" (ret)
30 : "i" (&global), "i" (f1), "i" (f2), "i" (f3)
31 : "11", "12", "cr0");
32 return ret;
33 }
34
35 static inline __attribute__ ((always_inline)) void *
36 inhibit_stack_protector
ifunc_one(int (* f1)(void))37 ifunc_one (int (*f1) (void))
38 {
39 register void *ret __asm__ ("r3");
40 __asm__ ("mflr 12\n\t"
41 "bcl 20,31,1f\n"
42 "1:\tmflr %0\n\t"
43 "mtlr 12\n\t"
44 "addis %0,%0,%1-1b@ha\n\t"
45 "addi %0,%0,%1-1b@l"
46 : "=r" (ret)
47 : "i" (f1)
48 : "12");
49 return ret;
50 }
51 #endif
52