]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add windows/arm64 cgo-linking code
authorRuss Cox <rsc@golang.org>
Wed, 14 Apr 2021 16:33:51 +0000 (12:33 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 23 Apr 2021 21:43:07 +0000 (21:43 +0000)
This code is needed for use with cgo proper
(as opposed to hand-written DLL calls, which
we always use but only exercise cgo execution,
not cgo linking).

Change-Id: Iddc31d9c1c924d83d032b80dca65ddfda6624046
Reviewed-on: https://go-review.googlesource.com/c/go/+/312041
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/cgo/gcc_windows_arm64.c [new file with mode: 0644]
src/runtime/rt0_windows_arm64.s
src/runtime/sys_windows_arm.s

diff --git a/src/runtime/cgo/gcc_windows_arm64.c b/src/runtime/cgo/gcc_windows_arm64.c
new file mode 100644 (file)
index 0000000..61ef094
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2009 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.
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <process.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include "libcgo.h"
+#include "libcgo_windows.h"
+
+static void threadentry(void*);
+static void (*setg_gcc)(void*);
+
+void
+x_cgo_init(G *g, void (*setg)(void*))
+{
+       setg_gcc = setg;
+}
+
+void
+_cgo_sys_thread_start(ThreadStart *ts)
+{
+       uintptr_t thandle;
+
+       thandle = _beginthread(threadentry, 0, ts);
+       if(thandle == -1) {
+               fprintf(stderr, "runtime: failed to create new OS thread (%d)\n", errno);
+               abort();
+       }
+}
+
+extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
+
+static void
+threadentry(void *v)
+{
+       ThreadStart ts;
+
+       ts = *(ThreadStart*)v;
+       free(v);
+
+       crosscall1(ts.fn, setg_gcc, (void *)ts.g);
+}
index 1e71a068d3a9815face34df6b62573d7c2a6b9ee..bad85c28ac5ce9f421693be2a953d8ff260c0aac 100644 (file)
 // kernel for an ordinary -buildmode=exe program.
 TEXT _rt0_arm64_windows(SB),NOSPLIT|NOFRAME,$0
        B       ·rt0_go(SB)
+
+TEXT _rt0_arm64_windows_lib(SB),NOSPLIT|NOFRAME,$0
+       MOVD    $_rt0_arm64_windows_lib_go(SB), R0
+       MOVD    $0, R1
+       MOVD    _cgo_sys_thread_create(SB), R2
+       B       (R2)
+
+TEXT _rt0_arm64_windows_lib_go(SB),NOSPLIT|NOFRAME,$0
+       MOVD    $0, R0
+       MOVD    $0, R1
+       MOVD    $runtime·rt0_go(SB), R2
+       B       (R2)
+
+TEXT main(SB),NOSPLIT,$0
+       MOVD    $runtime·rt0_go(SB), R2
+       B       (R2)
+
index 8073fc0198fe15f3b1c8bdd2a67f7bd8e4b57f64..6234203798031d02eff72606d684e1022d7bccef 100644 (file)
@@ -335,7 +335,7 @@ TEXT runtime·switchtothread(SB),NOSPLIT|NOFRAME,$0
 TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
        B       runtime·armPublicationBarrier(SB)
 
-// never called (cgo not supported)
+// never called (this is a GOARM=7 platform)
 TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0
        MOVW    $0xabcd, R0
        MOVW    R0, (R0)