| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 1 | /* | 
 | 2 |  * x86 instruction attribute tables | 
 | 3 |  * | 
 | 4 |  * Written by Masami Hiramatsu <mhiramat@redhat.com> | 
 | 5 |  * | 
 | 6 |  * This program is free software; you can redistribute it and/or modify | 
 | 7 |  * it under the terms of the GNU General Public License as published by | 
 | 8 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 9 |  * (at your option) any later version. | 
 | 10 |  * | 
 | 11 |  * This program is distributed in the hope that it will be useful, | 
 | 12 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 13 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 14 |  * GNU General Public License for more details. | 
 | 15 |  * | 
 | 16 |  * You should have received a copy of the GNU General Public License | 
 | 17 |  * along with this program; if not, write to the Free Software | 
 | 18 |  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 
 | 19 |  * | 
 | 20 |  */ | 
 | 21 | #include <asm/insn.h> | 
 | 22 |  | 
 | 23 | /* Attribute tables are generated from opcode map */ | 
 | 24 | #include "inat-tables.c" | 
 | 25 |  | 
 | 26 | /* Attribute search APIs */ | 
 | 27 | insn_attr_t inat_get_opcode_attribute(insn_byte_t opcode) | 
 | 28 | { | 
 | 29 | 	return inat_primary_table[opcode]; | 
 | 30 | } | 
 | 31 |  | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 32 | int inat_get_last_prefix_id(insn_byte_t last_pfx) | 
 | 33 | { | 
 | 34 | 	insn_attr_t lpfx_attr; | 
 | 35 |  | 
 | 36 | 	lpfx_attr = inat_get_opcode_attribute(last_pfx); | 
 | 37 | 	return inat_last_prefix_id(lpfx_attr); | 
 | 38 | } | 
 | 39 |  | 
 | 40 | insn_attr_t inat_get_escape_attribute(insn_byte_t opcode, int lpfx_id, | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 41 | 				      insn_attr_t esc_attr) | 
 | 42 | { | 
 | 43 | 	const insn_attr_t *table; | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 44 | 	int n; | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 45 |  | 
 | 46 | 	n = inat_escape_id(esc_attr); | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 47 |  | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 48 | 	table = inat_escape_tables[n][0]; | 
 | 49 | 	if (!table) | 
 | 50 | 		return 0; | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 51 | 	if (inat_has_variant(table[opcode]) && lpfx_id) { | 
 | 52 | 		table = inat_escape_tables[n][lpfx_id]; | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 53 | 		if (!table) | 
 | 54 | 			return 0; | 
 | 55 | 	} | 
 | 56 | 	return table[opcode]; | 
 | 57 | } | 
 | 58 |  | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 59 | insn_attr_t inat_get_group_attribute(insn_byte_t modrm, int lpfx_id, | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 60 | 				     insn_attr_t grp_attr) | 
 | 61 | { | 
 | 62 | 	const insn_attr_t *table; | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 63 | 	int n; | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 64 |  | 
 | 65 | 	n = inat_group_id(grp_attr); | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 66 |  | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 67 | 	table = inat_group_tables[n][0]; | 
 | 68 | 	if (!table) | 
 | 69 | 		return inat_group_common_attribute(grp_attr); | 
| Masami Hiramatsu | f8d98f1 | 2012-02-10 14:33:40 +0900 | [diff] [blame] | 70 | 	if (inat_has_variant(table[X86_MODRM_REG(modrm)]) && lpfx_id) { | 
 | 71 | 		table = inat_group_tables[n][lpfx_id]; | 
| Masami Hiramatsu | eb13296 | 2009-08-13 16:34:13 -0400 | [diff] [blame] | 72 | 		if (!table) | 
 | 73 | 			return inat_group_common_attribute(grp_attr); | 
 | 74 | 	} | 
 | 75 | 	return table[X86_MODRM_REG(modrm)] | | 
 | 76 | 	       inat_group_common_attribute(grp_attr); | 
 | 77 | } | 
 | 78 |  | 
| Masami Hiramatsu | e0e492e | 2009-10-27 16:42:27 -0400 | [diff] [blame] | 79 | insn_attr_t inat_get_avx_attribute(insn_byte_t opcode, insn_byte_t vex_m, | 
 | 80 | 				   insn_byte_t vex_p) | 
 | 81 | { | 
 | 82 | 	const insn_attr_t *table; | 
 | 83 | 	if (vex_m > X86_VEX_M_MAX || vex_p > INAT_LSTPFX_MAX) | 
 | 84 | 		return 0; | 
| Masami Hiramatsu | 130b78b | 2011-12-05 21:05:39 +0900 | [diff] [blame] | 85 | 	/* At first, this checks the master table */ | 
 | 86 | 	table = inat_avx_tables[vex_m][0]; | 
| Masami Hiramatsu | e0e492e | 2009-10-27 16:42:27 -0400 | [diff] [blame] | 87 | 	if (!table) | 
 | 88 | 		return 0; | 
| Masami Hiramatsu | 130b78b | 2011-12-05 21:05:39 +0900 | [diff] [blame] | 89 | 	if (!inat_is_group(table[opcode]) && vex_p) { | 
 | 90 | 		/* If this is not a group, get attribute directly */ | 
 | 91 | 		table = inat_avx_tables[vex_m][vex_p]; | 
 | 92 | 		if (!table) | 
 | 93 | 			return 0; | 
 | 94 | 	} | 
| Masami Hiramatsu | e0e492e | 2009-10-27 16:42:27 -0400 | [diff] [blame] | 95 | 	return table[opcode]; | 
 | 96 | } | 
 | 97 |  |