basic_asm.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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) ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8))
  21. #else
  22. #define STACK_FRAME_MIN_SIZE 112
  23. #define STACK_FRAME_TOC_POS 40
  24. #define __STACK_FRAME_PARAM(i) (48 + ((i)*8))
  25. /*
  26. * Caveat: if a function passed more than 8 doublewords, the caller will have
  27. * made more space... which would render the 112 incorrect.
  28. */
  29. #define __STACK_FRAME_LOCAL(_num_params,_var_num) (112 + ((_var_num)*8))
  30. #endif
  31. /* Parameter x saved to the stack */
  32. #define STACK_FRAME_PARAM(var) __STACK_FRAME_PARAM(var)
  33. /* Local variable x saved to the stack after x parameters */
  34. #define STACK_FRAME_LOCAL(num_params,var) __STACK_FRAME_LOCAL(num_params,var)
  35. #define STACK_FRAME_LR_POS 16
  36. #define STACK_FRAME_CR_POS 8
  37. /*
  38. * It is very important to note here that _extra is the extra amount of
  39. * stack space needed. This space can be accessed using STACK_FRAME_PARAM()
  40. * or STACK_FRAME_LOCAL() macros.
  41. *
  42. * r1 and r2 are not defined in ppc-asm.h (instead they are defined as sp
  43. * and toc). Kernel programmers tend to prefer rX even for r1 and r2, hence
  44. * %1 and %r2. r0 is defined in ppc-asm.h and therefore %r0 gets
  45. * preprocessed incorrectly, hence r0.
  46. */
  47. #define PUSH_BASIC_STACK(_extra) \
  48. mflr r0; \
  49. std r0,STACK_FRAME_LR_POS(%r1); \
  50. stdu %r1,-(_extra + STACK_FRAME_MIN_SIZE)(%r1); \
  51. mfcr r0; \
  52. stw r0,STACK_FRAME_CR_POS(%r1); \
  53. std %r2,STACK_FRAME_TOC_POS(%r1);
  54. #define POP_BASIC_STACK(_extra) \
  55. ld %r2,STACK_FRAME_TOC_POS(%r1); \
  56. lwz r0,STACK_FRAME_CR_POS(%r1); \
  57. mtcr r0; \
  58. addi %r1,%r1,(_extra + STACK_FRAME_MIN_SIZE); \
  59. ld r0,STACK_FRAME_LR_POS(%r1); \
  60. mtlr r0;
  61. #endif /* _SELFTESTS_POWERPC_BASIC_ASM_H */