asm.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 <linux/config.h>
  20. #include <asm/sgidefs.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. #define PRINT(string) \
  100. .set push; \
  101. .set reorder; \
  102. PTR_LA a0,8f; \
  103. jal printk; \
  104. .set pop; \
  105. TEXT(string)
  106. #define TEXT(msg) \
  107. .pushsection .data; \
  108. 8: .asciiz msg; \
  109. .popsection;
  110. /*
  111. * Build text tables
  112. */
  113. #define TTABLE(string) \
  114. .pushsection .text; \
  115. .word 1f; \
  116. .popsection \
  117. .pushsection .data; \
  118. 1: .asciiz string; \
  119. .popsection
  120. /*
  121. * MIPS IV pref instruction.
  122. * Use with .set noreorder only!
  123. *
  124. * MIPS IV implementations are free to treat this as a nop. The R5000
  125. * is one of them. So we should have an option not to use this instruction.
  126. */
  127. #ifdef CONFIG_CPU_HAS_PREFETCH
  128. #define PREF(hint,addr) \
  129. .set push; \
  130. .set mips4; \
  131. pref hint,addr; \
  132. .set pop
  133. #define PREFX(hint,addr) \
  134. .set push; \
  135. .set mips4; \
  136. prefx hint,addr; \
  137. .set pop
  138. #else /* !CONFIG_CPU_HAS_PREFETCH */
  139. #define PREF(hint,addr)
  140. #define PREFX(hint,addr)
  141. #endif /* !CONFIG_CPU_HAS_PREFETCH */
  142. /*
  143. * MIPS ISA IV/V movn/movz instructions and equivalents for older CPUs.
  144. */
  145. #if (_MIPS_ISA == _MIPS_ISA_MIPS1)
  146. #define MOVN(rd,rs,rt) \
  147. .set push; \
  148. .set reorder; \
  149. beqz rt,9f; \
  150. move rd,rs; \
  151. .set pop; \
  152. 9:
  153. #define MOVZ(rd,rs,rt) \
  154. .set push; \
  155. .set reorder; \
  156. bnez rt,9f; \
  157. move rd,rs; \
  158. .set pop; \
  159. 9:
  160. #endif /* _MIPS_ISA == _MIPS_ISA_MIPS1 */
  161. #if (_MIPS_ISA == _MIPS_ISA_MIPS2) || (_MIPS_ISA == _MIPS_ISA_MIPS3)
  162. #define MOVN(rd,rs,rt) \
  163. .set push; \
  164. .set noreorder; \
  165. bnezl rt,9f; \
  166. move rd,rs; \
  167. .set pop; \
  168. 9:
  169. #define MOVZ(rd,rs,rt) \
  170. .set push; \
  171. .set noreorder; \
  172. beqzl rt,9f; \
  173. move rd,rs; \
  174. .set pop; \
  175. 9:
  176. #endif /* (_MIPS_ISA == _MIPS_ISA_MIPS2) || (_MIPS_ISA == _MIPS_ISA_MIPS3) */
  177. #if (_MIPS_ISA == _MIPS_ISA_MIPS4 ) || (_MIPS_ISA == _MIPS_ISA_MIPS5) || \
  178. (_MIPS_ISA == _MIPS_ISA_MIPS32) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
  179. #define MOVN(rd,rs,rt) \
  180. movn rd,rs,rt
  181. #define MOVZ(rd,rs,rt) \
  182. movz rd,rs,rt
  183. #endif /* MIPS IV, MIPS V, MIPS32 or MIPS64 */
  184. /*
  185. * Stack alignment
  186. */
  187. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  188. #define ALSZ 7
  189. #define ALMASK ~7
  190. #endif
  191. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  192. #define ALSZ 15
  193. #define ALMASK ~15
  194. #endif
  195. /*
  196. * Macros to handle different pointer/register sizes for 32/64-bit code
  197. */
  198. /*
  199. * Size of a register
  200. */
  201. #ifdef __mips64
  202. #define SZREG 8
  203. #else
  204. #define SZREG 4
  205. #endif
  206. /*
  207. * Use the following macros in assemblercode to load/store registers,
  208. * pointers etc.
  209. */
  210. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  211. #define REG_S sw
  212. #define REG_L lw
  213. #define REG_SUBU subu
  214. #define REG_ADDU addu
  215. #endif
  216. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  217. #define REG_S sd
  218. #define REG_L ld
  219. #define REG_SUBU dsubu
  220. #define REG_ADDU daddu
  221. #endif
  222. /*
  223. * How to add/sub/load/store/shift C int variables.
  224. */
  225. #if (_MIPS_SZINT == 32)
  226. #define INT_ADD add
  227. #define INT_ADDU addu
  228. #define INT_ADDI addi
  229. #define INT_ADDIU addiu
  230. #define INT_SUB sub
  231. #define INT_SUBU subu
  232. #define INT_L lw
  233. #define INT_S sw
  234. #define INT_SLL sll
  235. #define INT_SLLV sllv
  236. #define INT_SRL srl
  237. #define INT_SRLV srlv
  238. #define INT_SRA sra
  239. #define INT_SRAV srav
  240. #endif
  241. #if (_MIPS_SZINT == 64)
  242. #define INT_ADD dadd
  243. #define INT_ADDU daddu
  244. #define INT_ADDI daddi
  245. #define INT_ADDIU daddiu
  246. #define INT_SUB dsub
  247. #define INT_SUBU dsubu
  248. #define INT_L ld
  249. #define INT_S sd
  250. #define INT_SLL dsll
  251. #define INT_SLLV dsllv
  252. #define INT_SRL dsrl
  253. #define INT_SRLV dsrlv
  254. #define INT_SRA dsra
  255. #define INT_SRAV dsrav
  256. #endif
  257. /*
  258. * How to add/sub/load/store/shift C long variables.
  259. */
  260. #if (_MIPS_SZLONG == 32)
  261. #define LONG_ADD add
  262. #define LONG_ADDU addu
  263. #define LONG_ADDI addi
  264. #define LONG_ADDIU addiu
  265. #define LONG_SUB sub
  266. #define LONG_SUBU subu
  267. #define LONG_L lw
  268. #define LONG_S sw
  269. #define LONG_SLL sll
  270. #define LONG_SLLV sllv
  271. #define LONG_SRL srl
  272. #define LONG_SRLV srlv
  273. #define LONG_SRA sra
  274. #define LONG_SRAV srav
  275. #define LONG .word
  276. #define LONGSIZE 4
  277. #define LONGMASK 3
  278. #define LONGLOG 2
  279. #endif
  280. #if (_MIPS_SZLONG == 64)
  281. #define LONG_ADD dadd
  282. #define LONG_ADDU daddu
  283. #define LONG_ADDI daddi
  284. #define LONG_ADDIU daddiu
  285. #define LONG_SUB dsub
  286. #define LONG_SUBU dsubu
  287. #define LONG_L ld
  288. #define LONG_S sd
  289. #define LONG_SLL dsll
  290. #define LONG_SLLV dsllv
  291. #define LONG_SRL dsrl
  292. #define LONG_SRLV dsrlv
  293. #define LONG_SRA dsra
  294. #define LONG_SRAV dsrav
  295. #define LONG .dword
  296. #define LONGSIZE 8
  297. #define LONGMASK 7
  298. #define LONGLOG 3
  299. #endif
  300. /*
  301. * How to add/sub/load/store/shift pointers.
  302. */
  303. #if (_MIPS_SZPTR == 32)
  304. #define PTR_ADD add
  305. #define PTR_ADDU addu
  306. #define PTR_ADDI addi
  307. #define PTR_ADDIU addiu
  308. #define PTR_SUB sub
  309. #define PTR_SUBU subu
  310. #define PTR_L lw
  311. #define PTR_S sw
  312. #define PTR_LA la
  313. #define PTR_SLL sll
  314. #define PTR_SLLV sllv
  315. #define PTR_SRL srl
  316. #define PTR_SRLV srlv
  317. #define PTR_SRA sra
  318. #define PTR_SRAV srav
  319. #define PTR_SCALESHIFT 2
  320. #define PTR .word
  321. #define PTRSIZE 4
  322. #define PTRLOG 2
  323. #endif
  324. #if (_MIPS_SZPTR == 64)
  325. #define PTR_ADD dadd
  326. #define PTR_ADDU daddu
  327. #define PTR_ADDI daddi
  328. #define PTR_ADDIU daddiu
  329. #define PTR_SUB dsub
  330. #define PTR_SUBU dsubu
  331. #define PTR_L ld
  332. #define PTR_S sd
  333. #define PTR_LA dla
  334. #define PTR_SLL dsll
  335. #define PTR_SLLV dsllv
  336. #define PTR_SRL dsrl
  337. #define PTR_SRLV dsrlv
  338. #define PTR_SRA dsra
  339. #define PTR_SRAV dsrav
  340. #define PTR_SCALESHIFT 3
  341. #define PTR .dword
  342. #define PTRSIZE 8
  343. #define PTRLOG 3
  344. #endif
  345. /*
  346. * Some cp0 registers were extended to 64bit for MIPS III.
  347. */
  348. #if (_MIPS_SIM == _MIPS_SIM_ABI32)
  349. #define MFC0 mfc0
  350. #define MTC0 mtc0
  351. #endif
  352. #if (_MIPS_SIM == _MIPS_SIM_NABI32) || (_MIPS_SIM == _MIPS_SIM_ABI64)
  353. #define MFC0 dmfc0
  354. #define MTC0 dmtc0
  355. #endif
  356. #define SSNOP sll zero,zero,1
  357. #endif /* __ASM_ASM_H */