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# - hugepagesize: size of a huge page in bytes
18#	(used only to decide when to use madvise with MADV_[NO]HUGEPAGE)
19#	(set to 0 if there are no huge pages)
20# - int64align: alignment of int64 type in bytes
21# - maxalign: maximum alignment of values of Go types in bytes
22# - minframesize: size of smallest possible function frame in bytes
23#	(not currently used, may never be used)
24# - pcquantum: minimum size of a single instruction in bytes
25# - ptrsize: size of a pointer in bytes
26
27if test $# -ne 2; then
28    echo 1>&2 "usage: goarch <goarch> <keyword>"
29    exit 1
30fi
31
32goarch=$1
33keyword=$2
34
35# Default values
36bigendian=false
37cachelinesize=64
38defaultphyspagesize=4096
39family=unknown
40hugepagesize=0
41int64align=8
42maxalign=8
43minframesize=0
44pcquantum=1
45ptrsize=8
46
47case $goarch in
48    386)
49	family=I386
50	hugepagesize="1 << 21"
51	int64align=4
52	maxalign=4
53	ptrsize=4
54	;;
55    alpha)
56	family=ALPHA
57	defaultphyspagesize=8192
58	pcquantum=4
59	;;
60    amd64 | amd64p32)
61	family=AMD64
62	hugepagesize="1 << 21"
63	;;
64    arm | armbe)
65	family=ARM
66	cachelinesize=32
67	minframesize=4
68	pcquantum=4
69	ptrsize=4
70	case $goarch in
71	    *be)
72		bigendian=true
73		;;
74	esac
75	;;
76    arm64 | arm64be)
77	family=ARM64
78	cachelinesize=32
79	defaultphyspagesize=65536
80	minframesize=8
81	pcquantum=4
82	case $goarch in
83	    *be)
84		bigendian=true
85		;;
86	esac
87	;;
88    ia64)
89	family=IA64
90	cachelinesize=128
91	defaultphyspagesize=65536
92	;;
93    m68k)
94	family=M68K
95	bigendian=true
96	cachelinesize=16
97	int64align=2
98	maxalign=2
99	pcquantum=4
100	ptrsize=4
101	;;
102    mips | mipsle | mips64p32 | mips64p32le)
103	family=MIPS
104	bigendian=true
105	cachelinesize=32
106	defaultphyspagesize=16384
107	minframesize=4
108	pcquantum=4
109	ptrsize=4
110	case $goarch in
111	    *le)
112		bigendian=false
113	        ;;
114	esac
115	;;
116    mips64 | mips64le)
117	family=MIPS64
118	bigendian=true
119	cachelinesize=32
120	defaultphyspagesize=16384
121	minframesize=8
122	pcquantum=4
123	case $goarch in
124	    *le)
125		bigendian=false
126		;;
127	esac
128	;;
129    ppc)
130	family=PPC
131	bigendian=true
132	defaultphyspagesize=65536
133	minframesize=32
134	pcquantum=4
135	ptrsize=4
136	;;
137    ppc64 | ppc64le)
138	family=PPC64
139	bigendian=true
140	defaultphyspagesize=65536
141	minframesize=32
142	pcquantum=4
143	case $goarch in
144	    *le)
145		bigendian=false
146		;;
147	esac
148	;;
149    riscv64)
150	family=RISCV64
151	pcquantum=2
152	;;
153    s390)
154	family=S390
155	bigendian=true
156	cachelinesize=256
157	minframesize=4
158	pcquantum=2
159	ptrsize=4
160	;;
161    s390x)
162	family=S390X
163	bigendian=true
164	cachelinesize=256
165	minframesize=8
166	pcquantum=2
167	;;
168    sh | shbe)
169	family=SH
170	cachelinesize=16
171	int64align=4
172	minframesize=4
173	pcquantum=2
174	ptrsize=4
175	case $goarch in
176	    *be)
177		bigendian=true
178		;;
179	esac
180	;;
181    sparc)
182	family=SPARC
183	bigendian=true
184	defaultphyspagesize=8192
185	pcquantum=4
186	ptrsize=4
187	;;
188    sparc64)
189	family=SPARC64
190	bigendian=true
191	defaultphyspagesize=8192
192	pcquantum=4
193	;;
194    *)
195	echo 1>&2 "unrecognized goarch value \"$goarch\""
196	exit 1
197	;;
198esac
199
200if test "$family" = "unknown"; then
201    echo 1>&2 "internal error: no family for goarch value \"$goarch\""
202    exit 1
203fi
204
205case $keyword in
206    bigendian)
207	echo $bigendian
208	;;
209    cachelinesize)
210	echo $cachelinesize
211	;;
212    defaultphyspagesize)
213	echo $defaultphyspagesize
214	;;
215    family)
216	echo $family
217	;;
218    hugepagesize)
219	echo $hugepagesize
220	;;
221    int64align)
222	echo $int64align
223	;;
224    maxalign)
225	echo $maxalign
226	;;
227    minframesize)
228	echo $minframesize
229	;;
230    pcquantum)
231	echo $pcquantum
232	;;
233    ptrsize)
234	echo $ptrsize
235	;;
236    *)
237	echo 1>&2 "unrecognized keyword \"$keyword\""
238	exit 1
239	;;
240esac
241
242exit 0
243