forked from canonical/lxd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
architectures.go
107 lines (91 loc) · 3.17 KB
/
architectures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package shared
import (
"fmt"
)
const (
ARCH_UNKNOWN = 0
ARCH_32BIT_INTEL_X86 = 1
ARCH_64BIT_INTEL_X86 = 2
ARCH_32BIT_ARMV7_LITTLE_ENDIAN = 3
ARCH_64BIT_ARMV8_LITTLE_ENDIAN = 4
ARCH_32BIT_POWERPC_BIG_ENDIAN = 5
ARCH_64BIT_POWERPC_BIG_ENDIAN = 6
ARCH_64BIT_POWERPC_LITTLE_ENDIAN = 7
ARCH_64BIT_S390_BIG_ENDIAN = 8
)
var architectureNames = map[int]string{
ARCH_32BIT_INTEL_X86: "i686",
ARCH_64BIT_INTEL_X86: "x86_64",
ARCH_32BIT_ARMV7_LITTLE_ENDIAN: "armv7l",
ARCH_64BIT_ARMV8_LITTLE_ENDIAN: "aarch64",
ARCH_32BIT_POWERPC_BIG_ENDIAN: "ppc",
ARCH_64BIT_POWERPC_BIG_ENDIAN: "ppc64",
ARCH_64BIT_POWERPC_LITTLE_ENDIAN: "ppc64le",
ARCH_64BIT_S390_BIG_ENDIAN: "s390x",
}
var architectureAliases = map[int][]string{
ARCH_32BIT_INTEL_X86: []string{"i386"},
ARCH_64BIT_INTEL_X86: []string{"amd64"},
ARCH_32BIT_ARMV7_LITTLE_ENDIAN: []string{"armel", "armhf"},
ARCH_64BIT_ARMV8_LITTLE_ENDIAN: []string{"arm64"},
ARCH_32BIT_POWERPC_BIG_ENDIAN: []string{"powerpc"},
ARCH_64BIT_POWERPC_BIG_ENDIAN: []string{"powerpc64"},
ARCH_64BIT_POWERPC_LITTLE_ENDIAN: []string{"ppc64el"},
}
var architecturePersonalities = map[int]string{
ARCH_32BIT_INTEL_X86: "linux32",
ARCH_64BIT_INTEL_X86: "linux64",
ARCH_32BIT_ARMV7_LITTLE_ENDIAN: "linux32",
ARCH_64BIT_ARMV8_LITTLE_ENDIAN: "linux64",
ARCH_32BIT_POWERPC_BIG_ENDIAN: "linux32",
ARCH_64BIT_POWERPC_BIG_ENDIAN: "linux64",
ARCH_64BIT_POWERPC_LITTLE_ENDIAN: "linux64",
ARCH_64BIT_S390_BIG_ENDIAN: "linux64",
}
var architectureSupportedPersonalities = map[int][]int{
ARCH_32BIT_INTEL_X86: []int{},
ARCH_64BIT_INTEL_X86: []int{ARCH_32BIT_INTEL_X86},
ARCH_32BIT_ARMV7_LITTLE_ENDIAN: []int{},
ARCH_64BIT_ARMV8_LITTLE_ENDIAN: []int{ARCH_32BIT_ARMV7_LITTLE_ENDIAN},
ARCH_32BIT_POWERPC_BIG_ENDIAN: []int{},
ARCH_64BIT_POWERPC_BIG_ENDIAN: []int{ARCH_32BIT_POWERPC_BIG_ENDIAN},
ARCH_64BIT_POWERPC_LITTLE_ENDIAN: []int{},
ARCH_64BIT_S390_BIG_ENDIAN: []int{},
}
const ArchitectureDefault = "x86_64"
func ArchitectureName(arch int) (string, error) {
arch_name, exists := architectureNames[arch]
if exists {
return arch_name, nil
}
return "unknown", fmt.Errorf("Architecture isn't supported: %d", arch)
}
func ArchitectureId(arch string) (int, error) {
for arch_id, arch_name := range architectureNames {
if arch_name == arch {
return arch_id, nil
}
}
for arch_id, arch_aliases := range architectureAliases {
for _, arch_name := range arch_aliases {
if arch_name == arch {
return arch_id, nil
}
}
}
return 0, fmt.Errorf("Architecture isn't supported: %s", arch)
}
func ArchitecturePersonality(arch int) (string, error) {
arch_personality, exists := architecturePersonalities[arch]
if exists {
return arch_personality, nil
}
return "", fmt.Errorf("Architecture isn't supported: %d", arch)
}
func ArchitecturePersonalities(arch int) ([]int, error) {
personalities, exists := architectureSupportedPersonalities[arch]
if exists {
return personalities, nil
}
return []int{}, fmt.Errorf("Architecture isn't supported: %d", arch)
}