1
0

context_gcc.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * File : context_gcc.S
  3. * Change Logs:
  4. * Date Author Notes
  5. * 2010-05-17 swkyer first version
  6. * 2010-09-11 bernard port to Jz4755
  7. */
  8. #include "../common/mips.inc"
  9. #include "../common/stackframe.h"
  10. #include "jz47xx.h"
  11. .section ".text", "ax"
  12. .set noreorder
  13. /*
  14. * rt_base_t rt_hw_interrupt_disable()
  15. */
  16. .globl rt_hw_interrupt_disable
  17. rt_hw_interrupt_disable:
  18. mfc0 v0, CP0_STATUS
  19. and v1, v0, 0xfffffffe
  20. mtc0 v1, CP0_STATUS
  21. jr ra
  22. nop
  23. /*
  24. * void rt_hw_interrupt_enable(rt_base_t level)
  25. */
  26. .globl rt_hw_interrupt_enable
  27. rt_hw_interrupt_enable:
  28. mtc0 a0, CP0_STATUS
  29. jr ra
  30. nop
  31. /*
  32. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
  33. * a0 --> from
  34. * a1 --> to
  35. */
  36. .globl rt_hw_context_switch
  37. rt_hw_context_switch:
  38. mtc0 ra, CP0_EPC
  39. SAVE_ALL
  40. sw sp, 0(a0) /* store sp in preempted tasks TCB */
  41. lw sp, 0(a1) /* get new task stack pointer */
  42. RESTORE_ALL_AND_RET
  43. /*
  44. * void rt_hw_context_switch_to(rt_uint32 to)/*
  45. * a0 --> to
  46. */
  47. .globl rt_hw_context_switch_to
  48. rt_hw_context_switch_to:
  49. lw sp, 0(a0) /* get new task stack pointer */
  50. RESTORE_ALL_AND_RET
  51. /*
  52. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
  53. */
  54. .globl rt_thread_switch_interrput_flag
  55. .globl rt_interrupt_from_thread
  56. .globl rt_interrupt_to_thread
  57. .globl rt_hw_context_switch_interrupt
  58. rt_hw_context_switch_interrupt:
  59. la t0, rt_thread_switch_interrput_flag
  60. lw t1, 0(t0)
  61. nop
  62. bnez t1, _reswitch
  63. nop
  64. li t1, 0x01 /* set rt_thread_switch_interrput_flag to 1 */
  65. sw t1, 0(t0)
  66. la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  67. sw a0, 0(t0)
  68. _reswitch:
  69. la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  70. sw a1, 0(t0)
  71. jr ra
  72. nop
  73. .globl system_dump
  74. /*
  75. * void rt_hw_context_switch_interrupt_do(rt_base_t flag)
  76. */
  77. .globl rt_interrupt_enter
  78. .globl rt_interrupt_leave
  79. .globl mips_irq_handle
  80. mips_irq_handle:
  81. SAVE_ALL
  82. mfc0 t0, CP0_CAUSE
  83. mfc0 t1, CP0_STATUS
  84. and t0, t1
  85. andi t0, 0xff00
  86. beqz t0, spurious_interrupt
  87. nop
  88. /* let k0 keep the current context sp */
  89. move k0, sp
  90. /* switch to kernel stack */
  91. li sp, SYSTEM_STACK
  92. jal rt_interrupt_enter
  93. nop
  94. jal rt_interrupt_dispatch
  95. nop
  96. jal rt_interrupt_leave
  97. nop
  98. /* switch sp back to thread's context */
  99. move sp, k0
  100. /*
  101. * if rt_thread_switch_interrput_flag set, jump to
  102. * rt_hw_context_switch_interrupt_do and don't return
  103. */
  104. la k0, rt_thread_switch_interrput_flag
  105. lw k1, 0(k0)
  106. beqz k1, spurious_interrupt
  107. nop
  108. sw zero, 0(k0) /* clear flag */
  109. nop
  110. /*
  111. * switch to the new thread
  112. */
  113. la k0, rt_interrupt_from_thread
  114. lw k1, 0(k0)
  115. nop
  116. sw sp, 0(k1) /* store sp in preempted tasks's TCB */
  117. la k0, rt_interrupt_to_thread
  118. lw k1, 0(k0)
  119. nop
  120. lw sp, 0(k1) /* get new task's stack pointer */
  121. j spurious_interrupt
  122. nop
  123. spurious_interrupt:
  124. RESTORE_ALL_AND_RET
  125. .set reorder