sclp.S 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  2. * Mini SCLP driver.
  3. *
  4. * Copyright IBM Corp. 2004,2009
  5. *
  6. * Author(s): Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>,
  7. * Heiko Carstens <heiko.carstens@de.ibm.com>,
  8. *
  9. */
  10. LC_EXT_NEW_PSW = 0x58 # addr of ext int handler
  11. LC_EXT_NEW_PSW_64 = 0x1b0 # addr of ext int handler 64 bit
  12. LC_EXT_INT_PARAM = 0x80 # addr of ext int parameter
  13. LC_EXT_INT_CODE = 0x86 # addr of ext int code
  14. LC_AR_MODE_ID = 0xa3
  15. #
  16. # Subroutine which waits synchronously until either an external interruption
  17. # or a timeout occurs.
  18. #
  19. # Parameters:
  20. # R2 = 0 for no timeout, non-zero for timeout in (approximated) seconds
  21. #
  22. # Returns:
  23. # R2 = 0 on interrupt, 2 on timeout
  24. # R3 = external interruption parameter if R2=0
  25. #
  26. _sclp_wait_int:
  27. stm %r6,%r15,24(%r15) # save registers
  28. basr %r13,0 # get base register
  29. .LbaseS1:
  30. ahi %r15,-96 # create stack frame
  31. la %r8,LC_EXT_NEW_PSW # register int handler
  32. la %r9,.LextpswS1-.LbaseS1(%r13)
  33. #ifdef CONFIG_64BIT
  34. tm LC_AR_MODE_ID,1
  35. jno .Lesa1
  36. la %r8,LC_EXT_NEW_PSW_64 # register int handler 64 bit
  37. la %r9,.LextpswS1_64-.LbaseS1(%r13)
  38. .Lesa1:
  39. #endif
  40. mvc .LoldpswS1-.LbaseS1(16,%r13),0(%r8)
  41. mvc 0(16,%r8),0(%r9)
  42. lhi %r6,0x0200 # cr mask for ext int (cr0.54)
  43. ltr %r2,%r2
  44. jz .LsetctS1
  45. ahi %r6,0x0800 # cr mask for clock int (cr0.52)
  46. stck .LtimeS1-.LbaseS1(%r13) # initiate timeout
  47. al %r2,.LtimeS1-.LbaseS1(%r13)
  48. st %r2,.LtimeS1-.LbaseS1(%r13)
  49. sckc .LtimeS1-.LbaseS1(%r13)
  50. .LsetctS1:
  51. stctl %c0,%c0,.LctlS1-.LbaseS1(%r13) # enable required interrupts
  52. l %r0,.LctlS1-.LbaseS1(%r13)
  53. lhi %r1,~(0x200 | 0x800) # clear old values
  54. nr %r1,%r0
  55. or %r1,%r6 # set new value
  56. st %r1,.LctlS1-.LbaseS1(%r13)
  57. lctl %c0,%c0,.LctlS1-.LbaseS1(%r13)
  58. st %r0,.LctlS1-.LbaseS1(%r13)
  59. lhi %r2,2 # return code for timeout
  60. .LloopS1:
  61. lpsw .LwaitpswS1-.LbaseS1(%r13) # wait until interrupt
  62. .LwaitS1:
  63. lh %r7,LC_EXT_INT_CODE
  64. chi %r7,0x1004 # timeout?
  65. je .LtimeoutS1
  66. chi %r7,0x2401 # service int?
  67. jne .LloopS1
  68. sr %r2,%r2
  69. l %r3,LC_EXT_INT_PARAM
  70. .LtimeoutS1:
  71. lctl %c0,%c0,.LctlS1-.LbaseS1(%r13) # restore interrupt setting
  72. # restore old handler
  73. mvc 0(16,%r8),.LoldpswS1-.LbaseS1(%r13)
  74. lm %r6,%r15,120(%r15) # restore registers
  75. br %r14 # return to caller
  76. .align 8
  77. .LoldpswS1:
  78. .long 0, 0, 0, 0 # old ext int PSW
  79. .LextpswS1:
  80. .long 0x00080000, 0x80000000+.LwaitS1 # PSW to handle ext int
  81. #ifdef CONFIG_64BIT
  82. .LextpswS1_64:
  83. .quad 0x0000000180000000, .LwaitS1 # PSW to handle ext int, 64 bit
  84. #endif
  85. .LwaitpswS1:
  86. .long 0x010a0000, 0x00000000+.LloopS1 # PSW to wait for ext int
  87. .LtimeS1:
  88. .quad 0 # current time
  89. .LctlS1:
  90. .long 0 # CT0 contents
  91. #
  92. # Subroutine to synchronously issue a service call.
  93. #
  94. # Parameters:
  95. # R2 = command word
  96. # R3 = sccb address
  97. #
  98. # Returns:
  99. # R2 = 0 on success, 1 on failure
  100. # R3 = sccb response code if R2 = 0
  101. #
  102. _sclp_servc:
  103. stm %r6,%r15,24(%r15) # save registers
  104. ahi %r15,-96 # create stack frame
  105. lr %r6,%r2 # save command word
  106. lr %r7,%r3 # save sccb address
  107. .LretryS2:
  108. lhi %r2,1 # error return code
  109. .insn rre,0xb2200000,%r6,%r7 # servc
  110. brc 1,.LendS2 # exit if not operational
  111. brc 8,.LnotbusyS2 # go on if not busy
  112. sr %r2,%r2 # wait until no longer busy
  113. bras %r14,_sclp_wait_int
  114. j .LretryS2 # retry
  115. .LnotbusyS2:
  116. sr %r2,%r2 # wait until result
  117. bras %r14,_sclp_wait_int
  118. sr %r2,%r2
  119. lh %r3,6(%r7)
  120. .LendS2:
  121. lm %r6,%r15,120(%r15) # restore registers
  122. br %r14
  123. #
  124. # Subroutine to set up the SCLP interface.
  125. #
  126. # Parameters:
  127. # R2 = 0 to activate, non-zero to deactivate
  128. #
  129. # Returns:
  130. # R2 = 0 on success, non-zero on failure
  131. #
  132. _sclp_setup:
  133. stm %r6,%r15,24(%r15) # save registers
  134. ahi %r15,-96 # create stack frame
  135. basr %r13,0 # get base register
  136. .LbaseS3:
  137. l %r6,.LsccbS0-.LbaseS3(%r13) # prepare init mask sccb
  138. mvc 0(.LinitendS3-.LinitsccbS3,%r6),.LinitsccbS3-.LbaseS3(%r13)
  139. ltr %r2,%r2 # initialization?
  140. jz .LdoinitS3 # go ahead
  141. # clear masks
  142. xc .LinitmaskS3-.LinitsccbS3(8,%r6),.LinitmaskS3-.LinitsccbS3(%r6)
  143. .LdoinitS3:
  144. l %r2,.LwritemaskS3-.LbaseS3(%r13)# get command word
  145. lr %r3,%r6 # get sccb address
  146. bras %r14,_sclp_servc # issue service call
  147. ltr %r2,%r2 # servc successful?
  148. jnz .LerrorS3
  149. chi %r3,0x20 # write mask successful?
  150. jne .LerrorS3
  151. # check masks
  152. la %r2,.LinitmaskS3-.LinitsccbS3(%r6)
  153. l %r1,0(%r2) # receive mask ok?
  154. n %r1,12(%r2)
  155. cl %r1,0(%r2)
  156. jne .LerrorS3
  157. l %r1,4(%r2) # send mask ok?
  158. n %r1,8(%r2)
  159. cl %r1,4(%r2)
  160. sr %r2,%r2
  161. je .LendS3
  162. .LerrorS3:
  163. lhi %r2,1 # error return code
  164. .LendS3:
  165. lm %r6,%r15,120(%r15) # restore registers
  166. br %r14
  167. .LwritemaskS3:
  168. .long 0x00780005 # SCLP command for write mask
  169. .LinitsccbS3:
  170. .word .LinitendS3-.LinitsccbS3
  171. .byte 0,0,0,0
  172. .word 0
  173. .word 0
  174. .word 4
  175. .LinitmaskS3:
  176. .long 0x80000000
  177. .long 0x40000000
  178. .long 0
  179. .long 0
  180. .LinitendS3:
  181. #
  182. # Subroutine which prints a given text to the SCLP console.
  183. #
  184. # Parameters:
  185. # R2 = address of nil-terminated ASCII text
  186. #
  187. # Returns:
  188. # R2 = 0 on success, 1 on failure
  189. #
  190. _sclp_print:
  191. stm %r6,%r15,24(%r15) # save registers
  192. ahi %r15,-96 # create stack frame
  193. basr %r13,0 # get base register
  194. .LbaseS4:
  195. l %r8,.LsccbS0-.LbaseS4(%r13) # prepare write data sccb
  196. mvc 0(.LmtoS4-.LwritesccbS4,%r8),.LwritesccbS4-.LbaseS4(%r13)
  197. la %r7,.LmtoS4-.LwritesccbS4(%r8) # current mto addr
  198. sr %r0,%r0
  199. l %r10,.Lascebc-.LbaseS4(%r13) # address of translation table
  200. .LinitmtoS4:
  201. # initialize mto
  202. mvc 0(.LmtoendS4-.LmtoS4,%r7),.LmtoS4-.LbaseS4(%r13)
  203. lhi %r6,.LmtoendS4-.LmtoS4 # current mto length
  204. .LloopS4:
  205. ic %r0,0(%r2) # get character
  206. ahi %r2,1
  207. ltr %r0,%r0 # end of string?
  208. jz .LfinalizemtoS4
  209. chi %r0,0x15 # end of line (NL)?
  210. jz .LfinalizemtoS4
  211. stc %r0,0(%r6,%r7) # copy to mto
  212. la %r11,0(%r6,%r7)
  213. tr 0(1,%r11),0(%r10) # translate to EBCDIC
  214. ahi %r6,1
  215. j .LloopS4
  216. .LfinalizemtoS4:
  217. sth %r6,0(%r7) # update mto length
  218. lh %r9,.LmdbS4-.LwritesccbS4(%r8) # update mdb length
  219. ar %r9,%r6
  220. sth %r9,.LmdbS4-.LwritesccbS4(%r8)
  221. lh %r9,.LevbufS4-.LwritesccbS4(%r8)# update evbuf length
  222. ar %r9,%r6
  223. sth %r9,.LevbufS4-.LwritesccbS4(%r8)
  224. lh %r9,0(%r8) # update sccb length
  225. ar %r9,%r6
  226. sth %r9,0(%r8)
  227. ar %r7,%r6 # update current mto address
  228. ltr %r0,%r0 # more characters?
  229. jnz .LinitmtoS4
  230. l %r2,.LwritedataS4-.LbaseS4(%r13)# write data
  231. lr %r3,%r8
  232. bras %r14,_sclp_servc
  233. ltr %r2,%r2 # servc successful?
  234. jnz .LendS4
  235. chi %r3,0x20 # write data successful?
  236. je .LendS4
  237. lhi %r2,1 # error return code
  238. .LendS4:
  239. lm %r6,%r15,120(%r15) # restore registers
  240. br %r14
  241. #
  242. # Function which prints a given text to the SCLP console.
  243. #
  244. # Parameters:
  245. # R2 = address of nil-terminated ASCII text
  246. #
  247. # Returns:
  248. # R2 = 0 on success, 1 on failure
  249. #
  250. .globl _sclp_print_early
  251. _sclp_print_early:
  252. stm %r6,%r15,24(%r15) # save registers
  253. ahi %r15,-96 # create stack frame
  254. #ifdef CONFIG_64BIT
  255. tm LC_AR_MODE_ID,1
  256. jno .Lesa2
  257. ahi %r15,-80
  258. stmh %r6,%r15,96(%r15) # store upper register halves
  259. .Lesa2:
  260. #endif
  261. lr %r10,%r2 # save string pointer
  262. lhi %r2,0
  263. bras %r14,_sclp_setup # enable console
  264. ltr %r2,%r2
  265. jnz .LendS5
  266. lr %r2,%r10
  267. bras %r14,_sclp_print # print string
  268. ltr %r2,%r2
  269. jnz .LendS5
  270. lhi %r2,1
  271. bras %r14,_sclp_setup # disable console
  272. .LendS5:
  273. #ifdef CONFIG_64BIT
  274. tm LC_AR_MODE_ID,1
  275. jno .Lesa3
  276. lmh %r6,%r15,96(%r15) # store upper register halves
  277. ahi %r15,80
  278. .Lesa3:
  279. #endif
  280. lm %r6,%r15,120(%r15) # restore registers
  281. br %r14
  282. .LwritedataS4:
  283. .long 0x00760005 # SCLP command for write data
  284. .LwritesccbS4:
  285. # sccb
  286. .word .LmtoS4-.LwritesccbS4
  287. .byte 0
  288. .byte 0,0,0
  289. .word 0
  290. # evbuf
  291. .LevbufS4:
  292. .word .LmtoS4-.LevbufS4
  293. .byte 0x02
  294. .byte 0
  295. .word 0
  296. .LmdbS4:
  297. # mdb
  298. .word .LmtoS4-.LmdbS4
  299. .word 1
  300. .long 0xd4c4c240
  301. .long 1
  302. # go
  303. .LgoS4:
  304. .word .LmtoS4-.LgoS4
  305. .word 1
  306. .long 0
  307. .byte 0,0,0,0,0,0,0,0
  308. .byte 0,0,0
  309. .byte 0
  310. .byte 0,0,0,0,0,0,0
  311. .byte 0
  312. .word 0
  313. .byte 0,0,0,0,0,0,0,0,0,0
  314. .byte 0,0,0,0,0,0,0,0
  315. .byte 0,0,0,0,0,0,0,0
  316. .LmtoS4:
  317. .word .LmtoendS4-.LmtoS4
  318. .word 4
  319. .word 0x1000
  320. .byte 0
  321. .byte 0,0,0
  322. .LmtoendS4:
  323. # Global constants
  324. .LsccbS0:
  325. .long _sclp_work_area
  326. .Lascebc:
  327. .long _ascebc
  328. .section .data,"aw",@progbits
  329. .balign 4096
  330. _sclp_work_area:
  331. .fill 4096
  332. .previous