context_gcc.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. .section ".text", "ax"
  19. .set noreorder
  20. /*
  21. * rt_base_t rt_hw_interrupt_disable()
  22. */
  23. .globl rt_hw_interrupt_disable
  24. rt_hw_interrupt_disable:
  25. mfc0 v0, CP0_STATUS
  26. and v1, v0, 0xfffffffe
  27. mtc0 v1, CP0_STATUS
  28. jr ra
  29. nop
  30. /*
  31. * void rt_hw_interrupt_enable(rt_base_t level)
  32. */
  33. .globl rt_hw_interrupt_enable
  34. rt_hw_interrupt_enable:
  35. ori a0, 0x00000800
  36. mtc0 a0, CP0_STATUS
  37. ehb
  38. mfc0 v0, CP0_CAUSE
  39. ehb
  40. or v1, v0, 0x800000 //EBASE + 0x200
  41. mtc0 v1, CP0_CAUSE
  42. ehb
  43. jr ra
  44. nop
  45. /*
  46. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
  47. * a0 --> from
  48. * a1 --> to
  49. */
  50. .globl rt_hw_context_switch
  51. rt_hw_context_switch:
  52. mtc0 ra, CP0_EPC
  53. SAVE_ALL
  54. sw sp, 0(a0) /* store sp in preempted tasks TCB */
  55. lw sp, 0(a1) /* get new task stack pointer */
  56. RESTORE_ALL_AND_RET
  57. /*
  58. * void rt_hw_context_switch_to(rt_uint32 to)/*
  59. * a0 --> to
  60. */
  61. .globl rt_hw_context_switch_to
  62. rt_hw_context_switch_to:
  63. lw sp, 0(a0) /* get new task stack pointer */
  64. RESTORE_ALL_AND_RET
  65. /*
  66. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
  67. */
  68. .globl rt_thread_switch_interrupt_flag
  69. .globl rt_interrupt_from_thread
  70. .globl rt_interrupt_to_thread
  71. .globl rt_hw_context_switch_interrupt
  72. rt_hw_context_switch_interrupt:
  73. la t0, rt_thread_switch_interrupt_flag
  74. lw t1, 0(t0)
  75. nop
  76. bnez t1, _reswitch
  77. nop
  78. li t1, 0x01 /* set rt_thread_switch_interrupt_flag to 1 */
  79. sw t1, 0(t0)
  80. la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  81. sw a0, 0(t0)
  82. _reswitch:
  83. la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  84. sw a1, 0(t0)
  85. jr ra
  86. nop
  87. /*
  88. * void rt_hw_context_switch_interrupt_do(rt_base_t flag)
  89. */
  90. .globl rt_interrupt_enter
  91. .globl rt_interrupt_leave
  92. .globl mips_irq_handle
  93. mips_irq_handle:
  94. SAVE_ALL
  95. mfc0 t0, CP0_CAUSE
  96. and t1, t0, 0xff
  97. bnez t1, spurious_interrupt /* check exception */
  98. nop
  99. /* let k0 keep the current context sp */
  100. move k0, sp
  101. /* switch to kernel stack */
  102. li sp, SYSTEM_STACK
  103. jal rt_interrupt_enter
  104. nop
  105. jal rt_interrupt_dispatch
  106. nop
  107. jal rt_interrupt_leave
  108. nop
  109. /* switch sp back to thread's context */
  110. move sp, k0
  111. /*
  112. * if rt_thread_switch_interrupt_flag set, jump to
  113. * rt_hw_context_switch_interrupt_do and don't return
  114. */
  115. la k0, rt_thread_switch_interrupt_flag
  116. lw k1, 0(k0)
  117. beqz k1, spurious_interrupt
  118. nop
  119. sw zero, 0(k0) /* clear flag */
  120. nop
  121. /*
  122. * switch to the new thread
  123. */
  124. la k0, rt_interrupt_from_thread
  125. lw k1, 0(k0)
  126. nop
  127. sw sp, 0(k1) /* store sp in preempted tasks's TCB */
  128. la k0, rt_interrupt_to_thread
  129. lw k1, 0(k0)
  130. nop
  131. lw sp, 0(k1) /* get new task's stack pointer */
  132. j spurious_interrupt
  133. nop
  134. spurious_interrupt:
  135. RESTORE_ALL_AND_RET
  136. .set reorder