OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [infra/] [current/] [src/] [fancy.cxx] - Blame information for rev 851

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      fancy.cxx
4
//
5
//      Fancy formatting trace and assert functions
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):   nickg
43
// Contributors:        nickg
44
// Date:        1997-12-04
45
// Purpose:     Fancy Trace and assert functions
46
// Description: The functions in this file are fancy implementations of the
47
//              standard trace and assert functions. These do printf
48
//              style formatting, printing the string and arguments.
49
//
50
//####DESCRIPTIONEND####
51
//
52
//==========================================================================
53
 
54
#include <pkgconf/system.h>
55
#include <pkgconf/infra.h>
56
 
57
#ifdef CYGDBG_INFRA_DEBUG_TRACE_ASSERT_FANCY
58
 
59
#include <cyg/infra/cyg_type.h>         // base types
60
#include <cyg/infra/cyg_trac.h>         // tracing macros
61
#include <cyg/infra/cyg_ass.h>          // assertion macros
62
 
63
#include <pkgconf/hal.h>                // HAL configury
64
#include <cyg/infra/diag.h>             // HAL polled output
65
#include <cyg/hal/hal_arch.h>           // architectural stuff for...
66
#include <cyg/hal/hal_intr.h>           // interrupt control
67
 
68
#ifdef CYGPKG_KERNEL
69
#include <pkgconf/kernel.h>             // kernel configury
70
#include <cyg/kernel/thread.hxx>        // thread id to print
71
#include <cyg/kernel/sched.hxx>         // ancillaries for above
72
#include <cyg/kernel/thread.inl>        // ancillaries for above
73
#endif
74
 
75
// -------------------------------------------------------------------------
76
// Local Configuration: hack me!
77
 
78
// these are generally:
79
//      if 0, feature is disabled
80
//      if 1, feature is enabled, printing is default width
81
//      if >1, field is padded up to that width if necessary
82
//              (not truncated ever)
83
 
84
#define CYG_FILENAME    20
85
#define CYG_THREADID    0 // DO NOT SET IF NO KERNEL
86
#define CYG_LINENUM     4
87
#define CYG_FUNCNAME    100
88
#define CYG_DIAG_PRINTF 1
89
#define CYG_FUNC_INDENT 2
90
 
91
#ifndef CYGPKG_KERNEL
92
# undef  CYG_THREADID
93
# define CYG_THREADID 0
94
#endif
95
 
96
#if CYG_FUNCNAME == 1
97
#define CYG_FBUF_SIZE   100
98
#else
99
#define CYG_FBUF_SIZE   (CYG_FUNCNAME+20)
100
#endif
101
 
102
// -------------------------------------------------------------------------
103
// Functions to trim file names and function names down to printable lengths
104
// (these are shared between trace and assert functions)
105
 
106
#ifdef CYGDBG_USE_TRACING
107
 
108
#if 0
109
static char * tracepremsgs[] = {
110
    "  INFO:",
111
    "ENTER :",
112
    "ARGS  :",
113
    "RETURN:",
114
    "bad code"
115
};
116
#endif
117
 
118
static char * tracepremsgs[] = {
119
    "'",
120
    "{{",
121
    "((",
122
    "}}",
123
    "bad code"
124
};
125
 
126
static char * tracepostmsgs[] = {
127
    "'",
128
    "",
129
    "))",
130
    "",
131
    "bad code"
132
};
133
 
134
static void
135
write_whattrace( cyg_uint32 what )
136
{
137
#if CYG_FUNC_INDENT
138
    static cyg_uint32 cyg_indent = 0;
139
    if ( 3 == what )
140
        cyg_indent -= CYG_FUNC_INDENT;
141
    cyg_uint32 i = cyg_indent;
142
    for ( ; i > 0; i-- )
143
        diag_write_string( " " );
144
#endif // CYG_FUNC_INDENT
145
    diag_write_string( tracepremsgs[ what > 4 ? 4 : what ] );
146
#if CYG_FUNC_INDENT
147
    if ( 1 == what )
148
        cyg_indent += CYG_FUNC_INDENT;
149
#endif // CYG_FUNC_INDENT
150
}
151
 
152
static void
153
write_whattracepost( cyg_uint32 what )
154
{
155
    diag_write_string( tracepostmsgs[ what > 4 ? 4 : what ] );
156
}
157
#endif // CYGDBG_USE_TRACING
158
 
159
static const char *trim_file(const char *file)
160
{
161
#if CYG_FILENAME
162
    if ( NULL == file )
163
        file = "<nofile>";
164
 
165
#if 1 == CYG_FILENAME
166
    const char *f = file;
167
    while( *f ) f++;
168
    while( *f != '/' && f != file ) f--;
169
    return f==file?f:(f+1);
170
#else
171
    static char fbuf2[100];
172
    const char *f = file;
173
    char *g = fbuf2;
174
    while( *f ) f++;
175
    while( *f != '/' && f != file ) f--;
176
    if ( f > file ) f++;
177
    while( *f ) *g++ = *f++;
178
    while( CYG_FILENAME > (g - fbuf2) ) *g++ = ' ';
179
    *g = 0;
180
    return fbuf2;
181
#endif
182
#else
183
    return "";
184
#endif
185
}
186
 
187
static const char *trim_func(const char *func)
188
{
189
#if CYG_FUNCNAME
190
    static char fbuf[CYG_FBUF_SIZE];
191
    int i;
192
 
193
    if ( NULL == func )
194
        func = "<nofunc>";
195
 
196
    for( i = 0; func[i] && func[i] != '(' && i < CYG_FBUF_SIZE-4 ; i++ )
197
        fbuf[i] = func[i];
198
 
199
    fbuf[i++] = '(';
200
    fbuf[i++] = ')';
201
    fbuf[i  ] = 0;
202
    i=0;
203
#if 1 == CYG_FUNCNAME
204
    return &fbuf[i];
205
#else
206
    char *p = &fbuf[i];
207
    while ( *p ) p++;
208
    while ( CYG_FUNCNAME > (p - (&fbuf[i])) ) *p++ = ' ';
209
    *p = 0;
210
    return &fbuf[i];
211
#endif
212
#else
213
    return "";
214
#endif
215
}
216
 
217
void write_lnum( cyg_uint32 lnum)
218
{
219
#if CYG_LINENUM
220
    diag_write_char('[');
221
#if 1 < CYG_LINENUM
222
    cyg_uint32 i, j;
223
    for ( i = 2, j = 100; i < CYG_LINENUM ; i++, j *= 10 )
224
        if ( lnum < j )
225
            diag_write_char(' ');
226
#endif    
227
    diag_write_dec(lnum);
228
    diag_write_char(']');
229
    diag_write_char(' ');
230
#endif
231
}
232
 
233
void write_thread_id()
234
{
235
#if CYG_THREADID    
236
    Cyg_Thread *t = Cyg_Thread::self();
237
    cyg_uint16 tid = 0xFFFF;
238
 
239
    if( t != NULL ) tid = t->get_unique_id();
240
 
241
    diag_write_char('<');
242
    diag_write_hex(tid);
243
    diag_write_char('>');
244
#endif
245
}
246
 
247
// -------------------------------------------------------------------------
248
// Trace functions:
249
 
250
#ifdef CYGDBG_USE_TRACING
251
 
252
externC void
253
cyg_tracenomsg( const char *psz_func, const char *psz_file, cyg_uint32 linenum )
254
{
255
    cyg_uint32 old_ints;
256
 
257
    HAL_DISABLE_INTERRUPTS(old_ints);
258
    DIAG_DEVICE_START_SYNC();
259
 
260
    diag_write_string("TRACE: ");
261
    write_thread_id();
262
    diag_write_string(trim_file(psz_file));
263
    write_lnum(linenum);
264
    diag_write_string(trim_func(psz_func));
265
    diag_write_char('\n');
266
 
267
    DIAG_DEVICE_END_SYNC();
268
    HAL_RESTORE_INTERRUPTS(old_ints);
269
 
270
};
271
 
272
// provide every other one of these as a space/caller bloat compromise.
273
 
274
externC void
275
cyg_tracemsg( cyg_uint32 what,
276
              const char *psz_func, const char *psz_file, cyg_uint32 linenum,
277
              const char *psz_msg )
278
{
279
    cyg_uint32 old_ints;
280
 
281
    HAL_DISABLE_INTERRUPTS(old_ints);
282
    DIAG_DEVICE_START_SYNC();
283
 
284
    if ( NULL == psz_msg )
285
        psz_msg = "<nomsg>";
286
 
287
    diag_write_string( "TRACE: " );
288
    write_thread_id();
289
    diag_write_string(trim_file(psz_file));
290
    write_lnum(linenum);
291
    diag_write_string(trim_func(psz_func));
292
    diag_write_char(' ');
293
    write_whattrace( what );
294
    diag_write_string(psz_msg);
295
    write_whattracepost( what );
296
    diag_write_char('\n');
297
 
298
    DIAG_DEVICE_END_SYNC();
299
    HAL_RESTORE_INTERRUPTS(old_ints);
300
 
301
};
302
 
303
externC void
304
cyg_tracemsg2( cyg_uint32 what,
305
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
306
               const char *psz_msg,
307
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1 )
308
{
309
    cyg_uint32 old_ints;
310
 
311
    HAL_DISABLE_INTERRUPTS(old_ints);
312
    DIAG_DEVICE_START_SYNC();
313
 
314
    if ( NULL == psz_msg )
315
        psz_msg = "<nomsg>";
316
 
317
    diag_write_string( "TRACE: " );
318
    write_thread_id();
319
    diag_write_string(trim_file(psz_file));
320
    write_lnum(linenum);
321
    diag_write_string(trim_func(psz_func));
322
    diag_write_char(' ');
323
    write_whattrace( what );
324
#if CYG_DIAG_PRINTF
325
    diag_printf( psz_msg, arg0, arg1 );
326
#else
327
    diag_write_string(psz_msg);
328
    diag_write_char(' ');
329
    diag_write_hex(arg0);
330
    diag_write_char(' ');
331
    diag_write_hex(arg1);
332
#endif    
333
    write_whattracepost( what );
334
    diag_write_char('\n');
335
    DIAG_DEVICE_END_SYNC();
336
    HAL_RESTORE_INTERRUPTS(old_ints);
337
};
338
 
339
externC void
340
cyg_tracemsg4( cyg_uint32 what,
341
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
342
               const char *psz_msg,
343
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1,
344
               CYG_ADDRWORD arg2,  CYG_ADDRWORD arg3 )
345
{
346
    cyg_uint32 old_ints;
347
 
348
    HAL_DISABLE_INTERRUPTS(old_ints);
349
    DIAG_DEVICE_START_SYNC();
350
 
351
    if ( NULL == psz_msg )
352
        psz_msg = "<nomsg>";
353
 
354
    diag_write_string( "TRACE: " );
355
    write_thread_id();
356
    diag_write_string(trim_file(psz_file));
357
    write_lnum(linenum);
358
    diag_write_string(trim_func(psz_func));
359
    diag_write_char(' ');
360
    write_whattrace( what );
361
#if CYG_DIAG_PRINTF
362
    diag_printf( psz_msg, arg0, arg1, arg2, arg3 );
363
#else
364
    diag_write_string(psz_msg);
365
    diag_write_char(' ');
366
    diag_write_hex(arg0);
367
    diag_write_char(' ');
368
    diag_write_hex(arg1);
369
    diag_write_char(' ');
370
    diag_write_hex(arg2);
371
    diag_write_char(' ');
372
    diag_write_hex(arg3);
373
#endif    
374
    write_whattracepost( what );
375
    diag_write_char('\n');
376
 
377
    DIAG_DEVICE_END_SYNC();
378
    HAL_RESTORE_INTERRUPTS(old_ints);
379
};
380
 
381
externC void
382
cyg_tracemsg6( cyg_uint32 what,
383
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
384
               const char *psz_msg,
385
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1,
386
               CYG_ADDRWORD arg2,  CYG_ADDRWORD arg3,
387
               CYG_ADDRWORD arg4,  CYG_ADDRWORD arg5 )
388
{
389
    cyg_uint32 old_ints;
390
 
391
    HAL_DISABLE_INTERRUPTS(old_ints);
392
    DIAG_DEVICE_START_SYNC();
393
 
394
    if ( NULL == psz_msg )
395
        psz_msg = "<nomsg>";
396
 
397
    diag_write_string( "TRACE: " );
398
    write_thread_id();
399
    diag_write_string(trim_file(psz_file));
400
    write_lnum(linenum);
401
    diag_write_string(trim_func(psz_func));
402
    diag_write_char(' ');
403
    write_whattrace( what );
404
#if CYG_DIAG_PRINTF
405
    diag_printf( psz_msg, arg0, arg1, arg2, arg3, arg4, arg5 );
406
#else
407
    diag_write_string(psz_msg);
408
    diag_write_char(' ');
409
    diag_write_hex(arg0);
410
    diag_write_char(' ');
411
    diag_write_hex(arg1);
412
    diag_write_char(' ');
413
    diag_write_hex(arg2);
414
    diag_write_char(' ');
415
    diag_write_hex(arg3);
416
    diag_write_char(' ');
417
    diag_write_hex(arg4);
418
    diag_write_char(' ');
419
    diag_write_hex(arg5);
420
#endif    
421
    write_whattracepost( what );
422
    diag_write_char('\n');
423
 
424
    DIAG_DEVICE_END_SYNC();
425
    HAL_RESTORE_INTERRUPTS(old_ints);
426
};
427
 
428
externC void
429
cyg_tracemsg8( cyg_uint32 what,
430
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
431
               const char *psz_msg,
432
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1,
433
               CYG_ADDRWORD arg2,  CYG_ADDRWORD arg3,
434
               CYG_ADDRWORD arg4,  CYG_ADDRWORD arg5,
435
               CYG_ADDRWORD arg6,  CYG_ADDRWORD arg7 )
436
{
437
    cyg_uint32 old_ints;
438
 
439
    HAL_DISABLE_INTERRUPTS(old_ints);
440
    DIAG_DEVICE_START_SYNC();
441
 
442
    if ( NULL == psz_msg )
443
        psz_msg = "<nomsg>";
444
 
445
    diag_write_string( "TRACE: " );
446
    write_thread_id();
447
    diag_write_string(trim_file(psz_file));
448
    write_lnum(linenum);
449
    diag_write_string(trim_func(psz_func));
450
    diag_write_char(' ');
451
    write_whattrace( what );
452
#if CYG_DIAG_PRINTF
453
    diag_printf( psz_msg, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
454
#else
455
    diag_write_string(psz_msg);
456
    diag_write_char(' ');
457
    diag_write_hex(arg0);
458
    diag_write_char(' ');
459
    diag_write_hex(arg1);
460
    diag_write_char(' ');
461
    diag_write_hex(arg2);
462
    diag_write_char(' ');
463
    diag_write_hex(arg3);
464
    diag_write_char(' ');
465
    diag_write_hex(arg4);
466
    diag_write_char(' ');
467
    diag_write_hex(arg5);
468
    diag_write_char(' ');
469
    diag_write_hex(arg6);
470
    diag_write_char(' ');
471
    diag_write_hex(arg7);
472
#endif    
473
    write_whattracepost( what );
474
    diag_write_char('\n');
475
 
476
    DIAG_DEVICE_END_SYNC();
477
    HAL_RESTORE_INTERRUPTS(old_ints);
478
};
479
 
480
// -------------------------------------------------------------------------
481
 
482
externC void
483
cyg_trace_dump(void)
484
{
485
#if defined(CYGPKG_KERNEL) && defined(CYG_DIAG_PRINTF)
486
 
487
    {
488
        diag_printf("\nScheduler:\n\n");
489
 
490
        Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler;
491
 
492
        diag_printf("Lock:                %d\n",sched->get_sched_lock() );
493
 
494
# ifdef CYGVAR_KERNEL_THREADS_NAME
495
 
496
        diag_printf("Current Thread:      %s\n",sched->get_current_thread()->get_name());
497
 
498
# else
499
 
500
        diag_printf("Current Thread:    %d\n",sched->get_current_thread()->get_unique_id());
501
 
502
# endif
503
 
504
    }
505
 
506
# ifdef CYGVAR_KERNEL_THREADS_LIST
507
 
508
    {
509
        Cyg_Thread *t = Cyg_Thread::get_list_head();
510
 
511
        diag_printf("\nThreads:\n\n");
512
 
513
        while( NULL != t )
514
        {
515
            cyg_uint32 state = t->get_state();
516
            char tstate[7];
517
            char *tstate1 = "SCUKX";
518
            static char *(reasons[8]) =
519
            {
520
                "NONE",                           // No recorded reason
521
                "WAIT",                           // Wait with no timeout
522
                "DELAY",                          // Simple time delay
523
                "TIMEOUT",                        // Wait with timeout/timeout expired
524
                "BREAK",                          // forced break out of sleep
525
                "DESTRUCT",                       // wait object destroyed[note]
526
                "EXIT",                           // forced termination
527
                "DONE"                            // Wait/delay complete
528
            };
529
 
530
            if( 0 != state )
531
            {
532
                // Knock out chars that do not correspond to set bits.
533
                for( int i = 0; i < 6 ; i++ )
534
                    if( 0 == (state & (1<<i)) )
535
                        tstate[i] = ' ';
536
                    else tstate[i] = tstate1[i];
537
                tstate[6] = 0;
538
            }
539
            else tstate[0] = 'R', tstate[1] = 0;
540
 
541
#   ifdef CYGVAR_KERNEL_THREADS_NAME
542
 
543
            diag_printf( "%20s pri = %3d state = %6s id = %3d\n",
544
                         t->get_name(),
545
                         t->get_priority(),
546
                         tstate,
547
                         t->get_unique_id()
548
                );
549
#   else
550
 
551
            diag_printf( "Thread %3d        pri = %3d state = %6s\n",
552
                         t->get_unique_id(),
553
                         t->get_priority(),
554
                         tstate
555
                );
556
 
557
#   endif        
558
            diag_printf( "%20s stack base = %08x ptr = %08x size = %08x\n",
559
                         "",
560
                         t->get_stack_base(),
561
#ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
562
                         t->get_saved_context(),
563
#else
564
                         0,
565
#endif
566
                         t->get_stack_size()
567
                );
568
 
569
            diag_printf( "%20s sleep reason %8s wake reason %8s\n",
570
                         "",
571
                         reasons[t->get_sleep_reason()],
572
                         reasons[t->get_wake_reason()]
573
                );
574
 
575
            diag_printf( "%20s queue = %08x      wait info = %08x\n",
576
                         "",
577
                         t->get_current_queue(),
578
                         t->get_wait_info()
579
                         );
580
 
581
            diag_printf("\n");
582
            t = t->get_list_next();
583
        }
584
 
585
    }
586
# endif // CYGVAR_KERNEL_THREADS_LIST
587
 
588
#endif // CYG_DIAG_PRINTF
589
}
590
 
591
#endif // CYGDBG_USE_TRACING
592
 
593
// -------------------------------------------------------------------------
594
// Assert functions:
595
 
596
#ifdef CYGDBG_USE_ASSERTS
597
 
598
externC void
599
cyg_assert_fail( const char *psz_func, const char *psz_file,
600
                 cyg_uint32 linenum, const char *psz_msg ) __THROW
601
{
602
    cyg_uint32 old_ints;
603
 
604
    HAL_DISABLE_INTERRUPTS(old_ints);
605
    DIAG_DEVICE_START_SYNC();
606
 
607
    diag_write_string("ASSERT FAIL: ");
608
    write_thread_id();
609
    diag_write_string(trim_file(psz_file));
610
    write_lnum(linenum);
611
    diag_write_string(trim_func(psz_func));
612
    diag_write_char(' ');
613
    diag_write_string(psz_msg);
614
    diag_write_char('\n');
615
 
616
#ifdef CYGHWR_TEST_PROGRAM_EXIT
617
    CYGHWR_TEST_PROGRAM_EXIT();
618
#endif
619
    for(;;);
620
 
621
//    DIAG_DEVICE_END_SYNC();
622
//    HAL_RESTORE_INTERRUPTS(old_ints);
623
};
624
 
625
extern "C"
626
{
627
extern unsigned long _stext;
628
extern unsigned long _etext;
629
 
630
unsigned long stext_addr = (unsigned long)&_stext;
631
unsigned long etext_addr = (unsigned long)&_etext;
632
};
633
 
634
externC cyg_bool cyg_check_data_ptr(const void *ptr)
635
{
636
    unsigned long p = (unsigned long)ptr;
637
 
638
    if( p == 0 ) return false;
639
 
640
    if( p > stext_addr && p < etext_addr ) return false;
641
 
642
    return true;
643
}
644
 
645
externC cyg_bool cyg_check_func_ptr(void (*ptr)(void))
646
{
647
    unsigned long p = (unsigned long)ptr;
648
 
649
    if( p == 0 ) return false;
650
 
651
    if( p < stext_addr && p > etext_addr ) return false;
652
 
653
    return true;
654
}
655
 
656
#endif // CYGDBG_USE_ASSERTS
657
 
658
#endif // CYGDBG_INFRA_DEBUG_TRACE_ASSERT_FANCY
659
 
660
// -------------------------------------------------------------------------
661
// EOF fancy.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.