goarch.sh 4.3 KB

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