real2.S 6.3 KB

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