Mercurial > flash_v2
comparison packages/hal/mips/tx39/current/src/hal_diag.c @ 38:e7ba79f6d3a8 ecos-sw-1999-09-23
Merge from eCos master repository on 1999-09-23-20:10:25-BST
| author | jlarmour |
|---|---|
| date | Thu, 23 Sep 1999 19:52:27 +0000 |
| parents | d3fbcdfa1b2f |
| children | 7a6ac9edc838 |
comparison
equal
deleted
inserted
replaced
| 37:0b25345c9c69 | 38:e7ba79f6d3a8 |
|---|---|
| 53 #include <cyg/hal/hal_io.h> | 53 #include <cyg/hal/hal_io.h> |
| 54 | 54 |
| 55 /*---------------------------------------------------------------------------*/ | 55 /*---------------------------------------------------------------------------*/ |
| 56 | 56 |
| 57 //#define CYG_KERNEL_DIAG_LCD | 57 //#define CYG_KERNEL_DIAG_LCD |
| 58 #define CYG_KERNEL_DIAG_SERIAL0 | 58 #define CYG_KERNEL_DIAG_SERIAL0 // For ROM start but see immediately below: |
| 59 | 59 |
| 60 #if defined(CYG_HAL_USE_ROM_MONITOR) | 60 #if defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) |
| 61 | 61 #undef CYG_KERNEL_DIAG_SERIAL0 |
| 62 #undef CYG_KERNEL_DIAG_LCD | |
| 63 #define CYG_KERNEL_DIAG_CYGMON | |
| 62 #define CYG_KERNEL_DIAG_GDB | 64 #define CYG_KERNEL_DIAG_GDB |
| 63 | 65 |
| 64 #endif | 66 #endif |
| 65 | 67 |
| 66 /*---------------------------------------------------------------------------*/ | 68 /*---------------------------------------------------------------------------*/ |
| 83 #endif | 85 #endif |
| 84 } | 86 } |
| 85 | 87 |
| 86 /*---------------------------------------------------------------------------*/ | 88 /*---------------------------------------------------------------------------*/ |
| 87 | 89 |
| 88 #ifdef CYG_KERNEL_DIAG_SERIAL0 | 90 #if defined(CYG_KERNEL_DIAG_SERIAL0) || defined(CYG_KERNEL_DIAG_CYGMON) |
| 89 | 91 |
| 90 #define DIAG_BASE 0xfffff300 | 92 #define DIAG_BASE 0xfffff300 |
| 91 #define DIAG_SLCR (DIAG_BASE+0x00) | 93 #define DIAG_SLCR (DIAG_BASE+0x00) |
| 92 #define DIAG_SLSR (DIAG_BASE+0x04) | 94 #define DIAG_SLSR (DIAG_BASE+0x04) |
| 93 #define DIAG_SLDICR (DIAG_BASE+0x08) | 95 #define DIAG_SLDICR (DIAG_BASE+0x08) |
| 190 | 192 |
| 191 //hal_diag_led(0x40); | 193 //hal_diag_led(0x40); |
| 192 } | 194 } |
| 193 | 195 |
| 194 | 196 |
| 197 #if defined(CYG_KERNEL_DIAG_CYGMON) | |
| 198 void hal_diag_dumb_write_char(char c) | |
| 199 #else | |
| 195 void hal_diag_write_char(char c) | 200 void hal_diag_write_char(char c) |
| 201 #endif | |
| 196 { | 202 { |
| 197 #ifdef CYG_KERNEL_DIAG_GDB | 203 #ifdef CYG_KERNEL_DIAG_GDB |
| 198 #if 0 //defined(CYG_HAL_USE_ROM_MONITOR) | 204 #if 0 //defined(CYG_HAL_USE_ROM_MONITOR) |
| 199 | 205 |
| 200 typedef void rom_write_fn(char c); | 206 typedef void rom_write_fn(char c); |
| 248 | 254 |
| 249 hal_diag_read_char_serial0( &c1 ); | 255 hal_diag_read_char_serial0( &c1 ); |
| 250 | 256 |
| 251 if( c1 == '+' ) break; | 257 if( c1 == '+' ) break; |
| 252 | 258 |
| 253 if( cyg_hal_is_break( &c1 , 1 ) ) | 259 { |
| 254 cyg_hal_user_break( NULL ); | 260 extern void cyg_hal_user_break(CYG_ADDRWORD *regs); |
| 261 extern cyg_bool cyg_hal_is_break(char *buf, int size); | |
| 262 if( cyg_hal_is_break( &c1 , 1 ) ) | |
| 263 cyg_hal_user_break( NULL ); | |
| 264 } | |
| 255 | 265 |
| 256 break; | 266 break; |
| 257 } | 267 } |
| 258 | 268 |
| 259 pos = 0; | 269 pos = 0; |
| 269 #endif | 279 #endif |
| 270 #else | 280 #else |
| 271 hal_diag_write_char_serial0(c); | 281 hal_diag_write_char_serial0(c); |
| 272 #endif | 282 #endif |
| 273 } | 283 } |
| 284 | |
| 274 | 285 |
| 275 void hal_diag_read_char(char *c) | 286 void hal_diag_read_char(char *c) |
| 276 { | 287 { |
| 277 for(;;) | 288 for(;;) |
| 278 { | 289 { |
| 312 | 323 |
| 313 break; | 324 break; |
| 314 } | 325 } |
| 315 } | 326 } |
| 316 | 327 |
| 317 #endif | 328 #endif // defined(CYG_KERNEL_DIAG_SERIAL0) || defined(CYG_KERNEL_DIAG_CYGMON) |
| 329 | |
| 330 | |
| 331 #if defined(CYG_KERNEL_DIAG_CYGMON) // only | |
| 332 | |
| 333 /* This code has been imported from the BSP module. The definitions have | |
| 334 * been left as-is, even though there was scope for doing more, to avoid | |
| 335 * too much drift from the original sources | |
| 336 */ | |
| 337 | |
| 338 struct bsp_comm_procs { | |
| 339 void *ch_data; | |
| 340 void (*__write)(void *ch_data, const char *buf, int len); | |
| 341 int (*__read)(void *ch_data, char *buf, int len); | |
| 342 void (*__putc)(void *ch_data, char ch); | |
| 343 int (*__getc)(void *ch_data); | |
| 344 int (*__control)(void *ch_data, int func, ...); | |
| 345 }; | |
| 346 | |
| 347 // This is pointed to by entry BSP_NOTVEC_BSP_COMM_PROCS: | |
| 348 typedef struct { | |
| 349 int version; /* version number for future expansion */ | |
| 350 void *__ictrl_table; | |
| 351 void *__exc_table; | |
| 352 void *__dbg_vector; | |
| 353 void *__kill_vector; | |
| 354 struct bsp_comm_procs *__console_procs; | |
| 355 struct bsp_comm_procs *__debug_procs; | |
| 356 void *__flush_dcache; | |
| 357 void *__flush_icache; | |
| 358 void *__cpu_data; | |
| 359 void *__board_data; | |
| 360 void *__sysinfo; | |
| 361 int (*__set_debug_comm)(int __comm_id); | |
| 362 int (*__set_console_comm)(int __comm_id); | |
| 363 int (*__set_serial_baud)(int __comm_id, int baud); | |
| 364 void *__dbg_data; | |
| 365 void (*__reset)(void); | |
| 366 int __console_interrupt_flag; | |
| 367 } bsp_shared_t; | |
| 368 | |
| 369 /* | |
| 370 * Core Exception vectors. | |
| 371 */ | |
| 372 #define BSP_EXC_INT 0 | |
| 373 #define BSP_EXC_TLBMOD 1 | |
| 374 #define BSP_EXC_TLBL 2 | |
| 375 #define BSP_EXC_TLBS 3 | |
| 376 #define BSP_EXC_ADEL 4 | |
| 377 #define BSP_EXC_ADES 5 | |
| 378 #define BSP_EXC_IBE 6 | |
| 379 #define BSP_EXC_DBE 7 | |
| 380 #define BSP_EXC_SYSCALL 8 | |
| 381 #define BSP_EXC_BREAK 9 | |
| 382 #define BSP_EXC_ILL 10 | |
| 383 #define BSP_EXC_CPU 11 | |
| 384 #define BSP_EXC_OV 12 | |
| 385 #define BSP_EXC_TRAP 13 | |
| 386 #define BSP_EXC_VCEI 14 | |
| 387 #define BSP_EXC_FPE 15 | |
| 388 #define BSP_EXC_RSV16 16 | |
| 389 #define BSP_EXC_RSV17 17 | |
| 390 #define BSP_EXC_RSV18 18 | |
| 391 #define BSP_EXC_RSV19 19 | |
| 392 #define BSP_EXC_RSV20 20 | |
| 393 #define BSP_EXC_RSV21 21 | |
| 394 #define BSP_EXC_RSV22 22 | |
| 395 #define BSP_EXC_WATCH 23 | |
| 396 #define BSP_EXC_RSV24 24 | |
| 397 #define BSP_EXC_RSV25 25 | |
| 398 #define BSP_EXC_RSV26 26 | |
| 399 #define BSP_EXC_RSV27 27 | |
| 400 #define BSP_EXC_RSV28 28 | |
| 401 #define BSP_EXC_RSV29 29 | |
| 402 #define BSP_EXC_RSV30 30 | |
| 403 #define BSP_EXC_VCED 31 | |
| 404 /* tx39 debug exception */ | |
| 405 #define BSP_EXC_DEBUG 32 | |
| 406 #define BSP_EXC_TLB 33 | |
| 407 #define BSP_EXC_NMI 34 | |
| 408 /* | |
| 409 * Hack for eCos on tx39 to set an async breakpoint. | |
| 410 */ | |
| 411 #define BSP_VEC_BP_HOOK 35 | |
| 412 | |
| 413 #define BSP_EXC_XTLB 36 | |
| 414 #define BSP_EXC_CACHE 37 | |
| 415 | |
| 416 #define BSP_MAX_EXCEPTIONS 38 | |
| 417 | |
| 418 /* | |
| 419 * Another hack for tx39 eCos compatibility. | |
| 420 */ | |
| 421 #if defined(__CPU_R3900__) | |
| 422 #define BSP_VEC_MT_DEBUG 15 | |
| 423 #else | |
| 424 #define BSP_VEC_MT_DEBUG 38 | |
| 425 #endif | |
| 426 | |
| 427 #define BSP_VEC_STUB_ENTRY 39 | |
| 428 #define BSP_VEC_BSPDATA 40 | |
| 429 #define BSP_VEC_MAGIC 41 | |
| 430 #define BSP_VEC_IRQ_CHECK 42 | |
| 431 | |
| 432 #define BSP_VEC_PAD 43 | |
| 433 #define NUM_VTAB_ENTRIES 44 | |
| 434 | |
| 435 | |
| 436 #define BSP_MAGIC_VAL 0x55aa4321 | |
| 437 | |
| 438 #define SYS_interrupt 1000 | |
| 439 | |
| 440 // These vectors should be called with: | |
| 441 // | |
| 442 // k0 - Exception Number | |
| 443 | |
| 444 #define CYGMON_VECTOR_TABLE_BASE 0x80000100 | |
| 445 #define CYGMON_VECTOR_TABLE ((CYG_ADDRESS *)CYGMON_VECTOR_TABLE_BASE) | |
| 446 | |
| 447 #if 0 // UNUSED | |
| 448 static int | |
| 449 hal_bsp_set_debug_comm(int arg) | |
| 450 { | |
| 451 bsp_shared_t *shared; | |
| 452 | |
| 453 shared = (bsp_shared_t *) | |
| 454 (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]); | |
| 455 | |
| 456 if (0 != shared->__set_debug_comm) { | |
| 457 return (*(shared->__set_debug_comm))(arg); | |
| 458 } | |
| 459 return 0; | |
| 460 } | |
| 461 | |
| 462 static int | |
| 463 hal_bsp_set_console_comm(int arg) | |
| 464 { | |
| 465 bsp_shared_t *shared; | |
| 466 | |
| 467 shared = (bsp_shared_t *) | |
| 468 (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]); | |
| 469 | |
| 470 if (0 != shared->__set_console_comm) { | |
| 471 return (*(shared->__set_console_comm))(arg); | |
| 472 } | |
| 473 return 0; | |
| 474 } | |
| 475 #endif // 0 UNUSED | |
| 476 | |
| 477 static void bsp_trap(int trap_num); | |
| 478 | |
| 479 static int | |
| 480 hal_bsp_console_write(const void *p, int len) | |
| 481 { | |
| 482 bsp_shared_t *shared; | |
| 483 struct bsp_comm_procs *com; | |
| 484 int magic; | |
| 485 | |
| 486 /*hal_bsp_set_console_comm(0);*/ | |
| 487 | |
| 488 /* If this is not a BSP-based CygMon, return 0 */ | |
| 489 magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]); | |
| 490 if (magic != BSP_MAGIC_VAL) | |
| 491 return 0; | |
| 492 | |
| 493 shared = (bsp_shared_t *) | |
| 494 (CYGMON_VECTOR_TABLE[ BSP_VEC_BSPDATA ]); | |
| 495 | |
| 496 com = shared->__console_procs; | |
| 497 | |
| 498 if (0 != com) { | |
| 499 shared->__console_interrupt_flag = 0; | |
| 500 com->__write(com->ch_data, p, len); | |
| 501 if (shared->__console_interrupt_flag) { | |
| 502 /* debug interrupt; stop here */ | |
| 503 bsp_trap(SYS_interrupt); | |
| 504 } | |
| 505 | |
| 506 return 1; | |
| 507 } | |
| 508 return 0; | |
| 509 } | |
| 510 | |
| 511 static void | |
| 512 bsp_trap(int trap_num) | |
| 513 { | |
| 514 asm("syscall\n"); | |
| 515 } | |
| 516 | |
| 517 | |
| 518 static void | |
| 519 hal_dumb_serial_write(const char *p, int len) | |
| 520 { | |
| 521 int i; | |
| 522 for ( i = 0 ; i < len; i++ ) { | |
| 523 hal_diag_dumb_write_char(p[i]); | |
| 524 } | |
| 525 } | |
| 526 | |
| 527 void hal_diag_write_char(char c) | |
| 528 { | |
| 529 static char line[100]; | |
| 530 static int pos = 0; | |
| 531 | |
| 532 // No need to send CRs | |
| 533 if( c == '\r' ) return; | |
| 534 | |
| 535 line[pos++] = c; | |
| 536 | |
| 537 if( c == '\n' || pos == sizeof(line) ) { | |
| 538 CYG_INTERRUPT_STATE old; | |
| 539 | |
| 540 // Disable interrupts. This prevents GDB trying to interrupt us | |
| 541 // while we are in the middle of sending a packet. The serial | |
| 542 // receive interrupt will be seen when we re-enable interrupts | |
| 543 // later. | |
| 544 | |
| 545 HAL_DISABLE_INTERRUPTS(old); | |
| 546 | |
| 547 if ( ! hal_bsp_console_write( line, pos ) ) | |
| 548 // then there is no function registered, just spew it out serial | |
| 549 hal_dumb_serial_write( line, pos ); | |
| 550 | |
| 551 pos = 0; | |
| 552 | |
| 553 // And re-enable interrupts | |
| 554 HAL_RESTORE_INTERRUPTS(old); | |
| 555 | |
| 556 } | |
| 557 } | |
| 558 | |
| 559 int | |
| 560 hal_diag_irq_check(int vector) | |
| 561 { | |
| 562 typedef int irq_check_fn(int irq_nr); | |
| 563 irq_check_fn *fn = (irq_check_fn *)(CYGMON_VECTOR_TABLE[ BSP_VEC_IRQ_CHECK ]); | |
| 564 int magic; | |
| 565 | |
| 566 | |
| 567 /* If this is not a BSP-based CygMon, return 0 */ | |
| 568 magic = (int)(CYGMON_VECTOR_TABLE[ BSP_VEC_MAGIC ]); | |
| 569 if (magic != BSP_MAGIC_VAL) | |
| 570 return 0; | |
| 571 | |
| 572 #if defined(CYGPKG_HAL_MIPS_TX3904) | |
| 573 /* convert vector to BSP irq number */ | |
| 574 if (vector == 16) | |
| 575 vector = 2; | |
| 576 else | |
| 577 vector += 3; | |
| 578 #endif | |
| 579 | |
| 580 return fn(vector); | |
| 581 } | |
| 582 | |
| 583 #endif // defined(CYG_KERNEL_DIAG_CYGMON) *only* | |
| 318 | 584 |
| 319 /*---------------------------------------------------------------------------*/ | 585 /*---------------------------------------------------------------------------*/ |
| 320 | 586 |
| 321 #if defined(CYGPKG_HAL_MIPS_TX39_JMR3904) && defined(CYG_KERNEL_DIAG_LCD) | 587 #if defined(CYGPKG_HAL_MIPS_TX39_JMR3904) && defined(CYG_KERNEL_DIAG_LCD) |
| 322 | 588 |
