diff --git a/internal/fakecgo/callbacks.go b/internal/fakecgo/callbacks.go index 27d4c98c..069a55e2 100644 --- a/internal/fakecgo/callbacks.go +++ b/internal/fakecgo/callbacks.go @@ -12,35 +12,6 @@ import ( // TODO: decide if we need _runtime_cgo_panic_internal -//go:linkname x_cgo_init_trampoline x_cgo_init_trampoline -//go:linkname _cgo_init _cgo_init -var x_cgo_init_trampoline byte -var _cgo_init = &x_cgo_init_trampoline - -// Creates a new system thread without updating any Go state. -// -// This method is invoked during shared library loading to create a new OS -// thread to perform the runtime initialization. This method is similar to -// _cgo_sys_thread_start except that it doesn't update any Go state. - -//go:linkname x_cgo_thread_start_trampoline x_cgo_thread_start_trampoline -//go:linkname _cgo_thread_start _cgo_thread_start -var x_cgo_thread_start_trampoline byte -var _cgo_thread_start = &x_cgo_thread_start_trampoline - -// Notifies that the runtime has been initialized. -// -// We currently block at every CGO entry point (via _cgo_wait_runtime_init_done) -// to ensure that the runtime has been initialized before the CGO call is -// executed. This is necessary for shared libraries where we kickoff runtime -// initialization in a separate thread and return without waiting for this -// thread to complete the init. - -//go:linkname x_cgo_notify_runtime_init_done_trampoline x_cgo_notify_runtime_init_done_trampoline -//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done -var x_cgo_notify_runtime_init_done_trampoline byte -var _cgo_notify_runtime_init_done = &x_cgo_notify_runtime_init_done_trampoline - // Indicates whether a dummy thread key has been created or not. // // When calling go exported function from C, we register a destructor @@ -60,34 +31,5 @@ func set_crosscall2() { //go:linkname _set_crosscall2 runtime.set_crosscall2 var _set_crosscall2 = set_crosscall2 -// Store the g into the thread-specific value. -// So that pthread_key_destructor will dropm when the thread is exiting. - -//go:linkname x_cgo_bindm_trampoline x_cgo_bindm_trampoline -//go:linkname _cgo_bindm _cgo_bindm -var x_cgo_bindm_trampoline byte -var _cgo_bindm = &x_cgo_bindm_trampoline - // TODO: decide if we need x_cgo_set_context_function // TODO: decide if we need _cgo_yield - -var ( - // In Go 1.20 the race detector was rewritten to pure Go - // on darwin. This means that when CGO_ENABLED=0 is set - // fakecgo is built with race detector code. This is not - // good since this code is pretending to be C. The go:norace - // pragma is not enough, since it only applies to the native - // ABIInternal function. The ABIO wrapper (which is necessary, - // since all references to text symbols from assembly will use it) - // does not inherit the go:norace pragma, so it will still be - // instrumented by the race detector. - // - // To circumvent this issue, using closure calls in the - // assembly, which forces the compiler to use the ABIInternal - // native implementation (which has go:norace) instead. - threadentry_call = threadentry - x_cgo_init_call = x_cgo_init - x_cgo_setenv_call = x_cgo_setenv - x_cgo_unsetenv_call = x_cgo_unsetenv - x_cgo_thread_start_call = x_cgo_thread_start -) diff --git a/internal/fakecgo/gen.go b/internal/fakecgo/gen.go index 59f1f44d..428ac01d 100644 --- a/internal/fakecgo/gen.go +++ b/internal/fakecgo/gen.go @@ -17,6 +17,75 @@ import ( "text/template" ) +var templateArchTrampolines = template.Must(template.New("arch_trampolines").Funcs(funcs).Parse( + `// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build {{.Tag}} + +#include "textflag.h" +#include "go_asm.h" + +// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. +{{ range .Symbols }} +{{- if $.Arch.StackBased }} +{{- if eq .ArgsCount 0 }} +TEXT _x_cgo_{{.Name}}_trampoline(SB), NOSPLIT, $0-0 + CALL ·x_cgo_{{.Name}}(SB) + RET +{{- else }} +TEXT _x_cgo_{{.Name}}_trampoline(SB), NOSPLIT, ${{mul .ArgsCount $.Arch.WordSize}}-0 +{{- if eq $.Arch.Goarch "arm" }} +{{- range $i := .ArgsCount }} + {{- $dstOffset := add 4 (mul $i $.Arch.WordSize) }} + {{$.Arch.MOV}} R{{$i}}, {{$dstOffset}}(R13) +{{- end }} + {{$.Arch.MOV}} ·_cgo_{{.Name}}_call(SB), {{$.Arch.VolatileReg}} + {{$.Arch.MOV}} ({{$.Arch.VolatileReg}}), {{$.Arch.VolatileReg}} +{{- if $.Arch.CallNeedsParens }} + CALL ({{$.Arch.VolatileReg}}) +{{- else }} + CALL {{$.Arch.VolatileReg}} +{{- end }} + RET +{{- else }} +{{- $frameSize := mul .ArgsCount $.Arch.WordSize }} +{{- $retAddrSize := $.Arch.WordSize }} +{{- range $i := .ArgsCount }} + {{- $srcOffset := add $frameSize $retAddrSize }} + {{- $srcOffset = add $srcOffset (mul $i $.Arch.WordSize) }} + {{- $dstOffset := mul $i $.Arch.WordSize }} + {{$.Arch.MOV}} {{$srcOffset}}(SP), AX + {{$.Arch.MOV}} AX, {{$dstOffset}}(SP) +{{- end }} + {{$.Arch.MOV}} ·_cgo_{{.Name}}_call(SB), {{$.Arch.VolatileReg}} + {{$.Arch.MOV}} ({{$.Arch.VolatileReg}}), {{$.Arch.VolatileReg}} + CALL {{$.Arch.VolatileReg}} + RET +{{- end }} +{{- end }} +{{- else }} +TEXT _x_cgo_{{.Name}}_trampoline(SB), NOSPLIT, ${{mul .ArgsCount $.Arch.WordSize}} +{{- range $i := .ArgsCount }} + {{- $src := index $.Arch.C.IntRegArgs $i }} + {{- $dst := index $.Arch.GoABI0.IntRegArgs $i }} + {{- if ne $src $dst }} + {{$.Arch.MOV}} {{$src}}, {{$dst}} + {{- end }} +{{- end }} + {{$.Arch.MOV}} ·_cgo_{{.Name}}_call(SB), {{$.Arch.VolatileReg}} + {{$.Arch.MOV}} ({{$.Arch.VolatileReg}}), {{$.Arch.VolatileReg}} +{{- if $.Arch.CallNeedsParens }} + CALL ({{$.Arch.VolatileReg}}) +{{- else }} + CALL {{$.Arch.VolatileReg}} +{{- end }} + RET +{{- end }} +{{ end }}`)) + var templateSymbols = template.Must(template.New("symbols").Funcs(funcs).Parse( `// Code generated by 'go generate' with gen.go. DO NOT EDIT. @@ -99,6 +168,35 @@ TEXT _{{.Name}}(SB), NOSPLIT|NOFRAME, $0-0 {{ end -}} `)) +var templateCallbacks = template.Must(template.New("callbacks").Funcs(funcs).Parse( + `// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && (darwin || freebsd || linux || netbsd) + +package fakecgo + +import ( + _ "unsafe" +) + +{{ range .Symbols }} +//go:linkname _x_cgo_{{.Name}}_trampoline _x_cgo_{{.Name}}_trampoline +//go:linkname _cgo_{{.Name}} {{if .Package}}{{.Package}}.{{end}}_cgo_{{.Name}} +var _x_cgo_{{.Name}}_trampoline byte +var _cgo_{{.Name}} = &_x_cgo_{{.Name}}_trampoline +{{- end }} + +var ( + threadentry_call = threadentry +{{- range .Symbols }} + _cgo_{{.Name}}_call = x_cgo_{{.Name}} +{{- end }} +) +`)) + type Arg struct { Name string Type string @@ -142,6 +240,8 @@ var ( var funcs = map[string]any{ "hasPrefix": strings.HasPrefix, "imports": imports, + "mul": func(a, b int) int { return a * b }, + "add": func(a, b int) int { return a + b }, } var GOOSes = []string{"darwin", "freebsd", "linux", "netbsd"} @@ -285,9 +385,133 @@ func run() error { } } } + for _, arch := range archs { + if err := writeArchTrampolines(arch); err != nil { + return err + } + } + if err := execute(templateCallbacks, "zcallbacks.go", struct{ Symbols []AsmGoSymbol }{Symbols: asmGoSymbols}); err != nil { + return err + } return nil } +type Arch struct { + Goarch string + GoABI0 ABI + C ABI + WordSize int // 4 on 32-bit systems, 8 on 64-bit systems + MOV string // MOV instruction, e.g., "MOVL" or "MOVQ" + VolatileReg string // Scratch register for intermediate values + CallNeedsParens bool + StackBased bool // true if using stack-based calling convention (e.g., 386) +} + +type ABI struct { + IntRegArgs [5]string // Name of integer argument registers in order. If empty, stack-based calling convention is used. + OutRegArg string // Name of the register for the single return value. If empty, stack-based calling convention is used. +} + +// AsmGoSymbols are symbols that called from Go Assembly. +type AsmGoSymbol struct { + Name string + ArgsCount int + Package string +} + +var ( + archs = []Arch{ + { + Goarch: "386", + WordSize: 4, + GoABI0: ABI{}, // stack-based calling convention + C: ABI{}, // stack-based calling convention + MOV: "MOVL", + VolatileReg: "CX", + StackBased: true, + }, + { + Goarch: "amd64", + WordSize: 8, + GoABI0: ABI{IntRegArgs: [5]string{"AX", "BX", "CX", "DX", "SI"}, OutRegArg: "AX"}, + C: ABI{IntRegArgs: [5]string{"DI", "SI", "DX", "CX", "R8"}, OutRegArg: "AX"}, + MOV: "MOVQ", + VolatileReg: "R11", + }, + { + Goarch: "arm", + WordSize: 4, + GoABI0: ABI{}, // stack-based calling convention + C: ABI{}, // stack-based calling convention + MOV: "MOVW", + VolatileReg: "R12", + StackBased: true, + CallNeedsParens: true, + }, + { + Goarch: "arm64", + WordSize: 8, + GoABI0: ABI{IntRegArgs: [5]string{"R0", "R1", "R2", "R3", "R4"}, OutRegArg: "R0"}, + C: ABI{IntRegArgs: [5]string{"R0", "R1", "R2", "R3", "R4"}, OutRegArg: "R0"}, + MOV: "MOVD", + VolatileReg: "R9", + }, + { + Goarch: "loong64", + WordSize: 8, + GoABI0: ABI{IntRegArgs: [5]string{"R4", "R5", "R6", "R7", "R8"}, OutRegArg: "R4"}, + C: ABI{IntRegArgs: [5]string{"R4", "R5", "R6", "R7", "R8"}, OutRegArg: "R4"}, + MOV: "MOVV", + VolatileReg: "R23", + CallNeedsParens: true, + }, + { + Goarch: "riscv64", + WordSize: 8, + GoABI0: ABI{IntRegArgs: [5]string{"X10", "X11", "X12", "X13", "X14"}, OutRegArg: "X10"}, + C: ABI{IntRegArgs: [5]string{"X10", "X11", "X12", "X13", "X14"}, OutRegArg: "X10"}, + MOV: "MOV ", + VolatileReg: "X5", + }, + } + asmGoSymbols = []AsmGoSymbol{ + {"init", 2, ""}, + {"thread_start", 1, ""}, + {"setenv", 1, "runtime"}, + {"unsetenv", 1, "runtime"}, + {"notify_runtime_init_done", 0, ""}, + {"bindm", 0, ""}, + } +) + +func writeArchTrampolines(arch Arch) error { + var gooses []string + switch arch.Goarch { + case "amd64", "arm64": + gooses = []string{"darwin", "freebsd", "linux"} + case "loong64", "riscv64": + gooses = []string{"linux"} + case "386": + gooses = []string{"freebsd", "linux"} + default: + gooses = GOOSes + } + tag := "!cgo && (" + strings.Join(gooses, " || ") + ")" + if len(gooses) == 1 { + tag = "!cgo && " + gooses[0] + } + data := struct { + Tag string + Symbols []AsmGoSymbol + Arch Arch + }{ + Tag: tag, + Symbols: asmGoSymbols, + Arch: arch, + } + return execute(templateArchTrampolines, fmt.Sprintf("ztrampolines_%s.s", arch.Goarch), data) +} + func main() { if err := run(); err != nil { log.Fatal(err) diff --git a/internal/fakecgo/setenv.go b/internal/fakecgo/setenv.go deleted file mode 100644 index 82308b8c..00000000 --- a/internal/fakecgo/setenv.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2011 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. - -//go:build !cgo && (darwin || freebsd || linux || netbsd) - -package fakecgo - -import _ "unsafe" // for go:linkname - -//go:linkname x_cgo_setenv_trampoline x_cgo_setenv_trampoline -//go:linkname _cgo_setenv runtime._cgo_setenv -var x_cgo_setenv_trampoline byte -var _cgo_setenv = &x_cgo_setenv_trampoline - -//go:linkname x_cgo_unsetenv_trampoline x_cgo_unsetenv_trampoline -//go:linkname _cgo_unsetenv runtime._cgo_unsetenv -var x_cgo_unsetenv_trampoline byte -var _cgo_unsetenv = &x_cgo_unsetenv_trampoline diff --git a/internal/fakecgo/trampolines_386.s b/internal/fakecgo/trampolines_386.s index cd3492ea..4683d429 100644 --- a/internal/fakecgo/trampolines_386.s +++ b/internal/fakecgo/trampolines_386.s @@ -24,51 +24,6 @@ // Go ABI0 on 386 expects arguments starting at 0(FP) which equals N+4(SP) // after the prologue (where N is the local frame size). -TEXT x_cgo_init_trampoline(SB), NOSPLIT, $8-0 - // C args at 12(SP) and 16(SP) after frame setup (8 bytes local + 4 bytes ret addr) - // Go function expects args at 0(SP) and 4(SP) in local frame - MOVL 12(SP), AX // first C arg - MOVL 16(SP), BX // second C arg - MOVL AX, 0(SP) // Go arg 1 - MOVL BX, 4(SP) // Go arg 2 - MOVL ·x_cgo_init_call(SB), CX - MOVL (CX), CX - CALL CX - RET - -TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $4-0 - // C args at 8(SP) after frame setup (4 bytes local + 4 bytes ret addr) - MOVL 8(SP), AX // first C arg - MOVL AX, 0(SP) // Go arg 1 - MOVL ·x_cgo_thread_start_call(SB), CX - MOVL (CX), CX - CALL CX - RET - -TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $4-0 - MOVL 8(SP), AX // first C arg - MOVL AX, 0(SP) // Go arg 1 - MOVL ·x_cgo_setenv_call(SB), CX - MOVL (CX), CX - CALL CX - RET - -TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $4-0 - MOVL 8(SP), AX // first C arg - MOVL AX, 0(SP) // Go arg 1 - MOVL ·x_cgo_unsetenv_call(SB), CX - MOVL (CX), CX - CALL CX - RET - -TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0 - CALL ·x_cgo_notify_runtime_init_done(SB) - RET - -TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0 - CALL ·x_cgo_bindm(SB) - RET - // func setg_trampoline(setg uintptr, g uintptr) // This is called from Go, so args are at normal FP positions TEXT ·setg_trampoline(SB), NOSPLIT, $4-8 diff --git a/internal/fakecgo/trampolines_amd64.s b/internal/fakecgo/trampolines_amd64.s index e4e4c75a..71f59cd8 100644 --- a/internal/fakecgo/trampolines_amd64.s +++ b/internal/fakecgo/trampolines_amd64.s @@ -24,41 +24,6 @@ temporary register is R11 // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. -TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16 - MOVQ DI, AX - MOVQ SI, BX - MOVQ ·x_cgo_init_call(SB), R11 - MOVQ (R11), R11 - CALL R11 - RET - -TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8 - MOVQ DI, AX - MOVQ ·x_cgo_thread_start_call(SB), R11 - MOVQ (R11), R11 - CALL R11 - RET - -TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8 - MOVQ DI, AX - MOVQ ·x_cgo_setenv_call(SB), R11 - MOVQ (R11), R11 - CALL R11 - RET - -TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8 - MOVQ DI, AX - MOVQ ·x_cgo_unsetenv_call(SB), R11 - MOVQ (R11), R11 - CALL R11 - RET - -TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0 - JMP ·x_cgo_notify_runtime_init_done(SB) - -TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0 - JMP ·x_cgo_bindm(SB) - // func setg_trampoline(setg uintptr, g uintptr) TEXT ·setg_trampoline(SB), NOSPLIT, $0-16 MOVQ G+8(FP), DI diff --git a/internal/fakecgo/trampolines_arm.s b/internal/fakecgo/trampolines_arm.s index 00b3177e..3035d7b8 100644 --- a/internal/fakecgo/trampolines_arm.s +++ b/internal/fakecgo/trampolines_arm.s @@ -10,43 +10,6 @@ // On ARM32, Go ABI0 uses stack-based calling convention. // Arguments are placed on the stack starting at 4(SP) after the prologue. -TEXT x_cgo_init_trampoline(SB), NOSPLIT, $8-0 - MOVW R0, 4(R13) - MOVW R1, 8(R13) - MOVW ·x_cgo_init_call(SB), R12 - MOVW (R12), R12 - CALL (R12) - RET - -TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8-0 - MOVW R0, 4(R13) - MOVW ·x_cgo_thread_start_call(SB), R12 - MOVW (R12), R12 - CALL (R12) - RET - -TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8-0 - MOVW R0, 4(R13) - MOVW ·x_cgo_setenv_call(SB), R12 - MOVW (R12), R12 - CALL (R12) - RET - -TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8-0 - MOVW R0, 4(R13) - MOVW ·x_cgo_unsetenv_call(SB), R12 - MOVW (R12), R12 - CALL (R12) - RET - -TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0 - CALL ·x_cgo_notify_runtime_init_done(SB) - RET - -TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0 - CALL ·x_cgo_bindm(SB) - RET - // func setg_trampoline(setg uintptr, g uintptr) TEXT ·setg_trampoline(SB), NOSPLIT, $0-8 MOVW G+4(FP), R0 diff --git a/internal/fakecgo/trampolines_arm64.s b/internal/fakecgo/trampolines_arm64.s index dceb1cac..cc6f1eca 100644 --- a/internal/fakecgo/trampolines_arm64.s +++ b/internal/fakecgo/trampolines_arm64.s @@ -11,38 +11,6 @@ // Note that C arguments are passed in R0-R7, which matches Go ABIInternal for the first eight arguments. // R9 is used as a temporary register. -TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-0 - MOVD ·x_cgo_init_call(SB), R9 - MOVD (R9), R9 - CALL R9 - RET - -TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $0-0 - MOVD ·x_cgo_thread_start_call(SB), R9 - MOVD (R9), R9 - CALL R9 - RET - -TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $0-0 - MOVD ·x_cgo_setenv_call(SB), R9 - MOVD (R9), R9 - CALL R9 - RET - -TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $0-0 - MOVD ·x_cgo_unsetenv_call(SB), R9 - MOVD (R9), R9 - CALL R9 - RET - -TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0 - CALL ·x_cgo_notify_runtime_init_done(SB) - RET - -TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0 - CALL ·x_cgo_bindm(SB) - RET - // func setg_trampoline(setg uintptr, g uintptr) TEXT ·setg_trampoline(SB), NOSPLIT, $0-16 MOVD G+8(FP), R0 diff --git a/internal/fakecgo/trampolines_loong64.s b/internal/fakecgo/trampolines_loong64.s index 7596f0da..889b5887 100644 --- a/internal/fakecgo/trampolines_loong64.s +++ b/internal/fakecgo/trampolines_loong64.s @@ -10,43 +10,6 @@ // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. // R23 is used as temporary register. -TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16 - MOVV R4, 8(R3) - MOVV R5, 16(R3) - MOVV ·x_cgo_init_call(SB), R23 - MOVV (R23), R23 - CALL (R23) - RET - -TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8 - MOVV R4, 8(R3) - MOVV ·x_cgo_thread_start_call(SB), R23 - MOVV (R23), R23 - CALL (R23) - RET - -TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8 - MOVV R4, 8(R3) - MOVV ·x_cgo_setenv_call(SB), R23 - MOVV (R23), R23 - CALL (R23) - RET - -TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8 - MOVV R4, 8(R3) - MOVV ·x_cgo_unsetenv_call(SB), R23 - MOVV (R23), R23 - CALL (R23) - RET - -TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0 - CALL ·x_cgo_notify_runtime_init_done(SB) - RET - -TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0 - CALL ·x_cgo_bindm(SB) - RET - // func setg_trampoline(setg uintptr, g uintptr) TEXT ·setg_trampoline(SB), NOSPLIT, $0 MOVV G+8(FP), R4 diff --git a/internal/fakecgo/trampolines_riscv64.s b/internal/fakecgo/trampolines_riscv64.s index 9298f8c7..004549b6 100644 --- a/internal/fakecgo/trampolines_riscv64.s +++ b/internal/fakecgo/trampolines_riscv64.s @@ -9,43 +9,6 @@ // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. // X5 is used as temporary register. -TEXT x_cgo_init_trampoline(SB), NOSPLIT, $16 - MOV X10, 8(SP) - MOV X11, 16(SP) - MOV ·x_cgo_init_call(SB), X5 - MOV (X5), X5 - CALL X5 - RET - -TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $8 - MOV X10, 8(SP) - MOV ·x_cgo_thread_start_call(SB), X5 - MOV (X5), X5 - CALL X5 - RET - -TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $8 - MOV X10, 8(SP) - MOV ·x_cgo_setenv_call(SB), X5 - MOV (X5), X5 - CALL X5 - RET - -TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8 - MOV X10, 8(SP) - MOV ·x_cgo_unsetenv_call(SB), X5 - MOV (X5), X5 - CALL X5 - RET - -TEXT x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0 - CALL ·x_cgo_notify_runtime_init_done(SB) - RET - -TEXT x_cgo_bindm_trampoline(SB), NOSPLIT, $0 - CALL ·x_cgo_bindm(SB) - RET - // func setg_trampoline(setg uintptr, g uintptr) TEXT ·setg_trampoline(SB), NOSPLIT, $0 MOV gp+8(FP), X10 diff --git a/internal/fakecgo/zcallbacks.go b/internal/fakecgo/zcallbacks.go new file mode 100644 index 00000000..94dc189c --- /dev/null +++ b/internal/fakecgo/zcallbacks.go @@ -0,0 +1,52 @@ +// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && (darwin || freebsd || linux || netbsd) + +package fakecgo + +import ( + _ "unsafe" +) + +//go:linkname _x_cgo_init_trampoline _x_cgo_init_trampoline +//go:linkname _cgo_init _cgo_init +var _x_cgo_init_trampoline byte +var _cgo_init = &_x_cgo_init_trampoline + +//go:linkname _x_cgo_thread_start_trampoline _x_cgo_thread_start_trampoline +//go:linkname _cgo_thread_start _cgo_thread_start +var _x_cgo_thread_start_trampoline byte +var _cgo_thread_start = &_x_cgo_thread_start_trampoline + +//go:linkname _x_cgo_setenv_trampoline _x_cgo_setenv_trampoline +//go:linkname _cgo_setenv runtime._cgo_setenv +var _x_cgo_setenv_trampoline byte +var _cgo_setenv = &_x_cgo_setenv_trampoline + +//go:linkname _x_cgo_unsetenv_trampoline _x_cgo_unsetenv_trampoline +//go:linkname _cgo_unsetenv runtime._cgo_unsetenv +var _x_cgo_unsetenv_trampoline byte +var _cgo_unsetenv = &_x_cgo_unsetenv_trampoline + +//go:linkname _x_cgo_notify_runtime_init_done_trampoline _x_cgo_notify_runtime_init_done_trampoline +//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done +var _x_cgo_notify_runtime_init_done_trampoline byte +var _cgo_notify_runtime_init_done = &_x_cgo_notify_runtime_init_done_trampoline + +//go:linkname _x_cgo_bindm_trampoline _x_cgo_bindm_trampoline +//go:linkname _cgo_bindm _cgo_bindm +var _x_cgo_bindm_trampoline byte +var _cgo_bindm = &_x_cgo_bindm_trampoline + +var ( + threadentry_call = threadentry + _cgo_init_call = x_cgo_init + _cgo_thread_start_call = x_cgo_thread_start + _cgo_setenv_call = x_cgo_setenv + _cgo_unsetenv_call = x_cgo_unsetenv + _cgo_notify_runtime_init_done_call = x_cgo_notify_runtime_init_done + _cgo_bindm_call = x_cgo_bindm +) diff --git a/internal/fakecgo/ztrampolines_386.s b/internal/fakecgo/ztrampolines_386.s new file mode 100644 index 00000000..070d48d3 --- /dev/null +++ b/internal/fakecgo/ztrampolines_386.s @@ -0,0 +1,53 @@ +// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && (freebsd || linux) + +#include "textflag.h" +#include "go_asm.h" + +// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. + +TEXT _x_cgo_init_trampoline(SB), NOSPLIT, $8-0 + MOVL 12(SP), AX + MOVL AX, 0(SP) + MOVL 16(SP), AX + MOVL AX, 4(SP) + MOVL ·_cgo_init_call(SB), CX + MOVL (CX), CX + CALL CX + RET + +TEXT _x_cgo_thread_start_trampoline(SB), NOSPLIT, $4-0 + MOVL 8(SP), AX + MOVL AX, 0(SP) + MOVL ·_cgo_thread_start_call(SB), CX + MOVL (CX), CX + CALL CX + RET + +TEXT _x_cgo_setenv_trampoline(SB), NOSPLIT, $4-0 + MOVL 8(SP), AX + MOVL AX, 0(SP) + MOVL ·_cgo_setenv_call(SB), CX + MOVL (CX), CX + CALL CX + RET + +TEXT _x_cgo_unsetenv_trampoline(SB), NOSPLIT, $4-0 + MOVL 8(SP), AX + MOVL AX, 0(SP) + MOVL ·_cgo_unsetenv_call(SB), CX + MOVL (CX), CX + CALL CX + RET + +TEXT _x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0 + CALL ·x_cgo_notify_runtime_init_done(SB) + RET + +TEXT _x_cgo_bindm_trampoline(SB), NOSPLIT, $0-0 + CALL ·x_cgo_bindm(SB) + RET diff --git a/internal/fakecgo/ztrampolines_amd64.s b/internal/fakecgo/ztrampolines_amd64.s new file mode 100644 index 00000000..9775fd22 --- /dev/null +++ b/internal/fakecgo/ztrampolines_amd64.s @@ -0,0 +1,52 @@ +// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && (darwin || freebsd || linux) + +#include "textflag.h" +#include "go_asm.h" + +// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. + +TEXT _x_cgo_init_trampoline(SB), NOSPLIT, $16 + MOVQ DI, AX + MOVQ SI, BX + MOVQ ·_cgo_init_call(SB), R11 + MOVQ (R11), R11 + CALL R11 + RET + +TEXT _x_cgo_thread_start_trampoline(SB), NOSPLIT, $8 + MOVQ DI, AX + MOVQ ·_cgo_thread_start_call(SB), R11 + MOVQ (R11), R11 + CALL R11 + RET + +TEXT _x_cgo_setenv_trampoline(SB), NOSPLIT, $8 + MOVQ DI, AX + MOVQ ·_cgo_setenv_call(SB), R11 + MOVQ (R11), R11 + CALL R11 + RET + +TEXT _x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8 + MOVQ DI, AX + MOVQ ·_cgo_unsetenv_call(SB), R11 + MOVQ (R11), R11 + CALL R11 + RET + +TEXT _x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0 + MOVQ ·_cgo_notify_runtime_init_done_call(SB), R11 + MOVQ (R11), R11 + CALL R11 + RET + +TEXT _x_cgo_bindm_trampoline(SB), NOSPLIT, $0 + MOVQ ·_cgo_bindm_call(SB), R11 + MOVQ (R11), R11 + CALL R11 + RET diff --git a/internal/fakecgo/ztrampolines_arm.s b/internal/fakecgo/ztrampolines_arm.s new file mode 100644 index 00000000..4e860582 --- /dev/null +++ b/internal/fakecgo/ztrampolines_arm.s @@ -0,0 +1,48 @@ +// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && (darwin || freebsd || linux || netbsd) + +#include "textflag.h" +#include "go_asm.h" + +// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. + +TEXT _x_cgo_init_trampoline(SB), NOSPLIT, $8-0 + MOVW R0, 4(R13) + MOVW R1, 8(R13) + MOVW ·_cgo_init_call(SB), R12 + MOVW (R12), R12 + CALL (R12) + RET + +TEXT _x_cgo_thread_start_trampoline(SB), NOSPLIT, $4-0 + MOVW R0, 4(R13) + MOVW ·_cgo_thread_start_call(SB), R12 + MOVW (R12), R12 + CALL (R12) + RET + +TEXT _x_cgo_setenv_trampoline(SB), NOSPLIT, $4-0 + MOVW R0, 4(R13) + MOVW ·_cgo_setenv_call(SB), R12 + MOVW (R12), R12 + CALL (R12) + RET + +TEXT _x_cgo_unsetenv_trampoline(SB), NOSPLIT, $4-0 + MOVW R0, 4(R13) + MOVW ·_cgo_unsetenv_call(SB), R12 + MOVW (R12), R12 + CALL (R12) + RET + +TEXT _x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0-0 + CALL ·x_cgo_notify_runtime_init_done(SB) + RET + +TEXT _x_cgo_bindm_trampoline(SB), NOSPLIT, $0-0 + CALL ·x_cgo_bindm(SB) + RET diff --git a/internal/fakecgo/ztrampolines_arm64.s b/internal/fakecgo/ztrampolines_arm64.s new file mode 100644 index 00000000..e829903e --- /dev/null +++ b/internal/fakecgo/ztrampolines_arm64.s @@ -0,0 +1,47 @@ +// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && (darwin || freebsd || linux) + +#include "textflag.h" +#include "go_asm.h" + +// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. + +TEXT _x_cgo_init_trampoline(SB), NOSPLIT, $16 + MOVD ·_cgo_init_call(SB), R9 + MOVD (R9), R9 + CALL R9 + RET + +TEXT _x_cgo_thread_start_trampoline(SB), NOSPLIT, $8 + MOVD ·_cgo_thread_start_call(SB), R9 + MOVD (R9), R9 + CALL R9 + RET + +TEXT _x_cgo_setenv_trampoline(SB), NOSPLIT, $8 + MOVD ·_cgo_setenv_call(SB), R9 + MOVD (R9), R9 + CALL R9 + RET + +TEXT _x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8 + MOVD ·_cgo_unsetenv_call(SB), R9 + MOVD (R9), R9 + CALL R9 + RET + +TEXT _x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0 + MOVD ·_cgo_notify_runtime_init_done_call(SB), R9 + MOVD (R9), R9 + CALL R9 + RET + +TEXT _x_cgo_bindm_trampoline(SB), NOSPLIT, $0 + MOVD ·_cgo_bindm_call(SB), R9 + MOVD (R9), R9 + CALL R9 + RET diff --git a/internal/fakecgo/ztrampolines_loong64.s b/internal/fakecgo/ztrampolines_loong64.s new file mode 100644 index 00000000..82b375ad --- /dev/null +++ b/internal/fakecgo/ztrampolines_loong64.s @@ -0,0 +1,47 @@ +// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && linux + +#include "textflag.h" +#include "go_asm.h" + +// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. + +TEXT _x_cgo_init_trampoline(SB), NOSPLIT, $16 + MOVV ·_cgo_init_call(SB), R23 + MOVV (R23), R23 + CALL (R23) + RET + +TEXT _x_cgo_thread_start_trampoline(SB), NOSPLIT, $8 + MOVV ·_cgo_thread_start_call(SB), R23 + MOVV (R23), R23 + CALL (R23) + RET + +TEXT _x_cgo_setenv_trampoline(SB), NOSPLIT, $8 + MOVV ·_cgo_setenv_call(SB), R23 + MOVV (R23), R23 + CALL (R23) + RET + +TEXT _x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8 + MOVV ·_cgo_unsetenv_call(SB), R23 + MOVV (R23), R23 + CALL (R23) + RET + +TEXT _x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0 + MOVV ·_cgo_notify_runtime_init_done_call(SB), R23 + MOVV (R23), R23 + CALL (R23) + RET + +TEXT _x_cgo_bindm_trampoline(SB), NOSPLIT, $0 + MOVV ·_cgo_bindm_call(SB), R23 + MOVV (R23), R23 + CALL (R23) + RET diff --git a/internal/fakecgo/ztrampolines_riscv64.s b/internal/fakecgo/ztrampolines_riscv64.s new file mode 100644 index 00000000..f062b89a --- /dev/null +++ b/internal/fakecgo/ztrampolines_riscv64.s @@ -0,0 +1,47 @@ +// Code generated by 'go generate' with gen.go. DO NOT EDIT. + +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Ebitengine Authors + +//go:build !cgo && linux + +#include "textflag.h" +#include "go_asm.h" + +// these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. + +TEXT _x_cgo_init_trampoline(SB), NOSPLIT, $16 + MOV ·_cgo_init_call(SB), X5 + MOV (X5), X5 + CALL X5 + RET + +TEXT _x_cgo_thread_start_trampoline(SB), NOSPLIT, $8 + MOV ·_cgo_thread_start_call(SB), X5 + MOV (X5), X5 + CALL X5 + RET + +TEXT _x_cgo_setenv_trampoline(SB), NOSPLIT, $8 + MOV ·_cgo_setenv_call(SB), X5 + MOV (X5), X5 + CALL X5 + RET + +TEXT _x_cgo_unsetenv_trampoline(SB), NOSPLIT, $8 + MOV ·_cgo_unsetenv_call(SB), X5 + MOV (X5), X5 + CALL X5 + RET + +TEXT _x_cgo_notify_runtime_init_done_trampoline(SB), NOSPLIT, $0 + MOV ·_cgo_notify_runtime_init_done_call(SB), X5 + MOV (X5), X5 + CALL X5 + RET + +TEXT _x_cgo_bindm_trampoline(SB), NOSPLIT, $0 + MOV ·_cgo_bindm_call(SB), X5 + MOV (X5), X5 + CALL X5 + RET