Mercurial > nand-ecoscentric
comparison packages/hal/mn10300/arch/current/src/vectors.S @ 143:6b5f480c6929 ecos-sw-2000-12-08
Merge from eCos master repository on 2000-12-08-02:09:36-GMT
| author | jlarmour |
|---|---|
| date | Fri, 08 Dec 2000 03:30:06 +0000 |
| parents | 77cec8369160 |
| children | 52c99470ec11 |
comparison
equal
deleted
inserted
replaced
| 142:12eccf9656f3 | 143:6b5f480c6929 |
|---|---|
| 57 | 57 |
| 58 ##----------------------------------------------------------------------------- | 58 ##----------------------------------------------------------------------------- |
| 59 | 59 |
| 60 .file "vectors.S" | 60 .file "vectors.S" |
| 61 | 61 |
| 62 #ifdef CYGPKG_CYGMON | |
| 63 ##----------------------------------------------------------------------------- | |
| 64 ## Macros for Stack handling when running Cygmon | |
| 65 | |
| 66 .macro hal_cygmon_switch_app_stack | |
| 67 # | |
| 68 # Switch to interrupt stack to handle exception | |
| 69 # | |
| 70 | |
| 71 # First, save some scratch registers | |
| 72 mov a2(a2_save) | |
| 73 mov a3,(a3_save) | |
| 74 | |
| 75 # Copy the exception frame | |
| 76 mov __cygmon_interrupt_stack-8,a2 | |
| 77 mov (sp),a3 // Copy over the saved EPSW | |
| 78 mov a3,(a2) | |
| 79 mov (4,sp),a3 // Copy over the saved PC | |
| 80 mov a3,(4,a2) | |
| 81 | |
| 82 # Save the pre-exception sp in the register image | |
| 83 add -4,a2 # space for SP | |
| 84 mov sp,a3 | |
| 85 add 8,a3 # adjust for exception frame | |
| 86 mov a3,(a2) | |
| 87 | |
| 88 # Actually switch the stack | |
| 89 mov a2,sp | |
| 90 | |
| 91 # Now, restore the scratch registers | |
| 92 mov (a2_save),a2 | |
| 93 mov (a3_save),a3 | |
| 94 .endm | |
| 95 | |
| 96 .macro hal_cygmon_restore_app_stack | |
| 97 // For cygmon we are switching stacks immediately on exception. | |
| 98 // We must wait until the very end before restoring the original stack. | |
| 99 | |
| 100 # Save some scratch registers | |
| 101 mov a2,(a2_save) | |
| 102 mov a3,(a3_save) | |
| 103 | |
| 104 # We need to restore the application stack pointer, but we also | |
| 105 # need to restore the exception frame. | |
| 106 mov (sp),a2 | |
| 107 add 4,sp // remove saved sp | |
| 108 add -8,a2 // adjust for exception frame | |
| 109 | |
| 110 mov (sp),a3 // Copy the saved EPSW | |
| 111 mov a3,(a2) | |
| 112 mov (4,sp),a3 // Copy the saved PC | |
| 113 mov a3,(4,a2) | |
| 114 mov a2,sp // Restore the frame-adjusted SP | |
| 115 | |
| 116 # Restore the scratch registers | |
| 117 mov (a2_save),a2 | |
| 118 mov (a3_save),a3 | |
| 119 .endm | |
| 120 | |
| 121 #endif // CYGPKG_CYGMON | |
| 122 | |
| 62 ##----------------------------------------------------------------------------- | 123 ##----------------------------------------------------------------------------- |
| 63 | 124 |
| 64 .section ".vectors","ax" | 125 .section ".vectors","ax" |
| 65 | 126 |
| 66 .globl reset_vector | 127 .globl reset_vector |
| 94 ##----------------------------------------------------------------------------- | 155 ##----------------------------------------------------------------------------- |
| 95 ## NMI vector | 156 ## NMI vector |
| 96 | 157 |
| 97 .globl __nmi | 158 .globl __nmi |
| 98 __nmi: | 159 __nmi: |
| 160 #ifdef CYGPKG_CYGMON | |
| 161 hal_cygmon_switch_app_stack | |
| 162 #else | |
| 99 add -4,sp # space for SP | 163 add -4,sp # space for SP |
| 164 #endif | |
| 100 hal_cpu_save_all # push all registers | 165 hal_cpu_save_all # push all registers |
| 101 mov (_hal_vsr_table+28),a0 | 166 mov (_hal_vsr_table+28),a0 |
| 102 jmp (a0) | 167 jmp (a0) |
| 103 | 168 |
| 104 ##----------------------------------------------------------------------------- | 169 ##----------------------------------------------------------------------------- |
| 105 ## Trap vector | 170 ## Trap vector |
| 106 | 171 |
| 107 .globl __trap | 172 .globl __trap |
| 108 __trap: | 173 __trap: |
| 174 #ifdef CYGPKG_CYGMON | |
| 175 add -4,sp # space for PSW | |
| 176 hal_cygmon_switch_app_stack | |
| 177 #else | |
| 109 add -8,sp # space for SP and PSW | 178 add -8,sp # space for SP and PSW |
| 179 #endif | |
| 110 hal_cpu_save_all # push all registers | 180 hal_cpu_save_all # push all registers |
| 111 mov (_hal_vsr_table+32),a0 | 181 mov (_hal_vsr_table+32),a0 |
| 112 jmp (a0) | 182 jmp (a0) |
| 113 | 183 |
| 114 ##----------------------------------------------------------------------------- | 184 ##----------------------------------------------------------------------------- |
| 115 ## Macro to define a hardware VSR | 185 ## Macro to define a hardware VSR |
| 116 | 186 |
| 117 .macro hardware_vector name | 187 .macro hardware_vector name |
| 118 .globl __hardware_vector_\name | 188 .globl __hardware_vector_\name |
| 119 __hardware_vector_\name: | 189 __hardware_vector_\name: |
| 190 #ifdef CYGPKG_CYGMON | |
| 191 hal_cygmon_switch_app_stack | |
| 192 #else | |
| 120 add -4,sp # space for SP | 193 add -4,sp # space for SP |
| 194 #endif | |
| 121 hal_cpu_save_all | 195 hal_cpu_save_all |
| 122 mov \name,d0 # d0 = vector id | 196 mov \name,d0 # d0 = vector id |
| 123 mov d0,(0,sp) # save in dummy stack loc | 197 mov d0,(0,sp) # save in dummy stack loc |
| 124 mov _hal_vsr_table,a0 # a0 = vsr table | 198 mov _hal_vsr_table,a0 # a0 = vsr table |
| 125 add \name<<2,a0 # a0 = &required vsr | 199 add \name<<2,a0 # a0 = &required vsr |
| 270 | 344 |
| 271 hal_diag_intr_start | 345 hal_diag_intr_start |
| 272 | 346 |
| 273 increment_sched_lock | 347 increment_sched_lock |
| 274 | 348 |
| 275 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK | 349 #if defined(CYGPKG_CYGMON) |
| 350 // For Cygmon, we saved this back when we originally switched stacks. | |
| 351 mov (sp),a2 # A2 = saved thread state | |
| 352 #elif defined(CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK) | |
| 276 # Increment interrupt nesting counter | 353 # Increment interrupt nesting counter |
| 277 mov __interrupt_stack,a0 # A0 = interrupt stack top | 354 mov __interrupt_stack,a0 # A0 = interrupt stack top |
| 278 mov sp,a2 # A2 = SP | 355 mov sp,a2 # A2 = SP |
| 279 cmp __interrupt_stack_base,a2 # compare with base of stack | 356 cmp __interrupt_stack_base,a2 # compare with base of stack |
| 280 blt 1f # if lt switch to int stack | 357 blt 1f # if lt switch to int stack |
| 373 # If interrupt was caused by GDB, the ISR call above | 450 # If interrupt was caused by GDB, the ISR call above |
| 374 # is skipped by jumping here. | 451 # is skipped by jumping here. |
| 375 2: | 452 2: |
| 376 #endif | 453 #endif |
| 377 | 454 |
| 378 #ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK | 455 #if defined(CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK) && !defined(CYGPKG_CYGMON) |
| 379 | 456 |
| 380 # If we are returning from the last nested interrupt, move back | 457 # If we are returning from the last nested interrupt, move back |
| 381 # to the thread stack. interrupt_end() must be called on the | 458 # to the thread stack. interrupt_end() must be called on the |
| 382 # thread stack since it potentially causes a context switch. | 459 # thread stack since it potentially causes a context switch. |
| 383 | 460 |
| 413 # show_interrupts | 490 # show_interrupts |
| 414 | 491 |
| 415 hal_diag_restore | 492 hal_diag_restore |
| 416 | 493 |
| 417 hal_cpu_load_all | 494 hal_cpu_load_all |
| 495 #ifdef CYGPKG_CYGMON | |
| 496 hal_cygmon_restore_app_stack | |
| 497 #else | |
| 418 add 4,sp | 498 add 4,sp |
| 499 #endif | |
| 419 rti # and return | 500 rti # and return |
| 420 | 501 |
| 421 ##----------------------------------------------------------------------------- | 502 ##----------------------------------------------------------------------------- |
| 422 ## Execute pending DSRs on the interrupt stack with interrupts enabled. | 503 ## Execute pending DSRs on the interrupt stack with interrupts enabled. |
| 423 ## Note: this can only be called from code running on a thread stack | 504 ## Note: this can only be called from code running on a thread stack |
| 508 | 589 |
| 509 mov d1,(sp) # save initial vector in spare save slot | 590 mov d1,(sp) # save initial vector in spare save slot |
| 510 | 591 |
| 511 mov sp,a1 # a1 = saved state | 592 mov sp,a1 # a1 = saved state |
| 512 | 593 |
| 513 #ifdef CYGPKG_CYGMON | |
| 514 # Switch to interrupt stack to handle exception | |
| 515 # This should probably be done as the first thing in the exception | |
| 516 # handler to guard against the possibility of having a bad SP to | |
| 517 # begin with. ie if the user sets the SP to a bad location, we | |
| 518 # will not run properly. Ideally we should switch to monitor mode | |
| 519 # on entry to any exception. However, a lot of other code | |
| 520 # assumes things work this way. | |
| 521 mov __interrupt_stack-4,a0 | |
| 522 mov a0, sp | |
| 523 mov a1,(sp) | |
| 524 add -4,sp | |
| 525 #endif | |
| 526 | |
| 527 mov a1,d0 # d0 = arg1 = saved state | 594 mov a1,d0 # d0 = arg1 = saved state |
| 528 | 595 |
| 529 add -16,sp # return link + args | 596 add -16,sp # return link + args |
| 530 mov d3,d1 # d1 = arg2 = ISR value | 597 mov d3,d1 # d1 = arg2 = ISR value |
| 531 | 598 |
| 532 calls _cyg_hal_exception_handler # call C code | 599 calls _cyg_hal_exception_handler # call C code |
| 533 | 600 |
| 534 add 16,sp # pop args | 601 add 16,sp # pop args |
| 535 | 602 |
| 536 #ifdef CYGPKG_CYGMON | |
| 537 add 4,sp # Restore the old stack | |
| 538 mov (sp),a1 | |
| 539 mov a1,sp | |
| 540 #endif | |
| 541 | |
| 542 hal_cpu_load_all | 603 hal_cpu_load_all |
| 543 | 604 |
| 544 #ifdef CYGPKG_CYGMON | 605 #ifdef CYGPKG_CYGMON |
| 545 mov d3,(d3_save) | 606 hal_cygmon_restore_app_stack |
| 546 mov a2,(a2_save) | |
| 547 mov a3,(a3_save) | |
| 548 | |
| 549 # Pop the potentially-new stack pointer into a2 | |
| 550 mov (sp),a2 | |
| 551 add 4,sp | |
| 552 | |
| 553 # Check to see if sp has been modified. | |
| 554 # The exception processing pushes 8 bytes onto the stack. | |
| 555 # If sp+8 = (sp) then the stack has not been modified. | |
| 556 mov sp,a3 | |
| 557 add 8, a3 | |
| 558 cmp a2,a3 | |
| 559 beq 8f | |
| 560 | |
| 561 # The stack has been modified. We need to setup for a proper rti | |
| 562 # so the stack is in the correct place. We just hope that the user | |
| 563 # put the stack somewhere we can write to. | |
| 564 # | |
| 565 # Copy 8 bytes from the old stack to the new stack (ie the exception frame) | |
| 566 mov (-4,a3), d3 | |
| 567 mov d3, (-4,a2) | |
| 568 mov (-8,a3), d3 | |
| 569 mov d3, (-8,a2) | |
| 570 | |
| 571 # Set the sp register to the new exception frame. | |
| 572 add -8, a2 | |
| 573 mov a2, sp | |
| 574 | |
| 575 8: mov (d3_save),d3 | |
| 576 mov (a2_save),a2 | |
| 577 mov (a3_save),a3 | |
| 578 #else | 607 #else |
| 579 add 4,sp | 608 add 4,sp |
| 580 #endif | 609 #endif |
| 581 | 610 |
| 582 rti | 611 rti |
| 588 .byte 3, 0, 1, 0 | 617 .byte 3, 0, 1, 0 |
| 589 .byte 2, 0, 1, 0 | 618 .byte 2, 0, 1, 0 |
| 590 | 619 |
| 591 #ifdef CYGPKG_CYGMON | 620 #ifdef CYGPKG_CYGMON |
| 592 .section ".bss" | 621 .section ".bss" |
| 622 d0_save: | |
| 623 .long 0 | |
| 624 d1_save: | |
| 625 .long 0 | |
| 626 d2_save: | |
| 627 .long 0 | |
| 593 d3_save: | 628 d3_save: |
| 594 .long 0 | 629 .long 0 |
| 630 a0_save: | |
| 631 .long 0 | |
| 632 a1_save: | |
| 633 .long 0 | |
| 595 a2_save: | 634 a2_save: |
| 596 .long 0 | 635 .long 0 |
| 597 a3_save: | 636 a3_save: |
| 637 .long 0 | |
| 638 sp_save: | |
| 598 .long 0 | 639 .long 0 |
| 599 #endif | 640 #endif |
| 600 | 641 |
| 601 ##----------------------------------------------------------------------------- | 642 ##----------------------------------------------------------------------------- |
| 602 ## Default TRAP VSR | 643 ## Default TRAP VSR |
| 612 mov 3,d1 # 3 == TRAP trap | 653 mov 3,d1 # 3 == TRAP trap |
| 613 mov d1,(0,sp) # save in spare save slot | 654 mov d1,(0,sp) # save in spare save slot |
| 614 calls _cyg_hal_exception_handler # call C code | 655 calls _cyg_hal_exception_handler # call C code |
| 615 add 8,sp # pop args | 656 add 8,sp # pop args |
| 616 hal_cpu_load_all | 657 hal_cpu_load_all |
| 658 #ifdef CYGPKG_CYGMON | |
| 659 hal_cygmon_restore_app_stack | |
| 660 #else | |
| 617 add 4,sp | 661 add 4,sp |
| 662 #endif | |
| 618 rets | 663 rets |
| 619 | 664 |
| 620 ##----------------------------------------------------------------------------- | 665 ##----------------------------------------------------------------------------- |
| 621 ## VSR table. The VSRs pointed to by this table are called from the stubs | 666 ## VSR table. The VSRs pointed to by this table are called from the stubs |
| 622 ## connected to the hardware. | 667 ## connected to the hardware. |
| 700 .balign 16 | 745 .balign 16 |
| 701 .global _cyg_interrupt_stack | 746 .global _cyg_interrupt_stack |
| 702 _cyg_interrupt_stack: | 747 _cyg_interrupt_stack: |
| 703 __interrupt_stack: | 748 __interrupt_stack: |
| 704 | 749 |
| 750 #ifdef CYGPKG_CYGMON | |
| 751 .balign 16 | |
| 752 .global __cygmon_interrupt_stack_base | |
| 753 __cygmon_interrupt_stack_base: | |
| 754 .rept CYGNUM_HAL_COMMON_INTERRUPTS_STACK_SIZE | |
| 755 .byte 0 | |
| 756 .endr | |
| 757 .balign 16 | |
| 758 .global __cygmon_interrupt_stack | |
| 759 __cygmon_interrupt_stack: | |
| 760 #endif | |
| 761 | |
| 705 .long 0,0,0,0,0,0,0,0 | 762 .long 0,0,0,0,0,0,0,0 |
| 706 | 763 |
| 707 ##----------------------------------------------------------------------------- | 764 ##----------------------------------------------------------------------------- |
| 708 | 765 |
| 709 .data | 766 .data |
