github.com/akaros/go-akaros@v0.0.0-20181004170632-85005d477eab/src/cmd/internal/rsc.io/arm/armasm/objdump_test.go (about)

     1  // Copyright 2014 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 armasm
     6  
     7  import (
     8  	"encoding/binary"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  func TestObjdumpARMTestdata(t *testing.T) { testObjdumpARM(t, testdataCases(t)) }
    14  func TestObjdumpARMManual(t *testing.T)   { testObjdumpARM(t, hexCases(t, objdumpManualTests)) }
    15  func TestObjdumpARMCond(t *testing.T)     { testObjdumpARM(t, condCases(t)) }
    16  func TestObjdumpARMUncond(t *testing.T)   { testObjdumpARM(t, uncondCases(t)) }
    17  func TestObjdumpARMVFP(t *testing.T)      { testObjdumpARM(t, vfpCases(t)) }
    18  
    19  // objdumpManualTests holds test cases that will be run by TestObjdumpARMManual.
    20  // If you are debugging a few cases that turned up in a longer run, it can be useful
    21  // to list them here and then use -run=Manual, particularly with tracing enabled.
    22  // Note that these are byte sequences, so they must be reversed from the usual
    23  // word presentation.
    24  var objdumpManualTests = `
    25  00000000
    26  `
    27  
    28  // allowedMismatchObjdump reports whether the mismatch between text and dec
    29  // should be allowed by the test.
    30  func allowedMismatchObjdump(text string, size int, inst *Inst, dec ExtInst) bool {
    31  	if hasPrefix(text, "error:") {
    32  		if hasPrefix(dec.text, unsupported...) || strings.Contains(dec.text, "invalid:") || strings.HasSuffix(dec.text, "^") || strings.Contains(dec.text, "f16.f64") || strings.Contains(dec.text, "f64.f16") {
    33  			return true
    34  		}
    35  		// word 4320F02C: libopcodes says 'nopmi {44}'.
    36  		if hasPrefix(dec.text, "nop") && strings.Contains(dec.text, "{") {
    37  			return true
    38  		}
    39  	}
    40  
    41  	if hasPrefix(dec.text, "error:") && text == "undef" && inst.Enc == 0xf7fabcfd {
    42  		return true
    43  	}
    44  
    45  	// word 00f02053: libopcodes says 'noppl {0}'.
    46  	if hasPrefix(dec.text, "nop") && hasPrefix(text, "nop") && dec.text == text+" {0}" {
    47  		return true
    48  	}
    49  
    50  	// word F57FF04F. we say 'dsb #15', libopcodes says 'dsb sy'.
    51  	if hasPrefix(text, "dsb") && hasPrefix(dec.text, "dsb") {
    52  		return true
    53  	}
    54  	// word F57FF06F. we say 'isb #15', libopcodes says 'isb sy'.
    55  	if hasPrefix(text, "isb") && hasPrefix(dec.text, "isb") {
    56  		return true
    57  	}
    58  	// word F57FF053. we say 'dmb #3', libopcodes says 'dmb osh'.
    59  	if hasPrefix(text, "dmb") && hasPrefix(dec.text, "dmb") {
    60  		return true
    61  	}
    62  
    63  	// word 992D0000. push/stmdb with no registers (undefined).
    64  	// we say 'stmdbls sp!, {}', libopcodes says 'pushls {}'.
    65  	if hasPrefix(text, "stmdb") && hasPrefix(dec.text, "push") && strings.Contains(text, "{}") && strings.Contains(dec.text, "{}") {
    66  		return true
    67  	}
    68  
    69  	// word 28BD0000. pop/ldm with no registers (undefined).
    70  	// we say 'ldmcs sp!, {}', libopcodes says 'popcs {}'.
    71  	if hasPrefix(text, "ldm") && hasPrefix(dec.text, "pop") && strings.Contains(text, "{}") && strings.Contains(dec.text, "{}") {
    72  		return true
    73  	}
    74  
    75  	// word 014640F0.
    76  	// libopcodes emits #-0 for negative zero; we don't.
    77  	if strings.Replace(dec.text, "#-0", "#0", -1) == text || strings.Replace(dec.text, ", #-0", "", -1) == text {
    78  		return true
    79  	}
    80  
    81  	// word 91EF90F0. we say 'strdls r9, [pc, #0]!' but libopcodes says 'strdls r9, [pc]'.
    82  	// word D16F60F0. we say 'strdle r6, [pc, #0]!' but libopcodes says 'strdle r6, [pc, #-0]'.
    83  	if strings.Replace(text, ", #0]!", "]", -1) == strings.Replace(dec.text, ", #-0]", "]", -1) {
    84  		return true
    85  	}
    86  
    87  	// word 510F4000. we say apsr, libopcodes says CPSR.
    88  	if strings.Replace(dec.text, "CPSR", "apsr", -1) == text {
    89  		return true
    90  	}
    91  
    92  	// word 06A4B059.
    93  	// for ssat and usat, libopcodes decodes asr #0 as asr #0 but the manual seems to say it should be asr #32.
    94  	// There is never an asr #0.
    95  	if strings.Replace(dec.text, ", asr #0", ", asr #32", -1) == text {
    96  		return true
    97  	}
    98  
    99  	if len(dec.enc) >= 4 {
   100  		raw := binary.LittleEndian.Uint32(dec.enc[:4])
   101  
   102  		// word 21FFF0B5.
   103  		// the manual is clear that this is pre-indexed mode (with !) but libopcodes generates post-index (without !).
   104  		if raw&0x01200000 == 0x01200000 && strings.Replace(text, "!", "", -1) == dec.text {
   105  			return true
   106  		}
   107  
   108  		// word C100543E: libopcodes says tst, but no evidence for that.
   109  		if strings.HasPrefix(dec.text, "tst") && raw&0x0ff00000 != 0x03100000 && raw&0x0ff00000 != 0x01100000 {
   110  			return true
   111  		}
   112  
   113  		// word C3203CE8: libopcodes says teq, but no evidence for that.
   114  		if strings.HasPrefix(dec.text, "teq") && raw&0x0ff00000 != 0x03300000 && raw&0x0ff00000 != 0x01300000 {
   115  			return true
   116  		}
   117  
   118  		// word D14C552E: libopcodes says cmp but no evidence for that.
   119  		if strings.HasPrefix(dec.text, "cmp") && raw&0x0ff00000 != 0x03500000 && raw&0x0ff00000 != 0x01500000 {
   120  			return true
   121  		}
   122  
   123  		// word 2166AA4A: libopcodes says cmn but no evidence for that.
   124  		if strings.HasPrefix(dec.text, "cmn") && raw&0x0ff00000 != 0x03700000 && raw&0x0ff00000 != 0x01700000 {
   125  			return true
   126  		}
   127  
   128  		// word E70AEEEF: libopcodes says str but no evidence for that.
   129  		if strings.HasPrefix(dec.text, "str") && len(dec.text) >= 5 && (dec.text[3] == ' ' || dec.text[5] == ' ') && raw&0x0e500018 != 0x06000000 && raw&0x0e500000 != 0x0400000 {
   130  			return true
   131  		}
   132  
   133  		// word B0AF48F4: libopcodes says strd but P=0,W=1 which is unpredictable.
   134  		if hasPrefix(dec.text, "ldr", "str") && raw&0x01200000 == 0x00200000 {
   135  			return true
   136  		}
   137  
   138  		// word B6CC1C76: libopcodes inexplicably says 'uxtab16lt r1, ip, r6, ROR #24' instead of 'uxtab16lt r1, ip, r6, ror #24'
   139  		if strings.ToLower(dec.text) == text {
   140  			return true
   141  		}
   142  
   143  		// word F410FDA1: libopcodes says PLDW but the manual is clear that PLDW is F5/F7, not F4.
   144  		// word F7D0FB17: libopcodes says PLDW but the manual is clear that PLDW has 0x10 clear
   145  		if hasPrefix(dec.text, "pld") && raw&0xfd000010 != 0xf5000000 {
   146  			return true
   147  		}
   148  
   149  		// word F650FE14: libopcodes says PLI but the manual is clear that PLI has 0x10 clear
   150  		if hasPrefix(dec.text, "pli") && raw&0xff000010 != 0xf6000000 {
   151  			return true
   152  		}
   153  	}
   154  
   155  	return false
   156  }
   157  
   158  // Instructions known to libopcodes (or xed) but not to us.
   159  // Most of these are floating point coprocessor instructions.
   160  var unsupported = strings.Fields(`
   161  	abs
   162  	acs
   163  	adf
   164  	aes
   165  	asn
   166  	atn
   167  	cdp
   168  	cf
   169  	cmf
   170  	cnf
   171  	cos
   172  	cps
   173  	crc32
   174  	dvf
   175  	eret
   176  	exp
   177  	fadd
   178  	fcmp
   179  	fcpy
   180  	fcvt
   181  	fdiv
   182  	fdv
   183  	fix
   184  	fld
   185  	flt
   186  	fmac
   187  	fmd
   188  	fml
   189  	fmr
   190  	fms
   191  	fmul
   192  	fmx
   193  	fneg
   194  	fnm
   195  	frd
   196  	fsit
   197  	fsq
   198  	fst
   199  	fsu
   200  	fto
   201  	fui
   202  	hlt
   203  	hvc
   204  	lda
   205  	ldc
   206  	ldf
   207  	lfm
   208  	lgn
   209  	log
   210  	mar
   211  	mcr
   212  	mcrr
   213  	mia
   214  	mnf
   215  	mra
   216  	mrc
   217  	mrrc
   218  	mrs
   219  	msr
   220  	msr
   221  	muf
   222  	mvf
   223  	nrm
   224  	pol
   225  	pow
   226  	rdf
   227  	rfc
   228  	rfe
   229  	rfs
   230  	rmf
   231  	rnd
   232  	rpw
   233  	rsf
   234  	sdiv
   235  	sev
   236  	sfm
   237  	sha1
   238  	sha256
   239  	sin
   240  	smc
   241  	sqt
   242  	srs
   243  	stc
   244  	stf
   245  	stl
   246  	suf
   247  	tan
   248  	udf
   249  	udiv
   250  	urd
   251  	vfma
   252  	vfms
   253  	vfnma
   254  	vfnms
   255  	vrint
   256  	wfc
   257  	wfs
   258  `)