1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#if !defined( VC_DEBUG_SYM_H )
29#define VC_DEBUG_SYM_H
30
31/* ---- Include Files ----------------------------------------------------- */
32
33#include <stddef.h>
34#include "interface/vcos/vcos_stdint.h"
35
36/* ---- Constants and Types ---------------------------------------------- */
37
38typedef struct
39{
40 const char *label;
41 uint32_t addr;
42 size_t size;
43
44} VC_DEBUG_SYMBOL_T;
45
46/*
47 * Debug header+params are constructed by makefiles/internals/memorymap.mk
48 * (first .text section) and stored in the VC binary
49 */
50typedef struct
51{
52 uint32_t symbolTableOffset;
53 uint32_t magic;
54 uint32_t paramSize;
55} VC_DEBUG_HEADER_T;
56
57typedef struct
58{
59 uint32_t vcMemBase; /* base address of loaded binary */
60 uint32_t vcMemSize;
61 uint32_t vcEntryPoint;
62 uint32_t symbolTableLength;
63} VC_DEBUG_PARAMS_T;
64
65#define VC_DEBUG_HEADER_MAGIC (('V' << 0) + ('C' << 8) + ('D' << 16) + ('H' << 24))
66
67// Offset within the videocore memory map to get the address of the debug header.
68#define VC_DEBUG_HEADER_OFFSET 0x2800
69
70#if (defined( __VC4_BIG_ISLAND__ ) || defined (PLATFORM_RASPBERRYPI)) && !defined( __COVERITY__ )
71
72 /* Use of the debug symbols only makes sense on machines which have
73 * some type of shared memory architecture.
74 */
75
76# define USE_VC_DEBUG_SYMS 1
77#else
78# define USE_VC_DEBUG_SYMS 0
79#endif
80
81#if USE_VC_DEBUG_SYMS
82# define VCDBG_PRAGMA(foo) pragma foo
83#else
84# define VCDBG_PRAGMA(foo)
85#endif
86
87/*
88 * NOTE: The section name has to start with .init or the linker will
89 * purge it out of the image (since nobody has any references to these).
90 */
91
92#if USE_VC_DEBUG_SYMS
93#define VC_DEBUG_SYMBOL(name,label,addr,size) \
94 VCDBG_PRAGMA( Data(LIT, ".init.vc_debug_sym" ); ) \
95 static const VC_DEBUG_SYMBOL_T vc_sym_##name = { label, (uint32_t)addr, size }; \
96 VCDBG_PRAGMA( Data )
97#else
98#define VC_DEBUG_SYMBOL(name,label,addr,size)
99#endif
100
101#define VC_DEBUG_VAR(var) VC_DEBUG_SYMBOL(var,#var,&var,sizeof(var))
102
103/*
104 * When using VC_DEBUG_VAR, you typically want to use uncached memory, otherwise
105 * it will go in cached memory and the host won't get a coherent view of the
106 * memory. So we take advantage of the .ucdata section which gets linked into
107 * the uncached memory space.
108 *
109 * Now this causes another problem, namely that the videocore linker ld/st
110 * instructions only have 27-bit relocations, and accessing a global from
111 * uncached memory is more than 27-bits away. So we create a couple of macros
112 * which can be used to declare a variable and put it into the .ucdata section
113 * and another macro which will dereference it as if it were a pointer.
114 *
115 * To use:
116 *
117 * VC_DEBUG_DECLARE_UNCACHED_VAR( int, foo, 0xCafeBeef );
118 * #define foo VC_DEBUG_ACCESS_UNCACHED_VAR(foo)
119 */
120
121#define VC_DEBUG_DECLARE_UNCACHED_VAR(var_type,var_name,var_init) \
122 VCDBG_PRAGMA( Data(".ucdata"); ) \
123 var_type var_name = (var_init); \
124 VCDBG_PRAGMA( Data(); ) \
125 var_type *vc_var_ptr_##var_name = &var_name; \
126 VC_DEBUG_VAR(var_name)
127
128#define VC_DEBUG_EXTERN_UNCACHED_VAR(var_type,var_name) \
129 extern var_type var_name; \
130 static var_type *vc_var_ptr_##var_name = &var_name
131
132#define VC_DEBUG_DECLARE_UNCACHED_STATIC_VAR(var_type,var_name,var_init) \
133 VCDBG_PRAGMA( Data(".ucdata"); ) \
134 static var_type var_name = (var_init); \
135 VCDBG_PRAGMA( Data(); ) \
136 static var_type *vc_var_ptr_##var_name = &var_name; \
137 VC_DEBUG_VAR(var_name)
138
139#define VC_DEBUG_DECLARE_UNCACHED_VAR_ZERO(var_type,var_name) \
140 VCDBG_PRAGMA( Data(".ucdata"); ) \
141 var_type var_name = {0}; \
142 VCDBG_PRAGMA( Data(); ) \
143 var_type *vc_var_ptr_##var_name = &var_name; \
144 VC_DEBUG_VAR(var_name)
145
146#define VC_DEBUG_DECLARE_UNCACHED_STATIC_VAR_ZERO(var_type,var_name) \
147 VCDBG_PRAGMA( Data(".ucdata"); ) \
148 static var_type var_name = {0}; \
149 VCDBG_PRAGMA( Data(); ) \
150 static var_type *vc_var_ptr_##var_name = &var_name; \
151 VC_DEBUG_VAR(var_name)
152
153#define VC_DEBUG_ACCESS_UNCACHED_VAR(var_name) (*vc_var_ptr_##var_name)
154
155/*
156 * Declare a constant character string. This doesn't need to be uncached
157 * since it never changes.
158 */
159
160#define VC_DEBUG_DECLARE_STRING_VAR(var_name,var_init) \
161 const char var_name[] = var_init; \
162 VC_DEBUG_VAR(var_name)
163
164/*
165 * Since some variable aren't actually referenced by the videocore
166 * this variant uses a .init.* section to ensure that the variable
167 * doesn't get pruned by the linker.
168 */
169
170#define VC_DEBUG_DECLARE_UNCACHED_STATIC_VAR_NO_PTR(var_type,var_name,var_init) \
171 VCDBG_PRAGMA( Data(".init.ucdata"); ) \
172 static var_type var_name = (var_init); \
173 VCDBG_PRAGMA( Data(); ) \
174 VC_DEBUG_VAR(var_name)
175
176/* ---- Variable Externs ------------------------------------------------- */
177
178#if USE_VC_DEBUG_SYMS
179extern VC_DEBUG_SYMBOL_T __VC_DEBUG_SYM_START[];
180extern VC_DEBUG_SYMBOL_T __VC_DEBUG_SYM_END[];
181#endif
182
183/* ---- Function Prototypes ---------------------------------------------- */
184
185#endif /* VC_DEBUG_SYM_H */
186
187