forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/arch/x86/tools/insn_sanity.c
....@@ -1,19 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * x86 decoder sanity test - based on test_get_insn.c
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation; either version 2 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
174 *
185 * Copyright (C) IBM Corporation, 2009
196 * Copyright (C) Hitachi, Ltd., 2011
....@@ -96,7 +83,7 @@
9683 }
9784
9885 static void dump_stream(FILE *fp, const char *msg, unsigned long nr_iter,
99
- unsigned char *insn_buf, struct insn *insn)
86
+ unsigned char *insn_buff, struct insn *insn)
10087 {
10188 int i;
10289
....@@ -109,7 +96,7 @@
10996 /* Input a decoded instruction sequence directly */
11097 fprintf(fp, " $ echo ");
11198 for (i = 0; i < MAX_INSN_SIZE; i++)
112
- fprintf(fp, " %02x", insn_buf[i]);
99
+ fprintf(fp, " %02x", insn_buff[i]);
113100 fprintf(fp, " | %s -i -\n", prog);
114101
115102 if (!input_file) {
....@@ -137,7 +124,7 @@
137124 }
138125
139126 /* Read given instruction sequence from the input file */
140
-static int read_next_insn(unsigned char *insn_buf)
127
+static int read_next_insn(unsigned char *insn_buff)
141128 {
142129 char buf[256] = "", *tmp;
143130 int i;
....@@ -147,7 +134,7 @@
147134 return 0;
148135
149136 for (i = 0; i < MAX_INSN_SIZE; i++) {
150
- insn_buf[i] = (unsigned char)strtoul(tmp, &tmp, 16);
137
+ insn_buff[i] = (unsigned char)strtoul(tmp, &tmp, 16);
151138 if (*tmp != ' ')
152139 break;
153140 }
....@@ -155,19 +142,19 @@
155142 return i;
156143 }
157144
158
-static int generate_insn(unsigned char *insn_buf)
145
+static int generate_insn(unsigned char *insn_buff)
159146 {
160147 int i;
161148
162149 if (input_file)
163
- return read_next_insn(insn_buf);
150
+ return read_next_insn(insn_buff);
164151
165152 /* Fills buffer with random binary up to MAX_INSN_SIZE */
166153 for (i = 0; i < MAX_INSN_SIZE - 1; i += 2)
167
- *(unsigned short *)(&insn_buf[i]) = random() & 0xffff;
154
+ *(unsigned short *)(&insn_buff[i]) = random() & 0xffff;
168155
169156 while (i < MAX_INSN_SIZE)
170
- insn_buf[i++] = random() & 0xff;
157
+ insn_buff[i++] = random() & 0xff;
171158
172159 return i;
173160 }
....@@ -239,31 +226,31 @@
239226 int insns = 0;
240227 int errors = 0;
241228 unsigned long i;
242
- unsigned char insn_buf[MAX_INSN_SIZE * 2];
229
+ unsigned char insn_buff[MAX_INSN_SIZE * 2];
243230
244231 parse_args(argc, argv);
245232
246233 /* Prepare stop bytes with NOPs */
247
- memset(insn_buf + MAX_INSN_SIZE, INSN_NOP, MAX_INSN_SIZE);
234
+ memset(insn_buff + MAX_INSN_SIZE, INSN_NOP, MAX_INSN_SIZE);
248235
249236 for (i = 0; i < iter_end; i++) {
250
- if (generate_insn(insn_buf) <= 0)
237
+ if (generate_insn(insn_buff) <= 0)
251238 break;
252239
253240 if (i < iter_start) /* Skip to given iteration number */
254241 continue;
255242
256243 /* Decode an instruction */
257
- insn_init(&insn, insn_buf, sizeof(insn_buf), x86_64);
244
+ insn_init(&insn, insn_buff, sizeof(insn_buff), x86_64);
258245 insn_get_length(&insn);
259246
260247 if (insn.next_byte <= insn.kaddr ||
261248 insn.kaddr + MAX_INSN_SIZE < insn.next_byte) {
262249 /* Access out-of-range memory */
263
- dump_stream(stderr, "Error: Found an access violation", i, insn_buf, &insn);
250
+ dump_stream(stderr, "Error: Found an access violation", i, insn_buff, &insn);
264251 errors++;
265252 } else if (verbose && !insn_complete(&insn))
266
- dump_stream(stdout, "Info: Found an undecodable input", i, insn_buf, &insn);
253
+ dump_stream(stdout, "Info: Found an undecodable input", i, insn_buff, &insn);
267254 else if (verbose >= 2)
268255 dump_insn(stdout, &insn);
269256 insns++;