...
Run Format

Source file src/cmd/internal/sys/arch.go

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

View as plain text