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