detached 0c858ac

internal/fakecgo: separate Linux and Darwin trampolines (#104)

commit
0c858ac9f9ff921a4d24b833c0354cda7fdafa1b
author
TotallyGamerJet · · 2023-02-21 13:54 UTC
committer
GitHub · · 2023-02-21 13:54 UTC
parent
11a897f
signature
GPG Unverified4AEE18F83AFDEB23 The key is unknown
refs
tag: v0.2.0
2 files · +74 -2
R internal/fakecgo/trampolines_amd64.s → internal/fakecgo/trampolines_darwin_amd64.s +0 -2 renamed, 98% similar
@@ -1,8 +1,6 @@
11 // SPDX-License-Identifier: Apache-2.0
22 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
33
4-//go:build darwin || linux
5-
64 /*
75 trampoline for emulating required C functions for cgo in go (see cgo.go)
86 (we convert cdecl calling convention to go and vice-versa)
@@ -1,8 +1,6 @@
1 // SPDX-License-Identifier: Apache-2.01 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors2 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3 3
4-//go:build darwin || linux
5-
6 /*4 /*
7 trampoline for emulating required C functions for cgo in go (see cgo.go)5 trampoline for emulating required C functions for cgo in go (see cgo.go)
8 (we convert cdecl calling convention to go and vice-versa)6 (we convert cdecl calling convention to go and vice-versa)
A internal/fakecgo/trampolines_linux_amd64.s +74 -0
@@ -0,0 +1,74 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3+
4+/*
5+trampoline for emulating required C functions for cgo in go (see cgo.go)
6+(we convert cdecl calling convention to go and vice-versa)
7+Since we're called from go and call into C we can cheat a bit with the calling conventions:
8+ - in go all the registers are caller saved
9+ - in C we have a couple of callee saved registers
10+=> we can use BX, R12, R13, R14, R15 instead of the stack
11+C Calling convention cdecl used here (we only need integer args):
12+1. arg: DI
13+2. arg: SI
14+3. arg: DX
15+4. arg: CX
16+5. arg: R8
17+6. arg: R9
18+We don't need floats with these functions -> AX=0
19+return value will be in AX
20+*/
21+#include "textflag.h"
22+#include "go_asm.h"
23+
24+// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
25+
26+TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16
27+ MOVQ DI, 0(SP)
28+ MOVQ SI, 8(SP)
29+ CALL ·x_cgo_init(SB)
30+ RET
31+
32+TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8
33+ MOVQ DI, 0(SP)
34+ CALL ·x_cgo_thread_start(SB)
35+ RET
36+
37+TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8
38+ MOVQ DI, 0(SP)
39+ CALL ·x_cgo_setenv(SB)
40+ RET
41+
42+TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8
43+ MOVQ DI, 0(SP)
44+ CALL ·x_cgo_unsetenv(SB)
45+ RET
46+
47+TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0
48+ CALL ·x_cgo_notify_runtime_init_done(SB)
49+ RET
50+
51+// func setg_trampoline(setg uintptr, g uintptr)
52+TEXT ·setg_trampoline(SB), NOSPLIT, $0-16
53+ MOVQ G+8(FP), DI
54+ MOVQ setg+0(FP), AX
55+ CALL AX
56+ RET
57+
58+TEXT threadentry_trampoline(SB), NOSPLIT, $16
59+ MOVQ DI, 0(SP)
60+ CALL ·threadentry(SB)
61+ MOVQ 8(SP), AX
62+ RET
63+
64+TEXT ·call5(SB), NOSPLIT, $0-56
65+ MOVQ fn+0(FP), BX
66+ MOVQ a1+8(FP), DI
67+ MOVQ a2+16(FP), SI
68+ MOVQ a3+24(FP), DX
69+ MOVQ a4+32(FP), CX
70+ MOVQ a5+40(FP), R8
71+ XORL AX, AX
72+ CALL BX
73+ MOVQ AX, ret+48(FP)
74+ RET
@@ -0,0 +1,74 @@
1+// SPDX-License-Identifier: Apache-2.0
2+// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
3+
4+/*
5+trampoline for emulating required C functions for cgo in go (see cgo.go)
6+(we convert cdecl calling convention to go and vice-versa)
7+Since we're called from go and call into C we can cheat a bit with the calling conventions:
8+ - in go all the registers are caller saved
9+ - in C we have a couple of callee saved registers
10+=> we can use BX, R12, R13, R14, R15 instead of the stack
11+C Calling convention cdecl used here (we only need integer args):
12+1. arg: DI
13+2. arg: SI
14+3. arg: DX
15+4. arg: CX
16+5. arg: R8
17+6. arg: R9
18+We don't need floats with these functions -> AX=0
19+return value will be in AX
20+*/
21+#include "textflag.h"
22+#include "go_asm.h"
23+
24+// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions.
25+
26+TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16
27+ MOVQ DI, 0(SP)
28+ MOVQ SI, 8(SP)
29+ CALL ·x_cgo_init(SB)
30+ RET
31+
32+TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8
33+ MOVQ DI, 0(SP)
34+ CALL ·x_cgo_thread_start(SB)
35+ RET
36+
37+TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8
38+ MOVQ DI, 0(SP)
39+ CALL ·x_cgo_setenv(SB)
40+ RET
41+
42+TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8
43+ MOVQ DI, 0(SP)
44+ CALL ·x_cgo_unsetenv(SB)
45+ RET
46+
47+TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0
48+ CALL ·x_cgo_notify_runtime_init_done(SB)
49+ RET
50+
51+// func setg_trampoline(setg uintptr, g uintptr)
52+TEXT ·setg_trampoline(SB), NOSPLIT, $0-16
53+ MOVQ G+8(FP), DI
54+ MOVQ setg+0(FP), AX
55+ CALL AX
56+ RET
57+
58+TEXT threadentry_trampoline(SB), NOSPLIT, $16
59+ MOVQ DI, 0(SP)
60+ CALL ·threadentry(SB)
61+ MOVQ 8(SP), AX
62+ RET
63+
64+TEXT ·call5(SB), NOSPLIT, $0-56
65+ MOVQ fn+0(FP), BX
66+ MOVQ a1+8(FP), DI
67+ MOVQ a2+16(FP), SI
68+ MOVQ a3+24(FP), DX
69+ MOVQ a4+32(FP), CX
70+ MOVQ a5+40(FP), R8
71+ XORL AX, AX
72+ CALL BX
73+ MOVQ AX, ret+48(FP)
74+ RET

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