asm.h 8.5 KB

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