1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 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. 17 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 21 * permission. 22 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 26 * countries. 27 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**************************************/ 39 40 41 42 43 44 45 46// 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. 53// 54 55#ifdef __linux__ 56#include <asm/asm.h> 57#include <asm/regdef.h> 58#define LA dla 59#else 60#include <machine/asm.h> 61#include <machine/regdef.h> 62#define LA la 63#endif 64 65.set noreorder 66.set noat 67LEAF(_mcount) 68 // 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. 76 // 77#ifdef __linux__ 78 dsubu sp, sp, 32 79#else 80 dsubu sp, sp, 16 81#endif 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 100return_c_pc: 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 108 109call_c_pc: 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. 112 dsubu sp, sp, 216 113 sd $1, 0(sp) 114 sd $2, 8(sp) 115 sd $3, 16(sp) 116 sd $4, 24(sp) 117 sd $5, 32(sp) 118 sd $6, 40(sp) 119 sd $7, 48(sp) 120 sd $8, 56(sp) 121 sd $9, 64(sp) 122 sd $10, 72(sp) 123 sd $11, 80(sp) 124 sd $12, 88(sp) 125 sd $13, 96(sp) 126 sd $14, 104(sp) 127 sd $15, 112(sp) 128 // s0, s1, s2, s3 are already saved 129 sd $20, 120(sp) 130 sd $21, 128(sp) 131 sd $22, 136(sp) 132 sd $23, 144(sp) 133 sd $24, 152(sp) 134 sd $25, 160(sp) 135 sd $26, 168(sp) 136 sd $27, 176(sp) 137 sd $28, 184(sp) 138 sd $29, 192(sp) 139 sd $30, 200(sp) 140 sd $31, 208(sp) 141 142 or a0, ra, ra 143 jal cvmx_log_pc 144 nop 145 146 ld $1, 0(sp) 147 ld $2, 8(sp) 148 ld $3, 16(sp) 149 ld $4, 24(sp) 150 ld $5, 32(sp) 151 ld $6, 40(sp) 152 ld $7, 48(sp) 153 ld $8, 56(sp) 154 ld $9, 64(sp) 155 ld $10, 72(sp) 156 ld $11, 80(sp) 157 ld $12, 88(sp) 158 ld $13, 96(sp) 159 ld $14, 104(sp) 160 ld $15, 112(sp) 161 // s0, s1, s2, s3 will be restored later 162 ld $20, 120(sp) 163 ld $21, 128(sp) 164 ld $22, 136(sp) 165 ld $23, 144(sp) 166 ld $24, 152(sp) 167 ld $25, 160(sp) 168 ld $26, 168(sp) 169 ld $27, 176(sp) 170 ld $28, 184(sp) 171 ld $29, 192(sp) 172 ld $30, 200(sp) 173 ld $31, 208(sp) 174 b return_c_pc 175 daddu sp, sp, 216 176 177END(_mcount) 178 179