1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
47 // The function defined here is called for every function as it is executed.
48 // These calls are automatically inserted by GCC when the switch "-pg" is
49 // used. This allows cvmx-log to add a PC entry as each function is executed.
50 // This information, along with the timestamps can give the user a good idea
51 // of the performance characteristics of their program. This function normally
52 // takes about 22 cycles to execute.
57 #include <asm/regdef.h>
60 #include <machine/asm.h>
61 #include <machine/regdef.h>
69 // All registers we use must be saved since calls are added by gcc
70 // after register allocation. The at register ($3) will contain the
71 // original ra register before the _mcount call. Also the compiler
72 // automatically performs a "dsubu sp, sp, 16" before we're called.
73 // At the end of this function all registers must have their original
74 // values and the stack pointr must be adjusted by 16. This code is
75 // pretty unreadable since it has been arranged to promote dual issue.
82 sd s3, 24(sp) // Save register
83 rdhwr s3, $31 // Read the cycle count
84 sd s0, 0(sp) // Save register
85 LA s0, cvmx_log_buffer_end_ptr // Load the address of the end of the log buffer
86 sd s1, 8(sp) // Save register
87 LA s1, cvmx_log_buffer_write_ptr // Load the address of the location in the log buffer
88 sd s2, 16(sp) // Save register
89 ld s0, 0(s0) // Get value of the current log buffer end location
90 ld s2, 0(s1) // Get value of the current log buffer location
91 dsubu s0, s0, s2 // Subtract the end pointer and the write pointer
92 sltiu s0, s0, 16 // Check if there are at least 16 bytes
93 bne s0, $0, call_c_pc // Call the slow C function if we don't have room in the log
94 li s0, 0x001 // 11 bit constant that matches the first 11 bits of a CVMX_LOG_TYPE_PC header
95 sd ra, 8(s2) // Write the pc to the log
96 dins s3, s0, 53, 11 // Overwrite the upper cycle count bits with the CVMX_LOG_TYPE_PC header
97 sd s3, 0(s2) // Write the log header
98 daddu s2, s2, 16 // Increment the write location ptr
99 sd s2, 0(s1) // Store the write location ptr
101 ld s0, 0(sp) // Restore register
102 ld s1, 8(sp) // Restore register
103 ld s2, 16(sp) // Restore register
104 ld s3, 24(sp) // Restore register
105 daddu sp, sp, 32 // Pop everything off the stack, even the 16 bytes done by gcc
106 jr ra // Return to the caller and
107 or ra, $1, $1 // make sure the ra is back to its original value
110 // The registers used by the C code may change based on optimizations. To be
111 // safe, I'll save all registers. We're in the slow path case anyway.
128 // s0, s1, s2, s3 are already saved
161 // s0, s1, s2, s3 will be restored later