context_iar.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * 2011-08-14 weety copy from mini2440
  9. * 2015-04-15 ArdaFu convert from context_gcc.s
  10. */
  11. #define NOINT 0xc0
  12. SECTION .text:CODE(6)
  13. /*
  14. * rt_base_t rt_hw_interrupt_disable();
  15. */
  16. PUBLIC rt_hw_interrupt_disable
  17. rt_hw_interrupt_disable:
  18. MRS R0, CPSR
  19. ORR R1, R0, #NOINT
  20. MSR CPSR_C, R1
  21. MOV PC, LR
  22. /*
  23. * void rt_hw_interrupt_enable(rt_base_t level);
  24. */
  25. PUBLIC rt_hw_interrupt_enable
  26. rt_hw_interrupt_enable:
  27. MSR CPSR_CXSF, R0
  28. MOV PC, LR
  29. /*
  30. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  31. * r0 --> from
  32. * r1 --> to
  33. */
  34. PUBLIC rt_hw_context_switch
  35. rt_hw_context_switch:
  36. STMFD SP!, {LR} ; push pc (lr should be pushed in place of PC)
  37. STMFD SP!, {R0-R12, LR} ; push lr & register file
  38. MRS R4, CPSR
  39. STMFD SP!, {R4} ; push cpsr
  40. STR SP, [R0] ; store sp in preempted tasks TCB
  41. LDR SP, [R1] ; get new task stack pointer
  42. LDMFD SP!, {R4} ; pop new task spsr
  43. MSR SPSR_cxsf, R4
  44. LDMFD SP!, {R0-R12, LR, PC}^ ; pop new task r0-r12, lr & pc
  45. /*
  46. * void rt_hw_context_switch_to(rt_uint32 to);
  47. * r0 --> to
  48. */
  49. PUBLIC rt_hw_context_switch_to
  50. rt_hw_context_switch_to:
  51. LDR SP, [R0] ; get new task stack pointer
  52. LDMFD SP!, {R4} ; pop new task spsr
  53. MSR SPSR_cxsf, R4
  54. LDMFD SP!, {R0-R12, LR, PC}^ ; pop new task r0-r12, lr & pc
  55. /*
  56. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  57. */
  58. IMPORT rt_thread_switch_interrupt_flag
  59. IMPORT rt_interrupt_from_thread
  60. IMPORT rt_interrupt_to_thread
  61. PUBLIC rt_hw_context_switch_interrupt
  62. rt_hw_context_switch_interrupt:
  63. LDR R2, =rt_thread_switch_interrupt_flag
  64. LDR R3, [R2]
  65. CMP R3, #1
  66. BEQ _reswitch
  67. MOV R3, #1 ; set flag to 1
  68. STR R3, [R2]
  69. LDR R2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread
  70. STR R0, [R2]
  71. _reswitch:
  72. LDR R2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread
  73. STR R1, [R2]
  74. MOV PC, LR
  75. END