asm.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. #ifndef CAT
  21. #ifdef __STDC__
  22. #define __CAT(str1, str2) str1##str2
  23. #else
  24. #define __CAT(str1, str2) str1/**/str2
  25. #endif
  26. #define CAT(str1, str2) __CAT(str1, str2)
  27. #endif
  28. /*
  29. * PIC specific declarations
  30. * Not used for the kernel but here seems to be the right place.
  31. */
  32. #ifdef __PIC__
  33. #define CPRESTORE(register) \
  34. .cprestore register
  35. #define CPADD(register) \
  36. .cpadd register
  37. #define CPLOAD(register) \
  38. .cpload register
  39. #else
  40. #define CPRESTORE(register)
  41. #define CPADD(register)
  42. #define CPLOAD(register)
  43. #endif
  44. /*
  45. * LEAF - declare leaf routine
  46. */
  47. #define LEAF(symbol) \
  48. .globl symbol; \
  49. .align 2; \
  50. .type symbol, @function; \
  51. .ent symbol, 0; \
  52. symbol: .frame sp, 0, ra
  53. /*
  54. * NESTED - declare nested routine entry point
  55. */
  56. #define NESTED(symbol, framesize, rpc) \
  57. .globl symbol; \
  58. .align 2; \
  59. .type symbol, @function; \
  60. .ent symbol, 0; \
  61. symbol: .frame sp, framesize, rpc
  62. /*
  63. * END - mark end of function
  64. */
  65. #define END(function) \
  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:
  81. /*
  82. * ABS - export absolute symbol
  83. */
  84. #define ABS(symbol,value) \
  85. .globl symbol; \
  86. symbol = value
  87. #define PANIC(msg) \
  88. .set push; \
  89. .set reorder; \
  90. PTR_LA a0, 8f; \
  91. jal panic; \
  92. 9: b 9b; \
  93. .set pop; \
  94. TEXT(msg)
  95. /*
  96. * Print formatted string
  97. */
  98. #ifdef CONFIG_PRINTK
  99. #define PRINT(string) \
  100. .set push; \
  101. .set reorder; \
  102. PTR_LA a0, 8f; \
  103. jal printk; \
  104. .set pop; \
  105. TEXT(string)
  106. #else
  107. #define PRINT(string)
  108. #endif
  109. #define TEXT(msg) \
  110. .pushsection .data; \
  111. 8: .asciiz msg; \
  112. .popsection;
  113. /*
  114. * Build text tables
  115. */
  116. #define TTABLE(string) \
  117. .pushsection .text; \
  118. .word 1f; \
  119. .popsection \
  120. .pushsection .data; \
  121. 1: .asciiz string; \
  122. .popsection
  123. /*
  124. * MIPS IV pref instruction.
  125. * Use with .set noreorder only!
  126. *
  127. * MIPS IV implementations are free to treat this as a nop. The R5000
  128. * is one of them. So we should have an option not to use this instruction.
  129. */
  130. #ifdef CONFIG_CPU_HAS_PREFETCH
  131. #define PREF(hint,addr) \
  132. .set push; \
  133. .set mips4; \
  134. pref hint, addr; \
  135. .set pop
  136. #define PREFX(hint,addr) \
  137. .set push; \
  138. .set mips4; \
  139. prefx hint, addr; \
  140. .set pop
  141. #else /* !CONFIG_CPU_HAS_PREFETCH */
  142. #define PREF(hint, addr)
  143. #define PREFX(hint, addr)
  144. #endif /* !CONFIG_CPU_HAS_PREFETCH */
  145. /*
  146. * MIPS ISA IV/V movn/movz instructions and equivalents for older CPUs.
  147. */
  148. #if (_MIPS_ISA == _MIPS_ISA_MIPS1)
  149. #define MOVN(rd, rs, rt) \
  150. .set push; \
  151. .set reorder; \
  152. beqz rt, 9f; \
  153. move rd, rs; \
  154. .set pop; \
  155. 9:
  156. #define MOVZ(rd, rs, rt) \
  157. .set push; \
  158. .set reorder; \
  159. bnez rt, 9f; \
  160. move rd, rs; \
  161. .set pop; \
  162. 9:
  163. #endif /* _MIPS_ISA == _MIPS_ISA_MIPS1 */
  164. #if (_MIPS_ISA == _MIPS_ISA_MIPS2) || (_MIPS_ISA == _MIPS_ISA_MIPS3)
  165. #define MOVN(rd, rs, rt) \
  166. .set push; \
  167. .set noreorder; \
  168. bnezl rt, 9f; \
  169. move rd, rs; \
  170. .set pop; \
  171. 9:
  172. #define MOVZ(rd, rs, rt) \
  173. .set push; \
  174. .set noreorder; \
  175. beqzl rt, 9f; \
  176. move rd, rs; \
  177. .set pop; \
  178. 9:
  179. #endif /* (_MIPS_ISA == _MIPS_ISA_MIPS2) || (_MIPS_ISA == _MIPS_ISA_MIPS3) */
  180. #if (_MIPS_ISA == _MIPS_ISA_MIPS4 ) || (_MIPS_ISA == _MIPS_ISA_MIPS5) || \
  181. (_MIPS_ISA == _MIPS_ISA_MIPS32) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
  182. #define MOVN(rd, rs, rt) \
  183. movn rd, rs, rt
  184. #define MOVZ(rd, rs, rt) \
  185. movz rd, rs, rt
  186. #endif /* MIPS IV, MIPS V, MIPS32 or MIPS64 */
  187. /*
  188. * Stack alignment
  189. */
  190. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  191. #define ALSZ 7
  192. #define ALMASK ~7
  193. #endif
  194. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  195. #define ALSZ 15
  196. #define ALMASK ~15
  197. #endif
  198. /*
  199. * Macros to handle different pointer/register sizes for 32/64-bit code
  200. */
  201. /*
  202. * Size of a register
  203. */
  204. #ifdef __mips64
  205. #define SZREG 8
  206. #else
  207. #define SZREG 4
  208. #endif
  209. /*
  210. * Use the following macros in assemblercode to load/store registers,
  211. * pointers etc.
  212. */
  213. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  214. #define REG_S sw
  215. #define REG_L lw
  216. #define REG_SUBU subu
  217. #define REG_ADDU addu
  218. #endif
  219. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  220. #define REG_S sd
  221. #define REG_L ld
  222. #define REG_SUBU dsubu
  223. #define REG_ADDU daddu
  224. #endif
  225. /*
  226. * How to add/sub/load/store/shift C int variables.
  227. */
  228. #if (_MIPS_SZINT == 32)
  229. #define INT_ADD add
  230. #define INT_ADDU addu
  231. #define INT_ADDI addi
  232. #define INT_ADDIU addiu
  233. #define INT_SUB sub
  234. #define INT_SUBU subu
  235. #define INT_L lw
  236. #define INT_S sw
  237. #define INT_SLL sll
  238. #define INT_SLLV sllv
  239. #define INT_SRL srl
  240. #define INT_SRLV srlv
  241. #define INT_SRA sra
  242. #define INT_SRAV srav
  243. #endif
  244. #if (_MIPS_SZINT == 64)
  245. #define INT_ADD dadd
  246. #define INT_ADDU daddu
  247. #define INT_ADDI daddi
  248. #define INT_ADDIU daddiu
  249. #define INT_SUB dsub
  250. #define INT_SUBU dsubu
  251. #define INT_L ld
  252. #define INT_S sd
  253. #define INT_SLL dsll
  254. #define INT_SLLV dsllv
  255. #define INT_SRL dsrl
  256. #define INT_SRLV dsrlv
  257. #define INT_SRA dsra
  258. #define INT_SRAV dsrav
  259. #endif
  260. /*
  261. * How to add/sub/load/store/shift C long variables.
  262. */
  263. #if (_MIPS_SZLONG == 32)
  264. #define LONG_ADD add
  265. #define LONG_ADDU addu
  266. #define LONG_ADDI addi
  267. #define LONG_ADDIU addiu
  268. #define LONG_SUB sub
  269. #define LONG_SUBU subu
  270. #define LONG_L lw
  271. #define LONG_S sw
  272. #define LONG_SLL sll
  273. #define LONG_SLLV sllv
  274. #define LONG_SRL srl
  275. #define LONG_SRLV srlv
  276. #define LONG_SRA sra
  277. #define LONG_SRAV srav
  278. #define LONG .word
  279. #define LONGSIZE 4
  280. #define LONGMASK 3
  281. #define LONGLOG 2
  282. #endif
  283. #if (_MIPS_SZLONG == 64)
  284. #define LONG_ADD dadd
  285. #define LONG_ADDU daddu
  286. #define LONG_ADDI daddi
  287. #define LONG_ADDIU daddiu
  288. #define LONG_SUB dsub
  289. #define LONG_SUBU dsubu
  290. #define LONG_L ld
  291. #define LONG_S sd
  292. #define LONG_SLL dsll
  293. #define LONG_SLLV dsllv
  294. #define LONG_SRL dsrl
  295. #define LONG_SRLV dsrlv
  296. #define LONG_SRA dsra
  297. #define LONG_SRAV dsrav
  298. #define LONG .dword
  299. #define LONGSIZE 8
  300. #define LONGMASK 7
  301. #define LONGLOG 3
  302. #endif
  303. /*
  304. * How to add/sub/load/store/shift pointers.
  305. */
  306. #if (_MIPS_SZPTR == 32)
  307. #define PTR_ADD add
  308. #define PTR_ADDU addu
  309. #define PTR_ADDI addi
  310. #define PTR_ADDIU addiu
  311. #define PTR_SUB sub
  312. #define PTR_SUBU subu
  313. #define PTR_L lw
  314. #define PTR_S sw
  315. #define PTR_LA la
  316. #define PTR_LI li
  317. #define PTR_SLL sll
  318. #define PTR_SLLV sllv
  319. #define PTR_SRL srl
  320. #define PTR_SRLV srlv
  321. #define PTR_SRA sra
  322. #define PTR_SRAV srav
  323. #define PTR_SCALESHIFT 2
  324. #define PTR .word
  325. #define PTRSIZE 4
  326. #define PTRLOG 2
  327. #endif
  328. #if (_MIPS_SZPTR == 64)
  329. #define PTR_ADD dadd
  330. #define PTR_ADDU daddu
  331. #define PTR_ADDI daddi
  332. #define PTR_ADDIU daddiu
  333. #define PTR_SUB dsub
  334. #define PTR_SUBU dsubu
  335. #define PTR_L ld
  336. #define PTR_S sd
  337. #define PTR_LA dla
  338. #define PTR_LI dli
  339. #define PTR_SLL dsll
  340. #define PTR_SLLV dsllv
  341. #define PTR_SRL dsrl
  342. #define PTR_SRLV dsrlv
  343. #define PTR_SRA dsra
  344. #define PTR_SRAV dsrav
  345. #define PTR_SCALESHIFT 3
  346. #define PTR .dword
  347. #define PTRSIZE 8
  348. #define PTRLOG 3
  349. #endif
  350. /*
  351. * Some cp0 registers were extended to 64bit for MIPS III.
  352. */
  353. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  354. #define MFC0 mfc0
  355. #define MTC0 mtc0
  356. #endif
  357. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  358. #define MFC0 dmfc0
  359. #define MTC0 dmtc0
  360. #endif
  361. #define SSNOP sll zero, zero, 1
  362. #ifdef CONFIG_SGI_IP28
  363. /* Inhibit speculative stores to volatile (e.g.DMA) or invalid addresses. */
  364. #include <asm/cacheops.h>
  365. #define R10KCBARRIER(addr) cache Cache_Barrier, addr;
  366. #else
  367. #define R10KCBARRIER(addr)
  368. #endif
  369. #endif /* __ASM_ASM_H */