blob: 4441e6c9c7d18d8757377b7493b2242ebee9b052 (
plain)
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
146
147
148
149
150
151
152
153
154
155
|
#!/usr/bin/env bash
#
# SPDX-License-Identifier: Unlicense
#
# Tests against m68k-none-elf-as.
AS=m68k-none-elf-as
OBJCOPY=m68k-none-elf-objcopy
TEST_DIR=/tmp/m68k-disasm-tests
TRACE_FILE=${TEST_DIR}/trace.txt
set -e
rm -rf ${TEST_DIR}
mkdir -p ${TEST_DIR}
echo "0" >${TRACE_FILE}
run_test_simple() {
test_name=$1
data=$2
file_orig_bin=${TEST_DIR}/${test_name}.orig.bin
file_asm=${TEST_DIR}/${test_name}.S
file_as_o=${TEST_DIR}/${test_name}.as.o
file_as_bin=${TEST_DIR}/${test_name}.as.bin
echo -ne "Test ${test_name}... "
echo -ne "${data}" >${file_orig_bin}
./cmake-build/m68k-disasm -t ${TRACE_FILE} -o ${file_asm} ${file_orig_bin}
${AS} -o ${file_as_o} ${file_asm}
${OBJCOPY} ${file_as_o} -O binary ${file_as_bin}
if ! cmp ${file_orig_bin} ${file_as_bin} >/dev/null 2>&1; then
echo "FAIL"
cat ${file_asm}
echo ${file_orig_bin}
hexdump -Cv ${file_orig_bin} | head -n1
echo ${file_as_bin}
hexdump -Cv ${file_as_bin} | head -n1
else
echo "OK"
#cat ${file_asm}
fi
}
run_test_iterative() {
test_name=$1
prefix=$2
offset=$3
count=$4
step=$5
suffix=$6
file_orig_bin=${TEST_DIR}/${test_name}.orig.bin
file_asm=${TEST_DIR}/${test_name}.S
file_as_o=${TEST_DIR}/${test_name}.as.o
file_as_bin=${TEST_DIR}/${test_name}.as.bin
for i in $(seq 0 $(( step )) $(( count*step-1 )) ); do
value=$(printf "%02x\n" $(( offset+i )))
run_test_simple $test_name "${prefix}\x${value}${suffix}"
done
}
jsr_m2() {
# 4e90..4e97
#
# All registers
run_test_iterative ${FUNCNAME} "\x4e" 0x90 8 1 ""
}
jsr_m5() {
# (4ea8..4eaf) xxxx
#
# Zero value
run_test_simple ${FUNCNAME} "\x4e\xa8\x00\x00"
# Positive value, all registers
run_test_iterative ${FUNCNAME} "\x4e" 0xa8 8 1 "\x00\x0a"
# Negative value
run_test_simple ${FUNCNAME} "\x4e\xa8\x80\x0f"
}
jsr_m6() {
# (4eb0..4eb7) xxxx
#
# Positive value, Arbitrary An register
run_test_iterative ${FUNCNAME} "\x4e" 0xb0 8 1 "\x00\x0f"
# Negative value
run_test_simple ${FUNCNAME} "\x4e\xb0\x00\xf0"
# Zero displacement
run_test_simple ${FUNCNAME} "\x4e\xb0\x00\x00"
# Address register
run_test_simple ${FUNCNAME} "\x4e\xb0\x80\x0a"
# Long displacement, positive
run_test_simple ${FUNCNAME} "\x4e\xb0\x08\x0c"
# Long displacement, negative
run_test_simple ${FUNCNAME} "\x4e\xb0\x08\xb0"
# Arbitrary Xn2
run_test_iterative ${FUNCNAME} "\x4e\xb0" 0x00 8 0x10 "\x0f"
}
jsr_m7_xn0() {
# 43b8 xxxx Word displacement
#
# Zero value
run_test_simple ${FUNCNAME} "\x4e\xb8\x00\x00"
# Positive value
run_test_simple ${FUNCNAME} "\x4e\xb8\x00\x1f"
# Negative value
run_test_simple ${FUNCNAME} "\x4e\xb8\x8a\x0c"
}
jsr_m7_xn1() {
# 43b9 xxxx Long displacement
#
# Zero value
run_test_simple ${FUNCNAME} "\x4e\xb9\x00\x00\x00\x00"
# Positive value
run_test_simple ${FUNCNAME} "\x4e\xb9\x10\xbb\x43\x1f"
# Negative value
run_test_simple ${FUNCNAME} "\x4e\xb9\x80\xcc\xd9\x8a"
}
jsr_m7_xn2() {
# 43ba xxxx
#
# Zero value
run_test_simple ${FUNCNAME} "\x4e\xba\x00\x00"
# Positive value
run_test_simple ${FUNCNAME} "\x4e\xba\x00\x1f"
# Negative value
run_test_simple ${FUNCNAME} "\x4e\xba\x8a\x0c"
}
jsr_m7_xn3() {
# 43bb xxxx
#
# Positive value, Arbitrary Xn register
run_test_iterative ${FUNCNAME} "\x4e\xbb" 0x00 8 0x10 "\x1a"
# Negative value
run_test_simple ${FUNCNAME} "\x4e\xbb\x00\xf0"
# Zero displacement
run_test_simple ${FUNCNAME} "\x4e\xbb\x00\x00"
# Address register
run_test_simple ${FUNCNAME} "\x4e\xbb\x80\x0a"
# Long displacement, positive
run_test_simple ${FUNCNAME} "\x4e\xbb\x08\x0c"
# Long displacement, negative
run_test_simple ${FUNCNAME} "\x4e\xbb\x08\xb0"
# Arbitrary Xn2
run_test_iterative ${FUNCNAME} "\x4e\xbb" 0x00 8 0x10 "\x0f"
}
jsr_m2
jsr_m5
jsr_m6
jsr_m7_xn0
jsr_m7_xn1
jsr_m7_xn2
jsr_m7_xn3
|