1
0

context_gcc.S 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2006-2018, Shanghai Real-Thread Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-01-20 Bernard first version
  9. */
  10. #define NOINT 0xc0
  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. orr r1, r0, #NOINT
  18. msr cpsr_c, r1
  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(rt_uint32 from, rt_uint32 to);
  29. * r0 --> from
  30. * r1 --> to
  31. */
  32. .globl rt_hw_context_switch
  33. rt_hw_context_switch:
  34. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  35. stmfd sp!, {r0-r12, lr} @ push lr & register file
  36. mrs r4, cpsr
  37. tst lr, #0x01
  38. beq _ARM_MODE
  39. orr r4, r4, #0x20 @ it's thumb code
  40. _ARM_MODE:
  41. stmfd sp!, {r4} @ push cpsr
  42. str sp, [r0] @ store sp in preempted tasks TCB
  43. ldr sp, [r1] @ get new task stack pointer
  44. ldmfd sp!, {r4} @ pop new task cpsr to spsr
  45. msr spsr_cxsf, r4
  46. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
  47. /*
  48. * void rt_hw_context_switch_to(rt_uint32 to);
  49. * r0 --> to
  50. */
  51. .globl rt_hw_context_switch_to
  52. rt_hw_context_switch_to:
  53. ldr sp, [r0] @ get new task stack pointer
  54. ldmfd sp!, {r4} @ pop new task spsr
  55. msr spsr_cxsf, r4
  56. bic r4, r4, #0x20 @ must be ARM mode
  57. msr cpsr_cxsf, r4
  58. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  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. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  72. str r3, [r2]
  73. ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  74. str r0, [r2]
  75. _reswitch:
  76. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  77. str r1, [r2]
  78. bx lr