context_iar.S 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. ; * 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. TST LR, #0x01
  40. ORRNE R4, R4, #0x20 ; it's thumb code
  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 spsr
  45. MSR SPSR_cxsf, R4
  46. LDMFD SP!, {R0-R12, LR, PC}^ ; pop new task r0-r12, lr & pc
  47. /*
  48. * void rt_hw_context_switch_to(rt_uint32 to);
  49. * r0 --> to
  50. */
  51. PUBLIC 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. IMPORT rt_thread_switch_interrupt_flag
  63. IMPORT rt_interrupt_from_thread
  64. IMPORT rt_interrupt_to_thread
  65. PUBLIC 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 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. MOV PC, LR
  79. END