context_gcc.S 2.2 KB

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