Debian Codegraph @

ppc64/ppc64asm/objdump_test.go

raw symbols SCIP
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 ppc64asm
6
7 import (
8 "encoding/binary"
9 "strings"
10 "testing"
11 )
12
13 func TestObjdumpPowerTestdata(t *testing.T) { testObjdump(t, testdataCases(t)) }
14 func 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 TestObjdumpPowerManual.
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.
25 var objdumpManualTests = `
26 6d746162
27 4c040000
28 88000017
29 `
30
31 // allowedMismatchObjdump reports whether the mismatch between text and dec
32 // should be allowed by the test.
33 func allowedMismatchObjdump(text string, size int, inst *Inst, dec ExtInst) bool {
34 // we support more instructions than binutils
35 if strings.Contains(dec.text, ".long") {
36 return true
37 }
38
39 switch inst.Op {
40 case BC: // We don't print PC relative branches the same way.
41 return true
42 case DCBF, DCBT: // We only support extended mnemonics, and may not print 0 where R0 == 0.
43 return true
44 case MTVSRWA, MTVSRWZ, MFVSRWZ, MFVSRD, MTVSRD: // We don't support extended mnemonics using VRs or FPRs
45 return true
46 case ISEL: // We decode the BI similar to conditional branch insn, objdump doesn't.
47 return true
48 case SYNC, WAIT, RFEBB: // ISA 3.1 adds more bits and extended mnemonics for these book ii instructions.
49 return true
50 case BL:
51 // TODO: Ignore these for now. The output format from gnu objdump is dependent on more than the
52 // instruction itself e.g: decode(48100009) = "bl 0x100008", 4, want "bl .+0x100008", 4
53 return true
54 }
55
56 if len(dec.enc) >= 4 {
57 _ = binary.BigEndian.Uint32(dec.enc[:4])
58 }
59
60 return false
61 }