asm.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995, 1996, 1997, 1999, 2001 by Ralf Baechle
  7. * Copyright (C) 1999 by Silicon Graphics, Inc.
  8. * Copyright (C) 2001 MIPS Technologies, Inc.
  9. * Copyright (C) 2002 Maciej W. Rozycki
  10. *
  11. * Some useful macros for MIPS assembler code
  12. *
  13. * Some of the routines below contain useless nops that will be optimized
  14. * away by gas in -O mode. These nops are however required to fill delay
  15. * slots in noreorder mode.
  16. */
  17. #ifndef __ASM_H__
  18. #define __ASM_H__
  19. /*
  20. * LEAF - declare leaf routine
  21. */
  22. #define LEAF(symbol) \
  23. .globl symbol; \
  24. .align 2; \
  25. .type symbol,@function; \
  26. .ent symbol,0; \
  27. symbol: .frame sp,0,ra
  28. /*
  29. * NESTED - declare nested routine entry point
  30. */
  31. #define NESTED(symbol, framesize, rpc) \
  32. .globl symbol; \
  33. .align 2; \
  34. .type symbol,@function; \
  35. .ent symbol,0; \
  36. symbol: .frame sp, framesize, rpc
  37. /*
  38. * END - mark end of function
  39. */
  40. #define END(function) \
  41. .end function; \
  42. .size function,.-function
  43. /*
  44. * EXPORT - export definition of symbol
  45. */
  46. #define EXPORT(symbol) \
  47. .globl symbol; \
  48. symbol:
  49. /*
  50. * FEXPORT - export definition of a function symbol
  51. */
  52. #define FEXPORT(symbol) \
  53. .globl symbol; \
  54. .type symbol,@function; \
  55. symbol:
  56. /*
  57. * Global data declaration with size.
  58. */
  59. #define EXPORTS(name,sz) \
  60. .globl name; \
  61. .type name,@object; \
  62. .size name,sz; \
  63. name:
  64. /*
  65. * Weak data declaration with size.
  66. */
  67. #define WEXPORT(name,sz) \
  68. .weakext name; \
  69. .type name,@object; \
  70. .size name,sz; \
  71. name:
  72. /*
  73. * Global data reference with size.
  74. */
  75. #define IMPORT(name, size) \
  76. .extern name,size
  77. /*
  78. * Global zeroed data.
  79. */
  80. #define BSS(name,size) \
  81. .type name,@object; \
  82. .comm name,size
  83. /*
  84. * Local zeroed data.
  85. */
  86. #define LBSS(name,size) \
  87. .lcomm name,size
  88. /*
  89. * ABS - export absolute symbol
  90. */
  91. #define ABS(symbol,value) \
  92. .globl symbol; \
  93. symbol = value
  94. #define TEXT(msg) \
  95. .pushsection .data; \
  96. 8: .asciiz msg; \
  97. .popsection;
  98. #define ENTRY(name) \
  99. .globl name; \
  100. .align 2; \
  101. .ent name,0; \
  102. name##:
  103. /*
  104. * Macros to handle different pointer/register sizes for 32/64-bit code
  105. */
  106. /*
  107. * Size of a register
  108. */
  109. #define SZREG 4
  110. /*
  111. * Use the following macros in assemblercode to load/store registers,
  112. * pointers etc.
  113. */
  114. #define REG_S sw
  115. #define REG_L lw
  116. #define REG_SUBU subu
  117. #define REG_ADDU addu
  118. /*
  119. * How to add/sub/load/store/shift C int variables.
  120. */
  121. #define INT_ADD add
  122. #define INT_ADDU addu
  123. #define INT_ADDI addi
  124. #define INT_ADDIU addiu
  125. #define INT_SUB sub
  126. #define INT_SUBU subu
  127. #define INT_L lw
  128. #define INT_S sw
  129. #define INT_SLL sll
  130. #define INT_SLLV sllv
  131. #define INT_SRL srl
  132. #define INT_SRLV srlv
  133. #define INT_SRA sra
  134. #define INT_SRAV srav
  135. /*
  136. * How to add/sub/load/store/shift C long variables.
  137. */
  138. #define LONG_ADD add
  139. #define LONG_ADDU addu
  140. #define LONG_ADDI addi
  141. #define LONG_ADDIU addiu
  142. #define LONG_SUB sub
  143. #define LONG_SUBU subu
  144. #define LONG_L lw
  145. #define LONG_S sw
  146. #define LONG_SLL sll
  147. #define LONG_SLLV sllv
  148. #define LONG_SRL srl
  149. #define LONG_SRLV srlv
  150. #define LONG_SRA sra
  151. #define LONG_SRAV srav
  152. #define LONG .word
  153. #define LONGSIZE 4
  154. #define LONGMASK 3
  155. #define LONGLOG 2
  156. /*
  157. * How to add/sub/load/store/shift pointers.
  158. */
  159. #define PTR_ADD add
  160. #define PTR_ADDU addu
  161. #define PTR_ADDI addi
  162. #define PTR_ADDIU addiu
  163. #define PTR_SUB sub
  164. #define PTR_SUBU subu
  165. #define PTR_L lw
  166. #define PTR_S sw
  167. #define PTR_LA la
  168. #define PTR_SLL sll
  169. #define PTR_SLLV sllv
  170. #define PTR_SRL srl
  171. #define PTR_SRLV srlv
  172. #define PTR_SRA sra
  173. #define PTR_SRAV srav
  174. #define PTR_SCALESHIFT 2
  175. #define PTR .word
  176. #define PTRSIZE 4
  177. #define PTRLOG 2
  178. /*
  179. * Some cp0 registers were extended to 64bit for MIPS III.
  180. */
  181. #define MFC0 mfc0
  182. #define MTC0 mtc0
  183. #define SSNOP sll zero, zero, 1
  184. #endif /* end of __ASM_H__ */