asm.h 8.4 KB

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