context_gcc.S 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. la s0, rt_current_thread
  18. LOAD s1, (s0)
  19. #ifdef RT_USING_SMART
  20. mv a0, s1
  21. jal lwp_aspace_switch
  22. #endif
  23. RESTORE_ALL
  24. sret
  25. /*
  26. * void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
  27. *
  28. * a0 --> from
  29. * a1 --> to
  30. */
  31. .globl rt_hw_context_switch
  32. rt_hw_context_switch:
  33. mv t2, sp
  34. li t0, 0x120//set SPIE and SPP = 1
  35. csrs sstatus, t0//if enter here,caller must be in system thread
  36. csrw sepc, ra//return address
  37. //saved from thread context
  38. SAVE_ALL
  39. STORE t2, 32 * REGBYTES(sp)//save user_sp
  40. STORE sp, (a0)
  41. //restore to thread context
  42. LOAD sp, (a1)
  43. la s0, rt_current_thread
  44. LOAD s1, (s0)
  45. #ifdef RT_USING_SMART
  46. mv a0, s1
  47. jal lwp_aspace_switch
  48. #endif
  49. RESTORE_ALL
  50. sret