]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/contrib/octeon-sdk/cvmx-log-arc.S
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / contrib / octeon-sdk / cvmx-log-arc.S
1 /***********************license start***************
2  * Copyright (c) 2003-2008 Cavium Networks (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 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
21  *       permission.
22  *
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.
33  *
34  *
35  * For any questions regarding licensing please contact marketing@caviumnetworks.com
36  *
37  ***********************license end**************************************/
38
39
40
41
42
43
44 //
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.
51 //
52
53 #ifdef __linux__
54 #include <asm/asm.h>
55 #include <asm/regdef.h>
56 #define LA dla
57 #else
58 #include <machine/asm.h>
59 #include <machine/regdef.h>
60 #define LA la
61 #endif
62
63 .set noreorder
64 .set noat
65 LEAF(_mcount)
66         //
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.
74         //
75 #ifdef __linux__
76         dsubu   sp, sp, 32
77 #else
78         dsubu   sp, sp, 16
79 #endif
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
98 return_c_pc:
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
106
107 call_c_pc:
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.
110         dsubu   sp, sp, 216
111         sd      $1, 0(sp)
112         sd      $2, 8(sp)
113         sd      $3, 16(sp)
114         sd      $4, 24(sp)
115         sd      $5, 32(sp)
116         sd      $6, 40(sp)
117         sd      $7, 48(sp)
118         sd      $8, 56(sp)
119         sd      $9, 64(sp)
120         sd      $10, 72(sp)
121         sd      $11, 80(sp)
122         sd      $12, 88(sp)
123         sd      $13, 96(sp)
124         sd      $14, 104(sp)
125         sd      $15, 112(sp)
126         // s0, s1, s2, s3 are already saved
127         sd      $20, 120(sp)
128         sd      $21, 128(sp)
129         sd      $22, 136(sp)
130         sd      $23, 144(sp)
131         sd      $24, 152(sp)
132         sd      $25, 160(sp)
133         sd      $26, 168(sp)
134         sd      $27, 176(sp)
135         sd      $28, 184(sp)
136         sd      $29, 192(sp)
137         sd      $30, 200(sp)
138         sd      $31, 208(sp)
139
140         or      a0, ra, ra
141         jal     cvmx_log_pc
142         nop
143
144         ld      $1, 0(sp)
145         ld      $2, 8(sp)
146         ld      $3, 16(sp)
147         ld      $4, 24(sp)
148         ld      $5, 32(sp)
149         ld      $6, 40(sp)
150         ld      $7, 48(sp)
151         ld      $8, 56(sp)
152         ld      $9, 64(sp)
153         ld      $10, 72(sp)
154         ld      $11, 80(sp)
155         ld      $12, 88(sp)
156         ld      $13, 96(sp)
157         ld      $14, 104(sp)
158         ld      $15, 112(sp)
159         // s0, s1, s2, s3 will be restored later
160         ld      $20, 120(sp)
161         ld      $21, 128(sp)
162         ld      $22, 136(sp)
163         ld      $23, 144(sp)
164         ld      $24, 152(sp)
165         ld      $25, 160(sp)
166         ld      $26, 168(sp)
167         ld      $27, 176(sp)
168         ld      $28, 184(sp)
169         ld      $29, 192(sp)
170         ld      $30, 200(sp)
171         ld      $31, 208(sp)
172         b       return_c_pc
173         daddu   sp, sp, 216
174
175 END(_mcount)
176