2007-06-28 H.J. Lu <hongjiu.lu@intel.com>

* Makefile.am (HFILES): Add i386-opc.h and i386-tbl.h.
	(CFILES): Add i386-gen.c.
	(i386-gen): New rule.
	(i386-gen.o): Likewise.
	(i386-tbl.h): Likewise.
	Run "make dep-am".
	* Makefile.in: Regenerated.

	* i386-gen.c: New file.
	* i386-opc.tbl: Likewise.
	* i386-reg.tbl: Likewise.
	* i386-tbl.h: Likewise.

	* i386-opc.c: Include "i386-tbl.h".
	(i386_optab): Removed.
	(i386_regtab): Likewise.
	(i386_regtab_size): Likewise.
This commit is contained in:
H.J. Lu 2007-06-28 14:29:56 +00:00
parent d5fb0879a5
commit 40b8e679e8
8 changed files with 6582 additions and 1708 deletions

View File

@ -1,3 +1,23 @@
2007-06-28 H.J. Lu <hongjiu.lu@intel.com>
* Makefile.am (HFILES): Add i386-opc.h and i386-tbl.h.
(CFILES): Add i386-gen.c.
(i386-gen): New rule.
(i386-gen.o): Likewise.
(i386-tbl.h): Likewise.
Run "make dep-am".
* Makefile.in: Regenerated.
* i386-gen.c: New file.
* i386-opc.tbl: Likewise.
* i386-reg.tbl: Likewise.
* i386-tbl.h: Likewise.
* i386-opc.c: Include "i386-tbl.h".
(i386_optab): Removed.
(i386_regtab): Likewise.
(i386_regtab_size): Likewise.
2007-06-26 Paul Brook <paul@codesourcery.com>
* arm-dis.c (coprocessor_opcodes): Add fmxr/fmrx mvfr0/mvfr1.

View File

@ -33,6 +33,8 @@ HFILES = \
fr30-desc.h fr30-opc.h \
frv-desc.h frv-opc.h \
h8500-opc.h \
i386-opc.h \
i386-tbl.h \
ia64-asmtab.h \
ia64-opc.h \
ip2k-desc.h ip2k-opc.h \
@ -95,6 +97,7 @@ CFILES = \
i370-opc.c \
i386-dis.c \
i386-opc.c \
i386-gen.c \
i860-dis.c \
i960-dis.c \
ia64-dis.c \
@ -563,6 +566,14 @@ stamp-xc16x: $(CGENDEPS) $(CPUDIR)/xc16x.cpu $(CPUDIR)/xc16x.opc
$(MAKE) run-cgen arch=xc16x prefix=xc16x options= \
archfile=$(CPUDIR)/xc16x.cpu opcfile=$(CPUDIR)/xc16x.opc extrafiles=
i386-gen: i386-gen.o
$(LINK) i386-gen.o $(LIBIBERTY)
i386-gen.o: i386-gen.c i386-opc.h
i386-tbl.h: @MAINT@ i386-gen i386-opc.tbl i386-reg.tbl
./i386-gen --srcdir $(srcdir) > $(srcdir)/i386-tbl.h
ia64-gen: ia64-gen.o
$(LINK) ia64-gen.o $(LIBIBERTY)
@ -783,6 +794,9 @@ i386-dis.lo: i386-dis.c $(INCDIR)/dis-asm.h $(BFD_H) \
$(INCDIR)/ansidecl.h opintl.h $(INCDIR)/opcode/i386.h
i386-opc.lo: i386-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
$(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h i386-opc.h \
$(INCDIR)/opcode/i386.h i386-tbl.h
i386-gen.lo: i386-gen.c $(INCDIR)/getopt.h $(INCDIR)/libiberty.h \
$(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h i386-opc.h \
$(INCDIR)/opcode/i386.h
i860-dis.lo: i860-dis.c $(INCDIR)/dis-asm.h $(BFD_H) \
$(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/opcode/i860.h

View File

@ -256,6 +256,8 @@ HFILES = \
fr30-desc.h fr30-opc.h \
frv-desc.h frv-opc.h \
h8500-opc.h \
i386-opc.h \
i386-tbl.h \
ia64-asmtab.h \
ia64-opc.h \
ip2k-desc.h ip2k-opc.h \
@ -319,6 +321,7 @@ CFILES = \
i370-opc.c \
i386-dis.c \
i386-opc.c \
i386-gen.c \
i860-dis.c \
i960-dis.c \
ia64-dis.c \
@ -1110,6 +1113,14 @@ stamp-xc16x: $(CGENDEPS) $(CPUDIR)/xc16x.cpu $(CPUDIR)/xc16x.opc
$(MAKE) run-cgen arch=xc16x prefix=xc16x options= \
archfile=$(CPUDIR)/xc16x.cpu opcfile=$(CPUDIR)/xc16x.opc extrafiles=
i386-gen: i386-gen.o
$(LINK) i386-gen.o $(LIBIBERTY)
i386-gen.o: i386-gen.c i386-opc.h
i386-tbl.h: @MAINT@ i386-gen i386-opc.tbl i386-reg.tbl
./i386-gen --srcdir $(srcdir) > $(srcdir)/i386-tbl.h
ia64-gen: ia64-gen.o
$(LINK) ia64-gen.o $(LIBIBERTY)
@ -1330,6 +1341,9 @@ i386-dis.lo: i386-dis.c $(INCDIR)/dis-asm.h $(BFD_H) \
$(INCDIR)/ansidecl.h opintl.h $(INCDIR)/opcode/i386.h
i386-opc.lo: i386-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
$(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h i386-opc.h \
$(INCDIR)/opcode/i386.h i386-tbl.h
i386-gen.lo: i386-gen.c $(INCDIR)/getopt.h $(INCDIR)/libiberty.h \
$(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h i386-opc.h \
$(INCDIR)/opcode/i386.h
i860-dis.lo: i860-dis.c $(INCDIR)/dis-asm.h $(BFD_H) \
$(INCDIR)/ansidecl.h $(INCDIR)/symcat.h $(INCDIR)/opcode/i860.h
@ -1771,6 +1785,3 @@ z8k-dis.lo: z8k-dis.c sysdep.h config.h $(INCDIR)/ansidecl.h \
z8kgen.lo: z8kgen.c sysdep.h config.h $(INCDIR)/ansidecl.h \
$(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

394
opcodes/i386-gen.c Normal file
View File

@ -0,0 +1,394 @@
/* Copyright 2007 Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler, and GDB, the GNU Debugger.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "getopt.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include "i386-opc.h"
#include <libintl.h>
#define _(String) gettext (String)
static const char *program_name = NULL;
static int debug = 0;
static void
fail (const char *message, ...)
{
va_list args;
va_start (args, message);
fprintf (stderr, _("%s: Error: "), program_name);
vfprintf (stderr, message, args);
va_end (args);
xexit (1);
}
/* Remove leading white spaces. */
static char *
remove_leading_whitespaces (char *str)
{
while (ISSPACE (*str))
str++;
return str;
}
/* Remove trailing white spaces. */
static void
remove_trailing_whitespaces (char *str)
{
size_t last = strlen (str);
if (last == 0)
return;
do
{
last--;
if (ISSPACE (str [last]))
str[last] = '\0';
else
break;
}
while (last != 0);
}
/* Find next field separated by '.' and terminate it. Return a
pointer to the one after it. */
static char *
next_field (char *str, char **next)
{
char *p;
p = remove_leading_whitespaces (str);
for (str = p; *str != ',' && *str != '\0'; str++);
*str = '\0';
remove_trailing_whitespaces (p);
*next = str + 1;
return p;
}
static void
process_i386_opcodes (void)
{
FILE *fp = fopen ("i386-opc.tbl", "r");
char buf[2048];
unsigned int i;
char *str, *p, *last;
char *name, *operands, *base_opcode, *extension_opcode;
char *cpu_flags, *opcode_modifier, *operand_types [MAX_OPERANDS];
if (fp == NULL)
fail (_("can't find i386-opc.tbl for reading\n"));
printf ("\n/* i386 opcode table. */\n\n");
printf ("const template i386_optab[] =\n{\n");
while (!feof (fp))
{
if (fgets (buf, sizeof (buf), fp) == NULL)
break;
p = remove_leading_whitespaces (buf);
/* Skip comments. */
str = strstr (p, "//");
if (str != NULL)
str[0] = '\0';
/* Remove trailing white spaces. */
remove_trailing_whitespaces (p);
switch (p[0])
{
case '#':
printf ("%s\n", p);
case '\0':
continue;
break;
default:
break;
}
last = p + strlen (p);
/* Find name. */
name = next_field (p, &str);
if (str >= last)
abort ();
/* Find number of operands. */
operands = next_field (str, &str);
if (str >= last)
abort ();
/* Find base_opcode. */
base_opcode = next_field (str, &str);
if (str >= last)
abort ();
/* Find extension_opcode. */
extension_opcode = next_field (str, &str);
if (str >= last)
abort ();
/* Find cpu_flags. */
cpu_flags = next_field (str, &str);
if (str >= last)
abort ();
/* Find opcode_modifier. */
opcode_modifier = next_field (str, &str);
if (str >= last)
abort ();
/* Remove the first {. */
str = remove_leading_whitespaces (str);
if (*str != '{')
abort ();
str = remove_leading_whitespaces (str + 1);
i = strlen (str);
/* There are at least "X}". */
if (i < 2)
abort ();
/* Remove trailing white spaces and }. */
do
{
i--;
if (ISSPACE (str[i]) || str[i] == '}')
str[i] = '\0';
else
break;
}
while (i != 0);
last = str + i;
/* Find operand_types. */
for (i = 0; i < ARRAY_SIZE (operand_types); i++)
{
if (str >= last)
{
operand_types [i] = NULL;
break;
}
operand_types [i] = next_field (str, &str);
if (*operand_types[i] == '0')
{
if (i != 0)
operand_types[i] = NULL;
break;
}
}
printf (" { \"%s\", %s, %s, %s, %s,\n",
name, operands, base_opcode, extension_opcode,
cpu_flags);
printf (" %s,\n", opcode_modifier);
printf (" { ");
for (i = 0; i < ARRAY_SIZE (operand_types); i++)
{
if (operand_types[i] == NULL
|| *operand_types[i] == '0')
{
if (i == 0)
printf ("0");
break;
}
if (i != 0)
printf (",\n ");
printf ("%s", operand_types[i]);
}
printf (" } },\n");
}
printf (" { NULL, 0, 0, 0, 0, 0, { 0 } }\n");
printf ("};\n");
}
static void
process_i386_registers (void)
{
FILE *fp = fopen ("i386-reg.tbl", "r");
char buf[2048];
char *str, *p, *last;
char *reg_name, *reg_type, *reg_flags, *reg_num;
if (fp == NULL)
fail (_("can't find i386-reg.tbl for reading\n"));
printf ("\n/* i386 register table. */\n\n");
printf ("const reg_entry i386_regtab[] =\n{\n");
while (!feof (fp))
{
if (fgets (buf, sizeof (buf), fp) == NULL)
break;
p = remove_leading_whitespaces (buf);
/* Skip comments. */
str = strstr (p, "//");
if (str != NULL)
str[0] = '\0';
/* Remove trailing white spaces. */
remove_trailing_whitespaces (p);
switch (p[0])
{
case '#':
printf ("%s\n", p);
case '\0':
continue;
break;
default:
break;
}
last = p + strlen (p);
/* Find reg_name. */
reg_name = next_field (p, &str);
if (str >= last)
abort ();
/* Find reg_type. */
reg_type = next_field (str, &str);
if (str >= last)
abort ();
/* Find reg_flags. */
reg_flags = next_field (str, &str);
if (str >= last)
abort ();
/* Find reg_num. */
reg_num = next_field (str, &str);
printf (" { \"%s\", %s, %s, %s },\n",
reg_name, reg_type, reg_flags, reg_num);
}
printf ("};\n");
printf ("\nconst unsigned int i386_regtab_size = ARRAY_SIZE (i386_regtab);\n");
}
/* Program options. */
#define OPTION_SRCDIR 200
struct option long_options[] =
{
{"srcdir", required_argument, NULL, OPTION_SRCDIR},
{"debug", no_argument, NULL, 'd'},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{0, no_argument, NULL, 0}
};
static void
print_version (void)
{
printf ("%s: version 1.0\n", program_name);
xexit (0);
}
static void
usage (FILE * stream, int status)
{
fprintf (stream, "Usage: %s [-V | --version] [-d | --debug] [--srcdir=dirname] [--help]\n",
program_name);
xexit (status);
}
int
main (int argc, char **argv)
{
extern int chdir (char *);
char *srcdir = NULL;
int c;
program_name = *argv;
xmalloc_set_program_name (program_name);
while ((c = getopt_long (argc, argv, "vVdh", long_options, 0)) != EOF)
switch (c)
{
case OPTION_SRCDIR:
srcdir = optarg;
break;
case 'V':
case 'v':
print_version ();
break;
case 'd':
debug = 1;
break;
case 'h':
case '?':
usage (stderr, 0);
default:
case 0:
break;
}
if (optind != argc)
usage (stdout, 1);
if (srcdir != NULL)
if (chdir (srcdir) != 0)
fail (_("unable to change directory to \"%s\", errno = %s\n"),
srcdir, strerror (errno));
printf ("/* This file is automatically generated by i386-gen. Do not edit! */\n");
process_i386_opcodes ();
process_i386_registers ();
exit (0);
}

File diff suppressed because it is too large Load Diff

1489
opcodes/i386-opc.tbl Normal file

File diff suppressed because it is too large Load Diff

182
opcodes/i386-reg.tbl Normal file
View File

@ -0,0 +1,182 @@
// i386 register table.
// Make %st first as we test for it.
st, FloatReg|FloatAcc, 0, 0
// 8 bit regs
al, Reg8|Acc, 0, 0
cl, Reg8|ShiftCount, 0, 1
dl, Reg8, 0, 2
bl, Reg8, 0, 3
ah, Reg8, 0, 4
ch, Reg8, 0, 5
dh, Reg8, 0, 6
bh, Reg8, 0, 7
axl, Reg8|Acc, RegRex64, 0
cxl, Reg8, RegRex64, 1
dxl, Reg8, RegRex64, 2
bxl, Reg8, RegRex64, 3
spl, Reg8, RegRex64, 4
bpl, Reg8, RegRex64, 5
sil, Reg8, RegRex64, 6
dil, Reg8, RegRex64, 7
r8b, Reg8, RegRex|RegRex64, 0
r9b, Reg8, RegRex|RegRex64, 1
r10b, Reg8, RegRex|RegRex64, 2
r11b, Reg8, RegRex|RegRex64, 3
r12b, Reg8, RegRex|RegRex64, 4
r13b, Reg8, RegRex|RegRex64, 5
r14b, Reg8, RegRex|RegRex64, 6
r15b, Reg8, RegRex|RegRex64, 7
// 16 bit regs
ax, Reg16|Acc, 0, 0
cx, Reg16, 0, 1
dx, Reg16|InOutPortReg, 0, 2
bx, Reg16|BaseIndex, 0, 3
sp, Reg16, 0, 4
bp, Reg16|BaseIndex, 0, 5
si, Reg16|BaseIndex, 0, 6
di, Reg16|BaseIndex, 0, 7
r8w, Reg16, RegRex, 0
r9w, Reg16, RegRex, 1
r10w, Reg16, RegRex, 2
r11w, Reg16, RegRex, 3
r12w, Reg16, RegRex, 4
r13w, Reg16, RegRex, 5
r14w, Reg16, RegRex, 6
r15w, Reg16, RegRex, 7
// 32 bit regs
eax, Reg32|BaseIndex|Acc, 0, 0
ecx, Reg32|BaseIndex, 0, 1
edx, Reg32|BaseIndex, 0, 2
ebx, Reg32|BaseIndex, 0, 3
esp, Reg32, 0, 4
ebp, Reg32|BaseIndex, 0, 5
esi, Reg32|BaseIndex, 0, 6
edi, Reg32|BaseIndex, 0, 7
r8d, Reg32|BaseIndex, RegRex, 0
r9d, Reg32|BaseIndex, RegRex, 1
r10d, Reg32|BaseIndex, RegRex, 2
r11d, Reg32|BaseIndex, RegRex, 3
r12d, Reg32|BaseIndex, RegRex, 4
r13d, Reg32|BaseIndex, RegRex, 5
r14d, Reg32|BaseIndex, RegRex, 6
r15d, Reg32|BaseIndex, RegRex, 7
rax, Reg64|BaseIndex|Acc, 0, 0
rcx, Reg64|BaseIndex, 0, 1
rdx, Reg64|BaseIndex, 0, 2
rbx, Reg64|BaseIndex, 0, 3
rsp, Reg64, 0, 4
rbp, Reg64|BaseIndex, 0, 5
rsi, Reg64|BaseIndex, 0, 6
rdi, Reg64|BaseIndex, 0, 7
r8, Reg64|BaseIndex, RegRex, 0
r9, Reg64|BaseIndex, RegRex, 1
r10, Reg64|BaseIndex, RegRex, 2
r11, Reg64|BaseIndex, RegRex, 3
r12, Reg64|BaseIndex, RegRex, 4
r13, Reg64|BaseIndex, RegRex, 5
r14, Reg64|BaseIndex, RegRex, 6
r15, Reg64|BaseIndex, RegRex, 7
// Segment registers.
es, SReg2, 0, 0
cs, SReg2, 0, 1
ss, SReg2, 0, 2
ds, SReg2, 0, 3
fs, SReg3, 0, 4
gs, SReg3, 0, 5
// Control registers.
cr0, Control, 0, 0
cr1, Control, 0, 1
cr2, Control, 0, 2
cr3, Control, 0, 3
cr4, Control, 0, 4
cr5, Control, 0, 5
cr6, Control, 0, 6
cr7, Control, 0, 7
cr8, Control, RegRex, 0
cr9, Control, RegRex, 1
cr10, Control, RegRex, 2
cr11, Control, RegRex, 3
cr12, Control, RegRex, 4
cr13, Control, RegRex, 5
cr14, Control, RegRex, 6
cr15, Control, RegRex, 7
// Debug registers.
db0, Debug, 0, 0
db1, Debug, 0, 1
db2, Debug, 0, 2
db3, Debug, 0, 3
db4, Debug, 0, 4
db5, Debug, 0, 5
db6, Debug, 0, 6
db7, Debug, 0, 7
db8, Debug, RegRex, 0
db9, Debug, RegRex, 1
db10, Debug, RegRex, 2
db11, Debug, RegRex, 3
db12, Debug, RegRex, 4
db13, Debug, RegRex, 5
db14, Debug, RegRex, 6
db15, Debug, RegRex, 7
dr0, Debug, 0, 0
dr1, Debug, 0, 1
dr2, Debug, 0, 2
dr3, Debug, 0, 3
dr4, Debug, 0, 4
dr5, Debug, 0, 5
dr6, Debug, 0, 6
dr7, Debug, 0, 7
dr8, Debug, RegRex, 0
dr9, Debug, RegRex, 1
dr10, Debug, RegRex, 2
dr11, Debug, RegRex, 3
dr12, Debug, RegRex, 4
dr13, Debug, RegRex, 5
dr14, Debug, RegRex, 6
dr15, Debug, RegRex, 7
// Test registers.
tr0, Test, 0, 0
tr1, Test, 0, 1
tr2, Test, 0, 2
tr3, Test, 0, 3
tr4, Test, 0, 4
tr5, Test, 0, 5
tr6, Test, 0, 6
tr7, Test, 0, 7
// MMX and simd registers.
mm0, RegMMX, 0, 0
mm1, RegMMX, 0, 1
mm2, RegMMX, 0, 2
mm3, RegMMX, 0, 3
mm4, RegMMX, 0, 4
mm5, RegMMX, 0, 5
mm6, RegMMX, 0, 6
mm7, RegMMX, 0, 7
xmm0, RegXMM, 0, 0
xmm1, RegXMM, 0, 1
xmm2, RegXMM, 0, 2
xmm3, RegXMM, 0, 3
xmm4, RegXMM, 0, 4
xmm5, RegXMM, 0, 5
xmm6, RegXMM, 0, 6
xmm7, RegXMM, 0, 7
xmm8, RegXMM, RegRex, 0
xmm9, RegXMM, RegRex, 1
xmm10, RegXMM, RegRex, 2
xmm11, RegXMM, RegRex, 3
xmm12, RegXMM, RegRex, 4
xmm13, RegXMM, RegRex, 5
xmm14, RegXMM, RegRex, 6
xmm15, RegXMM, RegRex, 7
// No type will make this register rejected for all purposes except
// for addressing. This saves creating one extra type for RIP.
rip, BaseIndex, 0, 0
// fp regs.
st(0), FloatReg|FloatAcc, 0, 0
st(1), FloatReg, 0, 1
st(2), FloatReg, 0, 2
st(3), FloatReg, 0, 3
st(4), FloatReg, 0, 4
st(5), FloatReg, 0, 5
st(6), FloatReg, 0, 6
st(7), FloatReg, 0, 7

4468
opcodes/i386-tbl.h Normal file

File diff suppressed because it is too large Load Diff