source: svn/trunk/newcon3bcm2_21bu/BSEAV/lib/bprofile/bsymbols.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bsymbols.c $
11 * $brcm_Revision: 4 $
12 * $brcm_Date: 12/8/06 7:22p $
13 *
14 * Module Description:
15 *
16 * Embeddeble profiler library
17 *              symbol module
18 *
19 * Revision History:
20 *
21 * $brcm_Log: /BSEAV/lib/bprofile/bsymbols.c $
22 *
23 * 4   12/8/06 7:22p vsilyaev
24 * PR 25997: Fixed offset handling
25 *
26 * 3   11/20/06 4:54p vsilyaev
27 * PR 25997: Decoupled profiling and symbol table
28 *
29 * 2   11/16/06 6:59p vsilyaev
30 * PR 25997: Added UCOS support
31 *
32 * 1   11/16/06 5:24p vsilyaev
33 * PR 25997: Embeddable profiler
34 *
35 *******************************************************************************/
36#include "bstd.h"
37#include "bkni.h"
38#include "bsymtable.h"
39
40BDBG_MODULE(bsymtable);
41
42
43
44static const bsymbol_entry b_sym_table[] = {
45#define B_SYM(addr,name) {addr,#name},
46#include "bsymbols.inc"
47        {0,""}
48};
49
50static bsymbol_table bsymbol_map = {
51        b_sym_table,
52        (sizeof(b_sym_table)/sizeof(*b_sym_table))-1,
53        0
54};
55
56
57static int 
58b_sym_strcmp(const char *s1, const char *s2)
59{
60        for(;;) {
61                int ch1 = *s1++;
62                int diff = ch1 - *s2++;
63                if (diff || /* strings are different */
64                        ch1 == 0 /* end of string reached */
65                        ) {
66                        return diff; /* return difference */
67                } 
68        }
69}
70
71static const bsymbol_entry s_dumby_entry[] = { {0, ""}};
72static const bsymbol_table s_dumby_table = { s_dumby_entry, 1,0};
73const bsymbol_table *
74bsymbol_fixup(void)
75{
76        unsigned i;
77        const unsigned size = (sizeof(b_sym_table)/sizeof(*b_sym_table))-1;
78        static const char self[] = "bsymbol_fixup";
79
80        BDBG_MSG(("size = %u", size));
81
82        /* Don't fail, just exit */
83        if (size <= 1)
84        {
85                return &s_dumby_table;
86        }
87       
88        BDBG_ASSERT(size>1); /* shall have more than one entry in the symbol table */
89        for(i=0;i<size;i++) {
90                if(b_sym_strcmp(self, b_sym_table[i].name)==0) {
91                        bsymbol_map.offset = (unsigned long)bsymbol_fixup - b_sym_table[i].addr;
92                        BDBG_MSG(("self %s(%#lx) table %s(%#x) offset %#lx", self, (unsigned long)bsymbol_fixup, b_sym_table[i].name, b_sym_table[i].addr, bsymbol_map.offset));
93#if 0
94                        if (offset>0) {
95                                /* move all entries to discovered offset */
96                                for(i=0;i<size;i++) {
97                                        b_sym_table[i].addr += offset;
98                                }
99                                BDBG_ASSERT(b_sym_table[0].addr < b_sym_table[size-1].addr);
100                        }
101#endif
102                        return &bsymbol_map;
103                }
104        }
105        /* no self entry was found */
106        BDBG_ASSERT(0);
107        return &bsymbol_map;
108}
Note: See TracBrowser for help on using the repository browser.