1 // $Id: profile_cg.c,v 1.1.2.1 2011/05/17 04:37:57 sadanan Exp $
2 /******************************************************************************
4 * Copyright (C) 2002 - 2014 Xilinx, Inc. All rights reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * Use of the Software is limited solely to applications:
17 * (a) running on a Xilinx device, or
18 * (b) that interact with a Xilinx device through a bus or interconnect.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * Except as contained in this notice, the name of the Xilinx shall not be used
29 * in advertising or otherwise to promote the sale, use or other dealings in
30 * this Software without prior written authorization from Xilinx.
32 ******************************************************************************/
35 #include "_profile_timer_hw.h"
36 #ifdef PROC_MICROBLAZE
37 #include "mblaze_nt_types.h"
41 * The mcount fucntion is excluded from the library, if the user defines
44 #ifndef PROFILE_NO_GRAPH
50 extern struct gmonparam *_gmonparam;
52 #ifdef PROFILE_NO_FUNCPTR
53 int searchpc( struct fromto_struct *cgtable, int cgtable_size, unsigned long frompc )
57 while( (index < cgtable_size) && (cgtable[index].frompc != frompc) ){
60 if( index == cgtable_size )
66 int searchpc( struct fromstruct *froms, int fromssize, unsigned long frompc )
70 while( (index < fromssize) && (froms[index].frompc != frompc) ){
73 if( index == fromssize )
78 #endif /* PROFILE_NO_FUNCPTR */
81 void mcount( unsigned long frompc, unsigned long selfpc )
83 register struct gmonparam *p = NULL;
84 register long toindex, fromindex;
89 //print("CG: "); putnum(frompc); print("->"); putnum(selfpc); print("\r\n");
90 // check that frompcindex is a reasonable pc value.
91 // for example: signal catchers get called from the stack,
92 // not from text space. too bad.
94 for(j = 0; j < n_gmon_sections; j++ ){
95 if((frompc >= _gmonparam[j].lowpc) && (frompc < _gmonparam[j].highpc)) {
100 if( j == n_gmon_sections )
103 #ifdef PROFILE_NO_FUNCPTR
104 fromindex = searchpc( p->cgtable, p->cgtable_size, frompc ) ;
105 if( fromindex == -1 ) {
106 fromindex = p->cgtable_size ;
108 p->cgtable[fromindex].frompc = frompc ;
109 p->cgtable[fromindex].selfpc = selfpc ;
110 p->cgtable[fromindex].count = 1 ;
113 p->cgtable[fromindex].count++ ;
115 fromindex = searchpc( p->froms, p->fromssize, frompc ) ;
116 if( fromindex == -1 ) {
117 fromindex = p->fromssize ;
119 //if( fromindex >= N_FROMS ) {
120 //print("Error : From PC table overflow\r\n") ;
123 p->froms[fromindex].frompc = frompc ;
124 p->froms[fromindex].link = -1 ;
126 toindex = p->froms[fromindex].link ;
127 while(toindex != -1) {
128 toindex = (p->tossize - toindex)-1 ;
129 if( p->tos[toindex].selfpc == selfpc ) {
130 p->tos[toindex].count++ ;
133 toindex = p->tos[toindex].link ;
137 //if( toindex == -1 ) {
140 //if( toindex >= N_TOS ) {
141 //print("Error : To PC table overflow\r\n") ;
144 p->tos[0].selfpc = selfpc ;
145 p->tos[0].count = 1 ;
146 p->tos[0].link = p->froms[fromindex].link ;
147 p->froms[fromindex].link = p->tossize-1 ;
151 p->state = GMON_PROF_ON;
154 p->state = GMON_PROF_ERROR;
161 #endif /* PROFILE_NO_GRAPH */