github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/obj/x86/asm6.go (about)

     1  // Inferno utils/6l/span.c
     2  // https://bitbucket.org/inferno-os/inferno-os/src/master/utils/6l/span.c
     3  //
     4  //	Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
     5  //	Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
     6  //	Portions Copyright © 1997-1999 Vita Nuova Limited
     7  //	Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
     8  //	Portions Copyright © 2004,2006 Bruce Ellis
     9  //	Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
    10  //	Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
    11  //	Portions Copyright © 2009 The Go Authors. All rights reserved.
    12  //
    13  // Permission is hereby granted, free of charge, to any person obtaining a copy
    14  // of this software and associated documentation files (the "Software"), to deal
    15  // in the Software without restriction, including without limitation the rights
    16  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    17  // copies of the Software, and to permit persons to whom the Software is
    18  // furnished to do so, subject to the following conditions:
    19  //
    20  // The above copyright notice and this permission notice shall be included in
    21  // all copies or substantial portions of the Software.
    22  //
    23  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    24  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    25  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    26  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    27  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    28  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    29  // THE SOFTWARE.
    30  
    31  package x86
    32  
    33  import (
    34  	"github.com/shogo82148/std/cmd/internal/obj"
    35  )
    36  
    37  type Optab struct {
    38  	as     obj.As
    39  	ytab   []ytab
    40  	prefix uint8
    41  	op     opBytes
    42  }
    43  
    44  const (
    45  	Yxxx = iota
    46  	Ynone
    47  	Yi0
    48  	Yi1
    49  	Yu2
    50  	Yi8
    51  	Yu8
    52  	Yu7
    53  	Ys32
    54  	Yi32
    55  	Yi64
    56  	Yiauto
    57  	Yal
    58  	Ycl
    59  	Yax
    60  	Ycx
    61  	Yrb
    62  	Yrl
    63  	Yrl32
    64  	Yrf
    65  	Yf0
    66  	Yrx
    67  	Ymb
    68  	Yml
    69  	Ym
    70  	Ybr
    71  	Ycs
    72  	Yss
    73  	Yds
    74  	Yes
    75  	Yfs
    76  	Ygs
    77  	Ygdtr
    78  	Yidtr
    79  	Yldtr
    80  	Ymsw
    81  	Ytask
    82  	Ycr0
    83  	Ycr1
    84  	Ycr2
    85  	Ycr3
    86  	Ycr4
    87  	Ycr5
    88  	Ycr6
    89  	Ycr7
    90  	Ycr8
    91  	Ydr0
    92  	Ydr1
    93  	Ydr2
    94  	Ydr3
    95  	Ydr4
    96  	Ydr5
    97  	Ydr6
    98  	Ydr7
    99  	Ytr0
   100  	Ytr1
   101  	Ytr2
   102  	Ytr3
   103  	Ytr4
   104  	Ytr5
   105  	Ytr6
   106  	Ytr7
   107  	Ymr
   108  	Ymm
   109  	Yxr0
   110  	YxrEvexMulti4
   111  	Yxr
   112  	YxrEvex
   113  	Yxm
   114  	YxmEvex
   115  	Yxvm
   116  	YxvmEvex
   117  	YyrEvexMulti4
   118  	Yyr
   119  	YyrEvex
   120  	Yym
   121  	YymEvex
   122  	Yyvm
   123  	YyvmEvex
   124  	YzrMulti4
   125  	Yzr
   126  	Yzm
   127  	Yzvm
   128  	Yk0
   129  	Yknot0
   130  	Yk
   131  	Ykm
   132  	Ytls
   133  	Ytextsize
   134  	Yindir
   135  	Ymax
   136  )
   137  
   138  const (
   139  	Zxxx = iota
   140  	Zlit
   141  	Zlitm_r
   142  	Zlitr_m
   143  	Zlit_m_r
   144  	Z_rp
   145  	Zbr
   146  	Zcall
   147  	Zcallcon
   148  	Zcallduff
   149  	Zcallind
   150  	Zcallindreg
   151  	Zib_
   152  	Zib_rp
   153  	Zibo_m
   154  	Zibo_m_xm
   155  	Zil_
   156  	Zil_rp
   157  	Ziq_rp
   158  	Zilo_m
   159  	Zjmp
   160  	Zjmpcon
   161  	Zloop
   162  	Zo_iw
   163  	Zm_o
   164  	Zm_r
   165  	Z_m_r
   166  	Zm2_r
   167  	Zm_r_xm
   168  	Zm_r_i_xm
   169  	Zm_r_xm_nr
   170  	Zr_m_xm_nr
   171  	Zibm_r
   172  	Zibr_m
   173  	Zmb_r
   174  	Zaut_r
   175  	Zo_m
   176  	Zo_m64
   177  	Zpseudo
   178  	Zr_m
   179  	Zr_m_xm
   180  	Zrp_
   181  	Z_ib
   182  	Z_il
   183  	Zm_ibo
   184  	Zm_ilo
   185  	Zib_rr
   186  	Zil_rr
   187  	Zbyte
   188  
   189  	Zvex_rm_v_r
   190  	Zvex_rm_v_ro
   191  	Zvex_r_v_rm
   192  	Zvex_i_rm_vo
   193  	Zvex_v_rm_r
   194  	Zvex_i_rm_r
   195  	Zvex_i_r_v
   196  	Zvex_i_rm_v_r
   197  	Zvex
   198  	Zvex_rm_r_vo
   199  	Zvex_i_r_rm
   200  	Zvex_hr_rm_v_r
   201  
   202  	Zevex_first
   203  	Zevex_i_r_k_rm
   204  	Zevex_i_r_rm
   205  	Zevex_i_rm_k_r
   206  	Zevex_i_rm_k_vo
   207  	Zevex_i_rm_r
   208  	Zevex_i_rm_v_k_r
   209  	Zevex_i_rm_v_r
   210  	Zevex_i_rm_vo
   211  	Zevex_k_rmo
   212  	Zevex_r_k_rm
   213  	Zevex_r_v_k_rm
   214  	Zevex_r_v_rm
   215  	Zevex_rm_k_r
   216  	Zevex_rm_v_k_r
   217  	Zevex_rm_v_r
   218  	Zevex_last
   219  
   220  	Zmax
   221  )
   222  
   223  const (
   224  	Px   = 0
   225  	Px1  = 1
   226  	P32  = 0x32
   227  	Pe   = 0x66
   228  	Pm   = 0x0f
   229  	Pq   = 0xff
   230  	Pb   = 0xfe
   231  	Pf2  = 0xf2
   232  	Pf3  = 0xf3
   233  	Pef3 = 0xf5
   234  	Pq3  = 0x67
   235  	Pq4  = 0x68
   236  	Pq4w = 0x69
   237  	Pq5  = 0x6a
   238  	Pq5w = 0x6b
   239  	Pfw  = 0xf4
   240  	Pw   = 0x48
   241  	Pw8  = 0x90
   242  	Py   = 0x80
   243  	Py1  = 0x81
   244  	Py3  = 0x83
   245  	Pavx = 0x84
   246  
   247  	RxrEvex = 1 << 4
   248  	Rxw     = 1 << 3
   249  	Rxr     = 1 << 2
   250  	Rxx     = 1 << 1
   251  	Rxb     = 1 << 0
   252  )
   253  
   254  // AsmBuf is a simple buffer to assemble variable-length x86 instructions into
   255  // and hold assembly state.
   256  type AsmBuf struct {
   257  	buf      [100]byte
   258  	off      int
   259  	rexflag  int
   260  	vexflag  bool
   261  	evexflag bool
   262  	rep      bool
   263  	repn     bool
   264  	lock     bool
   265  
   266  	evex evexBits
   267  }
   268  
   269  // Put1 appends one byte to the end of the buffer.
   270  func (ab *AsmBuf) Put1(x byte)
   271  
   272  // Put2 appends two bytes to the end of the buffer.
   273  func (ab *AsmBuf) Put2(x, y byte)
   274  
   275  // Put3 appends three bytes to the end of the buffer.
   276  func (ab *AsmBuf) Put3(x, y, z byte)
   277  
   278  // Put4 appends four bytes to the end of the buffer.
   279  func (ab *AsmBuf) Put4(x, y, z, w byte)
   280  
   281  // PutInt16 writes v into the buffer using little-endian encoding.
   282  func (ab *AsmBuf) PutInt16(v int16)
   283  
   284  // PutInt32 writes v into the buffer using little-endian encoding.
   285  func (ab *AsmBuf) PutInt32(v int32)
   286  
   287  // PutInt64 writes v into the buffer using little-endian encoding.
   288  func (ab *AsmBuf) PutInt64(v int64)
   289  
   290  // Put copies b into the buffer.
   291  func (ab *AsmBuf) Put(b []byte)
   292  
   293  // PutOpBytesLit writes zero terminated sequence of bytes from op,
   294  // starting at specified offset (e.g. z counter value).
   295  // Trailing 0 is not written.
   296  //
   297  // Intended to be used for literal Z cases.
   298  // Literal Z cases usually have "Zlit" in their name (Zlit, Zlitr_m, Zlitm_r).
   299  func (ab *AsmBuf) PutOpBytesLit(offset int, op *opBytes)
   300  
   301  // Insert inserts b at offset i.
   302  func (ab *AsmBuf) Insert(i int, b byte)
   303  
   304  // Last returns the byte at the end of the buffer.
   305  func (ab *AsmBuf) Last() byte
   306  
   307  // Len returns the length of the buffer.
   308  func (ab *AsmBuf) Len() int
   309  
   310  // Bytes returns the contents of the buffer.
   311  func (ab *AsmBuf) Bytes() []byte
   312  
   313  // Reset empties the buffer.
   314  func (ab *AsmBuf) Reset()
   315  
   316  // At returns the byte at offset i.
   317  func (ab *AsmBuf) At(i int) byte