asm.h 8.4 KB

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