1 | /* |
2 | Copyright (c) 2013, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, 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 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON 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 |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #if !defined( DEBUG_SYM_H ) |
29 | #define DEBUG_SYM_H |
30 | |
31 | /* ---- Include Files ----------------------------------------------------- */ |
32 | |
33 | #include "interface/vcos/vcos.h" |
34 | #include "interface/vcos/vcos_stdint.h" |
35 | |
36 | #ifdef __cplusplus |
37 | extern "C" { |
38 | #endif |
39 | |
40 | /* ---- Constants and Types ---------------------------------------------- */ |
41 | |
42 | typedef struct opaque_vc_mem_access_handle_t *VC_MEM_ACCESS_HANDLE_T; |
43 | |
44 | /* Since the VC might have a different memory model from the host |
45 | * (32-bit vs 64-bit), define fixed-width types that match the |
46 | * VC memory types */ |
47 | typedef uint32_t VC_MEM_ADDR_T; /* equivalent to uintptr_t */ |
48 | typedef uint32_t VC_MEM_SIZE_T; /* equivalent to size_t */ |
49 | typedef uint32_t VC_MEM_PTRDIFF_T; /* equivalent to ptrdiff_t */ |
50 | |
51 | #define TO_VC_MEM_ADDR(ptr) ((VC_MEM_ADDR_T)(unsigned long)(ptr)) |
52 | |
53 | /* ---- Variable Externs ------------------------------------------------- */ |
54 | |
55 | /* ---- Function Prototypes ---------------------------------------------- */ |
56 | |
57 | /* |
58 | * The following were taken from vcinclude/hardware_vc4_bigisland.h |
59 | */ |
60 | |
61 | #define ALIAS_NORMAL(x) ((VC_MEM_ADDR_T)(((unsigned long)(x)&~0xc0000000uL)|0x00000000uL)) // normal cached data (uses main 128K L2 cache) |
62 | #define IS_ALIAS_PERIPHERAL(x) (((unsigned long)(x)>>29)==0x3uL) |
63 | |
64 | /* |
65 | * Get access to the videocore memory space. Returns zero if the memory was |
66 | * opened successfully, or a negative value (-errno) if the access could not |
67 | * be obtained. |
68 | */ |
69 | int OpenVideoCoreMemory( VC_MEM_ACCESS_HANDLE_T *handle ); |
70 | |
71 | /* |
72 | * Get access to the videocore space from a file. The file might be /dev/mem, or |
73 | * it might be saved image on disk. |
74 | */ |
75 | int OpenVideoCoreMemoryFile( const char *filename, VC_MEM_ACCESS_HANDLE_T *vcHandlePtr ); |
76 | |
77 | /* |
78 | * Get access to the videocore space from a file, explicitly giving the |
79 | * offset of the load address (the start of the VC binary) relative to the |
80 | * start of the file. |
81 | * loadOffset is ignored if reading from memory instead of a saved image. |
82 | */ |
83 | int OpenVideoCoreMemoryFileWithOffset( const char *filename, |
84 | VC_MEM_ACCESS_HANDLE_T *vcHandlePtr, |
85 | size_t loadOffset ); |
86 | |
87 | /* |
88 | * Returns the number of symbols which were detected. |
89 | */ |
90 | unsigned NumVideoCoreSymbols( VC_MEM_ACCESS_HANDLE_T handle ); |
91 | |
92 | /* |
93 | * Returns the name, address and size of the i'th symbol. |
94 | */ |
95 | int GetVideoCoreSymbol( VC_MEM_ACCESS_HANDLE_T handle, |
96 | unsigned idx, |
97 | char *nameBuf, |
98 | size_t nameBufSize, |
99 | VC_MEM_ADDR_T *vcMemAddr, |
100 | size_t *vcMemSize ); |
101 | |
102 | /* |
103 | * Looks up the named, symbol. If the symbol is found, it's value and size |
104 | * are returned. |
105 | * |
106 | * Returns true if the lookup was successful. |
107 | */ |
108 | int LookupVideoCoreSymbol( VC_MEM_ACCESS_HANDLE_T handle, |
109 | const char *symbol, |
110 | VC_MEM_ADDR_T *vcMemAddr, |
111 | size_t *vcMemSize ); |
112 | |
113 | /* |
114 | * Looks up the named, symbol. If the symbol is found, and it's size is equal |
115 | * to the sizeof a uint32_t, then true is returned. |
116 | */ |
117 | int LookupVideoCoreUInt32Symbol( VC_MEM_ACCESS_HANDLE_T handle, |
118 | const char *symbol, |
119 | VC_MEM_ADDR_T *vcMemAddr ); |
120 | |
121 | /* |
122 | * Reads 'numBytes' from the videocore memory starting at 'vcMemAddr'. The |
123 | * results are stored in 'buf'. |
124 | * |
125 | * Returns true if the read was successful. |
126 | */ |
127 | int ReadVideoCoreMemory( VC_MEM_ACCESS_HANDLE_T handle, |
128 | void *buf, |
129 | VC_MEM_ADDR_T vcMemAddr, |
130 | size_t numBytes ); |
131 | |
132 | /* |
133 | * Reads an unsigned 32-bit value from videocore memory. |
134 | */ |
135 | VCOS_STATIC_INLINE int ReadVideoCoreUInt32( VC_MEM_ACCESS_HANDLE_T handle, |
136 | uint32_t *val, |
137 | VC_MEM_ADDR_T vcMemAddr ) |
138 | { |
139 | return ReadVideoCoreMemory( handle, val, vcMemAddr, sizeof( *val )); |
140 | } |
141 | |
142 | /* |
143 | * Reads a block of memory using the address associated with a symbol. |
144 | */ |
145 | int ReadVideoCoreMemoryBySymbol( VC_MEM_ACCESS_HANDLE_T vcHandle, |
146 | const char *symbol, |
147 | void *buf, |
148 | size_t numBytes ); |
149 | /* |
150 | * Reads an unsigned 32-bit value from videocore memory. |
151 | */ |
152 | VCOS_STATIC_INLINE int ReadVideoCoreUInt32BySymbol( VC_MEM_ACCESS_HANDLE_T handle, |
153 | const char *symbol, |
154 | uint32_t *val ) |
155 | { |
156 | return ReadVideoCoreMemoryBySymbol( handle, symbol, val, sizeof( *val )); |
157 | } |
158 | |
159 | /* |
160 | * Looksup a string symbol by name, and reads the contents into a user |
161 | * supplied buffer. |
162 | */ |
163 | int ReadVideoCoreStringBySymbol( VC_MEM_ACCESS_HANDLE_T handle, |
164 | const char *symbol, |
165 | char *buf, |
166 | size_t bufSize ); |
167 | |
168 | /* |
169 | * Writes 'numBytes' into the videocore memory starting at 'vcMemAddr'. The |
170 | * data is taken from 'buf'. |
171 | * |
172 | * Returns true if the write was successful. |
173 | */ |
174 | int WriteVideoCoreMemory( VC_MEM_ACCESS_HANDLE_T handle, |
175 | void *buf, |
176 | VC_MEM_ADDR_T vcMemAddr, |
177 | size_t numBytes ); |
178 | |
179 | /* |
180 | * Writes an unsigned 32-bit value into videocore memory. |
181 | */ |
182 | VCOS_STATIC_INLINE int WriteVideoCoreUInt32( VC_MEM_ACCESS_HANDLE_T handle, |
183 | uint32_t val, |
184 | VC_MEM_ADDR_T vcMemAddr ) |
185 | { |
186 | return WriteVideoCoreMemory( handle, &val, vcMemAddr, sizeof( val )); |
187 | } |
188 | |
189 | /* |
190 | * Closes the memory space opened previously via OpenVideoCoreMemory. |
191 | */ |
192 | void CloseVideoCoreMemory( VC_MEM_ACCESS_HANDLE_T handle ); |
193 | |
194 | /* |
195 | * Returns the base address of the videocore memory space. |
196 | */ |
197 | VC_MEM_ADDR_T GetVideoCoreMemoryBase( VC_MEM_ACCESS_HANDLE_T handle ); |
198 | |
199 | /* |
200 | * Returns the size of the videocore memory space. |
201 | */ |
202 | VC_MEM_SIZE_T GetVideoCoreMemorySize( VC_MEM_ACCESS_HANDLE_T handle ); |
203 | |
204 | /* |
205 | * Returns the videocore memory physical address. |
206 | */ |
207 | VC_MEM_ADDR_T GetVideoCoreMemoryPhysicalAddress( VC_MEM_ACCESS_HANDLE_T handle ); |
208 | |
209 | #ifdef __cplusplus |
210 | } |
211 | #endif |
212 | |
213 | |
214 | #endif /* DEBUG_SYM_H */ |
215 | |
216 | |