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 5package ppc64asm 6 7import ( 8 "encoding/binary" 9 "strings" 10 "testing" 11) 12 13func TestObjdumpPowerTestdata(t *testing.T) { testObjdump(t, testdataCases(t)) } 14func TestObjdumpPowerManual(t *testing.T) { testObjdump(t, hexCases(t, objdumpManualTests)) } 15 16// Disable this for now since generating all possible bit combinations within a word 17// generates lots of ppc64x instructions not possible with golang so not worth supporting.. 18//func TestObjdumpPowerRandom(t *testing.T) { testObjdump(t, randomCases(t)) } 19 20// objdumpManualTests holds test cases that will be run by TestObjdumpARMManual. 21// If you are debugging a few cases that turned up in a longer run, it can be useful 22// to list them here and then use -run=Manual, particularly with tracing enabled. 23// Note that these are byte sequences, so they must be reversed from the usual 24// word presentation. 25var objdumpManualTests = ` 266d746162 274c040000 2888000017 29` 30 31// allowedMismatchObjdump reports whether the mismatch between text and dec 32// should be allowed by the test. 33func allowedMismatchObjdump(text string, size int, inst *Inst, dec ExtInst) bool { 34 if hasPrefix(dec.text, deleted...) { 35 return true 36 } 37 38 // we support more instructions than binutils 39 if strings.Contains(dec.text, ".long") { 40 return true 41 } 42 43 if hasPrefix(text, "error:") { 44 if hasPrefix(dec.text, unsupported...) { 45 return true 46 } 47 } 48 49 switch inst.Op { 50 case BC, BCA, BL, BLA, BCL, BCLA, TDI, TWI, TW, TD: 51 return true // TODO(minux): we lack the support for extended opcodes here 52 case RLWNM, RLWNM_, RLDICL, RLDICL_, RLWINM, RLWINM_, RLDCL, RLDCL_: 53 return true // TODO(minux): we lack the support for extended opcodes here 54 case DCBTST, DCBT: 55 return true // objdump uses the embedded argument order, we use the server argument order 56 case MTFSF, MTFSF_: // objdump doesn't show the last two arguments 57 return true 58 case VSPLTB, VSPLTH, VSPLTW: // objdump generates unreasonable result "vspltw v6,v19,4" for 10c49a8c, the last 4 should be 0. 59 return true 60 } 61 if hasPrefix(text, "evm", "evl", "efs") { // objdump will disassemble them wrong (e.g. evmhoumia as vsldoi) 62 return true 63 } 64 65 if len(dec.enc) >= 4 { 66 _ = binary.BigEndian.Uint32(dec.enc[:4]) 67 } 68 69 return false 70} 71 72// Instructions known to libopcodes (or xed) but not to us. 73// TODO(minux): those single precision instructions are missing from ppc64.csv 74// those data cache instructions are deprecated, but must be treated as no-ops, see 4.3.2.1 pg. 774. 75var unsupported = strings.Fields(` 76fmsubs 77fmsubs. 78fnmadds 79fnmadds. 80fnmsubs 81fnmsubs. 82fmuls 83fmuls. 84fdivs 85fdivs. 86fadds 87fadds. 88fsubs 89fsubs. 90dst 91dstst 92dssall 93`) 94 95// Instructions explicitly dropped in Power ISA that were in POWER architecture. 96// See A.30 Deleted Instructions and A.31 Discontiued Opcodes 97var deleted = strings.Fields(` 98abs 99clcs 100clf 101cli 102dclst 103div 104divs 105doz 106dozi 107lscbx 108maskg 109maskir 110mfsri 111mul 112nabs 113rac 114rfi 115rfsvc 116rlmi 117rrib 118sle 119sleq 120sliq 121slliq 122sllq 123slq 124sraiq 125sraq 126sre 127srea 128sreq 129sriq 130srliq 131srlq 132srq 133maskg`) 134