switch_riscv_unix.h 758 B

1234567891011121314151617181920212223242526272829303132
  1. #define STACK_REFPLUS 1
  2. #ifdef SLP_EVAL
  3. #define STACK_MAGIC 0
  4. #define REGS_TO_SAVE "s0", "s1", "s2", "s3", "s4", "s5", \
  5. "s6", "s7", "s8", "s9", "s10", "s11", "fs0", "fs1", \
  6. "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", \
  7. "fs10", "fs11"
  8. static int
  9. slp_switch(void)
  10. {
  11. register int ret;
  12. register long *stackref, stsizediff;
  13. __asm__ volatile ("" : : : REGS_TO_SAVE);
  14. __asm__ volatile ("mv %0, sp" : "=r" (stackref) : );
  15. {
  16. SLP_SAVE_STATE(stackref, stsizediff);
  17. __asm__ volatile (
  18. "add sp, sp, %0\n\t"
  19. : /* no outputs */
  20. : "r" (stsizediff)
  21. );
  22. SLP_RESTORE_STATE();
  23. }
  24. __asm__ volatile ("" : : : REGS_TO_SAVE);
  25. __asm__ volatile ("mv %0, zero" : "=r" (ret) : );
  26. return ret;
  27. }
  28. #endif