context_gcc.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ; */
  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. STMFD SP!, {R4} @; push cpsr
  38. STR SP, [R0] @; store sp in preempted tasks tcb
  39. LDR SP, [R1] @; get new task stack pointer
  40. LDMFD SP!, {R4} @; pop new task spsr
  41. MSR SPSR_cxsf, R4
  42. LDMFD SP!, {R0-R12, LR, PC}^ @; pop new task r0-r12, lr & pc
  43. /*
  44. * void rt_hw_context_switch_to(rt_uint32 to);
  45. * r0 --> to
  46. */
  47. .globl rt_hw_context_switch_to
  48. rt_hw_context_switch_to:
  49. LDR SP, [R0] @; get new task stack pointer
  50. LDMFD SP!, {R4} @; pop new task cpsr
  51. MSR SPSR_cxsf, R4
  52. LDMFD SP!, {R0-R12, LR, PC}^ @; pop new task r0-r12, lr & pc
  53. /*
  54. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  55. */
  56. .globl rt_thread_switch_interrupt_flag
  57. .globl rt_interrupt_from_thread
  58. .globl rt_interrupt_to_thread
  59. .globl rt_hw_context_switch_interrupt
  60. rt_hw_context_switch_interrupt:
  61. LDR R2, =rt_thread_switch_interrupt_flag
  62. LDR R3, [R2]
  63. CMP R3, #1
  64. BEQ _reswitch
  65. MOV R3, #1 @; set flag to 1
  66. STR R3, [R2]
  67. LDR R2, =rt_interrupt_from_thread @; set rt_interrupt_from_thread
  68. STR R0, [R2]
  69. _reswitch:
  70. LDR R2, =rt_interrupt_to_thread @; set rt_interrupt_to_thread
  71. STR R1, [R2]
  72. BX LR