github.com/gernest/nezuko@v0.1.2/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 NoArch ArchFamily = iota 16 AMD64 17 ARM 18 ARM64 19 I386 20 MIPS 21 MIPS64 22 PPC64 23 S390X 24 Wasm 25 ) 26 27 // Arch represents an individual architecture. 28 type Arch struct { 29 Name string 30 Family ArchFamily 31 32 ByteOrder binary.ByteOrder 33 34 // PtrSize is the size in bytes of pointers and the 35 // predeclared "int", "uint", and "uintptr" types. 36 PtrSize int 37 38 // RegSize is the size in bytes of general purpose registers. 39 RegSize int 40 41 // MinLC is the minimum length of an instruction code. 42 MinLC int 43 } 44 45 // InFamily reports whether a is a member of any of the specified 46 // architecture families. 47 func (a *Arch) InFamily(xs ...ArchFamily) bool { 48 for _, x := range xs { 49 if a.Family == x { 50 return true 51 } 52 } 53 return false 54 } 55 56 var Arch386 = &Arch{ 57 Name: "386", 58 Family: I386, 59 ByteOrder: binary.LittleEndian, 60 PtrSize: 4, 61 RegSize: 4, 62 MinLC: 1, 63 } 64 65 var ArchAMD64 = &Arch{ 66 Name: "amd64", 67 Family: AMD64, 68 ByteOrder: binary.LittleEndian, 69 PtrSize: 8, 70 RegSize: 8, 71 MinLC: 1, 72 } 73 74 var ArchAMD64P32 = &Arch{ 75 Name: "amd64p32", 76 Family: AMD64, 77 ByteOrder: binary.LittleEndian, 78 PtrSize: 4, 79 RegSize: 8, 80 MinLC: 1, 81 } 82 83 var ArchARM = &Arch{ 84 Name: "arm", 85 Family: ARM, 86 ByteOrder: binary.LittleEndian, 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 PtrSize: 8, 97 RegSize: 8, 98 MinLC: 4, 99 } 100 101 var ArchMIPS = &Arch{ 102 Name: "mips", 103 Family: MIPS, 104 ByteOrder: binary.BigEndian, 105 PtrSize: 4, 106 RegSize: 4, 107 MinLC: 4, 108 } 109 110 var ArchMIPSLE = &Arch{ 111 Name: "mipsle", 112 Family: MIPS, 113 ByteOrder: binary.LittleEndian, 114 PtrSize: 4, 115 RegSize: 4, 116 MinLC: 4, 117 } 118 119 var ArchMIPS64 = &Arch{ 120 Name: "mips64", 121 Family: MIPS64, 122 ByteOrder: binary.BigEndian, 123 PtrSize: 8, 124 RegSize: 8, 125 MinLC: 4, 126 } 127 128 var ArchMIPS64LE = &Arch{ 129 Name: "mips64le", 130 Family: MIPS64, 131 ByteOrder: binary.LittleEndian, 132 PtrSize: 8, 133 RegSize: 8, 134 MinLC: 4, 135 } 136 137 var ArchPPC64 = &Arch{ 138 Name: "ppc64", 139 Family: PPC64, 140 ByteOrder: binary.BigEndian, 141 PtrSize: 8, 142 RegSize: 8, 143 MinLC: 4, 144 } 145 146 var ArchPPC64LE = &Arch{ 147 Name: "ppc64le", 148 Family: PPC64, 149 ByteOrder: binary.LittleEndian, 150 PtrSize: 8, 151 RegSize: 8, 152 MinLC: 4, 153 } 154 155 var ArchS390X = &Arch{ 156 Name: "s390x", 157 Family: S390X, 158 ByteOrder: binary.BigEndian, 159 PtrSize: 8, 160 RegSize: 8, 161 MinLC: 2, 162 } 163 164 var ArchWasm = &Arch{ 165 Name: "wasm", 166 Family: Wasm, 167 ByteOrder: binary.LittleEndian, 168 PtrSize: 8, 169 RegSize: 8, 170 MinLC: 1, 171 } 172 173 var Archs = [...]*Arch{ 174 Arch386, 175 ArchAMD64, 176 ArchAMD64P32, 177 ArchARM, 178 ArchARM64, 179 ArchMIPS, 180 ArchMIPSLE, 181 ArchMIPS64, 182 ArchMIPS64LE, 183 ArchPPC64, 184 ArchPPC64LE, 185 ArchS390X, 186 ArchWasm, 187 }