aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/sys/unix/asm_zos_s390x.s
blob: 2f67ba86d5746c850a771a650fa85ef2e8f2264d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build zos && s390x && gc

#include "textflag.h"

#define PSALAA            1208(R0)
#define GTAB64(x)           80(x)
#define LCA64(x)            88(x)
#define CAA(x)               8(x)
#define EDCHPXV(x)        1016(x)       // in the CAA
#define SAVSTACK_ASYNC(x)  336(x)       // in the LCA

// SS_*, where x=SAVSTACK_ASYNC
#define SS_LE(x)             0(x)
#define SS_GO(x)             8(x)
#define SS_ERRNO(x)         16(x)
#define SS_ERRNOJR(x)       20(x)

#define LE_CALL BYTE $0x0D; BYTE $0x76; // BL R7, R6

TEXT ·clearErrno(SB),NOSPLIT,$0-0
	BL	addrerrno<>(SB)
	MOVD	$0, 0(R3)
	RET

// Returns the address of errno in R3.
TEXT addrerrno<>(SB),NOSPLIT|NOFRAME,$0-0
	// Get library control area (LCA).
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8

	// Get __errno FuncDesc.
	MOVD	CAA(R8), R9
	MOVD	EDCHPXV(R9), R9
	ADD	$(0x156*16), R9
	LMG	0(R9), R5, R6

	// Switch to saved LE stack.
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R4
	MOVD	$0, 0(R9)

	// Call __errno function.
	LE_CALL
	NOPH

	// Switch back to Go stack.
	XOR	R0, R0      // Restore R0 to $0.
	MOVD	R4, 0(R9)   // Save stack pointer.
	RET

TEXT ·syscall_syscall(SB),NOSPLIT,$0-56
	BL	runtime·entersyscall(SB)
	MOVD	a1+8(FP), R1
	MOVD	a2+16(FP), R2
	MOVD	a3+24(FP), R3

	// Get library control area (LCA).
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8

	// Get function.
	MOVD	CAA(R8), R9
	MOVD	EDCHPXV(R9), R9
	MOVD	trap+0(FP), R5
	SLD	$4, R5
	ADD	R5, R9
	LMG	0(R9), R5, R6

	// Restore LE stack.
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R4
	MOVD	$0, 0(R9)

	// Call function.
	LE_CALL
	NOPH
	XOR	R0, R0      // Restore R0 to $0.
	MOVD	R4, 0(R9)   // Save stack pointer.

	MOVD	R3, r1+32(FP)
	MOVD	R0, r2+40(FP)
	MOVD	R0, err+48(FP)
	MOVW	R3, R4
	CMP	R4, $-1
	BNE	done
	BL	addrerrno<>(SB)
	MOVWZ	0(R3), R3
	MOVD	R3, err+48(FP)
done:
	BL	runtime·exitsyscall(SB)
	RET

TEXT ·syscall_rawsyscall(SB),NOSPLIT,$0-56
	MOVD	a1+8(FP), R1
	MOVD	a2+16(FP), R2
	MOVD	a3+24(FP), R3

	// Get library control area (LCA).
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8

	// Get function.
	MOVD	CAA(R8), R9
	MOVD	EDCHPXV(R9), R9
	MOVD	trap+0(FP), R5
	SLD	$4, R5
	ADD	R5, R9
	LMG	0(R9), R5, R6

	// Restore LE stack.
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R4
	MOVD	$0, 0(R9)

	// Call function.
	LE_CALL
	NOPH
	XOR	R0, R0      // Restore R0 to $0.
	MOVD	R4, 0(R9)   // Save stack pointer.

	MOVD	R3, r1+32(FP)
	MOVD	R0, r2+40(FP)
	MOVD	R0, err+48(FP)
	MOVW	R3, R4
	CMP	R4, $-1
	BNE	done
	BL	addrerrno<>(SB)
	MOVWZ	0(R3), R3
	MOVD	R3, err+48(FP)
done:
	RET

TEXT ·syscall_syscall6(SB),NOSPLIT,$0-80
	BL	runtime·entersyscall(SB)
	MOVD	a1+8(FP), R1
	MOVD	a2+16(FP), R2
	MOVD	a3+24(FP), R3

	// Get library control area (LCA).
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8

	// Get function.
	MOVD	CAA(R8), R9
	MOVD	EDCHPXV(R9), R9
	MOVD	trap+0(FP), R5
	SLD	$4, R5
	ADD	R5, R9
	LMG	0(R9), R5, R6

	// Restore LE stack.
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R4
	MOVD	$0, 0(R9)

	// Fill in parameter list.
	MOVD	a4+32(FP), R12
	MOVD	R12, (2176+24)(R4)
	MOVD	a5+40(FP), R12
	MOVD	R12, (2176+32)(R4)
	MOVD	a6+48(FP), R12
	MOVD	R12, (2176+40)(R4)

	// Call function.
	LE_CALL
	NOPH
	XOR	R0, R0      // Restore R0 to $0.
	MOVD	R4, 0(R9)   // Save stack pointer.

	MOVD	R3, r1+56(FP)
	MOVD	R0, r2+64(FP)
	MOVD	R0, err+72(FP)
	MOVW	R3, R4
	CMP	R4, $-1
	BNE	done
	BL	addrerrno<>(SB)
	MOVWZ	0(R3), R3
	MOVD	R3, err+72(FP)
done:
	BL	runtime·exitsyscall(SB)
	RET

TEXT ·syscall_rawsyscall6(SB),NOSPLIT,$0-80
	MOVD	a1+8(FP), R1
	MOVD	a2+16(FP), R2
	MOVD	a3+24(FP), R3

	// Get library control area (LCA).
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8

	// Get function.
	MOVD	CAA(R8), R9
	MOVD	EDCHPXV(R9), R9
	MOVD	trap+0(FP), R5
	SLD	$4, R5
	ADD	R5, R9
	LMG	0(R9), R5, R6

	// Restore LE stack.
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R4
	MOVD	$0, 0(R9)

	// Fill in parameter list.
	MOVD	a4+32(FP), R12
	MOVD	R12, (2176+24)(R4)
	MOVD	a5+40(FP), R12
	MOVD	R12, (2176+32)(R4)
	MOVD	a6+48(FP), R12
	MOVD	R12, (2176+40)(R4)

	// Call function.
	LE_CALL
	NOPH
	XOR	R0, R0      // Restore R0 to $0.
	MOVD	R4, 0(R9)   // Save stack pointer.

	MOVD	R3, r1+56(FP)
	MOVD	R0, r2+64(FP)
	MOVD	R0, err+72(FP)
	MOVW	R3, R4
	CMP	R4, $-1
	BNE	done
	BL	·rrno<>(SB)
	MOVWZ	0(R3), R3
	MOVD	R3, err+72(FP)
done:
	RET

TEXT ·syscall_syscall9(SB),NOSPLIT,$0
	BL	runtime·entersyscall(SB)
	MOVD	a1+8(FP), R1
	MOVD	a2+16(FP), R2
	MOVD	a3+24(FP), R3

	// Get library control area (LCA).
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8

	// Get function.
	MOVD	CAA(R8), R9
	MOVD	EDCHPXV(R9), R9
	MOVD	trap+0(FP), R5
	SLD	$4, R5
	ADD	R5, R9
	LMG	0(R9), R5, R6

	// Restore LE stack.
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R4
	MOVD	$0, 0(R9)

	// Fill in parameter list.
	MOVD	a4+32(FP), R12
	MOVD	R12, (2176+24)(R4)
	MOVD	a5+40(FP), R12
	MOVD	R12, (2176+32)(R4)
	MOVD	a6+48(FP), R12
	MOVD	R12, (2176+40)(R4)
	MOVD	a7+56(FP), R12
	MOVD	R12, (2176+48)(R4)
	MOVD	a8+64(FP), R12
	MOVD	R12, (2176+56)(R4)
	MOVD	a9+72(FP), R12
	MOVD	R12, (2176+64)(R4)

	// Call function.
	LE_CALL
	NOPH
	XOR	R0, R0      // Restore R0 to $0.
	MOVD	R4, 0(R9)   // Save stack pointer.

	MOVD	R3, r1+80(FP)
	MOVD	R0, r2+88(FP)
	MOVD	R0, err+96(FP)
	MOVW	R3, R4
	CMP	R4, $-1
	BNE	done
	BL	addrerrno<>(SB)
	MOVWZ	0(R3), R3
	MOVD	R3, err+96(FP)
done:
        BL	runtime·exitsyscall(SB)
        RET

TEXT ·syscall_rawsyscall9(SB),NOSPLIT,$0
	MOVD	a1+8(FP), R1
	MOVD	a2+16(FP), R2
	MOVD	a3+24(FP), R3

	// Get library control area (LCA).
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8

	// Get function.
	MOVD	CAA(R8), R9
	MOVD	EDCHPXV(R9), R9
	MOVD	trap+0(FP), R5
	SLD	$4, R5
	ADD	R5, R9
	LMG	0(R9), R5, R6

	// Restore LE stack.
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R4
	MOVD	$0, 0(R9)

	// Fill in parameter list.
	MOVD	a4+32(FP), R12
	MOVD	R12, (2176+24)(R4)
	MOVD	a5+40(FP), R12
	MOVD	R12, (2176+32)(R4)
	MOVD	a6+48(FP), R12
	MOVD	R12, (2176+40)(R4)
	MOVD	a7+56(FP), R12
	MOVD	R12, (2176+48)(R4)
	MOVD	a8+64(FP), R12
	MOVD	R12, (2176+56)(R4)
	MOVD	a9+72(FP), R12
	MOVD	R12, (2176+64)(R4)

	// Call function.
	LE_CALL
	NOPH
	XOR	R0, R0      // Restore R0 to $0.
	MOVD	R4, 0(R9)   // Save stack pointer.

	MOVD	R3, r1+80(FP)
	MOVD	R0, r2+88(FP)
	MOVD	R0, err+96(FP)
	MOVW	R3, R4
	CMP	R4, $-1
	BNE	done
	BL	addrerrno<>(SB)
	MOVWZ	0(R3), R3
	MOVD	R3, err+96(FP)
done:
	RET

// func svcCall(fnptr unsafe.Pointer, argv *unsafe.Pointer, dsa *uint64)
TEXT ·svcCall(SB),NOSPLIT,$0
	BL	runtime·save_g(SB)   // Save g and stack pointer
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	R15, 0(R9)

	MOVD	argv+8(FP), R1       // Move function arguments into registers
	MOVD	dsa+16(FP), g
	MOVD	fnptr+0(FP), R15

	BYTE	$0x0D                // Branch to function
	BYTE	$0xEF

	BL	runtime·load_g(SB)   // Restore g and stack pointer
	MOVW	PSALAA, R8
	MOVD	LCA64(R8), R8
	MOVD	SAVSTACK_ASYNC(R8), R9
	MOVD	0(R9), R15

	RET

// func svcLoad(name *byte) unsafe.Pointer
TEXT ·svcLoad(SB),NOSPLIT,$0
	MOVD	R15, R2          // Save go stack pointer
	MOVD	name+0(FP), R0   // Move SVC args into registers
	MOVD	$0x80000000, R1
	MOVD	$0, R15
	BYTE	$0x0A            // SVC 08 LOAD
	BYTE	$0x08
	MOVW	R15, R3          // Save return code from SVC
	MOVD	R2, R15          // Restore go stack pointer
	CMP	R3, $0           // Check SVC return code
	BNE	error

	MOVD	$-2, R3          // Reset last bit of entry point to zero
	AND	R0, R3
	MOVD	R3, addr+8(FP)   // Return entry point returned by SVC
	CMP	R0, R3           // Check if last bit of entry point was set
	BNE	done

	MOVD	R15, R2          // Save go stack pointer
	MOVD	$0, R15          // Move SVC args into registers (entry point still in r0 from SVC 08)
	BYTE	$0x0A            // SVC 09 DELETE
	BYTE	$0x09
	MOVD	R2, R15          // Restore go stack pointer

error:
	MOVD	$0, addr+8(FP)   // Return 0 on failure
done:
	XOR	R0, R0           // Reset r0 to 0
	RET

// func svcUnload(name *byte, fnptr unsafe.Pointer) int64
TEXT ·svcUnload(SB),NOSPLIT,$0
	MOVD	R15, R2          // Save go stack pointer
	MOVD	name+0(FP), R0   // Move SVC args into registers
	MOVD	addr+8(FP), R15
	BYTE	$0x0A            // SVC 09
	BYTE	$0x09
	XOR	R0, R0           // Reset r0 to 0
	MOVD	R15, R1          // Save SVC return code
	MOVD	R2, R15          // Restore go stack pointer
	MOVD	R1, rc+0(FP)     // Return SVC return code
	RET

// func gettid() uint64
TEXT ·gettid(SB), NOSPLIT, $0
	// Get library control area (LCA).
	MOVW PSALAA, R8
	MOVD LCA64(R8), R8

	// Get CEECAATHDID
	MOVD CAA(R8), R9
	MOVD 0x3D0(R9), R9
	MOVD R9, ret+0(FP)

	RET