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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [infra/] [v2_0/] [src/] [fancy.cxx] - Blame information for rev 665

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

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

powered by: WebSVN 2.1.0

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