real2.S 6.1 KB

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