context_gcc.S 3.6 KB

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