asm.h 8.4 KB

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