context_gcc.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * 2013-07-05 Bernard the first version
  9. */
  10. .section .text, "ax"
  11. /*
  12. * rt_base_t rt_hw_interrupt_disable();
  13. */
  14. .globl rt_hw_interrupt_disable
  15. rt_hw_interrupt_disable:
  16. mrs r0, cpsr
  17. cpsid i
  18. bx lr
  19. /*
  20. * void rt_hw_interrupt_enable(rt_base_t level);
  21. */
  22. .globl rt_hw_interrupt_enable
  23. rt_hw_interrupt_enable:
  24. msr cpsr_c, r0
  25. bx lr
  26. /*
  27. * void rt_hw_context_switch_to(rt_uint32 to);
  28. * r0 --> to
  29. */
  30. .globl rt_hw_context_switch_to
  31. rt_hw_context_switch_to:
  32. ldr sp, [r0] @ get new task stack pointer
  33. ldmfd sp!, {r4} @ pop new task spsr
  34. msr spsr_cxsf, r4
  35. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  36. .section .bss.share.isr
  37. _guest_switch_lvl:
  38. .word 0
  39. .globl vmm_virq_update
  40. .section .text.isr, "ax"
  41. /*
  42. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  43. * r0 --> from
  44. * r1 --> to
  45. */
  46. .globl rt_hw_context_switch
  47. rt_hw_context_switch:
  48. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  49. stmfd sp!, {r0-r12, lr} @ push lr & register file
  50. mrs r4, cpsr
  51. tst lr, #0x01
  52. orrne r4, r4, #0x20 @ it's thumb code
  53. stmfd sp!, {r4} @ push cpsr
  54. str sp, [r0] @ store sp in preempted tasks TCB
  55. ldr sp, [r1] @ get new task stack pointer
  56. ldmfd sp!, {r4} @ pop new task cpsr to spsr
  57. msr spsr_cxsf, r4
  58. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
  59. /*
  60. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  61. */
  62. .globl rt_thread_switch_interrupt_flag
  63. .globl rt_interrupt_from_thread
  64. .globl rt_interrupt_to_thread
  65. .globl rt_hw_context_switch_interrupt
  66. rt_hw_context_switch_interrupt:
  67. ldr r2, =rt_thread_switch_interrupt_flag
  68. ldr r3, [r2]
  69. cmp r3, #1
  70. beq _reswitch
  71. ldr ip, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  72. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  73. str r0, [ip]
  74. str r3, [r2]
  75. _reswitch:
  76. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  77. str r1, [r2]
  78. bx lr