basic_asm.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef _SELFTESTS_POWERPC_BASIC_ASM_H
  2. #define _SELFTESTS_POWERPC_BASIC_ASM_H
  3. #include <ppc-asm.h>
  4. #include <asm/unistd.h>
  5. #define LOAD_REG_IMMEDIATE(reg, expr) \
  6. lis reg, (expr)@highest; \
  7. ori reg, reg, (expr)@higher; \
  8. rldicr reg, reg, 32, 31; \
  9. oris reg, reg, (expr)@high; \
  10. ori reg, reg, (expr)@l;
  11. /*
  12. * Note: These macros assume that variables being stored on the stack are
  13. * doublewords, while this is usually the case it may not always be the
  14. * case for each use case.
  15. */
  16. #if defined(_CALL_ELF) && _CALL_ELF == 2
  17. #define STACK_FRAME_MIN_SIZE 32
  18. #define STACK_FRAME_TOC_POS 24
  19. #define __STACK_FRAME_PARAM(_param) (32 + ((_param)*8))
  20. #define __STACK_FRAME_LOCAL(_num_params, _var_num) \
  21. ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8))
  22. #else
  23. #define STACK_FRAME_MIN_SIZE 112
  24. #define STACK_FRAME_TOC_POS 40
  25. #define __STACK_FRAME_PARAM(i) (48 + ((i)*8))
  26. /*
  27. * Caveat: if a function passed more than 8 doublewords, the caller will have
  28. * made more space... which would render the 112 incorrect.
  29. */
  30. #define __STACK_FRAME_LOCAL(_num_params, _var_num) \
  31. (112 + ((_var_num)*8))
  32. #endif
  33. /* Parameter x saved to the stack */
  34. #define STACK_FRAME_PARAM(var) __STACK_FRAME_PARAM(var)
  35. /* Local variable x saved to the stack after x parameters */
  36. #define STACK_FRAME_LOCAL(num_params, var) \
  37. __STACK_FRAME_LOCAL(num_params, var)
  38. #define STACK_FRAME_LR_POS 16
  39. #define STACK_FRAME_CR_POS 8
  40. /*
  41. * It is very important to note here that _extra is the extra amount of
  42. * stack space needed. This space can be accessed using STACK_FRAME_PARAM()
  43. * or STACK_FRAME_LOCAL() macros.
  44. *
  45. * r1 and r2 are not defined in ppc-asm.h (instead they are defined as sp
  46. * and toc). Kernel programmers tend to prefer rX even for r1 and r2, hence
  47. * %1 and %r2. r0 is defined in ppc-asm.h and therefore %r0 gets
  48. * preprocessed incorrectly, hence r0.
  49. */
  50. #define PUSH_BASIC_STACK(_extra) \
  51. mflr r0; \
  52. std r0, STACK_FRAME_LR_POS(%r1); \
  53. stdu %r1, -(_extra + STACK_FRAME_MIN_SIZE)(%r1); \
  54. mfcr r0; \
  55. stw r0, STACK_FRAME_CR_POS(%r1); \
  56. std %r2, STACK_FRAME_TOC_POS(%r1);
  57. #define POP_BASIC_STACK(_extra) \
  58. ld %r2, STACK_FRAME_TOC_POS(%r1); \
  59. lwz r0, STACK_FRAME_CR_POS(%r1); \
  60. mtcr r0; \
  61. addi %r1, %r1, (_extra + STACK_FRAME_MIN_SIZE); \
  62. ld r0, STACK_FRAME_LR_POS(%r1); \
  63. mtlr r0;
  64. #endif /* _SELFTESTS_POWERPC_BASIC_ASM_H */