context_gcc.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include <p32xxxx.h>
  2. #include "../common/mips.inc"
  3. #include "../common/stackframe.h"
  4. .section ".text", "ax"
  5. .set noat
  6. .set noreorder
  7. /*
  8. * rt_base_t rt_hw_interrupt_disable()
  9. */
  10. .globl rt_hw_interrupt_disable
  11. rt_hw_interrupt_disable:
  12. mfc0 v0, CP0_STATUS /* v0 = status */
  13. addiu v1, zero, -2 /* v1 = 0-2 = 0xFFFFFFFE */
  14. and v1, v0, v1 /* v1 = v0 & 0xFFFFFFFE */
  15. mtc0 v1, CP0_STATUS /* status = v1 */
  16. jr ra
  17. nop
  18. /*
  19. * void rt_hw_interrupt_enable(rt_base_t level)
  20. */
  21. .globl rt_hw_interrupt_enable
  22. rt_hw_interrupt_enable:
  23. mtc0 a0, CP0_STATUS
  24. jr ra
  25. nop
  26. /*
  27. * void rt_hw_context_switch_to(rt_uint32 to)/*
  28. * a0 --> to
  29. */
  30. .globl rt_hw_context_switch_to
  31. rt_hw_context_switch_to:
  32. lw sp, 0(a0) /* get new task stack pointer */
  33. RESTORE_ALL_AND_RET
  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_interrupt(rt_uint32 from, rt_uint32 to)/*
  48. */
  49. .globl rt_thread_switch_interrupt_flag
  50. .globl rt_interrupt_from_thread
  51. .globl rt_interrupt_to_thread
  52. .globl rt_hw_context_switch_interrupt
  53. rt_hw_context_switch_interrupt:
  54. la t0, rt_thread_switch_interrupt_flag
  55. lw t1, 0(t0)
  56. nop
  57. bnez t1, _reswitch
  58. nop
  59. li t1, 0x01 /* set rt_thread_switch_interrupt_flag to 1 */
  60. sw t1, 0(t0)
  61. la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  62. sw a0, 0(t0)
  63. _reswitch:
  64. la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  65. sw a1, 0(t0)
  66. /* trigger the soft exception (causes context switch) */
  67. mfc0 t0, CP0_CAUSE /* t0 = Cause */
  68. ori t0, t0, (1<<8) /* t0 |= (1<<8) */
  69. mtc0 t0, CP0_CAUSE /* cause = t0 */
  70. addiu t1, zero, -257 /* t1 = ~(1<<8) */
  71. and t0, t0, t1 /* t0 &= t1 */
  72. mtc0 t0, CP0_CAUSE /* cause = t0 */
  73. jr ra
  74. nop
  75. /*
  76. * void __ISR(_CORE_SOFTWARE_0_VECTOR, ipl2) CoreSW0Handler(void)
  77. */
  78. .section ".text", "ax"
  79. .set noreorder
  80. .set noat
  81. .ent CoreSW0Handler
  82. .globl CoreSW0Handler
  83. CoreSW0Handler:
  84. SAVE_ALL
  85. /* mCS0ClearIntFlag(); */
  86. la t0, IFS0CLR /* t0 = IFS0CLR */
  87. addiu t1,zero,0x02 /* t1 = (1<<2) */
  88. sw t1, 0(t0) /* IFS0CLR = t1 */
  89. la k0, rt_thread_switch_interrupt_flag
  90. sw zero, 0(k0) /* clear flag */
  91. /*
  92. * switch to the new thread
  93. */
  94. la k0, rt_interrupt_from_thread
  95. lw k1, 0(k0)
  96. nop
  97. sw sp, 0(k1) /* store sp in preempted tasks's TCB */
  98. la k0, rt_interrupt_to_thread
  99. lw k1, 0(k0)
  100. nop
  101. lw sp, 0(k1) /* get new task's stack pointer */
  102. RESTORE_ALL_AND_RET
  103. .end CoreSW0Handler