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