mips_context_gcc.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2016-09-07 Urey first version
  9. */
  10. #ifndef __ASSEMBLY__
  11. #define __ASSEMBLY__
  12. #endif
  13. #include "../common/mips.h"
  14. .global rt_thread_switch_interrupt_flag
  15. .global rt_interrupt_from_thread
  16. .global rt_interrupt_to_thread
  17. .section .text,"ax",@progbits
  18. .set noreorder
  19. .set noat
  20. .globl rt_hw_interrupt_disable
  21. rt_hw_interrupt_disable:
  22. mfc0 v0,CP0_STATUS
  23. srl v1,v0,1
  24. sll v1,v1,1
  25. # and v1,v0,0xfffffffe
  26. mtc0 v1,CP0_STATUS
  27. jr ra
  28. nop
  29. LEAF(rt_hw_interrupt_enable)
  30. mtc0 a0,CP0_STATUS
  31. jr ra
  32. nop
  33. END(rt_hw_interrupt_enable)
  34. /*
  35. * void rt_hw_context_switch_to(rt_uint32 to)/*
  36. * a0 --> to
  37. */
  38. LEAF(rt_hw_context_switch_to)
  39. lw sp , 0(a0) /* switch to the new stack */
  40. RESTORE_CONTEXT
  41. END(rt_hw_context_switch_to)
  42. /*
  43. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
  44. * a0 --> from
  45. * a1 --> to
  46. */
  47. LEAF(rt_hw_context_switch)
  48. mtc0 ra, CP0_EPC
  49. SAVE_CONTEXT
  50. sw sp, 0(a0) /* store sp in preempted tasks TCB */
  51. lw sp, 0(a1) /* get new task stack pointer */
  52. RESTORE_CONTEXT
  53. END(rt_hw_context_switch)
  54. LEAF(rt_hw_context_switch_interrupt)
  55. la t0, rt_thread_switch_interrupt_flag
  56. lw t1, 0(t0)
  57. nop
  58. bnez t1, _reswitch
  59. nop
  60. li t1, 0x01 /* set rt_thread_switch_interrupt_flag to 1 */
  61. sw t1, 0(t0)
  62. la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  63. sw a0, 0(t0)
  64. _reswitch:
  65. la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  66. sw a1, 0(t0)
  67. jr ra
  68. nop
  69. END(rt_hw_context_switch_interrupt)