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 static const u32 ftrace_nop = 0x01000000;
10 notrace int ftrace_ip_converted(unsigned long ip)
12 u32 insn = *(u32 *) ip;
14 return (insn == ftrace_nop);
17 notrace unsigned char *ftrace_nop_replace(void)
19 return (char *)&ftrace_nop;
22 notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
27 off = ((s32)addr - (s32)ip);
28 call = 0x40000000 | ((u32)off >> 2);
30 return (unsigned char *) &call;
34 ftrace_modify_code(unsigned long ip, unsigned char *old_code,
35 unsigned char *new_code)
37 u32 old = *(u32 *)old_code;
38 u32 new = *(u32 *)new_code;
43 "1: cas [%[ip]], %[old], %[new]\n"
45 " mov 0, %[faulted]\n"
47 " .section .fixup,#alloc,#execinstr\n"
49 "3: sethi %%hi(2b), %[faulted]\n"
50 " jmpl %[faulted] + %%lo(2b), %%g0\n"
51 " mov 1, %[faulted]\n"
53 " .section __ex_table,\"a\"\n"
57 : "=r" (replaced), [faulted] "=r" (faulted)
58 : [new] "0" (new), [old] "r" (old), [ip] "r" (ip)
61 if (replaced != old && replaced != new)
67 notrace int ftrace_update_ftrace_func(ftrace_func_t func)
69 unsigned long ip = (unsigned long)(&ftrace_call);
70 unsigned char old[4], *new;
72 memcpy(old, &ftrace_call, 4);
73 new = ftrace_call_replace(ip, (unsigned long)func);
74 return ftrace_modify_code(ip, old, new);
77 notrace int ftrace_mcount_set(unsigned long *data)
79 unsigned long ip = (long)(&mcount_call);
80 unsigned long *addr = data;
81 unsigned char old[4], *new;
84 * Replace the mcount stub with a pointer to the
85 * ip recorder function.
87 memcpy(old, &mcount_call, 4);
88 new = ftrace_call_replace(ip, *addr);
89 *addr = ftrace_modify_code(ip, old, new);
95 int __init ftrace_dyn_arch_init(void *data)
97 ftrace_mcount_set(data);