1 /***********************license start***************
2 * Copyright (c) 2003-2008 Cavium Networks (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 Networks 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT
32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
45 // The function defined here is called for every function as it is executed.
46 // These calls are automatically inserted by GCC when the switch "-pg" is
47 // used. This allows cvmx-log to add a PC entry as each function is executed.
48 // This information, along with the timestamps can give the user a good idea
49 // of the performance characteristics of their program. This function normally
50 // takes about 22 cycles to execute.
55 #include <asm/regdef.h>
58 #include <machine/asm.h>
59 #include <machine/regdef.h>
67 // All registers we use must be saved since calls are added by gcc
68 // after register allocation. The at register ($3) will contain the
69 // original ra register before the _mcount call. Also the compiler
70 // automatically performs a "dsubu sp, sp, 16" before we're called.
71 // At the end of this function all registers must have their original
72 // values and the stack pointr must be adjusted by 16. This code is
73 // pretty unreadable since it has been arranged to promote dual issue.
80 sd s3, 24(sp) // Save register
81 rdhwr s3, $31 // Read the cycle count
82 sd s0, 0(sp) // Save register
83 LA s0, cvmx_log_buffer_end_ptr // Load the address of the end of the log buffer
84 sd s1, 8(sp) // Save register
85 LA s1, cvmx_log_buffer_write_ptr // Load the address of the location in the log buffer
86 sd s2, 16(sp) // Save register
87 ld s0, 0(s0) // Get value of the current log buffer end location
88 ld s2, 0(s1) // Get value of the current log buffer location
89 dsubu s0, s0, s2 // Subtract the end pointer and the write pointer
90 sltiu s0, s0, 16 // Check if there are at least 16 bytes
91 bne s0, $0, call_c_pc // Call the slow C function if we don't have room in the log
92 li s0, 0x001 // 11 bit constant that matches the first 11 bits of a CVMX_LOG_TYPE_PC header
93 sd ra, 8(s2) // Write the pc to the log
94 dins s3, s0, 53, 11 // Overwrite the upper cycle count bits with the CVMX_LOG_TYPE_PC header
95 sd s3, 0(s2) // Write the log header
96 daddu s2, s2, 16 // Increment the write location ptr
97 sd s2, 0(s1) // Store the write location ptr
99 ld s0, 0(sp) // Restore register
100 ld s1, 8(sp) // Restore register
101 ld s2, 16(sp) // Restore register
102 ld s3, 24(sp) // Restore register
103 daddu sp, sp, 32 // Pop everything off the stack, even the 16 bytes done by gcc
104 jr ra // Return to the caller and
105 or ra, $1, $1 // make sure the ra is back to its original value
108 // The registers used by the C code may change based on optimizations. To be
109 // safe, I'll save all registers. We're in the slow path case anyway.
126 // s0, s1, s2, s3 are already saved
159 // s0, s1, s2, s3 will be restored later