assembly.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. /*
  2. * Copyright (C) 1999 Hewlett-Packard (Frank Rowand)
  3. * Copyright (C) 1999 Philipp Rumpf <prumpf@tux.org>
  4. * Copyright (C) 1999 SuSE GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef _PARISC_ASSEMBLY_H
  21. #define _PARISC_ASSEMBLY_H
  22. #define CALLEE_FLOAT_FRAME_SIZE 80
  23. #ifdef CONFIG_64BIT
  24. #define LDREG ldd
  25. #define STREG std
  26. #define LDREGX ldd,s
  27. #define LDREGM ldd,mb
  28. #define STREGM std,ma
  29. #define SHRREG shrd
  30. #define SHLREG shld
  31. #define ANDCM andcm,*
  32. #define COND(x) * ## x
  33. #define RP_OFFSET 16
  34. #define FRAME_SIZE 128
  35. #define CALLEE_REG_FRAME_SIZE 144
  36. #define ASM_ULONG_INSN .dword
  37. #else /* CONFIG_64BIT */
  38. #define LDREG ldw
  39. #define STREG stw
  40. #define LDREGX ldwx,s
  41. #define LDREGM ldwm
  42. #define STREGM stwm
  43. #define SHRREG shr
  44. #define SHLREG shlw
  45. #define ANDCM andcm
  46. #define COND(x) x
  47. #define RP_OFFSET 20
  48. #define FRAME_SIZE 64
  49. #define CALLEE_REG_FRAME_SIZE 128
  50. #define ASM_ULONG_INSN .word
  51. #endif
  52. #define CALLEE_SAVE_FRAME_SIZE (CALLEE_REG_FRAME_SIZE + CALLEE_FLOAT_FRAME_SIZE)
  53. #ifdef CONFIG_PA20
  54. #define LDCW ldcw,co
  55. #define BL b,l
  56. # ifdef CONFIG_64BIT
  57. # define LEVEL 2.0w
  58. # else
  59. # define LEVEL 2.0
  60. # endif
  61. #else
  62. #define LDCW ldcw
  63. #define BL bl
  64. #define LEVEL 1.1
  65. #endif
  66. #ifdef __ASSEMBLY__
  67. #ifdef CONFIG_64BIT
  68. /* the 64-bit pa gnu assembler unfortunately defaults to .level 1.1 or 2.0 so
  69. * work around that for now... */
  70. .level 2.0w
  71. #endif
  72. #include <asm/asm-offsets.h>
  73. #include <asm/page.h>
  74. #include <asm/types.h>
  75. #include <asm/asmregs.h>
  76. sp = 30
  77. gp = 27
  78. ipsw = 22
  79. /*
  80. * We provide two versions of each macro to convert from physical
  81. * to virtual and vice versa. The "_r1" versions take one argument
  82. * register, but trashes r1 to do the conversion. The other
  83. * version takes two arguments: a src and destination register.
  84. * However, the source and destination registers can not be
  85. * the same register.
  86. */
  87. .macro tophys grvirt, grphys
  88. ldil L%(__PAGE_OFFSET), \grphys
  89. sub \grvirt, \grphys, \grphys
  90. .endm
  91. .macro tovirt grphys, grvirt
  92. ldil L%(__PAGE_OFFSET), \grvirt
  93. add \grphys, \grvirt, \grvirt
  94. .endm
  95. .macro tophys_r1 gr
  96. ldil L%(__PAGE_OFFSET), %r1
  97. sub \gr, %r1, \gr
  98. .endm
  99. .macro tovirt_r1 gr
  100. ldil L%(__PAGE_OFFSET), %r1
  101. add \gr, %r1, \gr
  102. .endm
  103. .macro delay value
  104. ldil L%\value, 1
  105. ldo R%\value(1), 1
  106. addib,UV,n -1,1,.
  107. addib,NUV,n -1,1,.+8
  108. nop
  109. .endm
  110. .macro debug value
  111. .endm
  112. /* Shift Left - note the r and t can NOT be the same! */
  113. .macro shl r, sa, t
  114. dep,z \r, 31-(\sa), 32-(\sa), \t
  115. .endm
  116. /* The PA 2.0 shift left */
  117. .macro shlw r, sa, t
  118. depw,z \r, 31-(\sa), 32-(\sa), \t
  119. .endm
  120. /* And the PA 2.0W shift left */
  121. .macro shld r, sa, t
  122. depd,z \r, 63-(\sa), 64-(\sa), \t
  123. .endm
  124. /* Shift Right - note the r and t can NOT be the same! */
  125. .macro shr r, sa, t
  126. extru \r, 31-(\sa), 32-(\sa), \t
  127. .endm
  128. /* pa20w version of shift right */
  129. .macro shrd r, sa, t
  130. extrd,u \r, 63-(\sa), 64-(\sa), \t
  131. .endm
  132. /* load 32-bit 'value' into 'reg' compensating for the ldil
  133. * sign-extension when running in wide mode.
  134. * WARNING!! neither 'value' nor 'reg' can be expressions
  135. * containing '.'!!!! */
  136. .macro load32 value, reg
  137. ldil L%\value, \reg
  138. ldo R%\value(\reg), \reg
  139. .endm
  140. .macro loadgp
  141. #ifdef CONFIG_64BIT
  142. ldil L%__gp, %r27
  143. ldo R%__gp(%r27), %r27
  144. #else
  145. ldil L%$global$, %r27
  146. ldo R%$global$(%r27), %r27
  147. #endif
  148. .endm
  149. #define SAVE_SP(r, where) mfsp r, %r1 ! STREG %r1, where
  150. #define REST_SP(r, where) LDREG where, %r1 ! mtsp %r1, r
  151. #define SAVE_CR(r, where) mfctl r, %r1 ! STREG %r1, where
  152. #define REST_CR(r, where) LDREG where, %r1 ! mtctl %r1, r
  153. .macro save_general regs
  154. STREG %r1, PT_GR1 (\regs)
  155. STREG %r2, PT_GR2 (\regs)
  156. STREG %r3, PT_GR3 (\regs)
  157. STREG %r4, PT_GR4 (\regs)
  158. STREG %r5, PT_GR5 (\regs)
  159. STREG %r6, PT_GR6 (\regs)
  160. STREG %r7, PT_GR7 (\regs)
  161. STREG %r8, PT_GR8 (\regs)
  162. STREG %r9, PT_GR9 (\regs)
  163. STREG %r10, PT_GR10(\regs)
  164. STREG %r11, PT_GR11(\regs)
  165. STREG %r12, PT_GR12(\regs)
  166. STREG %r13, PT_GR13(\regs)
  167. STREG %r14, PT_GR14(\regs)
  168. STREG %r15, PT_GR15(\regs)
  169. STREG %r16, PT_GR16(\regs)
  170. STREG %r17, PT_GR17(\regs)
  171. STREG %r18, PT_GR18(\regs)
  172. STREG %r19, PT_GR19(\regs)
  173. STREG %r20, PT_GR20(\regs)
  174. STREG %r21, PT_GR21(\regs)
  175. STREG %r22, PT_GR22(\regs)
  176. STREG %r23, PT_GR23(\regs)
  177. STREG %r24, PT_GR24(\regs)
  178. STREG %r25, PT_GR25(\regs)
  179. /* r26 is saved in get_stack and used to preserve a value across virt_map */
  180. STREG %r27, PT_GR27(\regs)
  181. STREG %r28, PT_GR28(\regs)
  182. /* r29 is saved in get_stack and used to point to saved registers */
  183. /* r30 stack pointer saved in get_stack */
  184. STREG %r31, PT_GR31(\regs)
  185. .endm
  186. .macro rest_general regs
  187. /* r1 used as a temp in rest_stack and is restored there */
  188. LDREG PT_GR2 (\regs), %r2
  189. LDREG PT_GR3 (\regs), %r3
  190. LDREG PT_GR4 (\regs), %r4
  191. LDREG PT_GR5 (\regs), %r5
  192. LDREG PT_GR6 (\regs), %r6
  193. LDREG PT_GR7 (\regs), %r7
  194. LDREG PT_GR8 (\regs), %r8
  195. LDREG PT_GR9 (\regs), %r9
  196. LDREG PT_GR10(\regs), %r10
  197. LDREG PT_GR11(\regs), %r11
  198. LDREG PT_GR12(\regs), %r12
  199. LDREG PT_GR13(\regs), %r13
  200. LDREG PT_GR14(\regs), %r14
  201. LDREG PT_GR15(\regs), %r15
  202. LDREG PT_GR16(\regs), %r16
  203. LDREG PT_GR17(\regs), %r17
  204. LDREG PT_GR18(\regs), %r18
  205. LDREG PT_GR19(\regs), %r19
  206. LDREG PT_GR20(\regs), %r20
  207. LDREG PT_GR21(\regs), %r21
  208. LDREG PT_GR22(\regs), %r22
  209. LDREG PT_GR23(\regs), %r23
  210. LDREG PT_GR24(\regs), %r24
  211. LDREG PT_GR25(\regs), %r25
  212. LDREG PT_GR26(\regs), %r26
  213. LDREG PT_GR27(\regs), %r27
  214. LDREG PT_GR28(\regs), %r28
  215. /* r29 points to register save area, and is restored in rest_stack */
  216. /* r30 stack pointer restored in rest_stack */
  217. LDREG PT_GR31(\regs), %r31
  218. .endm
  219. .macro save_fp regs
  220. fstd,ma %fr0, 8(\regs)
  221. fstd,ma %fr1, 8(\regs)
  222. fstd,ma %fr2, 8(\regs)
  223. fstd,ma %fr3, 8(\regs)
  224. fstd,ma %fr4, 8(\regs)
  225. fstd,ma %fr5, 8(\regs)
  226. fstd,ma %fr6, 8(\regs)
  227. fstd,ma %fr7, 8(\regs)
  228. fstd,ma %fr8, 8(\regs)
  229. fstd,ma %fr9, 8(\regs)
  230. fstd,ma %fr10, 8(\regs)
  231. fstd,ma %fr11, 8(\regs)
  232. fstd,ma %fr12, 8(\regs)
  233. fstd,ma %fr13, 8(\regs)
  234. fstd,ma %fr14, 8(\regs)
  235. fstd,ma %fr15, 8(\regs)
  236. fstd,ma %fr16, 8(\regs)
  237. fstd,ma %fr17, 8(\regs)
  238. fstd,ma %fr18, 8(\regs)
  239. fstd,ma %fr19, 8(\regs)
  240. fstd,ma %fr20, 8(\regs)
  241. fstd,ma %fr21, 8(\regs)
  242. fstd,ma %fr22, 8(\regs)
  243. fstd,ma %fr23, 8(\regs)
  244. fstd,ma %fr24, 8(\regs)
  245. fstd,ma %fr25, 8(\regs)
  246. fstd,ma %fr26, 8(\regs)
  247. fstd,ma %fr27, 8(\regs)
  248. fstd,ma %fr28, 8(\regs)
  249. fstd,ma %fr29, 8(\regs)
  250. fstd,ma %fr30, 8(\regs)
  251. fstd %fr31, 0(\regs)
  252. .endm
  253. .macro rest_fp regs
  254. fldd 0(\regs), %fr31
  255. fldd,mb -8(\regs), %fr30
  256. fldd,mb -8(\regs), %fr29
  257. fldd,mb -8(\regs), %fr28
  258. fldd,mb -8(\regs), %fr27
  259. fldd,mb -8(\regs), %fr26
  260. fldd,mb -8(\regs), %fr25
  261. fldd,mb -8(\regs), %fr24
  262. fldd,mb -8(\regs), %fr23
  263. fldd,mb -8(\regs), %fr22
  264. fldd,mb -8(\regs), %fr21
  265. fldd,mb -8(\regs), %fr20
  266. fldd,mb -8(\regs), %fr19
  267. fldd,mb -8(\regs), %fr18
  268. fldd,mb -8(\regs), %fr17
  269. fldd,mb -8(\regs), %fr16
  270. fldd,mb -8(\regs), %fr15
  271. fldd,mb -8(\regs), %fr14
  272. fldd,mb -8(\regs), %fr13
  273. fldd,mb -8(\regs), %fr12
  274. fldd,mb -8(\regs), %fr11
  275. fldd,mb -8(\regs), %fr10
  276. fldd,mb -8(\regs), %fr9
  277. fldd,mb -8(\regs), %fr8
  278. fldd,mb -8(\regs), %fr7
  279. fldd,mb -8(\regs), %fr6
  280. fldd,mb -8(\regs), %fr5
  281. fldd,mb -8(\regs), %fr4
  282. fldd,mb -8(\regs), %fr3
  283. fldd,mb -8(\regs), %fr2
  284. fldd,mb -8(\regs), %fr1
  285. fldd,mb -8(\regs), %fr0
  286. .endm
  287. .macro callee_save_float
  288. fstd,ma %fr12, 8(%r30)
  289. fstd,ma %fr13, 8(%r30)
  290. fstd,ma %fr14, 8(%r30)
  291. fstd,ma %fr15, 8(%r30)
  292. fstd,ma %fr16, 8(%r30)
  293. fstd,ma %fr17, 8(%r30)
  294. fstd,ma %fr18, 8(%r30)
  295. fstd,ma %fr19, 8(%r30)
  296. fstd,ma %fr20, 8(%r30)
  297. fstd,ma %fr21, 8(%r30)
  298. .endm
  299. .macro callee_rest_float
  300. fldd,mb -8(%r30), %fr21
  301. fldd,mb -8(%r30), %fr20
  302. fldd,mb -8(%r30), %fr19
  303. fldd,mb -8(%r30), %fr18
  304. fldd,mb -8(%r30), %fr17
  305. fldd,mb -8(%r30), %fr16
  306. fldd,mb -8(%r30), %fr15
  307. fldd,mb -8(%r30), %fr14
  308. fldd,mb -8(%r30), %fr13
  309. fldd,mb -8(%r30), %fr12
  310. .endm
  311. #ifdef CONFIG_64BIT
  312. .macro callee_save
  313. std,ma %r3, CALLEE_REG_FRAME_SIZE(%r30)
  314. mfctl %cr27, %r3
  315. std %r4, -136(%r30)
  316. std %r5, -128(%r30)
  317. std %r6, -120(%r30)
  318. std %r7, -112(%r30)
  319. std %r8, -104(%r30)
  320. std %r9, -96(%r30)
  321. std %r10, -88(%r30)
  322. std %r11, -80(%r30)
  323. std %r12, -72(%r30)
  324. std %r13, -64(%r30)
  325. std %r14, -56(%r30)
  326. std %r15, -48(%r30)
  327. std %r16, -40(%r30)
  328. std %r17, -32(%r30)
  329. std %r18, -24(%r30)
  330. std %r3, -16(%r30)
  331. .endm
  332. .macro callee_rest
  333. ldd -16(%r30), %r3
  334. ldd -24(%r30), %r18
  335. ldd -32(%r30), %r17
  336. ldd -40(%r30), %r16
  337. ldd -48(%r30), %r15
  338. ldd -56(%r30), %r14
  339. ldd -64(%r30), %r13
  340. ldd -72(%r30), %r12
  341. ldd -80(%r30), %r11
  342. ldd -88(%r30), %r10
  343. ldd -96(%r30), %r9
  344. ldd -104(%r30), %r8
  345. ldd -112(%r30), %r7
  346. ldd -120(%r30), %r6
  347. ldd -128(%r30), %r5
  348. ldd -136(%r30), %r4
  349. mtctl %r3, %cr27
  350. ldd,mb -CALLEE_REG_FRAME_SIZE(%r30), %r3
  351. .endm
  352. #else /* ! CONFIG_64BIT */
  353. .macro callee_save
  354. stw,ma %r3, CALLEE_REG_FRAME_SIZE(%r30)
  355. mfctl %cr27, %r3
  356. stw %r4, -124(%r30)
  357. stw %r5, -120(%r30)
  358. stw %r6, -116(%r30)
  359. stw %r7, -112(%r30)
  360. stw %r8, -108(%r30)
  361. stw %r9, -104(%r30)
  362. stw %r10, -100(%r30)
  363. stw %r11, -96(%r30)
  364. stw %r12, -92(%r30)
  365. stw %r13, -88(%r30)
  366. stw %r14, -84(%r30)
  367. stw %r15, -80(%r30)
  368. stw %r16, -76(%r30)
  369. stw %r17, -72(%r30)
  370. stw %r18, -68(%r30)
  371. stw %r3, -64(%r30)
  372. .endm
  373. .macro callee_rest
  374. ldw -64(%r30), %r3
  375. ldw -68(%r30), %r18
  376. ldw -72(%r30), %r17
  377. ldw -76(%r30), %r16
  378. ldw -80(%r30), %r15
  379. ldw -84(%r30), %r14
  380. ldw -88(%r30), %r13
  381. ldw -92(%r30), %r12
  382. ldw -96(%r30), %r11
  383. ldw -100(%r30), %r10
  384. ldw -104(%r30), %r9
  385. ldw -108(%r30), %r8
  386. ldw -112(%r30), %r7
  387. ldw -116(%r30), %r6
  388. ldw -120(%r30), %r5
  389. ldw -124(%r30), %r4
  390. mtctl %r3, %cr27
  391. ldw,mb -CALLEE_REG_FRAME_SIZE(%r30), %r3
  392. .endm
  393. #endif /* ! CONFIG_64BIT */
  394. .macro save_specials regs
  395. SAVE_SP (%sr0, PT_SR0 (\regs))
  396. SAVE_SP (%sr1, PT_SR1 (\regs))
  397. SAVE_SP (%sr2, PT_SR2 (\regs))
  398. SAVE_SP (%sr3, PT_SR3 (\regs))
  399. SAVE_SP (%sr4, PT_SR4 (\regs))
  400. SAVE_SP (%sr5, PT_SR5 (\regs))
  401. SAVE_SP (%sr6, PT_SR6 (\regs))
  402. SAVE_CR (%cr17, PT_IASQ0(\regs))
  403. mtctl %r0, %cr17
  404. SAVE_CR (%cr17, PT_IASQ1(\regs))
  405. SAVE_CR (%cr18, PT_IAOQ0(\regs))
  406. mtctl %r0, %cr18
  407. SAVE_CR (%cr18, PT_IAOQ1(\regs))
  408. #ifdef CONFIG_64BIT
  409. /* cr11 (sar) is a funny one. 5 bits on PA1.1 and 6 bit on PA2.0
  410. * For PA2.0 mtsar or mtctl always write 6 bits, but mfctl only
  411. * reads 5 bits. Use mfctl,w to read all six bits. Otherwise
  412. * we lose the 6th bit on a save/restore over interrupt.
  413. */
  414. mfctl,w %cr11, %r1
  415. STREG %r1, PT_SAR (\regs)
  416. #else
  417. SAVE_CR (%cr11, PT_SAR (\regs))
  418. #endif
  419. SAVE_CR (%cr19, PT_IIR (\regs))
  420. /*
  421. * Code immediately following this macro (in intr_save) relies
  422. * on r8 containing ipsw.
  423. */
  424. mfctl %cr22, %r8
  425. STREG %r8, PT_PSW(\regs)
  426. .endm
  427. .macro rest_specials regs
  428. REST_SP (%sr0, PT_SR0 (\regs))
  429. REST_SP (%sr1, PT_SR1 (\regs))
  430. REST_SP (%sr2, PT_SR2 (\regs))
  431. REST_SP (%sr3, PT_SR3 (\regs))
  432. REST_SP (%sr4, PT_SR4 (\regs))
  433. REST_SP (%sr5, PT_SR5 (\regs))
  434. REST_SP (%sr6, PT_SR6 (\regs))
  435. REST_SP (%sr7, PT_SR7 (\regs))
  436. REST_CR (%cr17, PT_IASQ0(\regs))
  437. REST_CR (%cr17, PT_IASQ1(\regs))
  438. REST_CR (%cr18, PT_IAOQ0(\regs))
  439. REST_CR (%cr18, PT_IAOQ1(\regs))
  440. REST_CR (%cr11, PT_SAR (\regs))
  441. REST_CR (%cr22, PT_PSW (\regs))
  442. .endm
  443. /* First step to create a "relied upon translation"
  444. * See PA 2.0 Arch. page F-4 and F-5.
  445. *
  446. * The ssm was originally necessary due to a "PCxT bug".
  447. * But someone decided it needed to be added to the architecture
  448. * and this "feature" went into rev3 of PA-RISC 1.1 Arch Manual.
  449. * It's been carried forward into PA 2.0 Arch as well. :^(
  450. *
  451. * "ssm 0,%r0" is a NOP with side effects (prefetch barrier).
  452. * rsm/ssm prevents the ifetch unit from speculatively fetching
  453. * instructions past this line in the code stream.
  454. * PA 2.0 processor will single step all insn in the same QUAD (4 insn).
  455. */
  456. .macro pcxt_ssm_bug
  457. rsm PSW_SM_I,%r0
  458. nop /* 1 */
  459. nop /* 2 */
  460. nop /* 3 */
  461. nop /* 4 */
  462. nop /* 5 */
  463. nop /* 6 */
  464. nop /* 7 */
  465. .endm
  466. /*
  467. * ASM_EXCEPTIONTABLE_ENTRY
  468. *
  469. * Creates an exception table entry.
  470. * Do not convert to a assembler macro. This won't work.
  471. */
  472. #define ASM_EXCEPTIONTABLE_ENTRY(fault_addr, except_addr) \
  473. .section __ex_table,"aw" ! \
  474. ASM_ULONG_INSN fault_addr, except_addr ! \
  475. .previous
  476. #endif /* __ASSEMBLY__ */
  477. #endif