Text file
src/runtime/asm_s390x.s
Documentation: runtime
1 // Copyright 2016 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
5 #include "go_asm.h"
6 #include "go_tls.h"
7 #include "funcdata.h"
8 #include "textflag.h"
9
10 // _rt0_s390x_lib is common startup code for s390x systems when
11 // using -buildmode=c-archive or -buildmode=c-shared. The linker will
12 // arrange to invoke this function as a global constructor (for
13 // c-archive) or when the shared library is loaded (for c-shared).
14 // We expect argc and argv to be passed in the usual C ABI registers
15 // R2 and R3.
16 TEXT _rt0_s390x_lib(SB), NOSPLIT|NOFRAME, $0
17 STMG R6, R15, 48(R15)
18 MOVD R2, _rt0_s390x_lib_argc<>(SB)
19 MOVD R3, _rt0_s390x_lib_argv<>(SB)
20
21 // Save R6-R15 in the register save area of the calling function.
22 STMG R6, R15, 48(R15)
23
24 // Allocate 80 bytes on the stack.
25 MOVD $-80(R15), R15
26
27 // Save F8-F15 in our stack frame.
28 FMOVD F8, 16(R15)
29 FMOVD F9, 24(R15)
30 FMOVD F10, 32(R15)
31 FMOVD F11, 40(R15)
32 FMOVD F12, 48(R15)
33 FMOVD F13, 56(R15)
34 FMOVD F14, 64(R15)
35 FMOVD F15, 72(R15)
36
37 // Synchronous initialization.
38 MOVD $runtime·libpreinit(SB), R1
39 BL R1
40
41 // Create a new thread to finish Go runtime initialization.
42 MOVD _cgo_sys_thread_create(SB), R1
43 CMP R1, $0
44 BEQ nocgo
45 MOVD $_rt0_s390x_lib_go(SB), R2
46 MOVD $0, R3
47 BL R1
48 BR restore
49
50 nocgo:
51 MOVD $0x800000, R1 // stacksize
52 MOVD R1, 0(R15)
53 MOVD $_rt0_s390x_lib_go(SB), R1
54 MOVD R1, 8(R15) // fn
55 MOVD $runtime·newosproc(SB), R1
56 BL R1
57
58 restore:
59 // Restore F8-F15 from our stack frame.
60 FMOVD 16(R15), F8
61 FMOVD 24(R15), F9
62 FMOVD 32(R15), F10
63 FMOVD 40(R15), F11
64 FMOVD 48(R15), F12
65 FMOVD 56(R15), F13
66 FMOVD 64(R15), F14
67 FMOVD 72(R15), F15
68 MOVD $80(R15), R15
69
70 // Restore R6-R15.
71 LMG 48(R15), R6, R15
72 RET
73
74 // _rt0_s390x_lib_go initializes the Go runtime.
75 // This is started in a separate thread by _rt0_s390x_lib.
76 TEXT _rt0_s390x_lib_go(SB), NOSPLIT|NOFRAME, $0
77 MOVD _rt0_s390x_lib_argc<>(SB), R2
78 MOVD _rt0_s390x_lib_argv<>(SB), R3
79 MOVD $runtime·rt0_go(SB), R1
80 BR R1
81
82 DATA _rt0_s390x_lib_argc<>(SB)/8, $0
83 GLOBL _rt0_s390x_lib_argc<>(SB), NOPTR, $8
84 DATA _rt0_s90x_lib_argv<>(SB)/8, $0
85 GLOBL _rt0_s390x_lib_argv<>(SB), NOPTR, $8
86
87 TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0
88 // R2 = argc; R3 = argv; R11 = temp; R13 = g; R15 = stack pointer
89 // C TLS base pointer in AR0:AR1
90
91 // initialize essential registers
92 XOR R0, R0
93
94 SUB $24, R15
95 MOVW R2, 8(R15) // argc
96 MOVD R3, 16(R15) // argv
97
98 // create istack out of the given (operating system) stack.
99 // _cgo_init may update stackguard.
100 MOVD $runtime·g0(SB), g
101 MOVD R15, R11
102 SUB $(64*1024), R11
103 MOVD R11, g_stackguard0(g)
104 MOVD R11, g_stackguard1(g)
105 MOVD R11, (g_stack+stack_lo)(g)
106 MOVD R15, (g_stack+stack_hi)(g)
107
108 // if there is a _cgo_init, call it using the gcc ABI.
109 MOVD _cgo_init(SB), R11
110 CMPBEQ R11, $0, nocgo
111 MOVW AR0, R4 // (AR0 << 32 | AR1) is the TLS base pointer; MOVD is translated to EAR
112 SLD $32, R4, R4
113 MOVW AR1, R4 // arg 2: TLS base pointer
114 MOVD $setg_gcc<>(SB), R3 // arg 1: setg
115 MOVD g, R2 // arg 0: G
116 // C functions expect 160 bytes of space on caller stack frame
117 // and an 8-byte aligned stack pointer
118 MOVD R15, R9 // save current stack (R9 is preserved in the Linux ABI)
119 SUB $160, R15 // reserve 160 bytes
120 MOVD $~7, R6
121 AND R6, R15 // 8-byte align
122 BL R11 // this call clobbers volatile registers according to Linux ABI (R0-R5, R14)
123 MOVD R9, R15 // restore stack
124 XOR R0, R0 // zero R0
125
126 nocgo:
127 // update stackguard after _cgo_init
128 MOVD (g_stack+stack_lo)(g), R2
129 ADD $const__StackGuard, R2
130 MOVD R2, g_stackguard0(g)
131 MOVD R2, g_stackguard1(g)
132
133 // set the per-goroutine and per-mach "registers"
134 MOVD $runtime·m0(SB), R2
135
136 // save m->g0 = g0
137 MOVD g, m_g0(R2)
138 // save m0 to g0->m
139 MOVD R2, g_m(g)
140
141 BL runtime·check(SB)
142
143 // argc/argv are already prepared on stack
144 BL runtime·args(SB)
145 BL runtime·osinit(SB)
146 BL runtime·schedinit(SB)
147
148 // create a new goroutine to start program
149 MOVD $runtime·mainPC(SB), R2 // entry
150 SUB $24, R15
151 MOVD R2, 16(R15)
152 MOVD $0, 8(R15)
153 MOVD $0, 0(R15)
154 BL runtime·newproc(SB)
155 ADD $24, R15
156
157 // start this M
158 BL runtime·mstart(SB)
159
160 MOVD $0, 1(R0)
161 RET
162
163 DATA runtime·mainPC+0(SB)/8,$runtime·main(SB)
164 GLOBL runtime·mainPC(SB),RODATA,$8
165
166 TEXT runtime·breakpoint(SB),NOSPLIT|NOFRAME,$0-0
167 MOVD $0, 2(R0)
168 RET
169
170 TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0
171 RET
172
173 TEXT runtime·mstart(SB),NOSPLIT|TOPFRAME,$0
174 CALL runtime·mstart0(SB)
175 RET // not reached
176
177 /*
178 * go-routine
179 */
180
181 // void gogo(Gobuf*)
182 // restore state from Gobuf; longjmp
183 TEXT runtime·gogo(SB), NOSPLIT|NOFRAME, $0-8
184 MOVD buf+0(FP), R5
185 MOVD gobuf_g(R5), R6
186 MOVD 0(R6), R7 // make sure g != nil
187 BR gogo<>(SB)
188
189 TEXT gogo<>(SB), NOSPLIT|NOFRAME, $0
190 MOVD R6, g
191 BL runtime·save_g(SB)
192
193 MOVD 0(g), R4
194 MOVD gobuf_sp(R5), R15
195 MOVD gobuf_lr(R5), LR
196 MOVD gobuf_ret(R5), R3
197 MOVD gobuf_ctxt(R5), R12
198 MOVD $0, gobuf_sp(R5)
199 MOVD $0, gobuf_ret(R5)
200 MOVD $0, gobuf_lr(R5)
201 MOVD $0, gobuf_ctxt(R5)
202 CMP R0, R0 // set condition codes for == test, needed by stack split
203 MOVD gobuf_pc(R5), R6
204 BR (R6)
205
206 // void mcall(fn func(*g))
207 // Switch to m->g0's stack, call fn(g).
208 // Fn must never return. It should gogo(&g->sched)
209 // to keep running g.
210 TEXT runtime·mcall(SB), NOSPLIT, $-8-8
211 // Save caller state in g->sched
212 MOVD R15, (g_sched+gobuf_sp)(g)
213 MOVD LR, (g_sched+gobuf_pc)(g)
214 MOVD $0, (g_sched+gobuf_lr)(g)
215
216 // Switch to m->g0 & its stack, call fn.
217 MOVD g, R3
218 MOVD g_m(g), R8
219 MOVD m_g0(R8), g
220 BL runtime·save_g(SB)
221 CMP g, R3
222 BNE 2(PC)
223 BR runtime·badmcall(SB)
224 MOVD fn+0(FP), R12 // context
225 MOVD 0(R12), R4 // code pointer
226 MOVD (g_sched+gobuf_sp)(g), R15 // sp = m->g0->sched.sp
227 SUB $16, R15
228 MOVD R3, 8(R15)
229 MOVD $0, 0(R15)
230 BL (R4)
231 BR runtime·badmcall2(SB)
232
233 // systemstack_switch is a dummy routine that systemstack leaves at the bottom
234 // of the G stack. We need to distinguish the routine that
235 // lives at the bottom of the G stack from the one that lives
236 // at the top of the system stack because the one at the top of
237 // the system stack terminates the stack walk (see topofstack()).
238 TEXT runtime·systemstack_switch(SB), NOSPLIT, $0-0
239 UNDEF
240 BL (LR) // make sure this function is not leaf
241 RET
242
243 // func systemstack(fn func())
244 TEXT runtime·systemstack(SB), NOSPLIT, $0-8
245 MOVD fn+0(FP), R3 // R3 = fn
246 MOVD R3, R12 // context
247 MOVD g_m(g), R4 // R4 = m
248
249 MOVD m_gsignal(R4), R5 // R5 = gsignal
250 CMPBEQ g, R5, noswitch
251
252 MOVD m_g0(R4), R5 // R5 = g0
253 CMPBEQ g, R5, noswitch
254
255 MOVD m_curg(R4), R6
256 CMPBEQ g, R6, switch
257
258 // Bad: g is not gsignal, not g0, not curg. What is it?
259 // Hide call from linker nosplit analysis.
260 MOVD $runtime·badsystemstack(SB), R3
261 BL (R3)
262 BL runtime·abort(SB)
263
264 switch:
265 // save our state in g->sched. Pretend to
266 // be systemstack_switch if the G stack is scanned.
267 BL gosave_systemstack_switch<>(SB)
268
269 // switch to g0
270 MOVD R5, g
271 BL runtime·save_g(SB)
272 MOVD (g_sched+gobuf_sp)(g), R15
273
274 // call target function
275 MOVD 0(R12), R3 // code pointer
276 BL (R3)
277
278 // switch back to g
279 MOVD g_m(g), R3
280 MOVD m_curg(R3), g
281 BL runtime·save_g(SB)
282 MOVD (g_sched+gobuf_sp)(g), R15
283 MOVD $0, (g_sched+gobuf_sp)(g)
284 RET
285
286 noswitch:
287 // already on m stack, just call directly
288 // Using a tail call here cleans up tracebacks since we won't stop
289 // at an intermediate systemstack.
290 MOVD 0(R12), R3 // code pointer
291 MOVD 0(R15), LR // restore LR
292 ADD $8, R15
293 BR (R3)
294
295 /*
296 * support for morestack
297 */
298
299 // Called during function prolog when more stack is needed.
300 // Caller has already loaded:
301 // R3: framesize, R4: argsize, R5: LR
302 //
303 // The traceback routines see morestack on a g0 as being
304 // the top of a stack (for example, morestack calling newstack
305 // calling the scheduler calling newm calling gc), so we must
306 // record an argument size. For that purpose, it has no arguments.
307 TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
308 // Cannot grow scheduler stack (m->g0).
309 MOVD g_m(g), R7
310 MOVD m_g0(R7), R8
311 CMPBNE g, R8, 3(PC)
312 BL runtime·badmorestackg0(SB)
313 BL runtime·abort(SB)
314
315 // Cannot grow signal stack (m->gsignal).
316 MOVD m_gsignal(R7), R8
317 CMP g, R8
318 BNE 3(PC)
319 BL runtime·badmorestackgsignal(SB)
320 BL runtime·abort(SB)
321
322 // Called from f.
323 // Set g->sched to context in f.
324 MOVD R15, (g_sched+gobuf_sp)(g)
325 MOVD LR, R8
326 MOVD R8, (g_sched+gobuf_pc)(g)
327 MOVD R5, (g_sched+gobuf_lr)(g)
328 MOVD R12, (g_sched+gobuf_ctxt)(g)
329
330 // Called from f.
331 // Set m->morebuf to f's caller.
332 MOVD R5, (m_morebuf+gobuf_pc)(R7) // f's caller's PC
333 MOVD R15, (m_morebuf+gobuf_sp)(R7) // f's caller's SP
334 MOVD g, (m_morebuf+gobuf_g)(R7)
335
336 // Call newstack on m->g0's stack.
337 MOVD m_g0(R7), g
338 BL runtime·save_g(SB)
339 MOVD (g_sched+gobuf_sp)(g), R15
340 // Create a stack frame on g0 to call newstack.
341 MOVD $0, -8(R15) // Zero saved LR in frame
342 SUB $8, R15
343 BL runtime·newstack(SB)
344
345 // Not reached, but make sure the return PC from the call to newstack
346 // is still in this function, and not the beginning of the next.
347 UNDEF
348
349 TEXT runtime·morestack_noctxt(SB),NOSPLIT|NOFRAME,$0-0
350 MOVD $0, R12
351 BR runtime·morestack(SB)
352
353 // reflectcall: call a function with the given argument list
354 // func call(stackArgsType *_type, f *FuncVal, stackArgs *byte, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs).
355 // we don't have variable-sized frames, so we use a small number
356 // of constant-sized-frame functions to encode a few bits of size in the pc.
357 // Caution: ugly multiline assembly macros in your future!
358
359 #define DISPATCH(NAME,MAXSIZE) \
360 MOVD $MAXSIZE, R4; \
361 CMP R3, R4; \
362 BGT 3(PC); \
363 MOVD $NAME(SB), R5; \
364 BR (R5)
365 // Note: can't just "BR NAME(SB)" - bad inlining results.
366
367 TEXT ·reflectcall(SB), NOSPLIT, $-8-48
368 MOVWZ frameSize+32(FP), R3
369 DISPATCH(runtime·call16, 16)
370 DISPATCH(runtime·call32, 32)
371 DISPATCH(runtime·call64, 64)
372 DISPATCH(runtime·call128, 128)
373 DISPATCH(runtime·call256, 256)
374 DISPATCH(runtime·call512, 512)
375 DISPATCH(runtime·call1024, 1024)
376 DISPATCH(runtime·call2048, 2048)
377 DISPATCH(runtime·call4096, 4096)
378 DISPATCH(runtime·call8192, 8192)
379 DISPATCH(runtime·call16384, 16384)
380 DISPATCH(runtime·call32768, 32768)
381 DISPATCH(runtime·call65536, 65536)
382 DISPATCH(runtime·call131072, 131072)
383 DISPATCH(runtime·call262144, 262144)
384 DISPATCH(runtime·call524288, 524288)
385 DISPATCH(runtime·call1048576, 1048576)
386 DISPATCH(runtime·call2097152, 2097152)
387 DISPATCH(runtime·call4194304, 4194304)
388 DISPATCH(runtime·call8388608, 8388608)
389 DISPATCH(runtime·call16777216, 16777216)
390 DISPATCH(runtime·call33554432, 33554432)
391 DISPATCH(runtime·call67108864, 67108864)
392 DISPATCH(runtime·call134217728, 134217728)
393 DISPATCH(runtime·call268435456, 268435456)
394 DISPATCH(runtime·call536870912, 536870912)
395 DISPATCH(runtime·call1073741824, 1073741824)
396 MOVD $runtime·badreflectcall(SB), R5
397 BR (R5)
398
399 #define CALLFN(NAME,MAXSIZE) \
400 TEXT NAME(SB), WRAPPER, $MAXSIZE-48; \
401 NO_LOCAL_POINTERS; \
402 /* copy arguments to stack */ \
403 MOVD stackArgs+16(FP), R4; \
404 MOVWZ stackArgsSize+24(FP), R5; \
405 MOVD $stack-MAXSIZE(SP), R6; \
406 loopArgs: /* copy 256 bytes at a time */ \
407 CMP R5, $256; \
408 BLT tailArgs; \
409 SUB $256, R5; \
410 MVC $256, 0(R4), 0(R6); \
411 MOVD $256(R4), R4; \
412 MOVD $256(R6), R6; \
413 BR loopArgs; \
414 tailArgs: /* copy remaining bytes */ \
415 CMP R5, $0; \
416 BEQ callFunction; \
417 SUB $1, R5; \
418 EXRL $callfnMVC<>(SB), R5; \
419 callFunction: \
420 MOVD f+8(FP), R12; \
421 MOVD (R12), R8; \
422 PCDATA $PCDATA_StackMapIndex, $0; \
423 BL (R8); \
424 /* copy return values back */ \
425 MOVD stackArgsType+0(FP), R7; \
426 MOVD stackArgs+16(FP), R6; \
427 MOVWZ stackArgsSize+24(FP), R5; \
428 MOVD $stack-MAXSIZE(SP), R4; \
429 MOVWZ stackRetOffset+28(FP), R1; \
430 ADD R1, R4; \
431 ADD R1, R6; \
432 SUB R1, R5; \
433 BL callRet<>(SB); \
434 RET
435
436 // callRet copies return values back at the end of call*. This is a
437 // separate function so it can allocate stack space for the arguments
438 // to reflectcallmove. It does not follow the Go ABI; it expects its
439 // arguments in registers.
440 TEXT callRet<>(SB), NOSPLIT, $40-0
441 MOVD R7, 8(R15)
442 MOVD R6, 16(R15)
443 MOVD R4, 24(R15)
444 MOVD R5, 32(R15)
445 MOVD $0, 40(R15)
446 BL runtime·reflectcallmove(SB)
447 RET
448
449 CALLFN(·call16, 16)
450 CALLFN(·call32, 32)
451 CALLFN(·call64, 64)
452 CALLFN(·call128, 128)
453 CALLFN(·call256, 256)
454 CALLFN(·call512, 512)
455 CALLFN(·call1024, 1024)
456 CALLFN(·call2048, 2048)
457 CALLFN(·call4096, 4096)
458 CALLFN(·call8192, 8192)
459 CALLFN(·call16384, 16384)
460 CALLFN(·call32768, 32768)
461 CALLFN(·call65536, 65536)
462 CALLFN(·call131072, 131072)
463 CALLFN(·call262144, 262144)
464 CALLFN(·call524288, 524288)
465 CALLFN(·call1048576, 1048576)
466 CALLFN(·call2097152, 2097152)
467 CALLFN(·call4194304, 4194304)
468 CALLFN(·call8388608, 8388608)
469 CALLFN(·call16777216, 16777216)
470 CALLFN(·call33554432, 33554432)
471 CALLFN(·call67108864, 67108864)
472 CALLFN(·call134217728, 134217728)
473 CALLFN(·call268435456, 268435456)
474 CALLFN(·call536870912, 536870912)
475 CALLFN(·call1073741824, 1073741824)
476
477 // Not a function: target for EXRL (execute relative long) instruction.
478 TEXT callfnMVC<>(SB),NOSPLIT|NOFRAME,$0-0
479 MVC $1, 0(R4), 0(R6)
480
481 TEXT runtime·procyield(SB),NOSPLIT,$0-0
482 RET
483
484 // void jmpdefer(fv, sp);
485 // called from deferreturn.
486 // 1. grab stored LR for caller
487 // 2. sub 6 bytes to get back to BL deferreturn (size of BRASL instruction)
488 // 3. BR to fn
489 TEXT runtime·jmpdefer(SB),NOSPLIT|NOFRAME,$0-16
490 MOVD 0(R15), R1
491 SUB $6, R1, LR
492
493 MOVD fv+0(FP), R12
494 MOVD argp+8(FP), R15
495 SUB $8, R15
496 MOVD 0(R12), R3
497 BR (R3)
498
499 // Save state of caller into g->sched,
500 // but using fake PC from systemstack_switch.
501 // Must only be called from functions with no locals ($0)
502 // or else unwinding from systemstack_switch is incorrect.
503 // Smashes R1.
504 TEXT gosave_systemstack_switch<>(SB),NOSPLIT|NOFRAME,$0
505 MOVD $runtime·systemstack_switch(SB), R1
506 ADD $16, R1 // get past prologue
507 MOVD R1, (g_sched+gobuf_pc)(g)
508 MOVD R15, (g_sched+gobuf_sp)(g)
509 MOVD $0, (g_sched+gobuf_lr)(g)
510 MOVD $0, (g_sched+gobuf_ret)(g)
511 // Assert ctxt is zero. See func save.
512 MOVD (g_sched+gobuf_ctxt)(g), R1
513 CMPBEQ R1, $0, 2(PC)
514 BL runtime·abort(SB)
515 RET
516
517 // func asmcgocall(fn, arg unsafe.Pointer) int32
518 // Call fn(arg) on the scheduler stack,
519 // aligned appropriately for the gcc ABI.
520 // See cgocall.go for more details.
521 TEXT ·asmcgocall(SB),NOSPLIT,$0-20
522 // R2 = argc; R3 = argv; R11 = temp; R13 = g; R15 = stack pointer
523 // C TLS base pointer in AR0:AR1
524 MOVD fn+0(FP), R3
525 MOVD arg+8(FP), R4
526
527 MOVD R15, R2 // save original stack pointer
528 MOVD g, R5
529
530 // Figure out if we need to switch to m->g0 stack.
531 // We get called to create new OS threads too, and those
532 // come in on the m->g0 stack already.
533 MOVD g_m(g), R6
534 MOVD m_g0(R6), R6
535 CMPBEQ R6, g, g0
536 BL gosave_systemstack_switch<>(SB)
537 MOVD R6, g
538 BL runtime·save_g(SB)
539 MOVD (g_sched+gobuf_sp)(g), R15
540
541 // Now on a scheduling stack (a pthread-created stack).
542 g0:
543 // Save room for two of our pointers, plus 160 bytes of callee
544 // save area that lives on the caller stack.
545 SUB $176, R15
546 MOVD $~7, R6
547 AND R6, R15 // 8-byte alignment for gcc ABI
548 MOVD R5, 168(R15) // save old g on stack
549 MOVD (g_stack+stack_hi)(R5), R5
550 SUB R2, R5
551 MOVD R5, 160(R15) // save depth in old g stack (can't just save SP, as stack might be copied during a callback)
552 MOVD $0, 0(R15) // clear back chain pointer (TODO can we give it real back trace information?)
553 MOVD R4, R2 // arg in R2
554 BL R3 // can clobber: R0-R5, R14, F0-F3, F5, F7-F15
555
556 XOR R0, R0 // set R0 back to 0.
557 // Restore g, stack pointer.
558 MOVD 168(R15), g
559 BL runtime·save_g(SB)
560 MOVD (g_stack+stack_hi)(g), R5
561 MOVD 160(R15), R6
562 SUB R6, R5
563 MOVD R5, R15
564
565 MOVW R2, ret+16(FP)
566 RET
567
568 // cgocallback(fn, frame unsafe.Pointer, ctxt uintptr)
569 // See cgocall.go for more details.
570 TEXT ·cgocallback(SB),NOSPLIT,$24-24
571 NO_LOCAL_POINTERS
572
573 // Load m and g from thread-local storage.
574 MOVB runtime·iscgo(SB), R3
575 CMPBEQ R3, $0, nocgo
576 BL runtime·load_g(SB)
577
578 nocgo:
579 // If g is nil, Go did not create the current thread.
580 // Call needm to obtain one for temporary use.
581 // In this case, we're running on the thread stack, so there's
582 // lots of space, but the linker doesn't know. Hide the call from
583 // the linker analysis by using an indirect call.
584 CMPBEQ g, $0, needm
585
586 MOVD g_m(g), R8
587 MOVD R8, savedm-8(SP)
588 BR havem
589
590 needm:
591 MOVD g, savedm-8(SP) // g is zero, so is m.
592 MOVD $runtime·needm(SB), R3
593 BL (R3)
594
595 // Set m->sched.sp = SP, so that if a panic happens
596 // during the function we are about to execute, it will
597 // have a valid SP to run on the g0 stack.
598 // The next few lines (after the havem label)
599 // will save this SP onto the stack and then write
600 // the same SP back to m->sched.sp. That seems redundant,
601 // but if an unrecovered panic happens, unwindm will
602 // restore the g->sched.sp from the stack location
603 // and then systemstack will try to use it. If we don't set it here,
604 // that restored SP will be uninitialized (typically 0) and
605 // will not be usable.
606 MOVD g_m(g), R8
607 MOVD m_g0(R8), R3
608 MOVD R15, (g_sched+gobuf_sp)(R3)
609
610 havem:
611 // Now there's a valid m, and we're running on its m->g0.
612 // Save current m->g0->sched.sp on stack and then set it to SP.
613 // Save current sp in m->g0->sched.sp in preparation for
614 // switch back to m->curg stack.
615 // NOTE: unwindm knows that the saved g->sched.sp is at 8(R1) aka savedsp-16(SP).
616 MOVD m_g0(R8), R3
617 MOVD (g_sched+gobuf_sp)(R3), R4
618 MOVD R4, savedsp-24(SP) // must match frame size
619 MOVD R15, (g_sched+gobuf_sp)(R3)
620
621 // Switch to m->curg stack and call runtime.cgocallbackg.
622 // Because we are taking over the execution of m->curg
623 // but *not* resuming what had been running, we need to
624 // save that information (m->curg->sched) so we can restore it.
625 // We can restore m->curg->sched.sp easily, because calling
626 // runtime.cgocallbackg leaves SP unchanged upon return.
627 // To save m->curg->sched.pc, we push it onto the curg stack and
628 // open a frame the same size as cgocallback's g0 frame.
629 // Once we switch to the curg stack, the pushed PC will appear
630 // to be the return PC of cgocallback, so that the traceback
631 // will seamlessly trace back into the earlier calls.
632 MOVD m_curg(R8), g
633 BL runtime·save_g(SB)
634 MOVD (g_sched+gobuf_sp)(g), R4 // prepare stack as R4
635 MOVD (g_sched+gobuf_pc)(g), R5
636 MOVD R5, -(24+8)(R4) // "saved LR"; must match frame size
637 // Gather our arguments into registers.
638 MOVD fn+0(FP), R1
639 MOVD frame+8(FP), R2
640 MOVD ctxt+16(FP), R3
641 MOVD $-(24+8)(R4), R15 // switch stack; must match frame size
642 MOVD R1, 8(R15)
643 MOVD R2, 16(R15)
644 MOVD R3, 24(R15)
645 BL runtime·cgocallbackg(SB)
646
647 // Restore g->sched (== m->curg->sched) from saved values.
648 MOVD 0(R15), R5
649 MOVD R5, (g_sched+gobuf_pc)(g)
650 MOVD $(24+8)(R15), R4 // must match frame size
651 MOVD R4, (g_sched+gobuf_sp)(g)
652
653 // Switch back to m->g0's stack and restore m->g0->sched.sp.
654 // (Unlike m->curg, the g0 goroutine never uses sched.pc,
655 // so we do not have to restore it.)
656 MOVD g_m(g), R8
657 MOVD m_g0(R8), g
658 BL runtime·save_g(SB)
659 MOVD (g_sched+gobuf_sp)(g), R15
660 MOVD savedsp-24(SP), R4 // must match frame size
661 MOVD R4, (g_sched+gobuf_sp)(g)
662
663 // If the m on entry was nil, we called needm above to borrow an m
664 // for the duration of the call. Since the call is over, return it with dropm.
665 MOVD savedm-8(SP), R6
666 CMPBNE R6, $0, droppedm
667 MOVD $runtime·dropm(SB), R3
668 BL (R3)
669 droppedm:
670
671 // Done!
672 RET
673
674 // void setg(G*); set g. for use by needm.
675 TEXT runtime·setg(SB), NOSPLIT, $0-8
676 MOVD gg+0(FP), g
677 // This only happens if iscgo, so jump straight to save_g
678 BL runtime·save_g(SB)
679 RET
680
681 // void setg_gcc(G*); set g in C TLS.
682 // Must obey the gcc calling convention.
683 TEXT setg_gcc<>(SB),NOSPLIT|NOFRAME,$0-0
684 // The standard prologue clobbers LR (R14), which is callee-save in
685 // the C ABI, so we have to use NOFRAME and save LR ourselves.
686 MOVD LR, R1
687 // Also save g, R10, and R11 since they're callee-save in C ABI
688 MOVD R10, R3
689 MOVD g, R4
690 MOVD R11, R5
691
692 MOVD R2, g
693 BL runtime·save_g(SB)
694
695 MOVD R5, R11
696 MOVD R4, g
697 MOVD R3, R10
698 MOVD R1, LR
699 RET
700
701 TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
702 MOVW (R0), R0
703 UNDEF
704
705 // int64 runtime·cputicks(void)
706 TEXT runtime·cputicks(SB),NOSPLIT,$0-8
707 // The TOD clock on s390 counts from the year 1900 in ~250ps intervals.
708 // This means that since about 1972 the msb has been set, making the
709 // result of a call to STORE CLOCK (stck) a negative number.
710 // We clear the msb to make it positive.
711 STCK ret+0(FP) // serialises before and after call
712 MOVD ret+0(FP), R3 // R3 will wrap to 0 in the year 2043
713 SLD $1, R3
714 SRD $1, R3
715 MOVD R3, ret+0(FP)
716 RET
717
718 // AES hashing not implemented for s390x
719 TEXT runtime·memhash(SB),NOSPLIT|NOFRAME,$0-32
720 JMP runtime·memhashFallback(SB)
721 TEXT runtime·strhash(SB),NOSPLIT|NOFRAME,$0-24
722 JMP runtime·strhashFallback(SB)
723 TEXT runtime·memhash32(SB),NOSPLIT|NOFRAME,$0-24
724 JMP runtime·memhash32Fallback(SB)
725 TEXT runtime·memhash64(SB),NOSPLIT|NOFRAME,$0-24
726 JMP runtime·memhash64Fallback(SB)
727
728 TEXT runtime·return0(SB), NOSPLIT, $0
729 MOVW $0, R3
730 RET
731
732 // Called from cgo wrappers, this function returns g->m->curg.stack.hi.
733 // Must obey the gcc calling convention.
734 TEXT _cgo_topofstack(SB),NOSPLIT|NOFRAME,$0
735 // g (R13), R10, R11 and LR (R14) are callee-save in the C ABI, so save them
736 MOVD g, R1
737 MOVD R10, R3
738 MOVD LR, R4
739 MOVD R11, R5
740
741 BL runtime·load_g(SB) // clobbers g (R13), R10, R11
742 MOVD g_m(g), R2
743 MOVD m_curg(R2), R2
744 MOVD (g_stack+stack_hi)(R2), R2
745
746 MOVD R1, g
747 MOVD R3, R10
748 MOVD R4, LR
749 MOVD R5, R11
750 RET
751
752 // The top-most function running on a goroutine
753 // returns to goexit+PCQuantum.
754 TEXT runtime·goexit(SB),NOSPLIT|NOFRAME|TOPFRAME,$0-0
755 BYTE $0x07; BYTE $0x00; // 2-byte nop
756 BL runtime·goexit1(SB) // does not return
757 // traceback from goexit1 must hit code range of goexit
758 BYTE $0x07; BYTE $0x00; // 2-byte nop
759
760 TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
761 // Stores are already ordered on s390x, so this is just a
762 // compile barrier.
763 RET
764
765 // This is called from .init_array and follows the platform, not Go, ABI.
766 // We are overly conservative. We could only save the registers we use.
767 // However, since this function is only called once per loaded module
768 // performance is unimportant.
769 TEXT runtime·addmoduledata(SB),NOSPLIT|NOFRAME,$0-0
770 // Save R6-R15 in the register save area of the calling function.
771 // Don't bother saving F8-F15 as we aren't doing any calls.
772 STMG R6, R15, 48(R15)
773
774 // append the argument (passed in R2, as per the ELF ABI) to the
775 // moduledata linked list.
776 MOVD runtime·lastmoduledatap(SB), R1
777 MOVD R2, moduledata_next(R1)
778 MOVD R2, runtime·lastmoduledatap(SB)
779
780 // Restore R6-R15.
781 LMG 48(R15), R6, R15
782 RET
783
784 TEXT ·checkASM(SB),NOSPLIT,$0-1
785 MOVB $1, ret+0(FP)
786 RET
787
788 // gcWriteBarrier performs a heap pointer write and informs the GC.
789 //
790 // gcWriteBarrier does NOT follow the Go ABI. It takes two arguments:
791 // - R2 is the destination of the write
792 // - R3 is the value being written at R2.
793 // It clobbers R10 (the temp register).
794 // It does not clobber any other general-purpose registers,
795 // but may clobber others (e.g., floating point registers).
796 TEXT runtime·gcWriteBarrier(SB),NOSPLIT,$104
797 // Save the registers clobbered by the fast path.
798 MOVD R1, 96(R15)
799 MOVD R4, 104(R15)
800 MOVD g_m(g), R1
801 MOVD m_p(R1), R1
802 // Increment wbBuf.next position.
803 MOVD $16, R4
804 ADD (p_wbBuf+wbBuf_next)(R1), R4
805 MOVD R4, (p_wbBuf+wbBuf_next)(R1)
806 MOVD (p_wbBuf+wbBuf_end)(R1), R1
807 // Record the write.
808 MOVD R3, -16(R4) // Record value
809 MOVD (R2), R10 // TODO: This turns bad writes into bad reads.
810 MOVD R10, -8(R4) // Record *slot
811 // Is the buffer full?
812 CMPBEQ R4, R1, flush
813 ret:
814 MOVD 96(R15), R1
815 MOVD 104(R15), R4
816 // Do the write.
817 MOVD R3, (R2)
818 RET
819
820 flush:
821 // Save all general purpose registers since these could be
822 // clobbered by wbBufFlush and were not saved by the caller.
823 STMG R2, R3, 8(R15) // set R2 and R3 as arguments for wbBufFlush
824 MOVD R0, 24(R15)
825 // R1 already saved.
826 // R4 already saved.
827 STMG R5, R12, 32(R15) // save R5 - R12
828 // R13 is g.
829 // R14 is LR.
830 // R15 is SP.
831
832 // This takes arguments R2 and R3.
833 CALL runtime·wbBufFlush(SB)
834
835 LMG 8(R15), R2, R3 // restore R2 - R3
836 MOVD 24(R15), R0 // restore R0
837 LMG 32(R15), R5, R12 // restore R5 - R12
838 JMP ret
839
840 // Note: these functions use a special calling convention to save generated code space.
841 // Arguments are passed in registers, but the space for those arguments are allocated
842 // in the caller's stack frame. These stubs write the args into that stack space and
843 // then tail call to the corresponding runtime handler.
844 // The tail call makes these stubs disappear in backtraces.
845 TEXT runtime·panicIndex(SB),NOSPLIT,$0-16
846 MOVD R0, x+0(FP)
847 MOVD R1, y+8(FP)
848 JMP runtime·goPanicIndex(SB)
849 TEXT runtime·panicIndexU(SB),NOSPLIT,$0-16
850 MOVD R0, x+0(FP)
851 MOVD R1, y+8(FP)
852 JMP runtime·goPanicIndexU(SB)
853 TEXT runtime·panicSliceAlen(SB),NOSPLIT,$0-16
854 MOVD R1, x+0(FP)
855 MOVD R2, y+8(FP)
856 JMP runtime·goPanicSliceAlen(SB)
857 TEXT runtime·panicSliceAlenU(SB),NOSPLIT,$0-16
858 MOVD R1, x+0(FP)
859 MOVD R2, y+8(FP)
860 JMP runtime·goPanicSliceAlenU(SB)
861 TEXT runtime·panicSliceAcap(SB),NOSPLIT,$0-16
862 MOVD R1, x+0(FP)
863 MOVD R2, y+8(FP)
864 JMP runtime·goPanicSliceAcap(SB)
865 TEXT runtime·panicSliceAcapU(SB),NOSPLIT,$0-16
866 MOVD R1, x+0(FP)
867 MOVD R2, y+8(FP)
868 JMP runtime·goPanicSliceAcapU(SB)
869 TEXT runtime·panicSliceB(SB),NOSPLIT,$0-16
870 MOVD R0, x+0(FP)
871 MOVD R1, y+8(FP)
872 JMP runtime·goPanicSliceB(SB)
873 TEXT runtime·panicSliceBU(SB),NOSPLIT,$0-16
874 MOVD R0, x+0(FP)
875 MOVD R1, y+8(FP)
876 JMP runtime·goPanicSliceBU(SB)
877 TEXT runtime·panicSlice3Alen(SB),NOSPLIT,$0-16
878 MOVD R2, x+0(FP)
879 MOVD R3, y+8(FP)
880 JMP runtime·goPanicSlice3Alen(SB)
881 TEXT runtime·panicSlice3AlenU(SB),NOSPLIT,$0-16
882 MOVD R2, x+0(FP)
883 MOVD R3, y+8(FP)
884 JMP runtime·goPanicSlice3AlenU(SB)
885 TEXT runtime·panicSlice3Acap(SB),NOSPLIT,$0-16
886 MOVD R2, x+0(FP)
887 MOVD R3, y+8(FP)
888 JMP runtime·goPanicSlice3Acap(SB)
889 TEXT runtime·panicSlice3AcapU(SB),NOSPLIT,$0-16
890 MOVD R2, x+0(FP)
891 MOVD R3, y+8(FP)
892 JMP runtime·goPanicSlice3AcapU(SB)
893 TEXT runtime·panicSlice3B(SB),NOSPLIT,$0-16
894 MOVD R1, x+0(FP)
895 MOVD R2, y+8(FP)
896 JMP runtime·goPanicSlice3B(SB)
897 TEXT runtime·panicSlice3BU(SB),NOSPLIT,$0-16
898 MOVD R1, x+0(FP)
899 MOVD R2, y+8(FP)
900 JMP runtime·goPanicSlice3BU(SB)
901 TEXT runtime·panicSlice3C(SB),NOSPLIT,$0-16
902 MOVD R0, x+0(FP)
903 MOVD R1, y+8(FP)
904 JMP runtime·goPanicSlice3C(SB)
905 TEXT runtime·panicSlice3CU(SB),NOSPLIT,$0-16
906 MOVD R0, x+0(FP)
907 MOVD R1, y+8(FP)
908 JMP runtime·goPanicSlice3CU(SB)
909 TEXT runtime·panicSliceConvert(SB),NOSPLIT,$0-16
910 MOVD R2, x+0(FP)
911 MOVD R3, y+8(FP)
912 JMP runtime·goPanicSliceConvert(SB)
913
View as plain text