]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/sparc64/kernel/ftrace.c
c17373195b1e849306eb0127953e0862c49f6df6
[linux-2.6-omap-h63xx.git] / arch / sparc64 / kernel / ftrace.c
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
8 static const u32 ftrace_nop = 0x01000000;
9
10 notrace unsigned char *ftrace_nop_replace(void)
11 {
12         return (char *)&ftrace_nop;
13 }
14
15 notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
16 {
17         static u32 call;
18         s32 off;
19
20         off = ((s32)addr - (s32)ip);
21         call = 0x40000000 | ((u32)off >> 2);
22
23         return (unsigned char *) &call;
24 }
25
26 notrace int
27 ftrace_modify_code(unsigned long ip, unsigned char *old_code,
28                    unsigned char *new_code)
29 {
30         u32 old = *(u32 *)old_code;
31         u32 new = *(u32 *)new_code;
32         u32 replaced;
33         int faulted;
34
35         __asm__ __volatile__(
36         "1:     cas     [%[ip]], %[old], %[new]\n"
37         "       flush   %[ip]\n"
38         "       mov     0, %[faulted]\n"
39         "2:\n"
40         "       .section .fixup,#alloc,#execinstr\n"
41         "       .align  4\n"
42         "3:     sethi   %%hi(2b), %[faulted]\n"
43         "       jmpl    %[faulted] + %%lo(2b), %%g0\n"
44         "        mov    1, %[faulted]\n"
45         "       .previous\n"
46         "       .section __ex_table,\"a\"\n"
47         "       .align  4\n"
48         "       .word   1b, 3b\n"
49         "       .previous\n"
50         : "=r" (replaced), [faulted] "=r" (faulted)
51         : [new] "0" (new), [old] "r" (old), [ip] "r" (ip)
52         : "memory");
53
54         if (replaced != old && replaced != new)
55                 faulted = 2;
56
57         return faulted;
58 }
59
60 notrace int ftrace_update_ftrace_func(ftrace_func_t func)
61 {
62         unsigned long ip = (unsigned long)(&ftrace_call);
63         unsigned char old[4], *new;
64
65         memcpy(old, &ftrace_call, 4);
66         new = ftrace_call_replace(ip, (unsigned long)func);
67         return ftrace_modify_code(ip, old, new);
68 }
69
70 notrace int ftrace_mcount_set(unsigned long *data)
71 {
72         unsigned long ip = (long)(&mcount_call);
73         unsigned long *addr = data;
74         unsigned char old[4], *new;
75
76         /*
77          * Replace the mcount stub with a pointer to the
78          * ip recorder function.
79          */
80         memcpy(old, &mcount_call, 4);
81         new = ftrace_call_replace(ip, *addr);
82         *addr = ftrace_modify_code(ip, old, new);
83
84         return 0;
85 }
86
87
88 int __init ftrace_dyn_arch_init(void *data)
89 {
90         ftrace_mcount_set(data);
91         return 0;
92 }