context_gcc.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * File : context_gcc.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-05-17 swkyer first version
  13. * 2010-09-11 bernard port to Loongson SoC3210
  14. * 2011-08-08 lgnq port to Loongson LS1B
  15. */
  16. #include "../common/mips.inc"
  17. #include "../common/stackframe.h"
  18. #include "stackframe_fpu.h"
  19. .section ".text", "ax"
  20. .set noreorder
  21. /*
  22. * rt_base_t rt_hw_interrupt_disable()
  23. */
  24. .globl rt_hw_interrupt_disable
  25. rt_hw_interrupt_disable:
  26. mfc0 v0, CP0_STATUS
  27. and v1, v0, 0xfffffffe
  28. mtc0 v1, CP0_STATUS
  29. jr ra
  30. nop
  31. /*
  32. * void rt_hw_interrupt_enable(rt_base_t level)
  33. */
  34. .globl rt_hw_interrupt_enable
  35. rt_hw_interrupt_enable:
  36. ori a0, 0x00000800
  37. mtc0 a0, CP0_STATUS
  38. ehb
  39. mfc0 v0, CP0_CAUSE
  40. ehb
  41. or v1, v0, 0x800000 //EBASE + 0x200
  42. mtc0 v1, CP0_CAUSE
  43. ehb
  44. jr ra
  45. nop
  46. /*
  47. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
  48. * a0 --> from
  49. * a1 --> to
  50. */
  51. .globl rt_hw_context_switch
  52. rt_hw_context_switch:
  53. mtc0 ra, CP0_EPC
  54. SAVE_ALL
  55. SAVE_FPU
  56. sw sp, 0(a0) /* store sp in preempted tasks TCB */
  57. lw sp, 0(a1) /* get new task stack pointer */
  58. RESTORE_FPU
  59. RESTORE_ALL_AND_RET
  60. /*
  61. * void rt_hw_context_switch_to(rt_uint32 to)/*
  62. * a0 --> to
  63. */
  64. .globl rt_hw_context_switch_to
  65. rt_hw_context_switch_to:
  66. lw sp, 0(a0) /* get new task stack pointer */
  67. RESTORE_FPU
  68. RESTORE_ALL_AND_RET
  69. /*
  70. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
  71. */
  72. .globl rt_thread_switch_interrupt_flag
  73. .globl rt_interrupt_from_thread
  74. .globl rt_interrupt_to_thread
  75. .globl rt_hw_context_switch_interrupt
  76. rt_hw_context_switch_interrupt:
  77. la t0, rt_thread_switch_interrupt_flag
  78. lw t1, 0(t0)
  79. nop
  80. bnez t1, _reswitch
  81. nop
  82. li t1, 0x01 /* set rt_thread_switch_interrupt_flag to 1 */
  83. sw t1, 0(t0)
  84. la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  85. sw a0, 0(t0)
  86. _reswitch:
  87. la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  88. sw a1, 0(t0)
  89. jr ra
  90. nop
  91. /*
  92. * void rt_hw_context_switch_interrupt_do(rt_base_t flag)
  93. */
  94. .globl rt_interrupt_enter
  95. .globl rt_interrupt_leave
  96. .globl mips_irq_handle
  97. mips_irq_handle:
  98. SAVE_ALL
  99. SAVE_FPU
  100. mfc0 t0, CP0_CAUSE
  101. and t1, t0, 0xff
  102. bnez t1, spurious_interrupt /* check exception */
  103. nop
  104. /* let k0 keep the current context sp */
  105. move k0, sp
  106. /* switch to kernel stack */
  107. li sp, SYSTEM_STACK
  108. jal rt_interrupt_enter
  109. nop
  110. jal rt_interrupt_dispatch
  111. nop
  112. jal rt_interrupt_leave
  113. nop
  114. /* switch sp back to thread's context */
  115. move sp, k0
  116. /*
  117. * if rt_thread_switch_interrupt_flag set, jump to
  118. * rt_hw_context_switch_interrupt_do and don't return
  119. */
  120. la k0, rt_thread_switch_interrupt_flag
  121. lw k1, 0(k0)
  122. beqz k1, spurious_interrupt
  123. nop
  124. sw zero, 0(k0) /* clear flag */
  125. nop
  126. /*
  127. * switch to the new thread
  128. */
  129. la k0, rt_interrupt_from_thread
  130. lw k1, 0(k0)
  131. nop
  132. sw sp, 0(k1) /* store sp in preempted tasks's TCB */
  133. la k0, rt_interrupt_to_thread
  134. lw k1, 0(k0)
  135. nop
  136. lw sp, 0(k1) /* get new task's stack pointer */
  137. j spurious_interrupt
  138. nop
  139. spurious_interrupt:
  140. RESTORE_FPU
  141. RESTORE_ALL_AND_RET
  142. .set reorder