aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc64/kernel')
-rw-r--r--arch/sparc64/kernel/Makefile1
-rw-r--r--arch/sparc64/kernel/ftrace.c99
2 files changed, 100 insertions, 0 deletions
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile
index ec4f5ebb1ca6..418b5782096e 100644
--- a/arch/sparc64/kernel/Makefile
+++ b/arch/sparc64/kernel/Makefile
@@ -14,6 +14,7 @@ obj-y := process.o setup.o cpu.o idprom.o \
14 power.o sbus.o sparc64_ksyms.o chmc.o \ 14 power.o sbus.o sparc64_ksyms.o chmc.o \
15 visemul.o prom.o of_device.o hvapi.o sstate.o mdesc.o 15 visemul.o prom.o of_device.o hvapi.o sstate.o mdesc.o
16 16
17obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
17obj-$(CONFIG_STACKTRACE) += stacktrace.o 18obj-$(CONFIG_STACKTRACE) += stacktrace.o
18obj-$(CONFIG_PCI) += ebus.o pci_common.o \ 19obj-$(CONFIG_PCI) += ebus.o pci_common.o \
19 pci_psycho.o pci_sabre.o pci_schizo.o \ 20 pci_psycho.o pci_sabre.o pci_schizo.o \
diff --git a/arch/sparc64/kernel/ftrace.c b/arch/sparc64/kernel/ftrace.c
new file mode 100644
index 000000000000..f449e6df6c4a
--- /dev/null
+++ b/arch/sparc64/kernel/ftrace.c
@@ -0,0 +1,99 @@
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>
7
8static const u32 ftrace_nop = 0x01000000;
9
10notrace int ftrace_ip_converted(unsigned long ip)
11{
12 u32 insn = *(u32 *) ip;
13
14 return (insn == ftrace_nop);
15}
16
17notrace unsigned char *ftrace_nop_replace(void)
18{
19 return (char *)&ftrace_nop;
20}
21
22notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
23{
24 static u32 call;
25 s32 off;
26
27 off = ((s32)addr - (s32)ip);
28 call = 0x40000000 | ((u32)off >> 2);
29
30 return (unsigned char *) &call;
31}
32
33notrace int
34ftrace_modify_code(unsigned long ip, unsigned char *old_code,
35 unsigned char *new_code)
36{
37 u32 old = *(u32 *)old_code;
38 u32 new = *(u32 *)new_code;
39 u32 replaced;
40 int faulted;
41
42 __asm__ __volatile__(
43 "1: cas [%[ip]], %[old], %[new]\n"
44 " flush %[ip]\n"
45 " mov 0, %[faulted]\n"
46 "2:\n"
47 " .section .fixup,#alloc,#execinstr\n"
48 " .align 4\n"
49 "3: sethi %%hi(2b), %[faulted]\n"
50 " jmpl %[faulted] + %%lo(2b), %%g0\n"
51 " mov 1, %[faulted]\n"
52 " .previous\n"
53 " .section __ex_table,\"a\"\n"
54 " .align 4\n"
55 " .word 1b, 3b\n"
56 " .previous\n"
57 : "=r" (replaced), [faulted] "=r" (faulted)
58 : [new] "0" (new), [old] "r" (old), [ip] "r" (ip)
59 : "memory");
60
61 if (replaced != old && replaced != new)
62 faulted = 2;
63
64 return faulted;
65}
66
67notrace int ftrace_update_ftrace_func(ftrace_func_t func)
68{
69 unsigned long ip = (unsigned long)(&ftrace_call);
70 unsigned char old[4], *new;
71
72 memcpy(old, &ftrace_call, 4);
73 new = ftrace_call_replace(ip, (unsigned long)func);
74 return ftrace_modify_code(ip, old, new);
75}
76
77notrace int ftrace_mcount_set(unsigned long *data)
78{
79 unsigned long ip = (long)(&mcount_call);
80 unsigned long *addr = data;
81 unsigned char old[4], *new;
82
83 /*
84 * Replace the mcount stub with a pointer to the
85 * ip recorder function.
86 */
87 memcpy(old, &mcount_call, 4);
88 new = ftrace_call_replace(ip, *addr);
89 *addr = ftrace_modify_code(ip, old, new);
90
91 return 0;
92}
93
94
95int __init ftrace_dyn_arch_init(void *data)
96{
97 ftrace_mcount_set(data);
98 return 0;
99}