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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      simple.cxx
4
//
5
//      Simple, non 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:     Simple Trace and assert functions
47
// Description: The functions in this file are simple implementations
48
//              of the standard trace and assert functions. These do not
49
//              do any printf style formatting, simply printing the string
50
//              and arguments directly.
51
//
52
//####DESCRIPTIONEND####
53
//
54
//==========================================================================
55
 
56
#include <pkgconf/system.h>
57
#include <pkgconf/infra.h>
58
 
59
#ifdef CYGDBG_INFRA_DEBUG_TRACE_ASSERT_SIMPLE
60
 
61
#include <cyg/infra/cyg_type.h>         // base types
62
#include <cyg/infra/cyg_trac.h>         // tracing macros
63
#include <cyg/infra/cyg_ass.h>          // assertion macros
64
 
65
#include <pkgconf/hal.h>                // HAL configury
66
#include <cyg/infra/diag.h>             // HAL polled output
67
#include <cyg/hal/hal_arch.h>           // architectural stuff for...
68
#include <cyg/hal/hal_intr.h>           // interrupt control
69
 
70
#ifdef CYGPKG_KERNEL
71
#include <pkgconf/kernel.h>             // kernel configury
72
#include <cyg/kernel/thread.hxx>        // thread id to print
73
#include <cyg/kernel/sched.hxx>         // ancillaries for above
74
#include <cyg/kernel/thread.inl>        // ancillaries for above
75
#endif
76
 
77
// -------------------------------------------------------------------------
78
// Local Configuration: hack me!
79
 
80
#define CYG_NO_FILENAME 1
81
#define CYG_NO_THREADID 0
82
#define CYG_NO_LINENUM  0
83
#define CYG_NO_FUNCNAME 0
84
#define CYG_DIAG_PRINTF 1
85
 
86
#ifndef CYGPKG_KERNEL
87
# undef  CYG_NO_THREADID
88
# define CYG_NO_THREADID 1
89
#endif
90
// -------------------------------------------------------------------------
91
// Functions to trim file names and function names down to printable lengths
92
// (these are shared between trace and assert functions)
93
 
94
static const char *trim_file(const char *file)
95
{
96
#if !CYG_NO_FILENAME
97
    if ( NULL == file )
98
        file = "<nofile>";
99
 
100
    const char *f = file;
101
 
102
    while( *f ) f++;
103
 
104
    while( *f != '/' && f != file ) f--;
105
 
106
    return f==file?f:(f+1);
107
#else
108
    return "";
109
#endif
110
}
111
 
112
static const char *trim_func(const char *func)
113
{
114
#if !CYG_NO_FUNCNAME
115
 
116
    static char fbuf[100];
117
    int i;
118
 
119
    if ( NULL == func )
120
        func = "<nofunc>";
121
 
122
    for( i = 0; func[i] && func[i] != '(' ; i++ )
123
        fbuf[i] = func[i];
124
 
125
    fbuf[i++] = '(';
126
    fbuf[i++] = ')';
127
    fbuf[i  ] = 0;
128
 
129
    return &fbuf[0];
130
#else
131
    return "";
132
#endif
133
}
134
 
135
void write_lnum( cyg_uint32 lnum)
136
{
137
#if !CYG_NO_LINENUM
138
    diag_write_char('[');
139
    diag_write_dec(lnum);
140
    diag_write_char(']');
141
#endif
142
}
143
 
144
void write_thread_id()
145
{
146
#if !CYG_NO_THREADID    
147
    Cyg_Thread *t = Cyg_Thread::self();
148
    cyg_uint16 tid = 0xFFFF;
149
 
150
    if( t != NULL ) tid = t->get_unique_id();
151
 
152
    diag_write_char('<');
153
    diag_write_hex(tid);
154
    diag_write_char('>');
155
#endif
156
}
157
 
158
 
159
// -------------------------------------------------------------------------
160
// Trace functions:
161
 
162
#ifdef CYGDBG_USE_TRACING
163
 
164
externC void
165
cyg_tracenomsg( const char *psz_func, const char *psz_file, cyg_uint32 linenum )
166
{
167
    cyg_uint32 old_ints;
168
 
169
    HAL_DISABLE_INTERRUPTS(old_ints);
170
    DIAG_DEVICE_START_SYNC();
171
 
172
    diag_write_string("TRACE: ");
173
    write_thread_id();
174
    diag_write_string(trim_file(psz_file));
175
    write_lnum(linenum);
176
    diag_write_string(trim_func(psz_func));
177
    diag_write_char('\n');
178
 
179
    DIAG_DEVICE_END_SYNC();
180
    HAL_RESTORE_INTERRUPTS(old_ints);
181
 
182
};
183
 
184
// provide every other one of these as a space/caller bloat compromise.
185
 
186
externC void
187
cyg_tracemsg( cyg_uint32 what,
188
              const char *psz_func, const char *psz_file, cyg_uint32 linenum,
189
              const char *psz_msg )
190
{
191
    cyg_uint32 old_ints;
192
 
193
    HAL_DISABLE_INTERRUPTS(old_ints);
194
    DIAG_DEVICE_START_SYNC();
195
 
196
    if ( NULL == psz_msg )
197
        psz_msg = "<nomsg>";
198
 
199
    diag_write_string("TRACE: ");
200
    write_thread_id();
201
    diag_write_string(trim_file(psz_file));
202
    write_lnum(linenum);
203
    diag_write_string(trim_func(psz_func));
204
    diag_write_char(' ');
205
    diag_write_string(psz_msg);
206
    diag_write_char('\n');
207
 
208
    DIAG_DEVICE_END_SYNC();
209
    HAL_RESTORE_INTERRUPTS(old_ints);
210
 
211
};
212
 
213
externC void
214
cyg_tracemsg2( cyg_uint32 what,
215
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
216
               const char *psz_msg,
217
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1 )
218
{
219
    cyg_uint32 old_ints;
220
 
221
    HAL_DISABLE_INTERRUPTS(old_ints);
222
    DIAG_DEVICE_START_SYNC();
223
 
224
    if ( NULL == psz_msg )
225
        psz_msg = "<nomsg>";
226
 
227
    diag_write_string("TRACE: ");
228
    write_thread_id();
229
    diag_write_string(trim_file(psz_file));
230
    write_lnum(linenum);
231
    diag_write_string(trim_func(psz_func));
232
    diag_write_char(' ');
233
#if CYG_DIAG_PRINTF
234
    diag_printf( psz_msg, arg0, arg1 );
235
#else
236
    diag_write_string(psz_msg);
237
    diag_write_char(' ');
238
    diag_write_hex(arg0);
239
    diag_write_char(' ');
240
    diag_write_hex(arg1);
241
#endif    
242
    diag_write_char('\n');
243
    DIAG_DEVICE_END_SYNC();
244
    HAL_RESTORE_INTERRUPTS(old_ints);
245
};
246
 
247
externC void
248
cyg_tracemsg4( cyg_uint32 what,
249
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
250
               const char *psz_msg,
251
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1,
252
               CYG_ADDRWORD arg2,  CYG_ADDRWORD arg3 )
253
{
254
    cyg_uint32 old_ints;
255
 
256
    HAL_DISABLE_INTERRUPTS(old_ints);
257
    DIAG_DEVICE_START_SYNC();
258
 
259
    if ( NULL == psz_msg )
260
        psz_msg = "<nomsg>";
261
 
262
    diag_write_string("TRACE: ");
263
    write_thread_id();
264
    diag_write_string(trim_file(psz_file));
265
    write_lnum(linenum);
266
    diag_write_string(trim_func(psz_func));
267
    diag_write_char(' ');
268
#if CYG_DIAG_PRINTF
269
    diag_printf( psz_msg, arg0, arg1, arg2, arg3 );
270
#else
271
    diag_write_string(psz_msg);
272
    diag_write_char(' ');
273
    diag_write_hex(arg0);
274
    diag_write_char(' ');
275
    diag_write_hex(arg1);
276
    diag_write_char(' ');
277
    diag_write_hex(arg2);
278
    diag_write_char(' ');
279
    diag_write_hex(arg3);
280
#endif    
281
    diag_write_char('\n');
282
 
283
    DIAG_DEVICE_END_SYNC();
284
    HAL_RESTORE_INTERRUPTS(old_ints);
285
};
286
 
287
externC void
288
cyg_tracemsg6( cyg_uint32 what,
289
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
290
               const char *psz_msg,
291
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1,
292
               CYG_ADDRWORD arg2,  CYG_ADDRWORD arg3,
293
               CYG_ADDRWORD arg4,  CYG_ADDRWORD arg5 )
294
{
295
    cyg_uint32 old_ints;
296
 
297
    HAL_DISABLE_INTERRUPTS(old_ints);
298
    DIAG_DEVICE_START_SYNC();
299
 
300
    if ( NULL == psz_msg )
301
        psz_msg = "<nomsg>";
302
 
303
    diag_write_string("TRACE: ");
304
    write_thread_id();
305
    diag_write_string(trim_file(psz_file));
306
    write_lnum(linenum);
307
    diag_write_string(trim_func(psz_func));
308
    diag_write_char(' ');
309
#if CYG_DIAG_PRINTF
310
    diag_printf( psz_msg, arg0, arg1, arg2, arg3, arg4, arg5 );
311
#else
312
    diag_write_string(psz_msg);
313
    diag_write_char(' ');
314
    diag_write_hex(arg0);
315
    diag_write_char(' ');
316
    diag_write_hex(arg1);
317
    diag_write_char(' ');
318
    diag_write_hex(arg2);
319
    diag_write_char(' ');
320
    diag_write_hex(arg3);
321
    diag_write_char(' ');
322
    diag_write_hex(arg4);
323
    diag_write_char(' ');
324
    diag_write_hex(arg5);
325
#endif    
326
    diag_write_char('\n');
327
 
328
    DIAG_DEVICE_END_SYNC();
329
    HAL_RESTORE_INTERRUPTS(old_ints);
330
};
331
 
332
externC void
333
cyg_tracemsg8( cyg_uint32 what,
334
               const char *psz_func, const char *psz_file, cyg_uint32 linenum,
335
               const char *psz_msg,
336
               CYG_ADDRWORD arg0,  CYG_ADDRWORD arg1,
337
               CYG_ADDRWORD arg2,  CYG_ADDRWORD arg3,
338
               CYG_ADDRWORD arg4,  CYG_ADDRWORD arg5,
339
               CYG_ADDRWORD arg6,  CYG_ADDRWORD arg7 )
340
{
341
    cyg_uint32 old_ints;
342
 
343
    HAL_DISABLE_INTERRUPTS(old_ints);
344
    DIAG_DEVICE_START_SYNC();
345
 
346
    if ( NULL == psz_msg )
347
        psz_msg = "<nomsg>";
348
 
349
    diag_write_string("TRACE: ");
350
    write_thread_id();
351
    diag_write_string(trim_file(psz_file));
352
    write_lnum(linenum);
353
    diag_write_string(trim_func(psz_func));
354
    diag_write_char(' ');
355
#if CYG_DIAG_PRINTF
356
    diag_printf( psz_msg, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
357
#else
358
    diag_write_string(psz_msg);
359
    diag_write_char(' ');
360
    diag_write_hex(arg0);
361
    diag_write_char(' ');
362
    diag_write_hex(arg1);
363
    diag_write_char(' ');
364
    diag_write_hex(arg2);
365
    diag_write_char(' ');
366
    diag_write_hex(arg3);
367
    diag_write_char(' ');
368
    diag_write_hex(arg4);
369
    diag_write_char(' ');
370
    diag_write_hex(arg5);
371
    diag_write_char(' ');
372
    diag_write_hex(arg6);
373
    diag_write_char(' ');
374
    diag_write_hex(arg7);
375
#endif    
376
    diag_write_char('\n');
377
 
378
    DIAG_DEVICE_END_SYNC();
379
    HAL_RESTORE_INTERRUPTS(old_ints);
380
};
381
 
382
// -------------------------------------------------------------------------
383
 
384
externC void
385
cyg_trace_dump(void)
386
{
387
#if defined(CYGPKG_KERNEL) && defined(CYG_DIAG_PRINTF)
388
 
389
    {
390
        diag_printf("\nScheduler:\n\n");
391
 
392
        Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler;
393
 
394
        diag_printf("Lock:                %d\n",sched->get_sched_lock() );
395
 
396
# ifdef CYGVAR_KERNEL_THREADS_NAME
397
 
398
        diag_printf("Current Thread:      %s\n",sched->get_current_thread()->get_name());
399
 
400
# else
401
 
402
        diag_printf("Current Thread:    %d\n",sched->get_current_thread()->get_unique_id());
403
 
404
# endif
405
 
406
    }
407
 
408
# ifdef CYGVAR_KERNEL_THREADS_LIST
409
 
410
    {
411
        Cyg_Thread *t = Cyg_Thread::get_list_head();
412
 
413
        diag_printf("\nThreads:\n\n");
414
 
415
        while( NULL != t )
416
        {
417
            cyg_uint32 state = t->get_state();
418
            char tstate[7];
419
            char *tstate1 = "SCUKX";
420
            static char *(reasons[8]) =
421
            {
422
                "NONE",                           // No recorded reason
423
                "WAIT",                           // Wait with no timeout
424
                "DELAY",                          // Simple time delay
425
                "TIMEOUT",                        // Wait with timeout/timeout expired
426
                "BREAK",                          // forced break out of sleep
427
                "DESTRUCT",                       // wait object destroyed[note]
428
                "EXIT",                           // forced termination
429
                "DONE"                            // Wait/delay complete
430
            };
431
 
432
            if( 0 != state )
433
            {
434
                // Knock out chars that do not correspond to set bits.
435
                for( int i = 0; i < 6 ; i++ )
436
                    if( 0 == (state & (1<<i)) )
437
                        tstate[i] = ' ';
438
                    else tstate[i] = tstate1[i];
439
                tstate[6] = 0;
440
            }
441
            else tstate[0] = 'R', tstate[1] = 0;
442
 
443
#   ifdef CYGVAR_KERNEL_THREADS_NAME
444
 
445
            diag_printf( "%20s pri = %3d state = %6s id = %3d\n",
446
                         t->get_name(),
447
                         t->get_priority(),
448
                         tstate,
449
                         t->get_unique_id()
450
                );
451
#   else
452
 
453
            diag_printf( "Thread %3d        pri = %3d state = %6s\n",
454
                         t->get_unique_id(),
455
                         t->get_priority(),
456
                         tstate
457
                );
458
 
459
#   endif        
460
            diag_printf( "%20s stack base = %08x ptr = %08x size = %08x\n",
461
                         "",
462
                         t->get_stack_base(),
463
#ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
464
                         t->get_saved_context(),
465
#else
466
                         0,
467
#endif
468
                         t->get_stack_size()
469
                );
470
 
471
            diag_printf( "%20s sleep reason %8s wake reason %8s\n",
472
                         "",
473
                         reasons[t->get_sleep_reason()],
474
                         reasons[t->get_wake_reason()]
475
                );
476
 
477
            diag_printf( "%20s queue = %08x      wait info = %08x\n",
478
                         "",
479
                         t->get_current_queue(),
480
                         t->get_wait_info()
481
                         );
482
 
483
            diag_printf("\n");
484
            t = t->get_list_next();
485
        }
486
 
487
    }
488
# endif // CYGVAR_KERNEL_THREADS_LIST
489
 
490
#endif // CYG_DIAG_PRINTF
491
}
492
 
493
#endif // CYGDBG_USE_TRACING
494
 
495
// -------------------------------------------------------------------------
496
// Assert functions:
497
 
498
#ifdef CYGDBG_USE_ASSERTS
499
 
500
externC void
501
cyg_assert_fail( const char *psz_func, const char *psz_file,
502
                 cyg_uint32 linenum, const char *psz_msg ) __THROW
503
{
504
    cyg_uint32 old_ints;
505
 
506
    HAL_DISABLE_INTERRUPTS(old_ints);
507
    DIAG_DEVICE_START_SYNC();
508
 
509
    diag_write_string("ASSERT FAIL: ");
510
    write_thread_id();
511
    diag_write_string(trim_file(psz_file));
512
    write_lnum(linenum);
513
    diag_write_string(trim_func(psz_func));
514
    diag_write_char(' ');
515
    diag_write_string(psz_msg);
516
    diag_write_char('\n');
517
 
518
#ifdef CYGHWR_TEST_PROGRAM_EXIT
519
    CYGHWR_TEST_PROGRAM_EXIT();
520
#endif
521
    for(;;);
522
 
523
//    DIAG_DEVICE_END_SYNC();
524
//    HAL_RESTORE_INTERRUPTS(old_ints);
525
};
526
 
527
extern "C"
528
{
529
extern unsigned long _stext;
530
extern unsigned long _etext;
531
 
532
unsigned long stext_addr = (unsigned long)&_stext;
533
unsigned long etext_addr = (unsigned long)&_etext;
534
};
535
 
536
externC cyg_bool cyg_check_data_ptr(const void *ptr)
537
{
538
    unsigned long p = (unsigned long)ptr;
539
 
540
    if( p == 0 ) return false;
541
 
542
    if( p > stext_addr && p < etext_addr ) return false;
543
 
544
    return true;
545
}
546
 
547
externC cyg_bool cyg_check_func_ptr(const void (*ptr)(void))
548
{
549
    unsigned long p = (unsigned long)ptr;
550
 
551
    if( p == 0 ) return false;
552
 
553
    if( p < stext_addr && p > etext_addr ) return false;
554
 
555
    return true;
556
}
557
 
558
#endif // CYGDBG_USE_ASSERTS
559
 
560
#endif // CYGDBG_INFRA_DEBUG_TRACE_ASSERT_SIMPLE
561
 
562
// -------------------------------------------------------------------------
563
// EOF simple.cxx

powered by: WebSVN 2.1.0

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