mips_context_gcc.S 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * File : mips_context_asm.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2016Äê9ÔÂ7ÈÕ Urey the first version
  23. */
  24. #ifndef __ASSEMBLY__
  25. # define __ASSEMBLY__
  26. #endif
  27. #include "../common/mips.h"
  28. .global rt_thread_switch_interrupt_flag
  29. .global rt_interrupt_from_thread
  30. .global rt_interrupt_to_thread
  31. .section .text,"ax",@progbits
  32. .set noreorder
  33. .set noat
  34. .globl rt_hw_interrupt_disable
  35. rt_hw_interrupt_disable:
  36. mfc0 v0,CP0_STATUS
  37. srl v1,v0,1
  38. sll v1,v1,1
  39. # and v1,v0,0xfffffffe
  40. mtc0 v1,CP0_STATUS
  41. jr ra
  42. nop
  43. LEAF(rt_hw_interrupt_enable)
  44. mtc0 a0,CP0_STATUS
  45. jr ra
  46. nop
  47. END(rt_hw_interrupt_enable)
  48. /*
  49. * void rt_hw_context_switch_to(rt_uint32 to)/*
  50. * a0 --> to
  51. */
  52. LEAF(rt_hw_context_switch_to)
  53. lw sp , 0(a0) /* switch to the new stack */
  54. RESTORE_CONTEXT
  55. END(rt_hw_context_switch_to)
  56. /*
  57. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
  58. * a0 --> from
  59. * a1 --> to
  60. */
  61. LEAF(rt_hw_context_switch)
  62. mtc0 ra, CP0_EPC
  63. SAVE_CONTEXT
  64. sw sp, 0(a0) /* store sp in preempted tasks TCB */
  65. lw sp, 0(a1) /* get new task stack pointer */
  66. RESTORE_CONTEXT
  67. END(rt_hw_context_switch)
  68. LEAF(rt_hw_context_switch_interrupt)
  69. la t0, rt_thread_switch_interrupt_flag
  70. lw t1, 0(t0)
  71. nop
  72. bnez t1, _reswitch
  73. nop
  74. li t1, 0x01 /* set rt_thread_switch_interrupt_flag to 1 */
  75. sw t1, 0(t0)
  76. la t0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  77. sw a0, 0(t0)
  78. _reswitch:
  79. la t0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  80. sw a1, 0(t0)
  81. jr ra
  82. nop
  83. END(rt_hw_context_switch_interrupt)