Mercurial > flash_v2
annotate packages/infra/current/src/simple.cxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children | c5536bad4c24 |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 2 | 3 // simple.cxx |
| 0 | 4 // |
| 5 // Simple, non formatting trace and assert functions | |
| 6 // | |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): nickg |
| 35 // Contributors: nickg | |
| 36 // Date: 1997-12-04 | |
| 37 // Purpose: Simple Trace and assert functions | |
| 38 // Description: The functions in this file are simple implementations | |
| 0 | 39 // of the standard trace and assert functions. These do not |
| 40 // do any printf style formatting, simply printing the string | |
| 41 // and arguments directly. | |
| 42 // | |
| 43 //####DESCRIPTIONEND#### | |
| 44 // | |
| 45 //========================================================================== | |
| 46 | |
| 47 #include <pkgconf/system.h> | |
| 48 #include <pkgconf/infra.h> | |
| 49 | |
| 50 #ifdef CYGDBG_INFRA_DEBUG_TRACE_ASSERT_SIMPLE | |
| 51 | |
| 52 #include <cyg/infra/cyg_type.h> // base types | |
| 53 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 54 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 55 | |
| 56 #include <pkgconf/hal.h> // HAL configury | |
| 57 #include <cyg/infra/diag.h> // HAL polled output | |
| 58 #include <cyg/hal/hal_arch.h> // architectural stuff for... | |
| 59 #include <cyg/hal/hal_intr.h> // interrupt control | |
| 60 | |
| 61 #ifdef CYGPKG_KERNEL | |
| 62 #include <pkgconf/kernel.h> // kernel configury | |
| 63 #include <cyg/kernel/thread.hxx> // thread id to print | |
| 64 #include <cyg/kernel/sched.hxx> // ancillaries for above | |
| 65 #include <cyg/kernel/thread.inl> // ancillaries for above | |
| 66 #endif | |
| 67 | |
| 68 // ------------------------------------------------------------------------- | |
| 69 // Local Configuration: hack me! | |
| 70 | |
| 71 #define CYG_NO_FILENAME 1 | |
| 72 #define CYG_NO_THREADID 0 | |
| 73 #define CYG_NO_LINENUM 0 | |
| 74 #define CYG_NO_FUNCNAME 0 | |
| 75 #define CYG_DIAG_PRINTF 1 | |
| 76 | |
| 77 #ifndef CYGPKG_KERNEL | |
| 78 # undef CYG_NO_THREADID | |
| 79 # define CYG_NO_THREADID 1 | |
| 80 #endif | |
| 81 // ------------------------------------------------------------------------- | |
| 82 // Functions to trim file names and function names down to printable lengths | |
| 83 // (these are shared between trace and assert functions) | |
| 84 | |
| 2 | 85 static const char *trim_file(const char *file) |
| 0 | 86 { |
| 87 #if !CYG_NO_FILENAME | |
| 88 if ( NULL == file ) | |
| 89 file = "<nofile>"; | |
| 90 | |
| 2 | 91 const char *f = file; |
| 0 | 92 |
| 93 while( *f ) f++; | |
| 94 | |
| 95 while( *f != '/' && f != file ) f--; | |
| 96 | |
| 97 return f==file?f:(f+1); | |
| 98 #else | |
| 99 return ""; | |
| 100 #endif | |
| 101 } | |
| 102 | |
| 2 | 103 static const char *trim_func(const char *func) |
| 0 | 104 { |
| 105 #if !CYG_NO_FUNCNAME | |
| 106 | |
| 107 static char fbuf[100]; | |
| 108 int i; | |
| 109 | |
| 110 if ( NULL == func ) | |
| 111 func = "<nofunc>"; | |
| 112 | |
| 113 for( i = 0; func[i] && func[i] != '(' ; i++ ) | |
| 114 fbuf[i] = func[i]; | |
| 115 | |
| 116 fbuf[i++] = '('; | |
| 117 fbuf[i++] = ')'; | |
| 2 | 118 fbuf[i ] = 0; |
| 0 | 119 |
| 2 | 120 return &fbuf[0]; |
| 0 | 121 #else |
| 122 return ""; | |
| 123 #endif | |
| 124 } | |
| 125 | |
| 126 void write_lnum( cyg_uint32 lnum) | |
| 127 { | |
| 128 #if !CYG_NO_LINENUM | |
| 129 diag_write_char('['); | |
| 130 diag_write_dec(lnum); | |
| 131 diag_write_char(']'); | |
| 132 #endif | |
| 133 } | |
| 134 | |
| 135 void write_thread_id() | |
| 136 { | |
| 137 #if !CYG_NO_THREADID | |
| 138 Cyg_Thread *t = Cyg_Thread::self(); | |
| 139 cyg_uint16 tid = 0xFFFF; | |
| 140 | |
| 141 if( t != NULL ) tid = t->get_unique_id(); | |
| 142 | |
| 143 diag_write_char('<'); | |
| 144 diag_write_hex(tid); | |
| 145 diag_write_char('>'); | |
| 146 #endif | |
| 147 } | |
| 148 | |
| 149 | |
| 150 // ------------------------------------------------------------------------- | |
| 151 // Trace functions: | |
| 152 | |
| 153 #ifdef CYGDBG_USE_TRACING | |
| 154 | |
| 155 externC void | |
| 156 cyg_tracenomsg( char *psz_func, char *psz_file, cyg_uint32 linenum ) | |
| 157 { | |
| 158 cyg_uint32 old_ints; | |
| 159 | |
| 160 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 161 DIAG_DEVICE_START_SYNC(); | |
| 162 | |
| 163 diag_write_string("TRACE: "); | |
| 164 write_thread_id(); | |
| 165 diag_write_string(trim_file(psz_file)); | |
| 166 write_lnum(linenum); | |
| 167 diag_write_string(trim_func(psz_func)); | |
| 168 diag_write_char('\n'); | |
| 169 | |
| 170 DIAG_DEVICE_END_SYNC(); | |
| 171 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 172 | |
| 173 }; | |
| 174 | |
| 175 // provide every other one of these as a space/caller bloat compromise. | |
| 176 | |
| 177 externC void | |
| 178 cyg_tracemsg( cyg_uint32 what, | |
| 179 char *psz_func, char *psz_file, cyg_uint32 linenum, | |
| 180 char *psz_msg ) | |
| 181 { | |
| 182 cyg_uint32 old_ints; | |
| 183 | |
| 184 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 185 DIAG_DEVICE_START_SYNC(); | |
| 186 | |
| 187 if ( NULL == psz_msg ) | |
| 188 psz_msg = "<nomsg>"; | |
| 189 | |
| 190 diag_write_string("TRACE: "); | |
| 191 write_thread_id(); | |
| 192 diag_write_string(trim_file(psz_file)); | |
| 193 write_lnum(linenum); | |
| 194 diag_write_string(trim_func(psz_func)); | |
| 195 diag_write_char(' '); | |
| 196 diag_write_string(psz_msg); | |
| 197 diag_write_char('\n'); | |
| 198 | |
| 199 DIAG_DEVICE_END_SYNC(); | |
| 200 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 201 | |
| 202 }; | |
| 203 | |
| 204 externC void | |
| 205 cyg_tracemsg2( cyg_uint32 what, | |
| 206 char *psz_func, char *psz_file, cyg_uint32 linenum, | |
| 207 char *psz_msg, | |
| 208 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1 ) | |
| 209 { | |
| 210 cyg_uint32 old_ints; | |
| 211 | |
| 212 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 213 DIAG_DEVICE_START_SYNC(); | |
| 214 | |
| 215 if ( NULL == psz_msg ) | |
| 216 psz_msg = "<nomsg>"; | |
| 217 | |
| 218 diag_write_string("TRACE: "); | |
| 219 write_thread_id(); | |
| 220 diag_write_string(trim_file(psz_file)); | |
| 221 write_lnum(linenum); | |
| 222 diag_write_string(trim_func(psz_func)); | |
| 223 diag_write_char(' '); | |
| 224 #if CYG_DIAG_PRINTF | |
| 225 diag_printf( psz_msg, arg0, arg1 ); | |
| 226 #else | |
| 227 diag_write_string(psz_msg); | |
| 228 diag_write_char(' '); | |
| 229 diag_write_hex(arg0); | |
| 230 diag_write_char(' '); | |
| 231 diag_write_hex(arg1); | |
| 232 #endif | |
| 233 diag_write_char('\n'); | |
| 234 DIAG_DEVICE_END_SYNC(); | |
| 235 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 236 }; | |
| 237 | |
| 238 externC void | |
| 239 cyg_tracemsg4( cyg_uint32 what, | |
| 240 char *psz_func, char *psz_file, cyg_uint32 linenum, | |
| 241 char *psz_msg, | |
| 242 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 243 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3 ) | |
| 244 { | |
| 245 cyg_uint32 old_ints; | |
| 246 | |
| 247 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 248 DIAG_DEVICE_START_SYNC(); | |
| 249 | |
| 250 if ( NULL == psz_msg ) | |
| 251 psz_msg = "<nomsg>"; | |
| 252 | |
| 253 diag_write_string("TRACE: "); | |
| 254 write_thread_id(); | |
| 255 diag_write_string(trim_file(psz_file)); | |
| 256 write_lnum(linenum); | |
| 257 diag_write_string(trim_func(psz_func)); | |
| 258 diag_write_char(' '); | |
| 259 #if CYG_DIAG_PRINTF | |
| 260 diag_printf( psz_msg, arg0, arg1, arg2, arg3 ); | |
| 261 #else | |
| 262 diag_write_string(psz_msg); | |
| 263 diag_write_char(' '); | |
| 264 diag_write_hex(arg0); | |
| 265 diag_write_char(' '); | |
| 266 diag_write_hex(arg1); | |
| 267 diag_write_char(' '); | |
| 268 diag_write_hex(arg2); | |
| 269 diag_write_char(' '); | |
| 270 diag_write_hex(arg3); | |
| 271 #endif | |
| 272 diag_write_char('\n'); | |
| 273 | |
| 274 DIAG_DEVICE_END_SYNC(); | |
| 275 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 276 }; | |
| 277 | |
| 278 externC void | |
| 279 cyg_tracemsg6( cyg_uint32 what, | |
| 280 char *psz_func, char *psz_file, cyg_uint32 linenum, | |
| 281 char *psz_msg, | |
| 282 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 283 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, | |
| 284 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5 ) | |
| 285 { | |
| 286 cyg_uint32 old_ints; | |
| 287 | |
| 288 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 289 DIAG_DEVICE_START_SYNC(); | |
| 290 | |
| 291 if ( NULL == psz_msg ) | |
| 292 psz_msg = "<nomsg>"; | |
| 293 | |
| 294 diag_write_string("TRACE: "); | |
| 295 write_thread_id(); | |
| 296 diag_write_string(trim_file(psz_file)); | |
| 297 write_lnum(linenum); | |
| 298 diag_write_string(trim_func(psz_func)); | |
| 299 diag_write_char(' '); | |
| 300 #if CYG_DIAG_PRINTF | |
| 301 diag_printf( psz_msg, arg0, arg1, arg2, arg3, arg4, arg5 ); | |
| 302 #else | |
| 303 diag_write_string(psz_msg); | |
| 304 diag_write_char(' '); | |
| 305 diag_write_hex(arg0); | |
| 306 diag_write_char(' '); | |
| 307 diag_write_hex(arg1); | |
| 308 diag_write_char(' '); | |
| 309 diag_write_hex(arg2); | |
| 310 diag_write_char(' '); | |
| 311 diag_write_hex(arg3); | |
| 312 diag_write_char(' '); | |
| 313 diag_write_hex(arg4); | |
| 314 diag_write_char(' '); | |
| 315 diag_write_hex(arg5); | |
| 316 #endif | |
| 317 diag_write_char('\n'); | |
| 318 | |
| 319 DIAG_DEVICE_END_SYNC(); | |
| 320 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 321 }; | |
| 322 | |
| 323 externC void | |
| 324 cyg_tracemsg8( cyg_uint32 what, | |
| 325 char *psz_func, char *psz_file, cyg_uint32 linenum, | |
| 326 char *psz_msg, | |
| 327 CYG_ADDRWORD arg0, CYG_ADDRWORD arg1, | |
| 328 CYG_ADDRWORD arg2, CYG_ADDRWORD arg3, | |
| 329 CYG_ADDRWORD arg4, CYG_ADDRWORD arg5, | |
| 330 CYG_ADDRWORD arg6, CYG_ADDRWORD arg7 ) | |
| 331 { | |
| 332 cyg_uint32 old_ints; | |
| 333 | |
| 334 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 335 DIAG_DEVICE_START_SYNC(); | |
| 336 | |
| 337 if ( NULL == psz_msg ) | |
| 338 psz_msg = "<nomsg>"; | |
| 339 | |
| 340 diag_write_string("TRACE: "); | |
| 341 write_thread_id(); | |
| 342 diag_write_string(trim_file(psz_file)); | |
| 343 write_lnum(linenum); | |
| 344 diag_write_string(trim_func(psz_func)); | |
| 345 diag_write_char(' '); | |
| 346 #if CYG_DIAG_PRINTF | |
| 347 diag_printf( psz_msg, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); | |
| 348 #else | |
| 349 diag_write_string(psz_msg); | |
| 350 diag_write_char(' '); | |
| 351 diag_write_hex(arg0); | |
| 352 diag_write_char(' '); | |
| 353 diag_write_hex(arg1); | |
| 354 diag_write_char(' '); | |
| 355 diag_write_hex(arg2); | |
| 356 diag_write_char(' '); | |
| 357 diag_write_hex(arg3); | |
| 358 diag_write_char(' '); | |
| 359 diag_write_hex(arg4); | |
| 360 diag_write_char(' '); | |
| 361 diag_write_hex(arg5); | |
| 362 diag_write_char(' '); | |
| 363 diag_write_hex(arg6); | |
| 364 diag_write_char(' '); | |
| 365 diag_write_hex(arg7); | |
| 366 #endif | |
| 367 diag_write_char('\n'); | |
| 368 | |
| 369 DIAG_DEVICE_END_SYNC(); | |
| 370 HAL_RESTORE_INTERRUPTS(old_ints); | |
| 371 }; | |
| 372 | |
| 373 #endif // CYGDBG_USE_TRACING | |
| 374 | |
| 375 // ------------------------------------------------------------------------- | |
| 376 // Assert functions: | |
| 377 | |
| 378 #ifdef CYGDBG_USE_ASSERTS | |
| 379 | |
| 380 externC void | |
| 2 | 381 cyg_assert_fail( const char *psz_func, const char *psz_file, |
| 382 cyg_uint32 linenum, const char *psz_msg ) | |
| 0 | 383 { |
| 384 cyg_uint32 old_ints; | |
| 385 | |
| 386 HAL_DISABLE_INTERRUPTS(old_ints); | |
| 387 DIAG_DEVICE_START_SYNC(); | |
| 388 | |
| 389 diag_write_string("ASSERT FAIL: "); | |
| 390 write_thread_id(); | |
| 391 diag_write_string(trim_file(psz_file)); | |
| 392 write_lnum(linenum); | |
| 393 diag_write_string(trim_func(psz_func)); | |
| 394 diag_write_char(' '); | |
| 395 diag_write_string(psz_msg); | |
| 396 diag_write_char('\n'); | |
| 397 | |
| 398 for(;;); | |
| 399 | |
| 400 // DIAG_DEVICE_END_SYNC(); | |
| 401 // HAL_RESTORE_INTERRUPTS(old_ints); | |
| 402 }; | |
| 403 | |
| 404 extern "C" | |
| 405 { | |
| 406 extern unsigned long CYG_LABEL_NAME(stext); | |
| 407 extern unsigned long CYG_LABEL_NAME(etext); | |
| 408 | |
| 409 unsigned long stext_addr = (unsigned long)&CYG_LABEL_NAME(stext); | |
| 410 unsigned long etext_addr = (unsigned long)&CYG_LABEL_NAME(etext); | |
| 411 }; | |
| 412 | |
| 413 externC cyg_bool cyg_check_data_ptr(void *ptr) | |
| 414 { | |
| 415 unsigned long p = (unsigned long)ptr; | |
| 416 | |
| 417 if( p == 0 ) return false; | |
| 418 | |
| 419 if( p > stext_addr && p < etext_addr ) return false; | |
| 420 | |
| 421 return true; | |
| 422 } | |
| 423 | |
| 424 externC cyg_bool cyg_check_func_ptr(void (*ptr)(void)) | |
| 425 { | |
| 426 unsigned long p = (unsigned long)ptr; | |
| 427 | |
| 428 if( p == 0 ) return false; | |
| 429 | |
| 430 if( p < stext_addr && p > etext_addr ) return false; | |
| 431 | |
| 432 return true; | |
| 433 } | |
| 434 | |
| 435 #endif // CYGDBG_USE_ASSERTS | |
| 436 | |
| 437 #endif // CYGDBG_INFRA_DEBUG_TRACE_ASSERT_SIMPLE | |
| 438 | |
| 439 // ------------------------------------------------------------------------- | |
| 440 // EOF simple.cxx |
