| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 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. |
|---|
| 17 | 4 | * |
|---|
| 18 | 5 | * Copyright (C) IBM Corporation, 2009 |
|---|
| 19 | 6 | * Copyright (C) Hitachi, Ltd., 2011 |
|---|
| .. | .. |
|---|
| 96 | 83 | } |
|---|
| 97 | 84 | |
|---|
| 98 | 85 | 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) |
|---|
| 100 | 87 | { |
|---|
| 101 | 88 | int i; |
|---|
| 102 | 89 | |
|---|
| .. | .. |
|---|
| 109 | 96 | /* Input a decoded instruction sequence directly */ |
|---|
| 110 | 97 | fprintf(fp, " $ echo "); |
|---|
| 111 | 98 | for (i = 0; i < MAX_INSN_SIZE; i++) |
|---|
| 112 | | - fprintf(fp, " %02x", insn_buf[i]); |
|---|
| 99 | + fprintf(fp, " %02x", insn_buff[i]); |
|---|
| 113 | 100 | fprintf(fp, " | %s -i -\n", prog); |
|---|
| 114 | 101 | |
|---|
| 115 | 102 | if (!input_file) { |
|---|
| .. | .. |
|---|
| 137 | 124 | } |
|---|
| 138 | 125 | |
|---|
| 139 | 126 | /* 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) |
|---|
| 141 | 128 | { |
|---|
| 142 | 129 | char buf[256] = "", *tmp; |
|---|
| 143 | 130 | int i; |
|---|
| .. | .. |
|---|
| 147 | 134 | return 0; |
|---|
| 148 | 135 | |
|---|
| 149 | 136 | 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); |
|---|
| 151 | 138 | if (*tmp != ' ') |
|---|
| 152 | 139 | break; |
|---|
| 153 | 140 | } |
|---|
| .. | .. |
|---|
| 155 | 142 | return i; |
|---|
| 156 | 143 | } |
|---|
| 157 | 144 | |
|---|
| 158 | | -static int generate_insn(unsigned char *insn_buf) |
|---|
| 145 | +static int generate_insn(unsigned char *insn_buff) |
|---|
| 159 | 146 | { |
|---|
| 160 | 147 | int i; |
|---|
| 161 | 148 | |
|---|
| 162 | 149 | if (input_file) |
|---|
| 163 | | - return read_next_insn(insn_buf); |
|---|
| 150 | + return read_next_insn(insn_buff); |
|---|
| 164 | 151 | |
|---|
| 165 | 152 | /* Fills buffer with random binary up to MAX_INSN_SIZE */ |
|---|
| 166 | 153 | 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; |
|---|
| 168 | 155 | |
|---|
| 169 | 156 | while (i < MAX_INSN_SIZE) |
|---|
| 170 | | - insn_buf[i++] = random() & 0xff; |
|---|
| 157 | + insn_buff[i++] = random() & 0xff; |
|---|
| 171 | 158 | |
|---|
| 172 | 159 | return i; |
|---|
| 173 | 160 | } |
|---|
| .. | .. |
|---|
| 239 | 226 | int insns = 0; |
|---|
| 240 | 227 | int errors = 0; |
|---|
| 241 | 228 | unsigned long i; |
|---|
| 242 | | - unsigned char insn_buf[MAX_INSN_SIZE * 2]; |
|---|
| 229 | + unsigned char insn_buff[MAX_INSN_SIZE * 2]; |
|---|
| 243 | 230 | |
|---|
| 244 | 231 | parse_args(argc, argv); |
|---|
| 245 | 232 | |
|---|
| 246 | 233 | /* 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); |
|---|
| 248 | 235 | |
|---|
| 249 | 236 | for (i = 0; i < iter_end; i++) { |
|---|
| 250 | | - if (generate_insn(insn_buf) <= 0) |
|---|
| 237 | + if (generate_insn(insn_buff) <= 0) |
|---|
| 251 | 238 | break; |
|---|
| 252 | 239 | |
|---|
| 253 | 240 | if (i < iter_start) /* Skip to given iteration number */ |
|---|
| 254 | 241 | continue; |
|---|
| 255 | 242 | |
|---|
| 256 | 243 | /* 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); |
|---|
| 258 | 245 | insn_get_length(&insn); |
|---|
| 259 | 246 | |
|---|
| 260 | 247 | if (insn.next_byte <= insn.kaddr || |
|---|
| 261 | 248 | insn.kaddr + MAX_INSN_SIZE < insn.next_byte) { |
|---|
| 262 | 249 | /* 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); |
|---|
| 264 | 251 | errors++; |
|---|
| 265 | 252 | } 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); |
|---|
| 267 | 254 | else if (verbose >= 2) |
|---|
| 268 | 255 | dump_insn(stdout, &insn); |
|---|
| 269 | 256 | insns++; |
|---|