blob: 285d07914b9562ade889e665829e9b950f932830 [file] [log] [blame]
// Copyright 2018 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.
#include "go_asm.h"
#include "go_tls.h"
#include "textflag.h"
TEXT runtime·threadinit(SB),NOSPLIT,$0
MOVQ DI, R8
MOVQ m_g0(R8), DX // g
MOVQ R8, g_m(DX)
// Layout new m scheduler stack on os stack.
// TODO: which os stack? do we need to make a new vmo?
LEAQ (-8*1024+104)(SP), BX
MOVQ BX, g_stackguard0(DX)
MOVQ BX, g_stackguard1(DX)
MOVQ BX, (g_stack+stack_lo)(DX)
MOVQ SP, (g_stack+stack_hi)(DX)
PUSHQ R8
// Set up tls.
LEAQ m_tls(R8), DI
CALL runtime·settls(SB)
get_tls(CX)
POPQ R8
MOVQ m_g0(R8), DX
MOVQ DX, g(CX)
CLD // convention is D is always left cleared
CALL runtime·stackcheck(SB) // clobbers AX,CX
CALL runtime·mstart(SB)
// TODO CALL syscall/zx·Sys_zircon_thread_exit(SB)
RET
// Set TLS base to DI for the thread handle supplied in SI.
TEXT runtime·settls(SB),NOSPLIT,$0
ADDQ $8, DI // ELF wants to use -8(FS)
PUSHQ DI
LEAQ 0(SP), DX // object_set_property takes a pointer to the base
SUBQ $28, SP
MOVL SI, 0(SP) // thread handle
MOVL $4, 4(SP) // ZX_PROP_REGISTER_FS
MOVQ DX, 8(SP) // pointer to fs base
MOVQ $8, 16(SP) // size
CALL runtime·vdsoCall_zx_object_set_property(SB)
// Stash return and restore SP
MOVL 24(SP), AX
ADDQ $28, SP
TESTL $0, AX
JZ 2(PC)
MOVL $0xf1, 0xf1 // crash
POPQ DI
RET
TEXT ·cgocallm0(SB),NOSPLIT,$0-20
MOVQ fn+0(FP), AX
MOVQ arg+8(FP), DI
MOVQ SP, BP // BP is callee-save in the x86-64 ABI
ANDQ $~15, SP
CALL AX
MOVQ BP, SP
get_tls(CX)
RET
// This implementation lives separately because the m/g for the profiler and
// exception watcher are faked, and this causes issues with runtime.exitsyscall
// not returning.
TEXT runtime·fake_m_object_wait_one(SB),NOSPLIT,$0-28
MOVL handle+0(FP), DI
MOVL signals+4(FP), SI
MOVQ deadline+8(FP), DX
MOVQ observed+16(FP), CX
MOVQ vdso_zx_object_wait_one(SB), AX
CALL AX
MOVL AX, ret+24(FP)
RET
TEXT runtime·osyield(SB),NOSPLIT,$0
MOVQ $0, DI
MOVQ vdso_zx_nanosleep(SB), AX
CALL AX
RET