MIPS: Tracing: Make function graph tracer work with -mmcount-ra-address
[linux-2.6-block.git] / arch / mips / kernel / mcount.S
index 522e91c688fc075fe371d8c48cb1fb9f875b7665..0a9cfdb271dd2c2c92f0cb8f31930f84d73c6127 100644 (file)
@@ -70,6 +70,9 @@ _mcount:
         nop
 
        MCOUNT_SAVE_REGS
+#ifdef KBUILD_MCOUNT_RA_ADDRESS
+       PTR_S   t0, PT_R12(sp)  /* t0 saved the location of the return address(at) by -mmcount-ra-address */
+#endif
 
        move    a0, ra          /* arg1: next ip, selfaddr */
        .globl ftrace_call
@@ -133,11 +136,22 @@ ftrace_stub:
 NESTED(ftrace_graph_caller, PT_SIZE, ra)
 #ifdef CONFIG_DYNAMIC_FTRACE
        PTR_L   a1, PT_R31(sp)  /* load the original ra from the stack */
+#ifdef KBUILD_MCOUNT_RA_ADDRESS
+       PTR_L   t0, PT_R12(sp)  /* load the original t0 from the stack */
+#endif
 #else
        MCOUNT_SAVE_REGS
        move    a1, ra          /* arg2: next ip, selfaddr */
 #endif
+
+#ifdef KBUILD_MCOUNT_RA_ADDRESS
+       bnez    t0, 1f          /* non-leaf func: t0 saved the location of the return address */
+        nop
+       PTR_LA  t0, PT_R1(sp)   /* leaf func: get the location of at(old ra) from our own stack */
+1:     move    a0, t0          /* arg1: the location of the return address */
+#else
        PTR_LA  a0, PT_R1(sp)   /* arg1: &AT -> a0 */
+#endif
        jal     prepare_ftrace_return
 #ifdef CONFIG_FRAME_POINTER
         move   a2, fp          /* arg3: frame pointer */