blob: 9f003aed051f90439c4cfd14fbb95c85c0f4d420 [file] [log] [blame]
Brad Fitzpatrick51947442016-03-01 22:57:46 +00001// Copyright 2014 The Go Authors. All rights reserved.
Russ Coxdcb2ec32014-12-05 16:24:20 -05002// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build ignore
6
7// Generate Windows callback assembly file.
8
9package main
10
11import (
12 "bytes"
13 "fmt"
14 "io/ioutil"
15 "os"
16)
17
18const maxCallback = 2000
19
Alex Brainman3f195412014-12-18 16:30:46 +110020func genasm() {
Russ Coxdcb2ec32014-12-05 16:24:20 -050021 var buf bytes.Buffer
22
23 buf.WriteString(`// generated by wincallback.go; run go generate
24
25// runtime·callbackasm is called by external code to
26// execute Go implemented callback function. It is not
27// called from the start, instead runtime·compilecallback
28// always returns address into runtime·callbackasm offset
29// appropriately so different callbacks start with different
30// CALL instruction in runtime·callbackasm. This determines
31// which Go callback function is executed later on.
32TEXT runtime·callbackasm(SB),7,$0
33`)
34 for i := 0; i < maxCallback; i++ {
35 buf.WriteString("\tCALL\truntime·callbackasm1(SB)\n")
36 }
37
38 err := ioutil.WriteFile("zcallback_windows.s", buf.Bytes(), 0666)
39 if err != nil {
40 fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
41 os.Exit(2)
42 }
43}
Alex Brainman3f195412014-12-18 16:30:46 +110044
45func gengo() {
46 var buf bytes.Buffer
47
48 buf.WriteString(fmt.Sprintf(`// generated by wincallback.go; run go generate
49
50package runtime
51
52const cb_max = %d // maximum number of windows callbacks allowed
53`, maxCallback))
54 err := ioutil.WriteFile("zcallback_windows.go", buf.Bytes(), 0666)
55 if err != nil {
56 fmt.Fprintf(os.Stderr, "wincallback: %s\n", err)
57 os.Exit(2)
58 }
59}
60
61func main() {
62 genasm()
63 gengo()
64}