github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/src/cmd/internal/sys/arch.go (about) 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 5 package sys 6 7 import "encoding/binary" 8 9 // ArchFamily represents a family of one or more related architectures. 10 // For example, amd64 and amd64p32 are both members of the AMD64 family, 11 // and ppc64 and ppc64le are both members of the PPC64 family. 12 type ArchFamily byte 13 14 const ( 15 AMD64 ArchFamily = iota 16 ARM 17 ARM64 18 I386 19 MIPS 20 MIPS64 21 PPC64 22 RISCV 23 S390X 24 ) 25 26 // Arch represents an individual architecture. 27 type Arch struct { 28 Name string 29 Family ArchFamily 30 31 ByteOrder binary.ByteOrder 32 33 IntSize int 34 PtrSize int 35 RegSize int 36 37 // MinLC is the minimum length of an instruction code. 38 MinLC int 39 } 40 41 // InFamily reports whether a is a member of any of the specified 42 // architecture families. 43 func (a *Arch) InFamily(xs ...ArchFamily) bool { 44 for _, x := range xs { 45 if a.Family == x { 46 return true 47 } 48 } 49 return false 50 } 51 52 var Arch386 = &Arch{ 53 Name: "386", 54 Family: I386, 55 ByteOrder: binary.LittleEndian, 56 IntSize: 4, 57 PtrSize: 4, 58 RegSize: 4, 59 MinLC: 1, 60 } 61 62 var ArchAMD64 = &Arch{ 63 Name: "amd64", 64 Family: AMD64, 65 ByteOrder: binary.LittleEndian, 66 IntSize: 8, 67 PtrSize: 8, 68 RegSize: 8, 69 MinLC: 1, 70 } 71 72 var ArchAMD64P32 = &Arch{ 73 Name: "amd64p32", 74 Family: AMD64, 75 ByteOrder: binary.LittleEndian, 76 IntSize: 4, 77 PtrSize: 4, 78 RegSize: 8, 79 MinLC: 1, 80 } 81 82 var ArchARM = &Arch{ 83 Name: "arm", 84 Family: ARM, 85 ByteOrder: binary.LittleEndian, 86 IntSize: 4, 87 PtrSize: 4, 88 RegSize: 4, 89 MinLC: 4, 90 } 91 92 var ArchARM64 = &Arch{ 93 Name: "arm64", 94 Family: ARM64, 95 ByteOrder: binary.LittleEndian, 96 IntSize: 8, 97 PtrSize: 8, 98 RegSize: 8, 99 MinLC: 4, 100 } 101 102 var ArchMIPS = &Arch{ 103 Name: "mips", 104 Family: MIPS, 105 ByteOrder: binary.BigEndian, 106 IntSize: 4, 107 PtrSize: 4, 108 RegSize: 4, 109 MinLC: 4, 110 } 111 112 var ArchMIPSLE = &Arch{ 113 Name: "mipsle", 114 Family: MIPS, 115 ByteOrder: binary.LittleEndian, 116 IntSize: 4, 117 PtrSize: 4, 118 RegSize: 4, 119 MinLC: 4, 120 } 121 122 var ArchMIPS64 = &Arch{ 123 Name: "mips64", 124 Family: MIPS64, 125 ByteOrder: binary.BigEndian, 126 IntSize: 8, 127 PtrSize: 8, 128 RegSize: 8, 129 MinLC: 4, 130 } 131 132 var ArchMIPS64LE = &Arch{ 133 Name: "mips64le", 134 Family: MIPS64, 135 ByteOrder: binary.LittleEndian, 136 IntSize: 8, 137 PtrSize: 8, 138 RegSize: 8, 139 MinLC: 4, 140 } 141 142 var ArchPPC64 = &Arch{ 143 Name: "ppc64", 144 Family: PPC64, 145 ByteOrder: binary.BigEndian, 146 IntSize: 8, 147 PtrSize: 8, 148 RegSize: 8, 149 MinLC: 4, 150 } 151 152 var ArchPPC64LE = &Arch{ 153 Name: "ppc64le", 154 Family: PPC64, 155 ByteOrder: binary.LittleEndian, 156 IntSize: 8, 157 PtrSize: 8, 158 RegSize: 8, 159 MinLC: 4, 160 } 161 162 var ArchRISCV = &Arch{ 163 Name: "riscv", 164 Family: RISCV, 165 ByteOrder: binary.LittleEndian, 166 IntSize: 8, 167 PtrSize: 8, 168 RegSize: 8, 169 MinLC: 4, 170 } 171 172 var ArchS390X = &Arch{ 173 Name: "s390x", 174 Family: S390X, 175 ByteOrder: binary.BigEndian, 176 IntSize: 8, 177 PtrSize: 8, 178 RegSize: 8, 179 MinLC: 2, 180 } 181 182 var Archs = [...]*Arch{ 183 Arch386, 184 ArchAMD64, 185 ArchAMD64P32, 186 ArchARM, 187 ArchARM64, 188 ArchMIPS, 189 ArchMIPSLE, 190 ArchMIPS64, 191 ArchMIPS64LE, 192 ArchPPC64, 193 ArchPPC64LE, 194 ArchS390X, 195 }