-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
- Loading branch information
David Miller
authored and
Thomas Gleixner
committed
May 23, 2008
1 parent
aa5e5ce
commit d05f5f9
Showing
5 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <linux/spinlock.h> | ||
#include <linux/hardirq.h> | ||
#include <linux/ftrace.h> | ||
#include <linux/percpu.h> | ||
#include <linux/init.h> | ||
#include <linux/list.h> | ||
|
||
static const u32 ftrace_nop = 0x01000000; | ||
|
||
notrace int ftrace_ip_converted(unsigned long ip) | ||
{ | ||
u32 insn = *(u32 *) ip; | ||
|
||
return (insn == ftrace_nop); | ||
} | ||
|
||
notrace unsigned char *ftrace_nop_replace(void) | ||
{ | ||
return (char *)&ftrace_nop; | ||
} | ||
|
||
notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr) | ||
{ | ||
static u32 call; | ||
s32 off; | ||
|
||
off = ((s32)addr - (s32)ip); | ||
call = 0x40000000 | ((u32)off >> 2); | ||
|
||
return (unsigned char *) &call; | ||
} | ||
|
||
notrace int | ||
ftrace_modify_code(unsigned long ip, unsigned char *old_code, | ||
unsigned char *new_code) | ||
{ | ||
u32 old = *(u32 *)old_code; | ||
u32 new = *(u32 *)new_code; | ||
u32 replaced; | ||
int faulted; | ||
|
||
__asm__ __volatile__( | ||
"1: cas [%[ip]], %[old], %[new]\n" | ||
" flush %[ip]\n" | ||
" mov 0, %[faulted]\n" | ||
"2:\n" | ||
" .section .fixup,#alloc,#execinstr\n" | ||
" .align 4\n" | ||
"3: sethi %%hi(2b), %[faulted]\n" | ||
" jmpl %[faulted] + %%lo(2b), %%g0\n" | ||
" mov 1, %[faulted]\n" | ||
" .previous\n" | ||
" .section __ex_table,\"a\"\n" | ||
" .align 4\n" | ||
" .word 1b, 3b\n" | ||
" .previous\n" | ||
: "=r" (replaced), [faulted] "=r" (faulted) | ||
: [new] "0" (new), [old] "r" (old), [ip] "r" (ip) | ||
: "memory"); | ||
|
||
if (replaced != old && replaced != new) | ||
faulted = 2; | ||
|
||
return faulted; | ||
} | ||
|
||
notrace int ftrace_update_ftrace_func(ftrace_func_t func) | ||
{ | ||
unsigned long ip = (unsigned long)(&ftrace_call); | ||
unsigned char old[4], *new; | ||
|
||
memcpy(old, &ftrace_call, 4); | ||
new = ftrace_call_replace(ip, (unsigned long)func); | ||
return ftrace_modify_code(ip, old, new); | ||
} | ||
|
||
notrace int ftrace_mcount_set(unsigned long *data) | ||
{ | ||
unsigned long ip = (long)(&mcount_call); | ||
unsigned long *addr = data; | ||
unsigned char old[4], *new; | ||
|
||
/* | ||
* Replace the mcount stub with a pointer to the | ||
* ip recorder function. | ||
*/ | ||
memcpy(old, &mcount_call, 4); | ||
new = ftrace_call_replace(ip, *addr); | ||
*addr = ftrace_modify_code(ip, old, new); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
int __init ftrace_dyn_arch_init(void *data) | ||
{ | ||
ftrace_mcount_set(data); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters