detached 0788778

purego: add wincallback.go (#337)

zcallback_amd64.s and zcallback_arm64.s were generated by wincallback.go
in the Go repository. To keep the reproducible repository states,
add wincallback.go with some modifications.
commit
0788778a755621f016b1087d6d6e81be85a784dc
author
Hajime Hoshi · · 2025-09-15 04:26 UTC
committer
GitHub · · 2025-09-15 04:26 UTC
parent
77ed153
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
5 files · +6087 -6002
M README.md +1 -0
@@ -84,6 +84,7 @@ License that can be found [in the Go Source](https://github.com/golang/go/blob/m
8484 This is a list of the copied files:
8585
8686 * `abi_*.h` from package `runtime/cgo`
87+* `wincallback.go` from package `runtime`
8788 * `zcallback_darwin_*.s` from package `runtime`
8889 * `internal/fakecgo/abi_*.h` from package `runtime/cgo`
8990 * `internal/fakecgo/asm_GOARCH.s` from package `runtime/cgo`
@@ -84,6 +84,7 @@ License that can be found [in the Go Source](https://github.com/golang/go/blob/m
84 This is a list of the copied files:84 This is a list of the copied files:
85 85
86 * `abi_*.h` from package `runtime/cgo`86 * `abi_*.h` from package `runtime/cgo`
87+* `wincallback.go` from package `runtime`
87 * `zcallback_darwin_*.s` from package `runtime`88 * `zcallback_darwin_*.s` from package `runtime`
88 * `internal/fakecgo/abi_*.h` from package `runtime/cgo`89 * `internal/fakecgo/abi_*.h` from package `runtime/cgo`
89 * `internal/fakecgo/asm_GOARCH.s` from package `runtime/cgo`90 * `internal/fakecgo/asm_GOARCH.s` from package `runtime/cgo`
A gen.go +6 -0
@@ -0,0 +1,6 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
3+
4+package purego
5+
6+//go:generate go run wincallback.go
@@ -0,0 +1,6 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2025 The Ebitengine Authors
3+
4+package purego
5+
6+//go:generate go run wincallback.go
A wincallback.go +78 -0
@@ -0,0 +1,78 @@
1+// Copyright 2014 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+//go:build ignore
6+
7+// Generate Windows callback assembly file.
8+// This was copied from the Go repository and modified to generate non-Windows assembly files.
9+
10+package main
11+
12+import (
13+ "bytes"
14+ "fmt"
15+ "os"
16+)
17+
18+const maxCallback = 2000
19+
20+func genasmAmd64() {
21+ var buf bytes.Buffer
22+
23+ buf.WriteString(`// Code generated by wincallback.go using 'go generate'. DO NOT EDIT.
24+
25+//go:build darwin || freebsd || linux || netbsd
26+
27+// runtime·callbackasm is called by external code to
28+// execute Go implemented callback function. It is not
29+// called from the start, instead runtime·compilecallback
30+// always returns address into runtime·callbackasm offset
31+// appropriately so different callbacks start with different
32+// CALL instruction in runtime·callbackasm. This determines
33+// which Go callback function is executed later on.
34+#include "textflag.h"
35+
36+TEXT callbackasm(SB),NOSPLIT|NOFRAME,$0
37+`)
38+ for i := 0; i < maxCallback; i++ {
39+ buf.WriteString("\tCALL\tcallbackasm1(SB)\n")
40+ }
41+ if err := os.WriteFile("zcallback_amd64.s", buf.Bytes(), 0644); err != nil {
42+ fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
43+ os.Exit(2)
44+ }
45+}
46+
47+func genasmArm64() {
48+ var buf bytes.Buffer
49+
50+ buf.WriteString(`// Code generated by wincallback.go using 'go generate'. DO NOT EDIT.
51+
52+//go:build darwin || freebsd || linux || netbsd
53+
54+// External code calls into callbackasm at an offset corresponding
55+// to the callback index. Callbackasm is a table of MOV and B instructions.
56+// The MOV instruction loads R12 with the callback index, and the
57+// B instruction branches to callbackasm1.
58+// callbackasm1 takes the callback index from R12 and
59+// indexes into an array that stores information about each callback.
60+// It then calls the Go implementation for that callback.
61+#include "textflag.h"
62+
63+TEXT callbackasm(SB),NOSPLIT|NOFRAME,$0
64+`)
65+ for i := 0; i < maxCallback; i++ {
66+ fmt.Fprintf(&buf, "\tMOVD\t$%d, R12\n", i)
67+ buf.WriteString("\tB\tcallbackasm1(SB)\n")
68+ }
69+ if err := os.WriteFile("zcallback_arm64.s", buf.Bytes(), 0644); err != nil {
70+ fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
71+ os.Exit(2)
72+ }
73+}
74+
75+func main() {
76+ genasmAmd64()
77+ genasmArm64()
78+}
@@ -0,0 +1,78 @@
1+// Copyright 2014 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+//go:build ignore
6+
7+// Generate Windows callback assembly file.
8+// This was copied from the Go repository and modified to generate non-Windows assembly files.
9+
10+package main
11+
12+import (
13+ "bytes"
14+ "fmt"
15+ "os"
16+)
17+
18+const maxCallback = 2000
19+
20+func genasmAmd64() {
21+ var buf bytes.Buffer
22+
23+ buf.WriteString(`// Code generated by wincallback.go using 'go generate'. DO NOT EDIT.
24+
25+//go:build darwin || freebsd || linux || netbsd
26+
27+// runtime·callbackasm is called by external code to
28+// execute Go implemented callback function. It is not
29+// called from the start, instead runtime·compilecallback
30+// always returns address into runtime·callbackasm offset
31+// appropriately so different callbacks start with different
32+// CALL instruction in runtime·callbackasm. This determines
33+// which Go callback function is executed later on.
34+#include "textflag.h"
35+
36+TEXT callbackasm(SB),NOSPLIT|NOFRAME,$0
37+`)
38+ for i := 0; i < maxCallback; i++ {
39+ buf.WriteString("\tCALL\tcallbackasm1(SB)\n")
40+ }
41+ if err := os.WriteFile("zcallback_amd64.s", buf.Bytes(), 0644); err != nil {
42+ fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
43+ os.Exit(2)
44+ }
45+}
46+
47+func genasmArm64() {
48+ var buf bytes.Buffer
49+
50+ buf.WriteString(`// Code generated by wincallback.go using 'go generate'. DO NOT EDIT.
51+
52+//go:build darwin || freebsd || linux || netbsd
53+
54+// External code calls into callbackasm at an offset corresponding
55+// to the callback index. Callbackasm is a table of MOV and B instructions.
56+// The MOV instruction loads R12 with the callback index, and the
57+// B instruction branches to callbackasm1.
58+// callbackasm1 takes the callback index from R12 and
59+// indexes into an array that stores information about each callback.
60+// It then calls the Go implementation for that callback.
61+#include "textflag.h"
62+
63+TEXT callbackasm(SB),NOSPLIT|NOFRAME,$0
64+`)
65+ for i := 0; i < maxCallback; i++ {
66+ fmt.Fprintf(&buf, "\tMOVD\t$%d, R12\n", i)
67+ buf.WriteString("\tB\tcallbackasm1(SB)\n")
68+ }
69+ if err := os.WriteFile("zcallback_arm64.s", buf.Bytes(), 0644); err != nil {
70+ fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
71+ os.Exit(2)
72+ }
73+}
74+
75+func main() {
76+ genasmAmd64()
77+ genasmArm64()
78+}
M zcallback_amd64.s +2001 -2001 large diff (4002 lines changed): collapsed
M zcallback_arm64.s +4001 -4001 large diff (8002 lines changed): collapsed

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close