context_gcc.S 3.4 KB

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