1
0

context_gcc.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ; */
  10. #define NOINT 0xC0
  11. .text
  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. ORR R1, R0, #NOINT
  19. MSR CPSR_c, R1
  20. BX LR
  21. /*
  22. * void rt_hw_interrupt_enable(rt_base_t level);
  23. */
  24. .globl rt_hw_interrupt_enable
  25. rt_hw_interrupt_enable:
  26. MSR CPSR, R0
  27. BX LR
  28. /*
  29. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  30. * r0 --> from
  31. * r1 --> to
  32. */
  33. .globl rt_hw_context_switch
  34. rt_hw_context_switch:
  35. STMFD SP!, {LR} @; push pc (lr should be pushed in place of pc)
  36. STMFD SP!, {R0-R12, LR} @; push lr & register file
  37. MRS R4, CPSR
  38. STMFD SP!, {R4} @; push cpsr
  39. STR SP, [R0] @; store sp in preempted tasks tcb
  40. LDR SP, [R1] @; get new task stack pointer
  41. LDMFD SP!, {R4} @; pop new task spsr
  42. MSR SPSR_cxsf, R4
  43. LDMFD SP!, {R0-R12, LR, PC}^ @; pop new task r0-r12, lr & pc
  44. /*
  45. * void rt_hw_context_switch_to(rt_uint32 to);
  46. * r0 --> to
  47. */
  48. .globl rt_hw_context_switch_to
  49. rt_hw_context_switch_to:
  50. LDR SP, [R0] @; get new task stack pointer
  51. LDMFD SP!, {R4} @; pop new task cpsr
  52. MSR SPSR_cxsf, R4
  53. LDMFD SP!, {R0-R12, LR, PC}^ @; pop new task r0-r12, lr & pc
  54. /*
  55. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  56. */
  57. .globl rt_thread_switch_interrupt_flag
  58. .globl rt_interrupt_from_thread
  59. .globl rt_interrupt_to_thread
  60. .globl rt_hw_context_switch_interrupt
  61. rt_hw_context_switch_interrupt:
  62. LDR R2, =rt_thread_switch_interrupt_flag
  63. LDR R3, [R2]
  64. CMP R3, #1
  65. BEQ _reswitch
  66. MOV R3, #1 @; set flag to 1
  67. STR R3, [R2]
  68. LDR R2, =rt_interrupt_from_thread @; set rt_interrupt_from_thread
  69. STR R0, [R2]
  70. _reswitch:
  71. LDR R2, =rt_interrupt_to_thread @; set rt_interrupt_to_thread
  72. STR R1, [R2]
  73. BX LR