1 #include <linux/spinlock.h>
2 #include <linux/hardirq.h>
3 #include <linux/ftrace.h>
4 #include <linux/percpu.h>
5 #include <linux/init.h>
6 #include <linux/list.h>
8 #include <asm/ftrace.h>
10 #ifdef CONFIG_DYNAMIC_FTRACE
11 static const u32 ftrace_nop
= 0x01000000;
13 static u32
ftrace_call_replace(unsigned long ip
, unsigned long addr
)
18 off
= ((s32
)addr
- (s32
)ip
);
19 call
= 0x40000000 | ((u32
)off
>> 2);
24 static int ftrace_modify_code(unsigned long ip
, u32 old
, u32
new)
30 "1: cas [%[ip]], %[old], %[new]\n"
32 " mov 0, %[faulted]\n"
34 " .section .fixup,#alloc,#execinstr\n"
36 "3: sethi %%hi(2b), %[faulted]\n"
37 " jmpl %[faulted] + %%lo(2b), %%g0\n"
38 " mov 1, %[faulted]\n"
40 " .section __ex_table,\"a\"\n"
44 : "=r" (replaced
), [faulted
] "=r" (faulted
)
45 : [new] "0" (new), [old
] "r" (old
), [ip
] "r" (ip
)
48 if (replaced
!= old
&& replaced
!= new)
54 int ftrace_make_nop(struct module
*mod
, struct dyn_ftrace
*rec
, unsigned long addr
)
56 unsigned long ip
= rec
->ip
;
59 old
= ftrace_call_replace(ip
, addr
);
61 return ftrace_modify_code(ip
, old
, new);
64 int ftrace_make_call(struct dyn_ftrace
*rec
, unsigned long addr
)
66 unsigned long ip
= rec
->ip
;
70 new = ftrace_call_replace(ip
, addr
);
71 return ftrace_modify_code(ip
, old
, new);
74 int ftrace_update_ftrace_func(ftrace_func_t func
)
76 unsigned long ip
= (unsigned long)(&ftrace_call
);
79 old
= *(u32
*) &ftrace_call
;
80 new = ftrace_call_replace(ip
, (unsigned long)func
);
81 return ftrace_modify_code(ip
, old
, new);
84 int __init
ftrace_dyn_arch_init(void *data
)
86 unsigned long *p
= data
;