@@ -304,33 +304,92 @@ TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
304
304
RET
305
305
306
306
// Thread related functions
307
- // Note: On darwin/arm64 , the runtime always use runtime/cgo to
308
- // create threads , so all thread related functions will just exit with a
309
- // unique status.
310
307
308
+ // mstart_stub is the first function executed on a new thread started by pthread_create.
309
+ // It just does some low - level setup and then calls mstart.
310
+ // Note: called with the C calling convention.
311
311
TEXT runtime·mstart_stub(SB) , NOSPLIT , $ 0
312
- MOVW $ 44 , R0
313
- BL libc_exit(SB)
312
+ // R0 points to the m.
313
+ // We are already on m's g0 stack.
314
+
315
+ // Save callee - save registers.
316
+ SUB $ 144 , RSP
317
+ MOVD R19 , 0 ( RSP )
318
+ MOVD R20 , 8 ( RSP )
319
+ MOVD R21 , 16 ( RSP )
320
+ MOVD R22 , 24 ( RSP )
321
+ MOVD R23 , 32 ( RSP )
322
+ MOVD R24 , 40 ( RSP )
323
+ MOVD R25 , 48 ( RSP )
324
+ MOVD R26 , 56 ( RSP )
325
+ MOVD R27 , 64 ( RSP )
326
+ MOVD g , 72 ( RSP )
327
+ FMOVD F8 , 80 ( RSP )
328
+ FMOVD F9 , 88 ( RSP )
329
+ FMOVD F10 , 96 ( RSP )
330
+ FMOVD F11 , 104 ( RSP )
331
+ FMOVD F12 , 112 ( RSP )
332
+ FMOVD F13 , 120 ( RSP )
333
+ FMOVD F14 , 128 ( RSP )
334
+ FMOVD F15 , 136 ( RSP )
335
+
336
+ MOVD m_g0(R0) , g
337
+
338
+ BL runtime·mstart(SB)
339
+
340
+ // Restore callee - save registers.
341
+ MOVD 0 ( RSP ) , R19
342
+ MOVD 8 ( RSP ) , R20
343
+ MOVD 16 ( RSP ) , R21
344
+ MOVD 24 ( RSP ) , R22
345
+ MOVD 32 ( RSP ) , R23
346
+ MOVD 40 ( RSP ) , R24
347
+ MOVD 48 ( RSP ) , R25
348
+ MOVD 56 ( RSP ) , R26
349
+ MOVD 64 ( RSP ) , R27
350
+ MOVD 72 ( RSP ) , g
351
+ FMOVD 80 ( RSP ) , F8
352
+ FMOVD 88 ( RSP ) , F9
353
+ FMOVD 96 ( RSP ) , F10
354
+ FMOVD 104 ( RSP ) , F11
355
+ FMOVD 112 ( RSP ) , F12
356
+ FMOVD 120 ( RSP ) , F13
357
+ FMOVD 128 ( RSP ) , F14
358
+ FMOVD 136 ( RSP ) , F15
359
+ ADD $ 144 , RSP
360
+
361
+ // Go is all done with this OS thread.
362
+ // Tell pthread everything is ok (we never join with this thread , so
363
+ // the value here doesn't really matter).
364
+ MOVD $ 0 , R0
365
+
314
366
RET
315
367
316
368
TEXT runtime·pthread_attr_init_trampoline(SB) , NOSPLIT , $ 0
317
- MOVW $ 45 , R0
318
- BL libc_exit (SB)
369
+ MOVD 0 (R0) , R0 // arg 1 attr
370
+ BL libc_pthread_attr_init (SB)
319
371
RET
320
372
321
373
TEXT runtime·pthread_attr_setstacksize_trampoline(SB) , NOSPLIT , $ 0
322
- MOVW $ 46 , R0
323
- BL libc_exit(SB)
374
+ MOVD 8 (R0) , R1 // arg 2 size
375
+ MOVD 0 (R0) , R0 // arg 1 attr
376
+ BL libc_pthread_attr_setstacksize(SB)
324
377
RET
325
378
326
379
TEXT runtime·pthread_attr_setdetachstate_trampoline(SB) , NOSPLIT , $ 0
327
- MOVW $ 47 , R0
328
- BL libc_exit(SB)
380
+ MOVD 8 (R0) , R1 // arg 2 state
381
+ MOVD 0 (R0) , R0 // arg 1 attr
382
+ BL libc_pthread_attr_setdetachstate(SB)
329
383
RET
330
384
331
385
TEXT runtime·pthread_create_trampoline(SB) , NOSPLIT , $ 0
332
- MOVW $ 48 , R0
333
- BL libc_exit(SB)
386
+ SUB $ 16 , RSP
387
+ MOVD 0 (R0) , R1 // arg 2 state
388
+ MOVD 8 (R0) , R2 // arg 3 start
389
+ MOVD 16 (R0) , R3 // arg 4 arg
390
+ MOVD RSP , R0 // arg 1 &threadid (which we throw away)
391
+ BL libc_pthread_create(SB)
392
+ ADD $ 16 , RSP
334
393
RET
335
394
336
395
TEXT runtime·raise_trampoline(SB) , NOSPLIT , $ 0
0 commit comments