File: objdump_test.go

package info (click to toggle)
golang-golang-x-arch 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,932 kB
  • sloc: ansic: 1,975; makefile: 59
file content (145 lines) | stat: -rw-r--r-- 3,658 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package loong64asm

import (
	"strconv"
	"strings"
	"testing"
)

func TestObjdumpLoong64TestDecodeGNUSyntaxdata(t *testing.T) {
	testObjdumpLoong64(t, testdataCases(t, "gnu"))
}

func TestObjdumpLoong64TestDecodeGoSyntaxdata(t *testing.T) {
	testObjdumpLoong64(t, testdataCases(t, "plan9"))
}

func TestObjdumpLoong64Manual(t *testing.T) {
	testObjdumpLoong64(t, hexCases(t, objdumpManualTests))
}

// objdumpManualTests holds test cases that will be run by TestObjdumpLoong64Manual.
// If you are debugging a few cases that turned up in a longer run, it can be useful
// to list them here and then use -run=Manual, particularly with tracing enabled.
// Note that these are byte sequences, so they must be reversed from the usual
// word presentation.
var objdumpManualTests = `
00007238
00807238
00004003
00100050
ac410028
ac41002a
ac41c028
ac414028
ac41402a
ac418028
ac41802a
ac397838
acb97938
acb97838
ac397938
ac397a38
acb97b38
acb97a38
ac397b38
ac110026
ac110024
ac390038
ac392038
ac390c38
ac390438
ac392438
ac390838
ac392838
ac391600
ac391400
ac391500
ac418003
`

// allowedMismatchObjdump reports whether the mismatch between text and dec
// should be allowed by the test.
func allowedMismatchObjdump(text string, inst *Inst, dec ExtInst) bool {
	// GNU objdump use register, decode use alias of register, so corrected it in here
	var dec_text = strings.Replace(dec.text, " ", ",", -1)
	var decsp []string = strings.Split(dec_text, ",")
	var num int = cap(decsp)
	for i := 0; i < num; i++ {
		dex := strings.Index(decsp[i], "$r")
		fdex := strings.Index(decsp[i], "$f")
		ddex := strings.Index(decsp[i], "(")
		if ddex > 0 {
			// ldptr.w $r12,$r13,16(0x10)
			decsp[i] = decsp[i][0:ddex]
		}
		xdex := strings.Index(decsp[i], "0x")
		// convert registers to registers aliases
		if dex >= 0 {
			reg, _ := strconv.Atoi(decsp[i][dex+2:])
			// r12~r20 $t0~t8
			if reg >= 12 && reg <= 20 {
				decsp[i] = strings.Join([]string{"t", strconv.Itoa(reg - 12)}, "")
			}
			// r4~r11 $a0~a7
			if reg >= 4 && reg <= 11 {
				decsp[i] = strings.Join([]string{"a", strconv.Itoa(reg - 4)}, "")
			}
			// r23~r31 $s0~s8
			if reg >= 23 && reg <= 31 {
				decsp[i] = strings.Join([]string{"s", strconv.Itoa(reg - 23)}, "")
			}
			// r0 zero
			if reg == 0 {
				decsp[i] = strings.Join([]string{"zero"}, "")
			}
			// r1 ra
			if reg == 1 {
				decsp[i] = strings.Join([]string{"ra"}, "")
			}
			// r2 tp
			if reg == 2 {
				decsp[i] = strings.Join([]string{"tp"}, "")
			}
			// r3 sp
			if reg == 3 {
				decsp[i] = strings.Join([]string{"sp"}, "")
			}
			// r21 x
			if reg == 21 {
				decsp[i] = strings.Join([]string{"x"}, "")
			}
			// r22 fp
			if reg == 22 {
				decsp[i] = strings.Join([]string{"fp"}, "")
			}
		}
		// convert hexadecimal to decimal
		if xdex >= 0 {
			parseint, _ := strconv.ParseInt(decsp[i][xdex+2:], 16, 32)
			decsp[i] = strings.Join([]string{strconv.Itoa(int(parseint))}, "")
		}
		// convert floating-point registers to floating-point aliases
		if fdex >= 0 && !strings.Contains(decsp[i], "$fcc") {
			freg, _ := strconv.Atoi(decsp[i][fdex+2:])
			// f0~f7 fa0~fa7
			if freg >= 0 && freg <= 7 {
				decsp[i] = strings.Join([]string{"fa", strconv.Itoa(freg - 0)}, "")
			}
			// f8~f23 ft0~ft15
			if freg >= 8 && freg <= 23 {
				decsp[i] = strings.Join([]string{"ft", strconv.Itoa(freg - 8)}, "")
			}
			// f24~f31 fs0~fs7
			if freg >= 24 && freg <= 31 {
				decsp[i] = strings.Join([]string{"fs", strconv.Itoa(freg - 24)}, "")
			}
		}
	}

	return false
}