/*1* MIPS specific _mcount support2*3* This file is subject to the terms and conditions of the GNU General Public4* License. See the file "COPYING" in the main directory of this archive for5* more details.6*7* Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University, China8* Copyright (C) 2010 DSLab, Lanzhou University, China9* Author: Wu Zhangjin <[email protected]>10*/1112#include <asm/regdef.h>13#include <asm/stackframe.h>14#include <asm/ftrace.h>1516.text17.set noreorder18.set noat1920.macro MCOUNT_SAVE_REGS21PTR_SUBU sp, PT_SIZE22PTR_S ra, PT_R31(sp)23PTR_S AT, PT_R1(sp)24PTR_S a0, PT_R4(sp)25PTR_S a1, PT_R5(sp)26PTR_S a2, PT_R6(sp)27PTR_S a3, PT_R7(sp)28#ifdef CONFIG_64BIT29PTR_S a4, PT_R8(sp)30PTR_S a5, PT_R9(sp)31PTR_S a6, PT_R10(sp)32PTR_S a7, PT_R11(sp)33#endif34.endm3536.macro MCOUNT_RESTORE_REGS37PTR_L ra, PT_R31(sp)38PTR_L AT, PT_R1(sp)39PTR_L a0, PT_R4(sp)40PTR_L a1, PT_R5(sp)41PTR_L a2, PT_R6(sp)42PTR_L a3, PT_R7(sp)43#ifdef CONFIG_64BIT44PTR_L a4, PT_R8(sp)45PTR_L a5, PT_R9(sp)46PTR_L a6, PT_R10(sp)47PTR_L a7, PT_R11(sp)48PTR_ADDIU sp, PT_SIZE49#else50PTR_ADDIU sp, (PT_SIZE + 8)51#endif52.endm5354.macro RETURN_BACK55jr ra56move ra, AT57.endm5859/*60* The -mmcount-ra-address option of gcc 4.5 uses register $12 to pass61* the location of the parent's return address.62*/63#define MCOUNT_RA_ADDRESS_REG $126465#ifdef CONFIG_DYNAMIC_FTRACE6667NESTED(ftrace_caller, PT_SIZE, ra)68.globl _mcount69_mcount:70b ftrace_stub71nop72lw t1, function_trace_stop73bnez t1, ftrace_stub74nop7576MCOUNT_SAVE_REGS77#ifdef KBUILD_MCOUNT_RA_ADDRESS78PTR_S MCOUNT_RA_ADDRESS_REG, PT_R12(sp)79#endif8081move a0, ra /* arg1: self return address */82.globl ftrace_call83ftrace_call:84nop /* a placeholder for the call to a real tracing function */85move a1, AT /* arg2: parent's return address */8687#ifdef CONFIG_FUNCTION_GRAPH_TRACER88.globl ftrace_graph_call89ftrace_graph_call:90nop91nop92#endif9394MCOUNT_RESTORE_REGS95.globl ftrace_stub96ftrace_stub:97RETURN_BACK98END(ftrace_caller)99100#else /* ! CONFIG_DYNAMIC_FTRACE */101102NESTED(_mcount, PT_SIZE, ra)103lw t1, function_trace_stop104bnez t1, ftrace_stub105nop106PTR_LA t1, ftrace_stub107PTR_L t2, ftrace_trace_function /* Prepare t2 for (1) */108bne t1, t2, static_trace109nop110111#ifdef CONFIG_FUNCTION_GRAPH_TRACER112PTR_L t3, ftrace_graph_return113bne t1, t3, ftrace_graph_caller114nop115PTR_LA t1, ftrace_graph_entry_stub116PTR_L t3, ftrace_graph_entry117bne t1, t3, ftrace_graph_caller118nop119#endif120b ftrace_stub121nop122123static_trace:124MCOUNT_SAVE_REGS125126move a0, ra /* arg1: self return address */127jalr t2 /* (1) call *ftrace_trace_function */128move a1, AT /* arg2: parent's return address */129130MCOUNT_RESTORE_REGS131.globl ftrace_stub132ftrace_stub:133RETURN_BACK134END(_mcount)135136#endif /* ! CONFIG_DYNAMIC_FTRACE */137138#ifdef CONFIG_FUNCTION_GRAPH_TRACER139140NESTED(ftrace_graph_caller, PT_SIZE, ra)141#ifndef CONFIG_DYNAMIC_FTRACE142MCOUNT_SAVE_REGS143#endif144145/* arg1: Get the location of the parent's return address */146#ifdef KBUILD_MCOUNT_RA_ADDRESS147#ifdef CONFIG_DYNAMIC_FTRACE148PTR_L a0, PT_R12(sp)149#else150move a0, MCOUNT_RA_ADDRESS_REG151#endif152bnez a0, 1f /* non-leaf func: stored in MCOUNT_RA_ADDRESS_REG */153nop154#endif155PTR_LA a0, PT_R1(sp) /* leaf func: the location in current stack */1561:157158/* arg2: Get self return address */159#ifdef CONFIG_DYNAMIC_FTRACE160PTR_L a1, PT_R31(sp)161#else162move a1, ra163#endif164165/* arg3: Get frame pointer of current stack */166#ifdef CONFIG_FRAME_POINTER167move a2, fp168#else /* ! CONFIG_FRAME_POINTER */169#ifdef CONFIG_64BIT170PTR_LA a2, PT_SIZE(sp)171#else172PTR_LA a2, (PT_SIZE+8)(sp)173#endif174#endif175176jal prepare_ftrace_return177nop178MCOUNT_RESTORE_REGS179RETURN_BACK180END(ftrace_graph_caller)181182.align 2183.globl return_to_handler184return_to_handler:185PTR_SUBU sp, PT_SIZE186PTR_S v0, PT_R2(sp)187188jal ftrace_return_to_handler189PTR_S v1, PT_R3(sp)190191/* restore the real parent address: v0 -> ra */192move ra, v0193194PTR_L v0, PT_R2(sp)195PTR_L v1, PT_R3(sp)196jr ra197PTR_ADDIU sp, PT_SIZE198#endif /* CONFIG_FUNCTION_GRAPH_TRACER */199200.set at201.set reorder202203204