asm.h 8.4 KB

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