real2.S 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. *
  3. * This file is subject to the terms and conditions of the GNU General Public
  4. * License. See the file "COPYING" in the main directory of this archive
  5. * for more details.
  6. *
  7. * Copyright (C) 2000 Hewlett Packard (Paul Bame bame@puffin.external.hp.com)
  8. *
  9. */
  10. #include <asm/pdc.h>
  11. #include <asm/psw.h>
  12. #include <asm/assembly.h>
  13. #include <asm/asm-offsets.h>
  14. #include <linux/linkage.h>
  15. .section .bss
  16. .export pdc_result
  17. .export pdc_result2
  18. .align 8
  19. pdc_result:
  20. .block ASM_PDC_RESULT_SIZE
  21. pdc_result2:
  22. .block ASM_PDC_RESULT_SIZE
  23. .export real_stack
  24. .export real32_stack
  25. .export real64_stack
  26. .align 64
  27. real_stack:
  28. real32_stack:
  29. real64_stack:
  30. .block 8192
  31. #ifdef CONFIG_64BIT
  32. # define REG_SZ 8
  33. #else
  34. # define REG_SZ 4
  35. #endif
  36. #define N_SAVED_REGS 9
  37. save_cr_space:
  38. .block REG_SZ * N_SAVED_REGS
  39. save_cr_end:
  40. /************************ 32-bit real-mode calls ***********************/
  41. /* This can be called in both narrow and wide kernels */
  42. .text
  43. /* unsigned long real32_call_asm(unsigned int *sp,
  44. * unsigned int *arg0p,
  45. * unsigned int iodc_fn)
  46. * sp is value of stack pointer to adopt before calling PDC (virt)
  47. * arg0p points to where saved arg values may be found
  48. * iodc_fn is the IODC function to call
  49. */
  50. ENTRY_CFI(real32_call_asm)
  51. STREG %rp, -RP_OFFSET(%sp) /* save RP */
  52. #ifdef CONFIG_64BIT
  53. callee_save
  54. ldo 2*REG_SZ(%sp), %sp /* room for a couple more saves */
  55. STREG %r27, -1*REG_SZ(%sp)
  56. STREG %r29, -2*REG_SZ(%sp)
  57. #endif
  58. STREG %sp, -REG_SZ(%arg0) /* save SP on real-mode stack */
  59. copy %arg0, %sp /* adopt the real-mode SP */
  60. /* save iodc_fn */
  61. copy %arg2, %r31
  62. /* load up the arg registers from the saved arg area */
  63. /* 32-bit calling convention passes first 4 args in registers */
  64. ldw 0(%arg1), %arg0 /* note overwriting arg0 */
  65. ldw -8(%arg1), %arg2
  66. ldw -12(%arg1), %arg3
  67. ldw -4(%arg1), %arg1 /* obviously must do this one last! */
  68. tophys_r1 %sp
  69. b,l rfi_virt2real,%r2
  70. nop
  71. b,l save_control_regs,%r2 /* modifies r1, r2, r28 */
  72. nop
  73. #ifdef CONFIG_64BIT
  74. rsm PSW_SM_W, %r0 /* go narrow */
  75. #endif
  76. load32 PA(ric_ret), %r2
  77. bv 0(%r31)
  78. nop
  79. ric_ret:
  80. #ifdef CONFIG_64BIT
  81. ssm PSW_SM_W, %r0 /* go wide */
  82. #endif
  83. /* restore CRs before going virtual in case we page fault */
  84. b,l restore_control_regs, %r2 /* modifies r1, r2, r26 */
  85. nop
  86. b,l rfi_real2virt,%r2
  87. nop
  88. tovirt_r1 %sp
  89. LDREG -REG_SZ(%sp), %sp /* restore SP */
  90. #ifdef CONFIG_64BIT
  91. LDREG -1*REG_SZ(%sp), %r27
  92. LDREG -2*REG_SZ(%sp), %r29
  93. ldo -2*REG_SZ(%sp), %sp
  94. callee_rest
  95. #endif
  96. LDREG -RP_OFFSET(%sp), %rp /* restore RP */
  97. bv 0(%rp)
  98. nop
  99. ENDPROC_CFI(real32_call_asm)
  100. # define PUSH_CR(r, where) mfctl r, %r1 ! STREG,ma %r1, REG_SZ(where)
  101. # define POP_CR(r, where) LDREG,mb -REG_SZ(where), %r1 ! mtctl %r1, r
  102. .text
  103. ENTRY_CFI(save_control_regs)
  104. load32 PA(save_cr_space), %r28
  105. PUSH_CR(%cr24, %r28)
  106. PUSH_CR(%cr25, %r28)
  107. PUSH_CR(%cr26, %r28)
  108. PUSH_CR(%cr27, %r28)
  109. PUSH_CR(%cr28, %r28)
  110. PUSH_CR(%cr29, %r28)
  111. PUSH_CR(%cr30, %r28)
  112. PUSH_CR(%cr31, %r28)
  113. PUSH_CR(%cr15, %r28)
  114. bv 0(%r2)
  115. nop
  116. ENDPROC_CFI(save_control_regs)
  117. ENTRY_CFI(restore_control_regs)
  118. load32 PA(save_cr_end), %r26
  119. POP_CR(%cr15, %r26)
  120. POP_CR(%cr31, %r26)
  121. POP_CR(%cr30, %r26)
  122. POP_CR(%cr29, %r26)
  123. POP_CR(%cr28, %r26)
  124. POP_CR(%cr27, %r26)
  125. POP_CR(%cr26, %r26)
  126. POP_CR(%cr25, %r26)
  127. POP_CR(%cr24, %r26)
  128. bv 0(%r2)
  129. nop
  130. ENDPROC_CFI(restore_control_regs)
  131. /* rfi_virt2real() and rfi_real2virt() could perhaps be adapted for
  132. * more general-purpose use by the several places which need RFIs
  133. */
  134. .text
  135. .align 128
  136. ENTRY_CFI(rfi_virt2real)
  137. #if !defined(BOOTLOADER)
  138. /* switch to real mode... */
  139. rsm PSW_SM_I,%r0
  140. load32 PA(rfi_v2r_1), %r1
  141. nop
  142. nop
  143. nop
  144. nop
  145. nop
  146. rsm PSW_SM_Q,%r0 /* disable Q & I bits to load iia queue */
  147. mtctl %r0, %cr17 /* Clear IIASQ tail */
  148. mtctl %r0, %cr17 /* Clear IIASQ head */
  149. mtctl %r1, %cr18 /* IIAOQ head */
  150. ldo 4(%r1), %r1
  151. mtctl %r1, %cr18 /* IIAOQ tail */
  152. load32 REAL_MODE_PSW, %r1
  153. mtctl %r1, %cr22
  154. rfi
  155. nop
  156. nop
  157. nop
  158. nop
  159. nop
  160. nop
  161. nop
  162. nop
  163. rfi_v2r_1:
  164. tophys_r1 %r2
  165. #endif /* defined(BOOTLOADER) */
  166. bv 0(%r2)
  167. nop
  168. ENDPROC_CFI(rfi_virt2real)
  169. .text
  170. .align 128
  171. ENTRY_CFI(rfi_real2virt)
  172. #if !defined(BOOTLOADER)
  173. rsm PSW_SM_I,%r0
  174. load32 (rfi_r2v_1), %r1
  175. nop
  176. nop
  177. nop
  178. nop
  179. nop
  180. rsm PSW_SM_Q,%r0 /* disable Q bit to load iia queue */
  181. mtctl %r0, %cr17 /* Clear IIASQ tail */
  182. mtctl %r0, %cr17 /* Clear IIASQ head */
  183. mtctl %r1, %cr18 /* IIAOQ head */
  184. ldo 4(%r1), %r1
  185. mtctl %r1, %cr18 /* IIAOQ tail */
  186. load32 KERNEL_PSW, %r1
  187. mtctl %r1, %cr22
  188. rfi
  189. nop
  190. nop
  191. nop
  192. nop
  193. nop
  194. nop
  195. nop
  196. nop
  197. rfi_r2v_1:
  198. tovirt_r1 %r2
  199. #endif /* defined(BOOTLOADER) */
  200. bv 0(%r2)
  201. nop
  202. ENDPROC_CFI(rfi_real2virt)
  203. #ifdef CONFIG_64BIT
  204. /************************ 64-bit real-mode calls ***********************/
  205. /* This is only usable in wide kernels right now and will probably stay so */
  206. .text
  207. /* unsigned long real64_call_asm(unsigned long *sp,
  208. * unsigned long *arg0p,
  209. * unsigned long fn)
  210. * sp is value of stack pointer to adopt before calling PDC (virt)
  211. * arg0p points to where saved arg values may be found
  212. * iodc_fn is the IODC function to call
  213. */
  214. ENTRY_CFI(real64_call_asm)
  215. std %rp, -0x10(%sp) /* save RP */
  216. std %sp, -8(%arg0) /* save SP on real-mode stack */
  217. copy %arg0, %sp /* adopt the real-mode SP */
  218. /* save fn */
  219. copy %arg2, %r31
  220. /* set up the new ap */
  221. ldo 64(%arg1), %r29
  222. /* load up the arg registers from the saved arg area */
  223. /* 32-bit calling convention passes first 4 args in registers */
  224. ldd 0*REG_SZ(%arg1), %arg0 /* note overwriting arg0 */
  225. ldd 2*REG_SZ(%arg1), %arg2
  226. ldd 3*REG_SZ(%arg1), %arg3
  227. ldd 4*REG_SZ(%arg1), %r22
  228. ldd 5*REG_SZ(%arg1), %r21
  229. ldd 6*REG_SZ(%arg1), %r20
  230. ldd 7*REG_SZ(%arg1), %r19
  231. ldd 1*REG_SZ(%arg1), %arg1 /* do this one last! */
  232. tophys_r1 %sp
  233. b,l rfi_virt2real,%r2
  234. nop
  235. b,l save_control_regs,%r2 /* modifies r1, r2, r28 */
  236. nop
  237. load32 PA(r64_ret), %r2
  238. bv 0(%r31)
  239. nop
  240. r64_ret:
  241. /* restore CRs before going virtual in case we page fault */
  242. b,l restore_control_regs, %r2 /* modifies r1, r2, r26 */
  243. nop
  244. b,l rfi_real2virt,%r2
  245. nop
  246. tovirt_r1 %sp
  247. ldd -8(%sp), %sp /* restore SP */
  248. ldd -0x10(%sp), %rp /* restore RP */
  249. bv 0(%rp)
  250. nop
  251. ENDPROC_CFI(real64_call_asm)
  252. #endif
  253. .text
  254. /* http://lists.parisc-linux.org/hypermail/parisc-linux/10916.html
  255. ** GCC 3.3 and later has a new function in libgcc.a for
  256. ** comparing function pointers.
  257. */
  258. ENTRY_CFI(__canonicalize_funcptr_for_compare)
  259. #ifdef CONFIG_64BIT
  260. bve (%r2)
  261. #else
  262. bv %r0(%r2)
  263. #endif
  264. copy %r26,%r28
  265. ENDPROC_CFI(__canonicalize_funcptr_for_compare)