context_gcc.S 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * 2018/10/28 Bernard The unify RISC-V porting implementation
  9. * 2018/12/27 Jesven Add SMP support
  10. * 2021/02/02 lizhirui Add userspace support
  11. */
  12. #include "cpuport.h"
  13. #include "stackframe.h"
  14. .globl rt_hw_context_switch_to
  15. rt_hw_context_switch_to:
  16. LOAD sp, (a0)
  17. jal rt_thread_self
  18. mv s1, a0
  19. #ifdef RT_USING_SMART
  20. jal lwp_aspace_switch
  21. #endif
  22. RESTORE_ALL
  23. sret
  24. /*
  25. * void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
  26. *
  27. * a0 --> from
  28. * a1 --> to
  29. */
  30. .globl rt_hw_context_switch
  31. rt_hw_context_switch:
  32. mv t2, sp
  33. li t0, 0x120//set SPIE and SPP = 1
  34. csrs sstatus, t0//if enter here,caller must be in system thread
  35. csrw sepc, ra//return address
  36. //saved from thread context
  37. SAVE_ALL
  38. STORE t2, 32 * REGBYTES(sp)//save user_sp
  39. STORE sp, (a0)
  40. //restore to thread context
  41. LOAD sp, (a1)
  42. jal rt_thread_self
  43. mv s1, a0
  44. #ifdef RT_USING_SMART
  45. jal lwp_aspace_switch
  46. #endif
  47. RESTORE_ALL
  48. sret