switch_arm32_ios.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * this is the internal transfer function.
  3. *
  4. * HISTORY
  5. * 31-May-15 iOS support. Ported from arm32. Proton <feisuzhu@163.com>
  6. *
  7. * NOTES
  8. *
  9. * It is not possible to detect if fp is used or not, so the supplied
  10. * switch function needs to support it, so that you can remove it if
  11. * it does not apply to you.
  12. *
  13. * POSSIBLE ERRORS
  14. *
  15. * "fp cannot be used in asm here"
  16. *
  17. * - Try commenting out "fp" in REGS_TO_SAVE.
  18. *
  19. */
  20. #define STACK_REFPLUS 1
  21. #ifdef SLP_EVAL
  22. #define STACK_MAGIC 0
  23. #define REG_SP "sp"
  24. #define REG_SPSP "sp,sp"
  25. #define REG_FP "r7"
  26. #define REG_FPFP "r7,r7"
  27. #define REGS_TO_SAVE_GENERAL "r4", "r5", "r6", "r8", "r10", "r11", "lr"
  28. #define REGS_TO_SAVE REGS_TO_SAVE_GENERAL, "d8", "d9", "d10", "d11", \
  29. "d12", "d13", "d14", "d15"
  30. static int
  31. #ifdef __GNUC__
  32. __attribute__((optimize("no-omit-frame-pointer")))
  33. #endif
  34. slp_switch(void)
  35. {
  36. void *fp;
  37. register int *stackref, stsizediff, result;
  38. __asm__ volatile ("" : : : REGS_TO_SAVE);
  39. __asm__ volatile ("str " REG_FP ",%0" : "=m" (fp));
  40. __asm__ ("mov %0," REG_SP : "=r" (stackref));
  41. {
  42. SLP_SAVE_STATE(stackref, stsizediff);
  43. __asm__ volatile (
  44. "add " REG_SPSP ",%0\n"
  45. "add " REG_FPFP ",%0\n"
  46. :
  47. : "r" (stsizediff)
  48. : REGS_TO_SAVE /* Clobber registers, force compiler to
  49. * recalculate address of void *fp from REG_SP or REG_FP */
  50. );
  51. SLP_RESTORE_STATE();
  52. }
  53. __asm__ volatile (
  54. "ldr " REG_FP ", %1\n\t"
  55. "mov %0, #0"
  56. : "=r" (result)
  57. : "m" (fp)
  58. : REGS_TO_SAVE /* Force compiler to restore saved registers after this */
  59. );
  60. return result;
  61. }
  62. #endif