/Modules/_ctypes/libffi/src/powerpc/asm.h

http://unladen-swallow.googlecode.com/ · C++ Header · 125 lines · 80 code · 11 blank · 34 comment · 0 complexity · 41549f68aeedd29e849159d4567ede07 MD5 · raw file

  1. /* -----------------------------------------------------------------------
  2. asm.h - Copyright (c) 1998 Geoffrey Keating
  3. PowerPC Assembly glue.
  4. Permission is hereby granted, free of charge, to any person obtaining
  5. a copy of this software and associated documentation files (the
  6. ``Software''), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sublicense, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice shall be included
  12. in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
  17. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  18. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  19. OTHER DEALINGS IN THE SOFTWARE.
  20. ----------------------------------------------------------------------- */
  21. #define ASM_GLOBAL_DIRECTIVE .globl
  22. #define C_SYMBOL_NAME(name) name
  23. /* Macro for a label. */
  24. #ifdef __STDC__
  25. #define C_LABEL(name) name##:
  26. #else
  27. #define C_LABEL(name) name/**/:
  28. #endif
  29. /* This seems to always be the case on PPC. */
  30. #define ALIGNARG(log2) log2
  31. /* For ELF we need the `.type' directive to make shared libs work right. */
  32. #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
  33. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
  34. /* If compiled for profiling, call `_mcount' at the start of each function. */
  35. #ifdef PROF
  36. /* The mcount code relies on a the return address being on the stack
  37. to locate our caller and so it can restore it; so store one just
  38. for its benefit. */
  39. #ifdef PIC
  40. #define CALL_MCOUNT \
  41. .pushsection; \
  42. .section ".data"; \
  43. .align ALIGNARG(2); \
  44. 0:.long 0; \
  45. .previous; \
  46. mflr %r0; \
  47. stw %r0,4(%r1); \
  48. bl _GLOBAL_OFFSET_TABLE_@local-4; \
  49. mflr %r11; \
  50. lwz %r0,0b@got(%r11); \
  51. bl JUMPTARGET(_mcount);
  52. #else /* PIC */
  53. #define CALL_MCOUNT \
  54. .section ".data"; \
  55. .align ALIGNARG(2); \
  56. 0:.long 0; \
  57. .previous; \
  58. mflr %r0; \
  59. lis %r11,0b@ha; \
  60. stw %r0,4(%r1); \
  61. addi %r0,%r11,0b@l; \
  62. bl JUMPTARGET(_mcount);
  63. #endif /* PIC */
  64. #else /* PROF */
  65. #define CALL_MCOUNT /* Do nothing. */
  66. #endif /* PROF */
  67. #define ENTRY(name) \
  68. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  69. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
  70. .align ALIGNARG(2); \
  71. C_LABEL(name) \
  72. CALL_MCOUNT
  73. #define EALIGN_W_0 /* No words to insert. */
  74. #define EALIGN_W_1 nop
  75. #define EALIGN_W_2 nop;nop
  76. #define EALIGN_W_3 nop;nop;nop
  77. #define EALIGN_W_4 EALIGN_W_3;nop
  78. #define EALIGN_W_5 EALIGN_W_4;nop
  79. #define EALIGN_W_6 EALIGN_W_5;nop
  80. #define EALIGN_W_7 EALIGN_W_6;nop
  81. /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
  82. past a 2^align boundary. */
  83. #ifdef PROF
  84. #define EALIGN(name, alignt, words) \
  85. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  86. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
  87. .align ALIGNARG(2); \
  88. C_LABEL(name) \
  89. CALL_MCOUNT \
  90. b 0f; \
  91. .align ALIGNARG(alignt); \
  92. EALIGN_W_##words; \
  93. 0:
  94. #else /* PROF */
  95. #define EALIGN(name, alignt, words) \
  96. ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name); \
  97. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
  98. .align ALIGNARG(alignt); \
  99. EALIGN_W_##words; \
  100. C_LABEL(name)
  101. #endif
  102. #define END(name) \
  103. ASM_SIZE_DIRECTIVE(name)
  104. #ifdef PIC
  105. #define JUMPTARGET(name) name##@plt
  106. #else
  107. #define JUMPTARGET(name) name
  108. #endif
  109. /* Local labels stripped out by the linker. */
  110. #define L(x) .L##x