asm_zos_s390x.s 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. // Copyright 2020 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build zos && s390x && gc
  5. // +build zos
  6. // +build s390x
  7. // +build gc
  8. #include "textflag.h"
  9. #define PSALAA 1208(R0)
  10. #define GTAB64(x) 80(x)
  11. #define LCA64(x) 88(x)
  12. #define CAA(x) 8(x)
  13. #define EDCHPXV(x) 1016(x) // in the CAA
  14. #define SAVSTACK_ASYNC(x) 336(x) // in the LCA
  15. // SS_*, where x=SAVSTACK_ASYNC
  16. #define SS_LE(x) 0(x)
  17. #define SS_GO(x) 8(x)
  18. #define SS_ERRNO(x) 16(x)
  19. #define SS_ERRNOJR(x) 20(x)
  20. #define LE_CALL BYTE $0x0D; BYTE $0x76; // BL R7, R6
  21. TEXT ·clearErrno(SB),NOSPLIT,$0-0
  22. BL addrerrno<>(SB)
  23. MOVD $0, 0(R3)
  24. RET
  25. // Returns the address of errno in R3.
  26. TEXT addrerrno<>(SB),NOSPLIT|NOFRAME,$0-0
  27. // Get library control area (LCA).
  28. MOVW PSALAA, R8
  29. MOVD LCA64(R8), R8
  30. // Get __errno FuncDesc.
  31. MOVD CAA(R8), R9
  32. MOVD EDCHPXV(R9), R9
  33. ADD $(0x156*16), R9
  34. LMG 0(R9), R5, R6
  35. // Switch to saved LE stack.
  36. MOVD SAVSTACK_ASYNC(R8), R9
  37. MOVD 0(R9), R4
  38. MOVD $0, 0(R9)
  39. // Call __errno function.
  40. LE_CALL
  41. NOPH
  42. // Switch back to Go stack.
  43. XOR R0, R0 // Restore R0 to $0.
  44. MOVD R4, 0(R9) // Save stack pointer.
  45. RET
  46. TEXT ·syscall_syscall(SB),NOSPLIT,$0-56
  47. BL runtime·entersyscall(SB)
  48. MOVD a1+8(FP), R1
  49. MOVD a2+16(FP), R2
  50. MOVD a3+24(FP), R3
  51. // Get library control area (LCA).
  52. MOVW PSALAA, R8
  53. MOVD LCA64(R8), R8
  54. // Get function.
  55. MOVD CAA(R8), R9
  56. MOVD EDCHPXV(R9), R9
  57. MOVD trap+0(FP), R5
  58. SLD $4, R5
  59. ADD R5, R9
  60. LMG 0(R9), R5, R6
  61. // Restore LE stack.
  62. MOVD SAVSTACK_ASYNC(R8), R9
  63. MOVD 0(R9), R4
  64. MOVD $0, 0(R9)
  65. // Call function.
  66. LE_CALL
  67. NOPH
  68. XOR R0, R0 // Restore R0 to $0.
  69. MOVD R4, 0(R9) // Save stack pointer.
  70. MOVD R3, r1+32(FP)
  71. MOVD R0, r2+40(FP)
  72. MOVD R0, err+48(FP)
  73. MOVW R3, R4
  74. CMP R4, $-1
  75. BNE done
  76. BL addrerrno<>(SB)
  77. MOVWZ 0(R3), R3
  78. MOVD R3, err+48(FP)
  79. done:
  80. BL runtime·exitsyscall(SB)
  81. RET
  82. TEXT ·syscall_rawsyscall(SB),NOSPLIT,$0-56
  83. MOVD a1+8(FP), R1
  84. MOVD a2+16(FP), R2
  85. MOVD a3+24(FP), R3
  86. // Get library control area (LCA).
  87. MOVW PSALAA, R8
  88. MOVD LCA64(R8), R8
  89. // Get function.
  90. MOVD CAA(R8), R9
  91. MOVD EDCHPXV(R9), R9
  92. MOVD trap+0(FP), R5
  93. SLD $4, R5
  94. ADD R5, R9
  95. LMG 0(R9), R5, R6
  96. // Restore LE stack.
  97. MOVD SAVSTACK_ASYNC(R8), R9
  98. MOVD 0(R9), R4
  99. MOVD $0, 0(R9)
  100. // Call function.
  101. LE_CALL
  102. NOPH
  103. XOR R0, R0 // Restore R0 to $0.
  104. MOVD R4, 0(R9) // Save stack pointer.
  105. MOVD R3, r1+32(FP)
  106. MOVD R0, r2+40(FP)
  107. MOVD R0, err+48(FP)
  108. MOVW R3, R4
  109. CMP R4, $-1
  110. BNE done
  111. BL addrerrno<>(SB)
  112. MOVWZ 0(R3), R3
  113. MOVD R3, err+48(FP)
  114. done:
  115. RET
  116. TEXT ·syscall_syscall6(SB),NOSPLIT,$0-80
  117. BL runtime·entersyscall(SB)
  118. MOVD a1+8(FP), R1
  119. MOVD a2+16(FP), R2
  120. MOVD a3+24(FP), R3
  121. // Get library control area (LCA).
  122. MOVW PSALAA, R8
  123. MOVD LCA64(R8), R8
  124. // Get function.
  125. MOVD CAA(R8), R9
  126. MOVD EDCHPXV(R9), R9
  127. MOVD trap+0(FP), R5
  128. SLD $4, R5
  129. ADD R5, R9
  130. LMG 0(R9), R5, R6
  131. // Restore LE stack.
  132. MOVD SAVSTACK_ASYNC(R8), R9
  133. MOVD 0(R9), R4
  134. MOVD $0, 0(R9)
  135. // Fill in parameter list.
  136. MOVD a4+32(FP), R12
  137. MOVD R12, (2176+24)(R4)
  138. MOVD a5+40(FP), R12
  139. MOVD R12, (2176+32)(R4)
  140. MOVD a6+48(FP), R12
  141. MOVD R12, (2176+40)(R4)
  142. // Call function.
  143. LE_CALL
  144. NOPH
  145. XOR R0, R0 // Restore R0 to $0.
  146. MOVD R4, 0(R9) // Save stack pointer.
  147. MOVD R3, r1+56(FP)
  148. MOVD R0, r2+64(FP)
  149. MOVD R0, err+72(FP)
  150. MOVW R3, R4
  151. CMP R4, $-1
  152. BNE done
  153. BL addrerrno<>(SB)
  154. MOVWZ 0(R3), R3
  155. MOVD R3, err+72(FP)
  156. done:
  157. BL runtime·exitsyscall(SB)
  158. RET
  159. TEXT ·syscall_rawsyscall6(SB),NOSPLIT,$0-80
  160. MOVD a1+8(FP), R1
  161. MOVD a2+16(FP), R2
  162. MOVD a3+24(FP), R3
  163. // Get library control area (LCA).
  164. MOVW PSALAA, R8
  165. MOVD LCA64(R8), R8
  166. // Get function.
  167. MOVD CAA(R8), R9
  168. MOVD EDCHPXV(R9), R9
  169. MOVD trap+0(FP), R5
  170. SLD $4, R5
  171. ADD R5, R9
  172. LMG 0(R9), R5, R6
  173. // Restore LE stack.
  174. MOVD SAVSTACK_ASYNC(R8), R9
  175. MOVD 0(R9), R4
  176. MOVD $0, 0(R9)
  177. // Fill in parameter list.
  178. MOVD a4+32(FP), R12
  179. MOVD R12, (2176+24)(R4)
  180. MOVD a5+40(FP), R12
  181. MOVD R12, (2176+32)(R4)
  182. MOVD a6+48(FP), R12
  183. MOVD R12, (2176+40)(R4)
  184. // Call function.
  185. LE_CALL
  186. NOPH
  187. XOR R0, R0 // Restore R0 to $0.
  188. MOVD R4, 0(R9) // Save stack pointer.
  189. MOVD R3, r1+56(FP)
  190. MOVD R0, r2+64(FP)
  191. MOVD R0, err+72(FP)
  192. MOVW R3, R4
  193. CMP R4, $-1
  194. BNE done
  195. BL ·rrno<>(SB)
  196. MOVWZ 0(R3), R3
  197. MOVD R3, err+72(FP)
  198. done:
  199. RET
  200. TEXT ·syscall_syscall9(SB),NOSPLIT,$0
  201. BL runtime·entersyscall(SB)
  202. MOVD a1+8(FP), R1
  203. MOVD a2+16(FP), R2
  204. MOVD a3+24(FP), R3
  205. // Get library control area (LCA).
  206. MOVW PSALAA, R8
  207. MOVD LCA64(R8), R8
  208. // Get function.
  209. MOVD CAA(R8), R9
  210. MOVD EDCHPXV(R9), R9
  211. MOVD trap+0(FP), R5
  212. SLD $4, R5
  213. ADD R5, R9
  214. LMG 0(R9), R5, R6
  215. // Restore LE stack.
  216. MOVD SAVSTACK_ASYNC(R8), R9
  217. MOVD 0(R9), R4
  218. MOVD $0, 0(R9)
  219. // Fill in parameter list.
  220. MOVD a4+32(FP), R12
  221. MOVD R12, (2176+24)(R4)
  222. MOVD a5+40(FP), R12
  223. MOVD R12, (2176+32)(R4)
  224. MOVD a6+48(FP), R12
  225. MOVD R12, (2176+40)(R4)
  226. MOVD a7+56(FP), R12
  227. MOVD R12, (2176+48)(R4)
  228. MOVD a8+64(FP), R12
  229. MOVD R12, (2176+56)(R4)
  230. MOVD a9+72(FP), R12
  231. MOVD R12, (2176+64)(R4)
  232. // Call function.
  233. LE_CALL
  234. NOPH
  235. XOR R0, R0 // Restore R0 to $0.
  236. MOVD R4, 0(R9) // Save stack pointer.
  237. MOVD R3, r1+80(FP)
  238. MOVD R0, r2+88(FP)
  239. MOVD R0, err+96(FP)
  240. MOVW R3, R4
  241. CMP R4, $-1
  242. BNE done
  243. BL addrerrno<>(SB)
  244. MOVWZ 0(R3), R3
  245. MOVD R3, err+96(FP)
  246. done:
  247. BL runtime·exitsyscall(SB)
  248. RET
  249. TEXT ·syscall_rawsyscall9(SB),NOSPLIT,$0
  250. MOVD a1+8(FP), R1
  251. MOVD a2+16(FP), R2
  252. MOVD a3+24(FP), R3
  253. // Get library control area (LCA).
  254. MOVW PSALAA, R8
  255. MOVD LCA64(R8), R8
  256. // Get function.
  257. MOVD CAA(R8), R9
  258. MOVD EDCHPXV(R9), R9
  259. MOVD trap+0(FP), R5
  260. SLD $4, R5
  261. ADD R5, R9
  262. LMG 0(R9), R5, R6
  263. // Restore LE stack.
  264. MOVD SAVSTACK_ASYNC(R8), R9
  265. MOVD 0(R9), R4
  266. MOVD $0, 0(R9)
  267. // Fill in parameter list.
  268. MOVD a4+32(FP), R12
  269. MOVD R12, (2176+24)(R4)
  270. MOVD a5+40(FP), R12
  271. MOVD R12, (2176+32)(R4)
  272. MOVD a6+48(FP), R12
  273. MOVD R12, (2176+40)(R4)
  274. MOVD a7+56(FP), R12
  275. MOVD R12, (2176+48)(R4)
  276. MOVD a8+64(FP), R12
  277. MOVD R12, (2176+56)(R4)
  278. MOVD a9+72(FP), R12
  279. MOVD R12, (2176+64)(R4)
  280. // Call function.
  281. LE_CALL
  282. NOPH
  283. XOR R0, R0 // Restore R0 to $0.
  284. MOVD R4, 0(R9) // Save stack pointer.
  285. MOVD R3, r1+80(FP)
  286. MOVD R0, r2+88(FP)
  287. MOVD R0, err+96(FP)
  288. MOVW R3, R4
  289. CMP R4, $-1
  290. BNE done
  291. BL addrerrno<>(SB)
  292. MOVWZ 0(R3), R3
  293. MOVD R3, err+96(FP)
  294. done:
  295. RET
  296. // func svcCall(fnptr unsafe.Pointer, argv *unsafe.Pointer, dsa *uint64)
  297. TEXT ·svcCall(SB),NOSPLIT,$0
  298. BL runtime·save_g(SB) // Save g and stack pointer
  299. MOVW PSALAA, R8
  300. MOVD LCA64(R8), R8
  301. MOVD SAVSTACK_ASYNC(R8), R9
  302. MOVD R15, 0(R9)
  303. MOVD argv+8(FP), R1 // Move function arguments into registers
  304. MOVD dsa+16(FP), g
  305. MOVD fnptr+0(FP), R15
  306. BYTE $0x0D // Branch to function
  307. BYTE $0xEF
  308. BL runtime·load_g(SB) // Restore g and stack pointer
  309. MOVW PSALAA, R8
  310. MOVD LCA64(R8), R8
  311. MOVD SAVSTACK_ASYNC(R8), R9
  312. MOVD 0(R9), R15
  313. RET
  314. // func svcLoad(name *byte) unsafe.Pointer
  315. TEXT ·svcLoad(SB),NOSPLIT,$0
  316. MOVD R15, R2 // Save go stack pointer
  317. MOVD name+0(FP), R0 // Move SVC args into registers
  318. MOVD $0x80000000, R1
  319. MOVD $0, R15
  320. BYTE $0x0A // SVC 08 LOAD
  321. BYTE $0x08
  322. MOVW R15, R3 // Save return code from SVC
  323. MOVD R2, R15 // Restore go stack pointer
  324. CMP R3, $0 // Check SVC return code
  325. BNE error
  326. MOVD $-2, R3 // Reset last bit of entry point to zero
  327. AND R0, R3
  328. MOVD R3, addr+8(FP) // Return entry point returned by SVC
  329. CMP R0, R3 // Check if last bit of entry point was set
  330. BNE done
  331. MOVD R15, R2 // Save go stack pointer
  332. MOVD $0, R15 // Move SVC args into registers (entry point still in r0 from SVC 08)
  333. BYTE $0x0A // SVC 09 DELETE
  334. BYTE $0x09
  335. MOVD R2, R15 // Restore go stack pointer
  336. error:
  337. MOVD $0, addr+8(FP) // Return 0 on failure
  338. done:
  339. XOR R0, R0 // Reset r0 to 0
  340. RET
  341. // func svcUnload(name *byte, fnptr unsafe.Pointer) int64
  342. TEXT ·svcUnload(SB),NOSPLIT,$0
  343. MOVD R15, R2 // Save go stack pointer
  344. MOVD name+0(FP), R0 // Move SVC args into registers
  345. MOVD addr+8(FP), R15
  346. BYTE $0x0A // SVC 09
  347. BYTE $0x09
  348. XOR R0, R0 // Reset r0 to 0
  349. MOVD R15, R1 // Save SVC return code
  350. MOVD R2, R15 // Restore go stack pointer
  351. MOVD R1, rc+0(FP) // Return SVC return code
  352. RET
  353. // func gettid() uint64
  354. TEXT ·gettid(SB), NOSPLIT, $0
  355. // Get library control area (LCA).
  356. MOVW PSALAA, R8
  357. MOVD LCA64(R8), R8
  358. // Get CEECAATHDID
  359. MOVD CAA(R8), R9
  360. MOVD 0x3D0(R9), R9
  361. MOVD R9, ret+0(FP)
  362. RET