asm.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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_ASM_H
  18. #define __ASM_ASM_H
  19. #include <asm/sgidefs.h>
  20. #include <asm/asm-eva.h>
  21. #include <asm/isa-rev.h>
  22. #ifndef __VDSO__
  23. /*
  24. * Emit CFI data in .debug_frame sections, not .eh_frame sections.
  25. * We don't do DWARF unwinding at runtime, so only the offline DWARF
  26. * information is useful to anyone. Note we should change this if we
  27. * ever decide to enable DWARF unwinding at runtime.
  28. */
  29. #define CFI_SECTIONS .cfi_sections .debug_frame
  30. #else
  31. /*
  32. * For the vDSO, emit both runtime unwind information and debug
  33. * symbols for the .dbg file.
  34. */
  35. #define CFI_SECTIONS
  36. #endif
  37. /*
  38. * LEAF - declare leaf routine
  39. */
  40. #define LEAF(symbol) \
  41. CFI_SECTIONS; \
  42. .globl symbol; \
  43. .align 2; \
  44. .type symbol, @function; \
  45. .ent symbol, 0; \
  46. symbol: .frame sp, 0, ra; \
  47. .cfi_startproc; \
  48. .insn
  49. /*
  50. * NESTED - declare nested routine entry point
  51. */
  52. #define NESTED(symbol, framesize, rpc) \
  53. CFI_SECTIONS; \
  54. .globl symbol; \
  55. .align 2; \
  56. .type symbol, @function; \
  57. .ent symbol, 0; \
  58. symbol: .frame sp, framesize, rpc; \
  59. .cfi_startproc; \
  60. .insn
  61. /*
  62. * END - mark end of function
  63. */
  64. #define END(function) \
  65. .cfi_endproc; \
  66. .end function; \
  67. .size function, .-function
  68. /*
  69. * EXPORT - export definition of symbol
  70. */
  71. #define EXPORT(symbol) \
  72. .globl symbol; \
  73. symbol:
  74. /*
  75. * FEXPORT - export definition of a function symbol
  76. */
  77. #define FEXPORT(symbol) \
  78. .globl symbol; \
  79. .type symbol, @function; \
  80. symbol: .insn
  81. /*
  82. * ABS - export absolute symbol
  83. */
  84. #define ABS(symbol,value) \
  85. .globl symbol; \
  86. symbol = value
  87. #define TEXT(msg) \
  88. .pushsection .data; \
  89. 8: .asciiz msg; \
  90. .popsection;
  91. #define ASM_PANIC(msg) \
  92. .set push; \
  93. .set reorder; \
  94. PTR_LA a0, 8f; \
  95. jal panic; \
  96. 9: b 9b; \
  97. .set pop; \
  98. TEXT(msg)
  99. /*
  100. * Print formatted string
  101. */
  102. #ifdef CONFIG_PRINTK
  103. #define ASM_PRINT(string) \
  104. .set push; \
  105. .set reorder; \
  106. PTR_LA a0, 8f; \
  107. jal _printk; \
  108. .set pop; \
  109. TEXT(string)
  110. #else
  111. #define ASM_PRINT(string)
  112. #endif
  113. /*
  114. * Stack alignment
  115. */
  116. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  117. #define ALSZ 7
  118. #define ALMASK ~7
  119. #endif
  120. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  121. #define ALSZ 15
  122. #define ALMASK ~15
  123. #endif
  124. /*
  125. * Macros to handle different pointer/register sizes for 32/64-bit code
  126. */
  127. /*
  128. * Size of a register
  129. */
  130. #ifdef __mips64
  131. #define SZREG 8
  132. #else
  133. #define SZREG 4
  134. #endif
  135. /*
  136. * Use the following macros in assemblercode to load/store registers,
  137. * pointers etc.
  138. */
  139. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  140. #define REG_S sw
  141. #define REG_L lw
  142. #define REG_SUBU subu
  143. #define REG_ADDU addu
  144. #endif
  145. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  146. #define REG_S sd
  147. #define REG_L ld
  148. #define REG_SUBU dsubu
  149. #define REG_ADDU daddu
  150. #endif
  151. /*
  152. * How to add/sub/load/store/shift C int variables.
  153. */
  154. #if (_MIPS_SZINT == 32)
  155. #define INT_ADD add
  156. #define INT_ADDU addu
  157. #define INT_ADDI addi
  158. #define INT_ADDIU addiu
  159. #define INT_SUB sub
  160. #define INT_SUBU subu
  161. #define INT_L lw
  162. #define INT_S sw
  163. #define INT_SLL sll
  164. #define INT_SLLV sllv
  165. #define INT_SRL srl
  166. #define INT_SRLV srlv
  167. #define INT_SRA sra
  168. #define INT_SRAV srav
  169. #endif
  170. #if (_MIPS_SZINT == 64)
  171. #define INT_ADD dadd
  172. #define INT_ADDU daddu
  173. #define INT_ADDI daddi
  174. #define INT_ADDIU daddiu
  175. #define INT_SUB dsub
  176. #define INT_SUBU dsubu
  177. #define INT_L ld
  178. #define INT_S sd
  179. #define INT_SLL dsll
  180. #define INT_SLLV dsllv
  181. #define INT_SRL dsrl
  182. #define INT_SRLV dsrlv
  183. #define INT_SRA dsra
  184. #define INT_SRAV dsrav
  185. #endif
  186. /*
  187. * How to add/sub/load/store/shift C long variables.
  188. */
  189. #if (_MIPS_SZLONG == 32)
  190. #define LONG_ADD add
  191. #define LONG_ADDU addu
  192. #define LONG_ADDI addi
  193. #define LONG_ADDIU addiu
  194. #define LONG_SUB sub
  195. #define LONG_SUBU subu
  196. #define LONG_L lw
  197. #define LONG_LL ll
  198. #define LONG_SC sc
  199. #define LONG_S sw
  200. #define LONG_SP swp
  201. #define LONG_SLL sll
  202. #define LONG_SLLV sllv
  203. #define LONG_SRL srl
  204. #define LONG_SRLV srlv
  205. #define LONG_SRA sra
  206. #define LONG_SRAV srav
  207. #define LONG_INS ins
  208. #define LONG_EXT ext
  209. #ifdef __ASSEMBLY__
  210. #define LONG .word
  211. #endif
  212. #define LONGSIZE 4
  213. #define LONGMASK 3
  214. #define LONGLOG 2
  215. #endif
  216. #if (_MIPS_SZLONG == 64)
  217. #define LONG_ADD dadd
  218. #define LONG_ADDU daddu
  219. #define LONG_ADDI daddi
  220. #define LONG_ADDIU daddiu
  221. #define LONG_SUB dsub
  222. #define LONG_SUBU dsubu
  223. #define LONG_L ld
  224. #define LONG_LL lld
  225. #define LONG_SC scd
  226. #define LONG_S sd
  227. #define LONG_SP sdp
  228. #define LONG_SLL dsll
  229. #define LONG_SLLV dsllv
  230. #define LONG_SRL dsrl
  231. #define LONG_SRLV dsrlv
  232. #define LONG_SRA dsra
  233. #define LONG_SRAV dsrav
  234. #define LONG_INS dins
  235. #define LONG_EXT dext
  236. #ifdef __ASSEMBLY__
  237. #define LONG .dword
  238. #endif
  239. #define LONGSIZE 8
  240. #define LONGMASK 7
  241. #define LONGLOG 3
  242. #endif
  243. /*
  244. * How to add/sub/load/store/shift pointers.
  245. */
  246. #if (_MIPS_SZPTR == 32)
  247. #define PTR_ADD add
  248. #define PTR_ADDU addu
  249. #define PTR_ADDI addi
  250. #define PTR_ADDIU addiu
  251. #define PTR_SUB sub
  252. #define PTR_SUBU subu
  253. #define PTR_L lw
  254. #define PTR_S sw
  255. #define PTR_LA la
  256. #define PTR_LI li
  257. #define PTR_SLL sll
  258. #define PTR_SLLV sllv
  259. #define PTR_SRL srl
  260. #define PTR_SRLV srlv
  261. #define PTR_SRA sra
  262. #define PTR_SRAV srav
  263. #define PTR_SCALESHIFT 2
  264. #define PTR_WD .word
  265. #define PTRSIZE 4
  266. #define PTRLOG 2
  267. #endif
  268. #if (_MIPS_SZPTR == 64)
  269. #define PTR_ADD dadd
  270. #define PTR_ADDU daddu
  271. #define PTR_ADDI daddi
  272. #define PTR_ADDIU daddiu
  273. #define PTR_SUB dsub
  274. #define PTR_SUBU dsubu
  275. #define PTR_L ld
  276. #define PTR_S sd
  277. #define PTR_LA dla
  278. #define PTR_LI dli
  279. #define PTR_SLL dsll
  280. #define PTR_SLLV dsllv
  281. #define PTR_SRL dsrl
  282. #define PTR_SRLV dsrlv
  283. #define PTR_SRA dsra
  284. #define PTR_SRAV dsrav
  285. #define PTR_SCALESHIFT 3
  286. #define PTR_WD .dword
  287. #define PTRSIZE 8
  288. #define PTRLOG 3
  289. #endif
  290. /*
  291. * Some cp0 registers were extended to 64bit for MIPS III.
  292. */
  293. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  294. #define MFC0 mfc0
  295. #define MTC0 mtc0
  296. #endif
  297. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  298. #define MFC0 dmfc0
  299. #define MTC0 dmtc0
  300. #endif
  301. #define SSNOP sll zero, zero, 1
  302. /*
  303. * Using a branch-likely instruction to check the result of an sc instruction
  304. * works around a bug present in R10000 CPUs prior to revision 3.0 that could
  305. * cause ll-sc sequences to execute non-atomically.
  306. */
  307. #ifdef CONFIG_WAR_R10000_LLSC
  308. # define SC_BEQZ beqzl
  309. #elif MIPS_ISA_REV >= 6
  310. # define SC_BEQZ beqzc
  311. #else
  312. # define SC_BEQZ beqz
  313. #endif
  314. #ifdef CONFIG_SGI_IP28
  315. /* Inhibit speculative stores to volatile (e.g.DMA) or invalid addresses. */
  316. #include <asm/cacheops.h>
  317. #define R10KCBARRIER(addr) cache Cache_Barrier, addr;
  318. #else
  319. #define R10KCBARRIER(addr)
  320. #endif
  321. #endif /* __ASM_ASM_H */