contex_ck802_gcc.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-01-01 Urey first version
  9. * 2018-06-05 tanek clean code
  10. */
  11. .file "contex_ck802.S"
  12. #undef VIC_TSPDR
  13. #define VIC_TSPDR 0XE000EC08
  14. .global rt_thread_switch_interrupt_flag
  15. .global rt_interrupt_from_thread
  16. .global rt_interrupt_to_thread
  17. .text
  18. .align 2
  19. /*
  20. * rt_base_t rt_hw_interrupt_disable(void);
  21. */
  22. .global rt_hw_interrupt_disable
  23. .type rt_hw_interrupt_disable, %function
  24. rt_hw_interrupt_disable:
  25. mfcr r0, psr
  26. psrclr ie
  27. rts
  28. /*
  29. * void rt_hw_interrupt_enable(rt_base_t psr);
  30. */
  31. .global rt_hw_interrupt_enable
  32. .type rt_hw_interrupt_enable, %function
  33. rt_hw_interrupt_enable:
  34. mtcr r0, psr
  35. rts
  36. /*
  37. * void rt_hw_context_switch_to(rt_uint32 to);
  38. * R0 --> to
  39. */
  40. .global rt_hw_context_switch_to
  41. .type rt_hw_context_switch_to, %function
  42. rt_hw_context_switch_to:
  43. lrw r2, rt_interrupt_to_thread
  44. stw r0, (r2)
  45. /* set form thread = 0 */
  46. lrw r2, rt_interrupt_from_thread
  47. movi r0, 0
  48. stw r0, (r2)
  49. psrclr ie
  50. jbr __tspend_handler_nosave
  51. /*
  52. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  53. * r0 --> from
  54. * r1 --> to
  55. */
  56. .global rt_hw_context_switch_interrupt
  57. .type rt_hw_context_switch_interrupt, %function
  58. rt_hw_context_switch_interrupt:
  59. lrw r2, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  60. stw r0, (r2)
  61. lrw r2, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  62. stw r1, (r2)
  63. lrw r0, VIC_TSPDR
  64. bgeni r1, 0
  65. stw r1, (r0)
  66. rts
  67. /*
  68. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
  69. * r0 --> from
  70. * r1 --> to
  71. */
  72. .global rt_hw_context_switch
  73. .type rt_hw_context_switch, %function
  74. rt_hw_context_switch:
  75. lrw r2, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  76. stw r0, (r2)
  77. lrw r2, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  78. stw r1, (r2)
  79. lrw r0, VIC_TSPDR
  80. bgeni r1, 0
  81. stw r1, (r0)
  82. rts
  83. .global PendSV_Handler
  84. .type PendSV_Handler, %function
  85. PendSV_Handler:
  86. subi sp, 68
  87. stm r0-r13, (sp)
  88. stw r15, (sp, 56)
  89. mfcr r0, epsr
  90. stw r0, (sp, 60)
  91. mfcr r0, epc
  92. stw r0, (sp, 64)
  93. lrw r0, rt_interrupt_from_thread
  94. ldw r1, (r0)
  95. stw sp, (r1)
  96. __tspend_handler_nosave:
  97. lrw r6, rt_interrupt_to_thread
  98. lrw r7, rt_interrupt_from_thread
  99. ldw r8, (r6)
  100. stw r8, (r7)
  101. ldw sp, (r8)
  102. #ifdef CONFIG_STACK_GUARD
  103. mfcr r3, cr<0, 4>
  104. bseti r3, 0
  105. bseti r3, 1
  106. mtcr r3, cr<0, 4>
  107. #endif
  108. ldw r0, (sp, 64)
  109. mtcr r0, epc
  110. ldw r0, (sp, 60)
  111. bseti r0, 6
  112. mtcr r0, epsr
  113. ldw r15, (sp, 56)
  114. ldm r0-r13, (sp)
  115. addi sp, 68
  116. rte