]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/standalone_v4_2/src/profile/profile_cg.c
Common scheduler code:
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / standalone_v4_2 / src / profile / profile_cg.c
1 // $Id: profile_cg.c,v 1.1.2.1 2011/05/17 04:37:57 sadanan Exp $
2 /******************************************************************************
3 *
4 * Copyright (C) 2002 - 2014 Xilinx, Inc.  All rights reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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.
19 *
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
26 * SOFTWARE.
27 *
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.
31 *
32 ******************************************************************************/
33
34 #include "profile.h"
35 #include "_profile_timer_hw.h"
36 #ifdef PROC_MICROBLAZE
37 #include "mblaze_nt_types.h"
38 #endif
39
40 /*
41  * The mcount fucntion is excluded from the library, if the user defines
42  * PROFILE_NO_GRAPH.
43  */
44 #ifndef PROFILE_NO_GRAPH
45
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49
50 extern struct gmonparam *_gmonparam;
51
52 #ifdef PROFILE_NO_FUNCPTR
53 int searchpc( struct fromto_struct *cgtable, int cgtable_size, unsigned long frompc )
54 {
55         int index = 0 ;
56
57         while( (index < cgtable_size) && (cgtable[index].frompc != frompc) ){
58                 index++ ;
59         }
60         if( index == cgtable_size )
61                 return -1 ;
62         else
63                 return index ;
64 }
65 #else
66 int searchpc( struct fromstruct *froms, int fromssize, unsigned long frompc )
67 {
68         int index = 0 ;
69
70         while( (index < fromssize) && (froms[index].frompc != frompc) ){
71                 index++ ;
72         }
73         if( index == fromssize )
74                 return -1 ;
75         else
76                 return index ;
77 }
78 #endif          /* PROFILE_NO_FUNCPTR */
79
80
81 void mcount( unsigned long frompc, unsigned long selfpc )
82 {
83         register struct gmonparam *p = NULL;
84         register long toindex, fromindex;
85         int j;
86
87         disable_timer();
88
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.
93         //
94         for(j = 0; j < n_gmon_sections; j++ ){
95                 if((frompc >= _gmonparam[j].lowpc) && (frompc < _gmonparam[j].highpc)) {
96                         p = &_gmonparam[j];
97                         break;
98                 }
99         }
100         if( j == n_gmon_sections )
101                 goto done;
102
103 #ifdef PROFILE_NO_FUNCPTR
104         fromindex = searchpc( p->cgtable, p->cgtable_size, frompc ) ;
105         if( fromindex == -1 ) {
106                 fromindex = p->cgtable_size ;
107                 p->cgtable_size++ ;
108                 p->cgtable[fromindex].frompc = frompc ;
109                 p->cgtable[fromindex].selfpc = selfpc ;
110                 p->cgtable[fromindex].count = 1 ;
111                 goto done ;
112         }
113         p->cgtable[fromindex].count++ ;
114 #else
115         fromindex = searchpc( p->froms, p->fromssize, frompc ) ;
116         if( fromindex == -1 ) {
117                 fromindex = p->fromssize ;
118                 p->fromssize++ ;
119                 //if( fromindex >= N_FROMS ) {
120                 //print("Error : From PC table overflow\r\n") ;
121                 //goto overflow ;
122                 //}
123                 p->froms[fromindex].frompc = frompc ;
124                 p->froms[fromindex].link = -1 ;
125         }else {
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++ ;
131                                 goto done ;
132                         }
133                         toindex = p->tos[toindex].link ;
134                 }
135         }
136
137         //if( toindex == -1 ) {
138         p->tos-- ;
139         p->tossize++ ;
140         //if( toindex >= N_TOS ) {
141         //print("Error : To PC table overflow\r\n") ;
142         //goto overflow ;
143         //}
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 ;
148 #endif
149
150  done:
151         p->state = GMON_PROF_ON;
152         goto enable_timer ;
153  //overflow:
154         p->state = GMON_PROF_ERROR;
155  enable_timer:
156         enable_timer();
157         return ;
158 }
159
160
161 #endif          /* PROFILE_NO_GRAPH */
162