1 /******************************************************************************
3 * Copyright (C) 2002 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
34 #include "_profile_timer_hw.h"
35 #ifdef PROC_MICROBLAZE
36 #include "mblaze_nt_types.h"
40 * The mcount fucntion is excluded from the library, if the user defines
43 #ifndef PROFILE_NO_GRAPH
49 #ifdef PROFILE_NO_FUNCPTR
50 s32 searchpc(const struct fromto_struct *cgtable, s32 cgtable_size, u32 frompc );
52 s32 searchpc(const struct fromstruct *froms, s32 fromssize, u32 frompc );
55 /*extern struct gmonparam *_gmonparam, */
57 #ifdef PROFILE_NO_FUNCPTR
58 s32 searchpc(const struct fromto_struct *cgtable, s32 cgtable_size, u32 frompc )
62 while( (index < cgtable_size) && (cgtable[index].frompc != frompc) ){
65 if( index == cgtable_size ) {
72 s32 searchpc(const struct fromstruct *froms, s32 fromssize, u32 frompc )
77 while( (index < fromssize) && (froms[index].frompc != frompc) ){
80 if( index == fromssize ) {
87 #endif /* PROFILE_NO_FUNCPTR */
90 void mcount( u32 frompc, u32 selfpc )
92 register struct gmonparam *p = NULL;
93 register s32 toindex, fromindex;
98 /*print("CG: "), putnum(frompc), print("->"), putnum(selfpc), print("\r\n") ,
99 * check that frompcindex is a reasonable pc value.
100 * for example: signal catchers get called from the stack,
101 * not from text space. too bad.
103 for(j = 0; j < n_gmon_sections; j++ ){
104 if((frompc >= _gmonparam[j].lowpc) && (frompc < _gmonparam[j].highpc)) {
109 if( j == n_gmon_sections ) {
113 #ifdef PROFILE_NO_FUNCPTR
114 fromindex = searchpc( p->cgtable, p->cgtable_size, frompc ) ;
115 if( fromindex == -1 ) {
116 fromindex = p->cgtable_size ;
118 p->cgtable[fromindex].frompc = frompc ;
119 p->cgtable[fromindex].selfpc = selfpc ;
120 p->cgtable[fromindex].count = 1 ;
123 p->cgtable[fromindex].count++ ;
125 fromindex = (s32)searchpc( p->froms, ((s32)p->fromssize), frompc ) ;
126 if( fromindex == -1 ) {
127 fromindex = (s32)p->fromssize ;
129 /*if( fromindex >= N_FROMS ) {
130 * print("Error : From PC table overflow\r\n")
133 p->froms[fromindex].frompc = frompc ;
134 p->froms[fromindex].link = -1 ;
136 toindex = ((s32)(p->froms[fromindex].link));
137 while(toindex != -1) {
138 toindex = (((s32)p->tossize) - toindex)-1 ;
139 if( p->tos[toindex].selfpc == selfpc ) {
140 p->tos[toindex].count++ ;
143 toindex = ((s32)(p->tos[toindex].link)) ;
147 /*if( toindex == -1 ) { */
150 /* if( toindex >= N_TOS ) {
151 * print("Error : To PC table overflow\r\n")
154 p->tos[0].selfpc = selfpc ;
155 p->tos[0].count = 1 ;
156 p->tos[0].link = p->froms[fromindex].link ;
157 p->froms[fromindex].link = ((s32)(p->tossize))-((s32)1);
161 p->state = GMON_PROF_ON;
162 goto enable_timer_label ;
164 /*p->state = GMON_PROF_ERROR */
171 #endif /* PROFILE_NO_GRAPH */