]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v4_1/src/profile/profile_cg.c
e94bd28656142c6dd04ef5c79b3d3fd8d1e71314
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v4_1 / src / profile / profile_cg.c
1 //
2 // Copyright (c) 2002-2010 Xilinx, Inc.  All rights reserved.
3 // Xilinx, Inc.
4 //
5 // XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
6 // COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
7 // ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
8 // STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
9 // IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
10 // FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
11 // XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
12 // THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
13 // ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
14 // FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
15 // AND FITNESS FOR A PARTICULAR PURPOSE.
16 //
17 // $Id: profile_cg.c,v 1.1.2.1 2011/05/17 04:37:57 sadanan Exp $
18 //
19
20 #include "profile.h"
21 #include "_profile_timer_hw.h"
22 #ifdef PROC_MICROBLAZE
23 #include "mblaze_nt_types.h"
24 #endif
25
26 /*
27  * The mcount fucntion is excluded from the library, if the user defines
28  * PROFILE_NO_GRAPH.
29  */
30 #ifndef PROFILE_NO_GRAPH
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 extern struct gmonparam *_gmonparam;
37
38 #ifdef PROFILE_NO_FUNCPTR
39 int searchpc( struct fromto_struct *cgtable, int cgtable_size, unsigned long frompc )
40 {
41         int index = 0 ;
42
43         while( (index < cgtable_size) && (cgtable[index].frompc != frompc) ){
44                 index++ ;
45         }
46         if( index == cgtable_size )
47                 return -1 ;
48         else
49                 return index ;
50 }
51 #else
52 int searchpc( struct fromstruct *froms, int fromssize, unsigned long frompc )
53 {
54         int index = 0 ;
55
56         while( (index < fromssize) && (froms[index].frompc != frompc) ){
57                 index++ ;
58         }
59         if( index == fromssize )
60                 return -1 ;
61         else
62                 return index ;
63 }
64 #endif          /* PROFILE_NO_FUNCPTR */
65
66
67 void mcount( unsigned long frompc, unsigned long selfpc )
68 {
69         register struct gmonparam *p = NULL;
70         register long toindex, fromindex;
71         int j;
72
73         disable_timer();
74
75         //print("CG: "); putnum(frompc); print("->"); putnum(selfpc); print("\r\n");
76         // check that frompcindex is a reasonable pc value.
77         // for example: signal catchers get called from the stack,
78         //              not from text space.  too bad.
79         //
80         for(j = 0; j < n_gmon_sections; j++ ){
81                 if((frompc >= _gmonparam[j].lowpc) && (frompc < _gmonparam[j].highpc)) {
82                         p = &_gmonparam[j];
83                         break;
84                 }
85         }
86         if( j == n_gmon_sections )
87                 goto done;
88
89 #ifdef PROFILE_NO_FUNCPTR
90         fromindex = searchpc( p->cgtable, p->cgtable_size, frompc ) ;
91         if( fromindex == -1 ) {
92                 fromindex = p->cgtable_size ;
93                 p->cgtable_size++ ;
94                 p->cgtable[fromindex].frompc = frompc ;
95                 p->cgtable[fromindex].selfpc = selfpc ;
96                 p->cgtable[fromindex].count = 1 ;
97                 goto done ;
98         }
99         p->cgtable[fromindex].count++ ;
100 #else
101         fromindex = searchpc( p->froms, p->fromssize, frompc ) ;
102         if( fromindex == -1 ) {
103                 fromindex = p->fromssize ;
104                 p->fromssize++ ;
105                 //if( fromindex >= N_FROMS ) {
106                 //print("Error : From PC table overflow\r\n") ;
107                 //goto overflow ;
108                 //}
109                 p->froms[fromindex].frompc = frompc ;
110                 p->froms[fromindex].link = -1 ;
111         }else {
112                 toindex = p->froms[fromindex].link ;
113                 while(toindex != -1) {
114                         toindex = (p->tossize - toindex)-1 ;
115                         if( p->tos[toindex].selfpc == selfpc ) {
116                                 p->tos[toindex].count++ ;
117                                 goto done ;
118                         }
119                         toindex = p->tos[toindex].link ;
120                 }
121         }
122
123         //if( toindex == -1 ) {
124         p->tos-- ;
125         p->tossize++ ;
126         //if( toindex >= N_TOS ) {
127         //print("Error : To PC table overflow\r\n") ;
128         //goto overflow ;
129         //}
130         p->tos[0].selfpc = selfpc ;
131         p->tos[0].count = 1 ;
132         p->tos[0].link = p->froms[fromindex].link ;
133         p->froms[fromindex].link = p->tossize-1 ;
134 #endif
135
136  done:
137         p->state = GMON_PROF_ON;
138         goto enable_timer ;
139  //overflow:
140         p->state = GMON_PROF_ERROR;
141  enable_timer:
142         enable_timer();
143         return ;
144 }
145
146
147 #endif          /* PROFILE_NO_GRAPH */
148