source: svn/newcon3bcm2_21bu/dst/dhl/src/DHL_DBG.c @ 45

Last change on this file since 45 was 45, checked in by megakiss, 11 years ago
  • Property svn:executable set to *
File size: 7.6 KB
Line 
1/**
2        @file
3                DHL_DBG.c
4
5        @brief
6                DHL Debug Module
7
8        Copyright 2006~2010 Digital STREAM Technology, Inc.
9        All Rights Reserved
10*/
11
12
13#include "DHL_OSAL.h"
14#include "DHL_DBG.h"
15
16#include "DHL_DBG_Priv.h"
17
18
19//#include <stdio.h>
20////#include <string.h>
21//#include <ctype.h>
22
23
24/*
25        DHL µð¹ö±× ¸ðµâ À̸§ Á¤ÀÇ ·ê Âü°í:
26
27        DHL ¸ðµâµéÀº ¸ðµÎ * ·Î ½ÃÀÛ.
28        API´Â ´ë¹®ÀÚ, Platform ¹× ±âŸ´Â ¼Ò¹®ÀÚ »ç¿ë.
29
30        µðÆúÆ® ·¹º§Àº 0À¸·Î ¼³Á¤ÇÑ´Ù. (0: ¿¡·¯ ¸Þ½ÃÁö¸¸ Ãâ·Â)
31       
32       
33*/
34
35//DHL_MODULE("*DBG", 0);
36
37
38
39#if COMMENT
40____Config____(){}
41#endif
42
43/*
44        ÀÌ ¸ðµâ ³»ºÎ¿¡¼­ »ç¿ëµÇ´Â °¢Á¾ configuration Á¤ÀÇ.
45*/
46
47
48/* #define SUPPORT_FAST_SWITCHING_OPTIMIZATION 1 */
49/* #define FUNC_MONITOR_TIMER_ID TIMER_ID_FUNC_MONITOR */
50
51#define max(a,b) (((a) > (b)) ? (a) : (b))
52#define min(a,b) (((a) < (b)) ? (a) : (b))
53
54
55
56#if COMMENT
57____Types____(){}
58#endif
59
60/*
61        ÀÌ ¸ðµâ ³»ºÎ¿¡¼­ »ç¿ëµÇ´Â structure ¹× enumerations.
62*/
63
64
65
66#if COMMENT
67____Variables____(){}
68#endif
69
70/*
71        global·Î Àû¿ëµÇ´Â variable Á¤ÀÇ.
72        °¢ function º°·Î Ư¼öÇÑ ¿ëµµÀÇ variableÀº °¢ functionX block ¿¡¼­ Á¤ÀÇ °¡´É.
73*/
74
75
76
77#if COMMENT
78____Group1____(){}
79#endif
80
81/*
82
83*/
84void DHL_DBG_GenerateAssert(BOOL cond, const char *msg, const char *file, unsigned line)
85{
86        if (!cond) 
87        {
88                int bForceExit = FALSE;
89               
90                DHL_OS_Printf("\n!! ASSERT failed on %s:%d\n", file, line);
91                DHL_OS_Printf("%s\n", msg);
92               
93                while(!bForceExit);
94        }
95}
96
97
98
99#if COMMENT
100____Group2____(){}
101#endif
102
103
104
105
106#if COMMENT
107____Debug____(){}
108#endif
109
110
111
112#if COMMENT
113____MemDump____(){}
114#endif
115
116#define isprint(c)      (((c) >= 32) && ((c) < 127))
117
118void DHL_DBG_MemDump3(void *buf0, int size, char *msg, UINT32 off, UINT32 flag)
119{
120        int i, k, skip, n;
121        unsigned char *p;
122        char line[100];
123        UINT8 *buf = buf0;
124       
125        if ((flag & MEMDUMP_NOHDR) == 0)
126                DHL_OS_Printf("  Dump '%s' %d(0x%x) bytes:\n", msg ? msg : "", size, size);
127
128        if (size <= 0)
129                return;
130               
131        if (flag & MEMDUMP_ALIGN)  // align print position by its address.
132                skip = (UINT32) buf % 16;
133        else skip = 0;  // do not align.
134
135        p = (unsigned char *)buf - skip;
136        size += skip;
137
138        for (i=0; i<size; i+=16, p+=16)
139        {
140                line[0] = 0;
141               
142                n = min(16, size-i) - skip;  // number of bytes to print in this line.
143
144                // dump p[0]~p[n-1] in one line (n bytes)
145                sprintf(line, "  %08x: ", (int)(p + off));  // off is used to adjust displayed address.
146
147                for (k=0; k<skip; k++) {  // skip..
148                        strcat(line, "__ ");
149                        if (k == 7) strcat(line, " "); // cafrii 030903
150                }
151
152                for (; k<n+skip; k++) {      // data : n
153                        sprintf(line+strlen(line), "%02x ", p[k]);
154                        if (k == 7) strcat(line, " ");
155                }
156                for (; k<16; k++) {   // fill remainings.
157                        strcat(line, "__ ");
158                        if (k == 7) strcat(line, " ");
159                }
160
161                strcat(line, " ");
162                for (k=0; k<skip; k++)
163                        strcat(line, ".");
164                for (; k<n+skip; k++)
165                        sprintf(line+strlen(line), "%c", isprint(p[k]) && p[k]!='%' ? p[k] : '.');
166                                // cafrii 030710
167                                // cafrii 060612 do not print % sign
168                for (; k<16; k++) {
169                        strcat(line, ".");
170                }
171
172                strcat(line, "\n");
173               
174                DHL_OS_Printf(line);
175                skip = 0;
176        }
177}
178
179void DHL_DBG_MemDump2(void *buf, int size, char *msg, UINT32 off)
180{
181        DHL_DBG_MemDump3(buf, size, msg, off, MEMDUMP_ALIGN);
182}
183
184
185void DHL_DBG_MemDump (void *buf, int size, char *msg)
186{
187        DHL_DBG_MemDump3(buf, size, msg, 0, MEMDUMP_ALIGN);
188}
189
190
191int DHL_DBG_MemCmp(const unsigned char *s1, const unsigned char *s2, int len)
192{
193        // return -1 if same.
194        // if mismatch, return offset which 1st difference.
195        int i;
196        for (i=0; i<len; i++) {
197                if (s1[i] != s2[i])
198                        return i;
199        }
200        return -1;
201}
202
203
204#if NOT_NEEDED  // ¾Æ·¡ memedit°¡ Á¦°øµÇ´Ï, ÀÌ ÇÔ¼öµéÀº ÇÊ¿ä ¾øÀ» µí ÇÔ.
205/*
206        ÀÌ ÇÔ¼ö´Â µð¹ö±ë ¿ëµµ·Î µî·ÏÇÏ´Â ÇÔ¼öÀ̰í API´Â ¾Æ´Ï´Ù.
207*/
208void DHL_DBG_MemWrite (UINT32 addr, UINT8 data)
209{
210        *(UINT8 *)addr = data;
211        DHL_OS_Printf("0x%08x <- 0x%02x, verify %02x\n", addr, data, *(UINT8 *)addr);
212}
213
214void DHL_DBG_MemWrite2 (UINT32 addr, UINT16 data)
215{
216        if (addr & 1) return;
217        *(UINT16 *)addr = data;
218        DHL_OS_Printf("0x%08x <- 0x%04x, verify %04x\n", addr, data, *(UINT16 *)addr);
219}
220
221void DHL_DBG_MemWrite4 (UINT32 addr, UINT32 data)
222{
223        if (addr & 3) return;
224        *(UINT32 *)addr = data;
225        DHL_OS_Printf("0x%08x <- 0x%08x, verify %08x\n", addr, data, *(UINT32 *)addr);
226}
227
228#endif
229
230
231
232#if COMMENT
233____memedit____(){}
234#endif
235
236#include "DHL_OSAL_Priv.h"
237
238/*
239       
240*/
241#define h2d(c) (\
242                ((c)>='0'&&(c)<='9') ? (c)-'0' : \
243                ((c)>='a'&&(c)<='f') ? (c)-'a'+10 : \
244                ((c)>='A'&&(c)<='F') ? (c)-'A'+10 : \
245                -1)
246static UINT32 read_hex(char *p)
247{
248        int i;
249        UINT32 data = 0;
250       
251        // skip spaces
252        while (*p == ' ' || *p == '\t') p++;
253       
254        for (i=0; *p && i<8; i++, p++) {
255                int d = h2d(*p);
256                if (d < 0) break;
257                data = (data << 4) | d;
258        }
259        return data;
260}
261
262/*
263        µð¹ö±ë Áß¿¡ ¸Þ¸ð¸®(·¹Áö½ºÅÍ)ÀÇ Æ¯Á¤ ¿µ¿ªÀ» ¼öÁ¤ÇϰíÀÚ ÇÏ´Â °æ¿ì¿¡
264        »ç¿ëµÉ ¼ö ÀÖ´Â À¯Æ¿¸®Æ¼.
265
266        Shell »ó¿¡¼­ ±×³É memedit ¶ó°í ÀÔ·ÂÇÏ¸é µÈ´Ù.
267        À߸ø µÈ ¹øÁö¸¦ Àаųª ±â·ÏÇÒ °æ¿ì exceptionÀÌ ¹ß»ýÇÒ ¼ö ÀÖ´Ù.
268*/
269void memedit(UINT32 addr)
270{
271        char buf[80];
272        int align = 1; // one of 1, 2, 4
273
274        #define print DHL_OS_Printf
275
276        if (addr == 0)
277                addr = (UINT32)&buf; // ¾Æ¹« ÀÇ¹Ì ¾øÀ½. 0¹øÁö´Â »ç¿ëÀÚ°¡ À߸ø ÀÔ·ÂÇÑ °ÍÀ¸·Î ÃßÁ¤.
278       
279        // print usage
280        print("memedit usage\n");
281        print("  > w 12345678 : write data of cur addr to 0x12345678\n");
282        print("  > m b0001000 : modify (goto) address b0001000\n");
283        print("  > [ENTER_KEY] : go to next addr without modifying\n");
284        print("  > a 2 : address align (1:byte, 2:16bit, 4:32bit)\n");
285        print("  > x : exit\n");
286        print("\n");
287
288        while(1) {
289                if(align == 4) {
290                        addr &= ~3;
291                        print("%08x:%08x > ", addr, *(UINT32 *)addr);
292                }
293                else if(align == 2) {
294                        addr &= ~1;
295                        print("%08x:%04x > ", addr, *(UINT16 *)addr);
296                }
297                else {
298                        print("%08x:%02x > ", addr, *(UINT8 *)addr);
299                }
300
301                // get user input.
302                dhl_os_get_line(buf, sizeof(buf), eDHL_OS_GLF_NORMAL);
303                if(buf[0] == 0) {
304                        addr += align;
305                }
306                else if (buf[1] != ' ' && buf[1] != 0) {
307                        continue; // invalid command. all cmd has one character.
308                }
309                else if (buf[0] == 'm') {
310                        UINT32 new_addr = read_hex(&buf[1]);
311                        if (new_addr == 0) 
312                                print("wrong addr\n");
313                        else
314                                addr = new_addr;
315                }
316                else if (buf[0] == 'w') {
317                        UINT32 data = read_hex(&buf[1]);
318                        print("write 0x%x..\n", data);
319                        if (align == 4)
320                                *(UINT32 *)addr = (UINT32)data;
321                        else if (align == 2)
322                                *(UINT16 *)addr = (UINT16)data;
323                        else
324                                *(UINT8 *)addr = (UINT8)data;
325                }
326                else if (buf[0] == 'a') {
327                        align = read_hex(&buf[1]);
328                        if (align != 4 && align != 2) 
329                                align = 1;
330                        print("acces unit: %d\n", align);
331                }
332                else if(buf[0] == 'x') {
333                        break;
334                }
335        }
336}
337
338
339
340
341#if COMMENT
342____Symbol____(){}
343#endif
344
345
346#if DHL_REGISTER_DEUBG_SYMBOLS
347
348static DHL_SymbolTable _symbols[] =
349{
350        //DHL_FNC_SYM_ENTRY2("symlkup", dhl_dbg_lookup_symbols),
351        //DHL_FNC_SYM_ENTRY2("which", dhl_dbg_lookup_symbols),
352        //DHL_FNC_SYM_ENTRY2("i", OS_ShowInfo),
353
354        DHL_FNC_SYM_ENTRY2("sml", (void *)DHL_DBG_SetModuleLevel),
355        DHL_FNC_SYM_ENTRY2("pml", (void *)DHL_DBG_PrintModuleLevel),
356        //DHL_FNC_SYM_ENTRY2("sdt", DHL_DBG_SetDbgKey),
357        //DHL_FNC_SYM_ENTRY2("pdt", DHL_DBG_PrintDbgKey),
358       
359        //-----
360        //DHL_VAR_SYM_ENTRY(dmc_bRequestVideoWidthReduction),
361       
362};
363
364#endif // DHL_REGISTER_DEUBG_SYMBOLS
365
366
367
368
369#if COMMENT
370____Init____(){}
371#endif
372
373
374
375void DHL_DBG_Init(void)
376{
377        //DHL_DBG_InitVendor();
378#if DHL_USING_DEBUG_SHELL_SYMBOLS       
379        dhl_dbg_init_symtab();
380        //dhl_dbg_init();
381
382        //BKNOTE: disable first boot. DHL_DBG_StartDbgShell();
383        //DHL_DBG_InitHeapDebug();
384#endif
385#if DHL_REGISTER_DEUBG_SYMBOLS
386        DHL_DBG_RegisterSymbols(_symbols, DHL_NUMSYMBOLS(_symbols));
387#endif
388
389}
390
391
392/* end of file */
393
Note: See TracBrowser for help on using the repository browser.