cbb45edad4646252f967c81dbb90efc8c4446fdf
[linux-2.6-block.git] / arch / mips / kernel / mcount.S
1 /*
2  * MIPS specific _mcount support
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive for
6  * more details.
7  *
8  * Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University, China
9  * Author: Wu Zhangjin <wuzj@lemote.com>
10  */
11
12 #include <asm/regdef.h>
13 #include <asm/stackframe.h>
14 #include <asm/ftrace.h>
15
16         .text
17         .set noreorder
18         .set noat
19
20         .macro MCOUNT_SAVE_REGS
21         PTR_SUBU        sp, PT_SIZE
22         PTR_S   ra, PT_R31(sp)
23         PTR_S   AT, PT_R1(sp)
24         PTR_S   a0, PT_R4(sp)
25         PTR_S   a1, PT_R5(sp)
26         PTR_S   a2, PT_R6(sp)
27         PTR_S   a3, PT_R7(sp)
28 #ifdef CONFIG_64BIT
29         PTR_S   a4, PT_R8(sp)
30         PTR_S   a5, PT_R9(sp)
31         PTR_S   a6, PT_R10(sp)
32         PTR_S   a7, PT_R11(sp)
33 #endif
34         .endm
35
36         .macro MCOUNT_RESTORE_REGS
37         PTR_L   ra, PT_R31(sp)
38         PTR_L   AT, PT_R1(sp)
39         PTR_L   a0, PT_R4(sp)
40         PTR_L   a1, PT_R5(sp)
41         PTR_L   a2, PT_R6(sp)
42         PTR_L   a3, PT_R7(sp)
43 #ifdef CONFIG_64BIT
44         PTR_L   a4, PT_R8(sp)
45         PTR_L   a5, PT_R9(sp)
46         PTR_L   a6, PT_R10(sp)
47         PTR_L   a7, PT_R11(sp)
48 #endif
49 #ifdef CONFIG_64BIT
50         PTR_ADDIU       sp, PT_SIZE
51 #else
52         PTR_ADDIU       sp, (PT_SIZE + 8)
53 #endif
54 .endm
55
56         .macro RETURN_BACK
57         jr ra
58          move ra, AT
59         .endm
60
61 NESTED(_mcount, PT_SIZE, ra)
62         lw      t0, function_trace_stop
63         bnez    t0, ftrace_stub
64          nop
65         PTR_LA  t0, ftrace_stub
66         PTR_L   t1, ftrace_trace_function /* Prepare t1 for (1) */
67         bne     t0, t1, static_trace
68          nop
69         b       ftrace_stub
70          nop
71
72 static_trace:
73         MCOUNT_SAVE_REGS
74
75         move    a0, ra          /* arg1: next ip, selfaddr */
76         jalr    t1      /* (1) call *ftrace_trace_function */
77          move   a1, AT          /* arg2: the caller's next ip, parent */
78
79         MCOUNT_RESTORE_REGS
80         .globl ftrace_stub
81 ftrace_stub:
82         RETURN_BACK
83         END(_mcount)
84
85         .set at
86         .set reorder