]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v6_6/src/profile/profile_cg.c
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v6_6 / src / profile / profile_cg.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2014 Xilinx, Inc. All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32
33 #include "profile.h"
34 #include "_profile_timer_hw.h"
35 #ifdef PROC_MICROBLAZE
36 #include "mblaze_nt_types.h"
37 #endif
38
39 /*
40  * The mcount fucntion is excluded from the library, if the user defines
41  * PROFILE_NO_GRAPH.
42  */
43 #ifndef PROFILE_NO_GRAPH
44
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48
49 #ifdef PROFILE_NO_FUNCPTR
50 s32 searchpc(const struct fromto_struct *cgtable, s32 cgtable_size, u32 frompc );
51 #else
52 s32 searchpc(const struct fromstruct *froms, s32 fromssize, u32 frompc );
53 #endif
54
55 /*extern struct gmonparam *_gmonparam, */
56
57 #ifdef PROFILE_NO_FUNCPTR
58 s32 searchpc(const struct fromto_struct *cgtable, s32 cgtable_size, u32 frompc )
59 {
60         s32 index = 0 ;
61
62         while( (index < cgtable_size) && (cgtable[index].frompc != frompc) ){
63                 index++ ;
64         }
65         if( index == cgtable_size ) {
66                 return -1 ;
67         } else {
68                 return index ;
69         }
70 }
71 #else
72 s32 searchpc(const struct fromstruct *froms, s32 fromssize, u32 frompc )
73 {
74         s32 index = 0 ;
75         s32 Status;
76
77         while( (index < fromssize) && (froms[index].frompc != frompc) ){
78                 index++ ;
79         }
80         if( index == fromssize ) {
81                 Status = -1 ;
82         } else {
83                 Status = index ;
84         }
85         return Status;
86 }
87 #endif          /* PROFILE_NO_FUNCPTR */
88
89
90 void mcount( u32 frompc, u32 selfpc )
91 {
92         register struct gmonparam *p = NULL;
93         register s32 toindex, fromindex;
94         s32 j;
95
96         disable_timer();
97
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.
102         */
103         for(j = 0; j < n_gmon_sections; j++ ){
104                 if((frompc >= _gmonparam[j].lowpc) && (frompc < _gmonparam[j].highpc)) {
105                         p = &_gmonparam[j];
106                         break;
107                 }
108         }
109         if( j == n_gmon_sections ) {
110                 goto done;
111         }
112
113 #ifdef PROFILE_NO_FUNCPTR
114         fromindex = searchpc( p->cgtable, p->cgtable_size, frompc ) ;
115         if( fromindex == -1 ) {
116                 fromindex = p->cgtable_size ;
117                 p->cgtable_size++ ;
118                 p->cgtable[fromindex].frompc = frompc ;
119                 p->cgtable[fromindex].selfpc = selfpc ;
120                 p->cgtable[fromindex].count = 1 ;
121                 goto done ;
122         }
123         p->cgtable[fromindex].count++ ;
124 #else
125         fromindex = (s32)searchpc( p->froms, ((s32)p->fromssize), frompc ) ;
126         if( fromindex == -1 ) {
127                 fromindex = (s32)p->fromssize ;
128                 p->fromssize++ ;
129                 /*if( fromindex >= N_FROMS ) {
130                 * print("Error : From PC table overflow\r\n")
131                 * goto overflow
132                 *}*/
133                 p->froms[fromindex].frompc = frompc ;
134                 p->froms[fromindex].link = -1 ;
135         }else {
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++ ;
141                                 goto done ;
142                         }
143                         toindex = ((s32)(p->tos[toindex].link)) ;
144                 }
145         }
146
147         /*if( toindex == -1 ) { */
148         p->tos-- ;
149         p->tossize++ ;
150         /* if( toindex >= N_TOS ) {
151         * print("Error : To PC table overflow\r\n")
152         * goto overflow
153         *} */
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);
158 #endif
159
160  done:
161         p->state = GMON_PROF_ON;
162         goto enable_timer_label ;
163  /* overflow: */
164         /*p->state = GMON_PROF_ERROR */
165  enable_timer_label:
166         enable_timer();
167         return ;
168 }
169
170
171 #endif          /* PROFILE_NO_GRAPH */