real2.S 6.2 KB

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