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) 61 family=AMD64 62 hugepagesize="1 << 21" 63 ;; 64 amd64p32) 65 family=AMD64 66 hugepagesize="1 << 21" 67 ptrsize=4 68 ;; 69 arm | armbe) 70 family=ARM 71 cachelinesize=32 72 minframesize=4 73 pcquantum=4 74 ptrsize=4 75 case $goarch in 76 *be) 77 bigendian=true 78 ;; 79 esac 80 ;; 81 arm64 | arm64be) 82 family=ARM64 83 cachelinesize=32 84 defaultphyspagesize=65536 85 minframesize=8 86 pcquantum=4 87 case $goarch in 88 *be) 89 bigendian=true 90 ;; 91 esac 92 ;; 93 ia64) 94 family=IA64 95 cachelinesize=128 96 defaultphyspagesize=65536 97 ;; 98 m68k) 99 family=M68K 100 bigendian=true 101 cachelinesize=16 102 int64align=2 103 maxalign=2 104 pcquantum=4 105 ptrsize=4 106 ;; 107 mips | mipsle | mips64p32 | mips64p32le) 108 family=MIPS 109 bigendian=true 110 cachelinesize=32 111 defaultphyspagesize=16384 112 minframesize=4 113 pcquantum=4 114 ptrsize=4 115 case $goarch in 116 *le) 117 bigendian=false 118 ;; 119 esac 120 ;; 121 mips64 | mips64le) 122 family=MIPS64 123 bigendian=true 124 cachelinesize=32 125 defaultphyspagesize=16384 126 minframesize=8 127 pcquantum=4 128 case $goarch in 129 *le) 130 bigendian=false 131 ;; 132 esac 133 ;; 134 nios2) 135 family=NIOS2 136 cachelinesize=32 137 minframesize=16 138 pcquantum=4 139 ptrsize=4 140 ;; 141 ppc) 142 family=PPC 143 bigendian=true 144 defaultphyspagesize=65536 145 minframesize=32 146 pcquantum=4 147 ptrsize=4 148 ;; 149 ppc64 | ppc64le) 150 family=PPC64 151 bigendian=true 152 defaultphyspagesize=65536 153 minframesize=32 154 pcquantum=4 155 case $goarch in 156 *le) 157 bigendian=false 158 ;; 159 esac 160 ;; 161 riscv) 162 family=RISCV 163 pcquantum=2 164 ptrsize=4 165 ;; 166 riscv64) 167 family=RISCV64 168 pcquantum=2 169 ;; 170 s390) 171 family=S390 172 bigendian=true 173 cachelinesize=256 174 minframesize=4 175 pcquantum=2 176 ptrsize=4 177 ;; 178 s390x) 179 family=S390X 180 bigendian=true 181 cachelinesize=256 182 minframesize=8 183 pcquantum=2 184 ;; 185 sh | shbe) 186 family=SH 187 cachelinesize=16 188 int64align=4 189 minframesize=4 190 pcquantum=2 191 ptrsize=4 192 case $goarch in 193 *be) 194 bigendian=true 195 ;; 196 esac 197 ;; 198 sparc) 199 family=SPARC 200 bigendian=true 201 defaultphyspagesize=8192 202 pcquantum=4 203 ptrsize=4 204 ;; 205 sparc64) 206 family=SPARC64 207 bigendian=true 208 defaultphyspagesize=8192 209 pcquantum=4 210 ;; 211 wasm) 212 family=WASM 213 defaultphyspagesize=65536 214 ;; 215 *) 216 echo 1>&2 "unrecognized goarch value \"$goarch\"" 217 exit 1 218 ;; 219esac 220 221if test "$family" = "unknown"; then 222 echo 1>&2 "internal error: no family for goarch value \"$goarch\"" 223 exit 1 224fi 225 226case $keyword in 227 bigendian) 228 echo $bigendian 229 ;; 230 cachelinesize) 231 echo $cachelinesize 232 ;; 233 defaultphyspagesize) 234 echo $defaultphyspagesize 235 ;; 236 family) 237 echo $family 238 ;; 239 hugepagesize) 240 echo $hugepagesize 241 ;; 242 int64align) 243 echo $int64align 244 ;; 245 maxalign) 246 echo $maxalign 247 ;; 248 minframesize) 249 echo $minframesize 250 ;; 251 pcquantum) 252 echo $pcquantum 253 ;; 254 ptrsize) 255 echo $ptrsize 256 ;; 257 *) 258 echo 1>&2 "unrecognized keyword \"$keyword\"" 259 exit 1 260 ;; 261esac 262 263exit 0 264