1#!/bin/sh
2
3# Copyright 2018 The Go Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6
7# Code in Makefile.am will invoke this script with two arguments.
8# The first is a GOARCH value.  The second is a keyword.
9# The script will print the value of that keyword for that GOARCH.
10# Keywords:
11# - bigendian: true or false
12# - cachelinesize: the cache line size in bytes
13#	(for performance only; it's not essential to get this right)
14# - defaultphyspagesize: the default physical page size in bytes
15#	(not currently used, but maybe some day)
16# - family: the processor family, from ALLGOARCHFAMILY in configure.ac
17# - int64align: alignment of int64 type in bytes
18# - maxalign: maximum alignment of values of Go types in bytes
19# - minframesize: size of smallest possible function frame in bytes
20#	(not currently used, may never be used)
21# - pcquantum: minimum size of a single instruction in bytes
22# - ptrsize: size of a pointer in bytes
23
24if test $# -ne 2; then
25    echo 1>&2 "usage: goarch <goarch> <keyword>"
26    exit 1
27fi
28
29goarch=$1
30keyword=$2
31
32# Default values
33bigendian=false
34cachelinesize=64
35defaultphyspagesize=4096
36family=unknown
37int64align=8
38maxalign=8
39minframesize=0
40pcquantum=1
41ptrsize=8
42
43case $goarch in
44    386)
45	family=I386
46	int64align=4
47	maxalign=4
48	ptrsize=4
49	;;
50    alpha)
51	family=ALPHA
52	defaultphyspagesize=8192
53	pcquantum=4
54	;;
55    amd64)
56	family=AMD64
57	;;
58    amd64p32)
59	family=AMD64
60	ptrsize=4
61	;;
62    arm | armbe)
63	family=ARM
64	cachelinesize=32
65	minframesize=4
66	pcquantum=4
67	ptrsize=4
68	case $goarch in
69	    *be)
70		bigendian=true
71		;;
72	esac
73	;;
74    arm64 | arm64be)
75	family=ARM64
76	cachelinesize=32
77	defaultphyspagesize=65536
78	minframesize=8
79	pcquantum=4
80	case $goarch in
81	    *be)
82		bigendian=true
83		;;
84	esac
85	;;
86    ia64)
87	family=IA64
88	cachelinesize=128
89	defaultphyspagesize=65536
90	;;
91    m68k)
92	family=M68K
93	bigendian=true
94	cachelinesize=16
95	int64align=2
96	maxalign=2
97	pcquantum=4
98	ptrsize=4
99	;;
100    mips | mipsle | mips64p32 | mips64p32le)
101	family=MIPS
102	bigendian=true
103	cachelinesize=32
104	defaultphyspagesize=16384
105	minframesize=4
106	pcquantum=4
107	ptrsize=4
108	case $goarch in
109	    *le)
110		bigendian=false
111	        ;;
112	esac
113	;;
114    mips64 | mips64le)
115	family=MIPS64
116	bigendian=true
117	cachelinesize=32
118	defaultphyspagesize=16384
119	minframesize=8
120	pcquantum=4
121	case $goarch in
122	    *le)
123		bigendian=false
124		;;
125	esac
126	;;
127    nios2)
128        family=NIOS2
129        cachelinesize=32
130        minframesize=16
131        pcquantum=4
132        ptrsize=4
133        ;;
134    ppc)
135	family=PPC
136	bigendian=true
137	defaultphyspagesize=65536
138	minframesize=32
139	pcquantum=4
140	ptrsize=4
141	;;
142    ppc64 | ppc64le)
143	family=PPC64
144	bigendian=true
145	defaultphyspagesize=65536
146	minframesize=32
147	pcquantum=4
148	case $goarch in
149	    *le)
150		bigendian=false
151		;;
152	esac
153	;;
154    riscv)
155	family=RISCV
156	pcquantum=2
157	ptrsize=4
158	;;
159    riscv64)
160	family=RISCV64
161	pcquantum=2
162	;;
163    s390)
164	family=S390
165	bigendian=true
166	cachelinesize=256
167	minframesize=4
168	pcquantum=2
169	ptrsize=4
170	;;
171    s390x)
172	family=S390X
173	bigendian=true
174	cachelinesize=256
175	minframesize=8
176	pcquantum=2
177	;;
178    sh | shbe)
179	family=SH
180	cachelinesize=16
181	int64align=4
182	minframesize=4
183	pcquantum=2
184	ptrsize=4
185	case $goarch in
186	    *be)
187		bigendian=true
188		;;
189	esac
190	;;
191    sparc)
192	family=SPARC
193	bigendian=true
194	defaultphyspagesize=8192
195	pcquantum=4
196	ptrsize=4
197	;;
198    sparc64)
199	family=SPARC64
200	bigendian=true
201	defaultphyspagesize=8192
202	pcquantum=4
203	;;
204    wasm)
205	family=WASM
206	defaultphyspagesize=65536
207	;;
208    *)
209	echo 1>&2 "unrecognized goarch value \"$goarch\""
210	exit 1
211	;;
212esac
213
214if test "$family" = "unknown"; then
215    echo 1>&2 "internal error: no family for goarch value \"$goarch\""
216    exit 1
217fi
218
219case $keyword in
220    bigendian)
221	echo $bigendian
222	;;
223    cachelinesize)
224	echo $cachelinesize
225	;;
226    defaultphyspagesize)
227	echo $defaultphyspagesize
228	;;
229    family)
230	echo $family
231	;;
232    int64align)
233	echo $int64align
234	;;
235    maxalign)
236	echo $maxalign
237	;;
238    minframesize)
239	echo $minframesize
240	;;
241    pcquantum)
242	echo $pcquantum
243	;;
244    ptrsize)
245	echo $ptrsize
246	;;
247    *)
248	echo 1>&2 "unrecognized keyword \"$keyword\""
249	exit 1
250	;;
251esac
252
253exit 0
254