asm.h 9.0 KB

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