arch.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package sys
  5. import "encoding/binary"
  6. // ArchFamily represents a family of one or more related architectures.
  7. // For example, ppc64 and ppc64le are both members of the PPC64 family.
  8. type ArchFamily byte
  9. const (
  10. NoArch ArchFamily = iota
  11. AMD64
  12. ARM
  13. ARM64
  14. I386
  15. MIPS
  16. MIPS64
  17. PPC64
  18. RISCV64
  19. S390X
  20. Wasm
  21. )
  22. // Arch represents an individual architecture.
  23. type Arch struct {
  24. Name string
  25. Family ArchFamily
  26. ByteOrder binary.ByteOrder
  27. // PtrSize is the size in bytes of pointers and the
  28. // predeclared "int", "uint", and "uintptr" types.
  29. PtrSize int
  30. // RegSize is the size in bytes of general purpose registers.
  31. RegSize int
  32. // MinLC is the minimum length of an instruction code.
  33. MinLC int
  34. }
  35. // InFamily reports whether a is a member of any of the specified
  36. // architecture families.
  37. func (a *Arch) InFamily(xs ...ArchFamily) bool {
  38. for _, x := range xs {
  39. if a.Family == x {
  40. return true
  41. }
  42. }
  43. return false
  44. }
  45. var Arch386 = &Arch{
  46. Name: "386",
  47. Family: I386,
  48. ByteOrder: binary.LittleEndian,
  49. PtrSize: 4,
  50. RegSize: 4,
  51. MinLC: 1,
  52. }
  53. var ArchAMD64 = &Arch{
  54. Name: "amd64",
  55. Family: AMD64,
  56. ByteOrder: binary.LittleEndian,
  57. PtrSize: 8,
  58. RegSize: 8,
  59. MinLC: 1,
  60. }
  61. var ArchARM = &Arch{
  62. Name: "arm",
  63. Family: ARM,
  64. ByteOrder: binary.LittleEndian,
  65. PtrSize: 4,
  66. RegSize: 4,
  67. MinLC: 4,
  68. }
  69. var ArchARM64 = &Arch{
  70. Name: "arm64",
  71. Family: ARM64,
  72. ByteOrder: binary.LittleEndian,
  73. PtrSize: 8,
  74. RegSize: 8,
  75. MinLC: 4,
  76. }
  77. var ArchMIPS = &Arch{
  78. Name: "mips",
  79. Family: MIPS,
  80. ByteOrder: binary.BigEndian,
  81. PtrSize: 4,
  82. RegSize: 4,
  83. MinLC: 4,
  84. }
  85. var ArchMIPSLE = &Arch{
  86. Name: "mipsle",
  87. Family: MIPS,
  88. ByteOrder: binary.LittleEndian,
  89. PtrSize: 4,
  90. RegSize: 4,
  91. MinLC: 4,
  92. }
  93. var ArchMIPS64 = &Arch{
  94. Name: "mips64",
  95. Family: MIPS64,
  96. ByteOrder: binary.BigEndian,
  97. PtrSize: 8,
  98. RegSize: 8,
  99. MinLC: 4,
  100. }
  101. var ArchMIPS64LE = &Arch{
  102. Name: "mips64le",
  103. Family: MIPS64,
  104. ByteOrder: binary.LittleEndian,
  105. PtrSize: 8,
  106. RegSize: 8,
  107. MinLC: 4,
  108. }
  109. var ArchPPC64 = &Arch{
  110. Name: "ppc64",
  111. Family: PPC64,
  112. ByteOrder: binary.BigEndian,
  113. PtrSize: 8,
  114. RegSize: 8,
  115. MinLC: 4,
  116. }
  117. var ArchPPC64LE = &Arch{
  118. Name: "ppc64le",
  119. Family: PPC64,
  120. ByteOrder: binary.LittleEndian,
  121. PtrSize: 8,
  122. RegSize: 8,
  123. MinLC: 4,
  124. }
  125. var ArchRISCV64 = &Arch{
  126. Name: "riscv64",
  127. Family: RISCV64,
  128. ByteOrder: binary.LittleEndian,
  129. PtrSize: 8,
  130. RegSize: 8,
  131. MinLC: 4,
  132. }
  133. var ArchS390X = &Arch{
  134. Name: "s390x",
  135. Family: S390X,
  136. ByteOrder: binary.BigEndian,
  137. PtrSize: 8,
  138. RegSize: 8,
  139. MinLC: 2,
  140. }
  141. var ArchWasm = &Arch{
  142. Name: "wasm",
  143. Family: Wasm,
  144. ByteOrder: binary.LittleEndian,
  145. PtrSize: 8,
  146. RegSize: 8,
  147. MinLC: 1,
  148. }
  149. var Archs = [...]*Arch{
  150. Arch386,
  151. ArchAMD64,
  152. ArchARM,
  153. ArchARM64,
  154. ArchMIPS,
  155. ArchMIPSLE,
  156. ArchMIPS64,
  157. ArchMIPS64LE,
  158. ArchPPC64,
  159. ArchPPC64LE,
  160. ArchRISCV64,
  161. ArchS390X,
  162. ArchWasm,
  163. }