This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] x86: fix register parsing and suffix recognition


>>> "H.J. Lu" <hjl.tools@gmail.com> 13.02.08 18:03 >>>
>On Feb 13, 2008 5:20 AM, Jan Beulich <jbeulich@novell.com> wrote:
>> Names of registers unavailable on the currently selected CPU should
>> never be parsed successfully (not just for 64-bit ones when .code64 is
>> not in effect) - these names must revert to ordinary symbol names in
>> such contexts.
>
>Please add some testcases for both Intel and AT&T syntaxes.

I added Intel tests; AT&T tests could only be error message tests (as
there's no collision between register and symbol name spaces), and
since I generally consider error message tests of at best marginal use
I'd like to skip those unless you insist.

Built and tested on i686-pc-linux-gnu and x86_64-unknown-linux-gnu.

gas/
2008-02-14  Jan Beulich  <jbeulich@novell.com>

	* config/tc-i386.c (match_template): Disallow 'l' suffix when
	currently selected CPU has no 32-bit support.
	(parse_real_register): Do not return registers not available on
	currently selected CPU.

gas/testsuite/
2008-02-14  Jan Beulich  <jbeulich@novell.com>

	* gas/i386/intel-regs.s, gas/i386/intel-regs.d: New.
	* gas/i386/i386.exp: Run new test.

--- 2008-02-13/gas/config/tc-i386.c	2008-02-13 11:13:40.000000000 +0100
+++ 2008-02-13/gas/config/tc-i386.c	2008-02-13 13:12:08.000000000 +0100
@@ -3287,6 +3287,19 @@ match_template (void)
 	      || t->extension_opcode != 1 /* cmpxchg8b */))
 	continue;
 
+      /* In general, don't allow 32-bit operands on pre-386.  */
+      else if (i.suffix == LONG_MNEM_SUFFIX
+	       && !cpu_arch_flags.bitfield.cpui386
+	       && (intel_syntax
+		   ? (!t->opcode_modifier.ignoresize
+		      && !intel_float_operand (t->name))
+		   : intel_float_operand (t->name) != 2)
+	       && ((!operand_types[0].bitfield.regmmx
+		    && !operand_types[0].bitfield.regxmm)
+		   || (!operand_types[t->operands > 1].bitfield.regmmx
+		       && !!operand_types[t->operands > 1].bitfield.regxmm)))
+	continue;
+
       /* Do not verify operands when there are none.  */
       else
 	{
@@ -7064,6 +7077,24 @@ parse_real_register (char *reg_string, c
   if (UINTS_ALL_ZERO (r->reg_type))
     return (const reg_entry *) NULL;
 
+  if ((r->reg_type.bitfield.reg32
+       || r->reg_type.bitfield.sreg3
+       || r->reg_type.bitfield.control
+       || r->reg_type.bitfield.debug
+       || r->reg_type.bitfield.test)
+      && !cpu_arch_flags.bitfield.cpui386)
+    return (const reg_entry *) NULL;
+
+  /* XXX
+  if (r->reg_type.bitfield.floatreg && !cpu_arch_flags.bitfield.cpu8087)
+    return (const reg_entry *) NULL; */
+
+  if (r->reg_type.bitfield.regmmx && !cpu_arch_flags.bitfield.cpummx)
+    return (const reg_entry *) NULL;
+
+  if (r->reg_type.bitfield.regxmm && !cpu_arch_flags.bitfield.cpusse)
+    return (const reg_entry *) NULL;
+
   /* Don't allow fake index register unless allow_index_reg isn't 0. */
   if (!allow_index_reg
       && (r->reg_num == RegEiz || r->reg_num == RegRiz))
--- 2008-02-13/gas/testsuite/gas/i386/i386.exp	2008-02-13 11:13:35.000000000 +0100
+++ 2008-02-13/gas/testsuite/gas/i386/i386.exp	2008-02-14 16:32:00.000000000 +0100
@@ -146,6 +146,7 @@ if [expr ([istarget "i*86-*-*"] ||  [ist
 	run_dump_test "reloc32"
 	run_list_test "reloc32" "--defsym _bad_=1"
 	run_dump_test "mixed-mode-reloc32"
+	run_dump_test "intel-regs"
     }
 
     # This is a PE specific test.
--- 2008-02-13/gas/testsuite/gas/i386/intel-regs.d	1970-01-01 01:00:00.000000000 +0100
+++ 2008-02-13/gas/testsuite/gas/i386/intel-regs.d	2008-02-14 16:28:44.000000000 +0100
@@ -0,0 +1,45 @@
+#objdump: -drw
+#name: i386 Intel register names
+
+.*: +file format .*i386.*
+
+Disassembly of section \.text:
+0+0 <.*>:
+.*[ 	]+R_386_16[ 	]+eax
+.*[ 	]+R_386_16[ 	]+rax
+.*[ 	]+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00:00.000000000 +0100
+++ 2008-02-13/gas/testsuite/gas/i386/intel-regs.s	2008-02-14 16:31:28.000000000 +0100
@@ -0,0 +1,50 @@
+	.text
+	.intel_syntax noprefix
+
+	.arch i286
+	.code16
+	mov	ax, eax			; add	[bx+si], al
+	mov	ax, rax			; add	[bx+si], al
+	mov	ax, axl			; add	[bx+si], al
+	mov	ax, r8b			; add	[bx+si], al
+	mov	ax, r8w			; add	[bx+si], al
+	mov	ax, r8d			; add	[bx+si], al
+	mov	ax, r8			; add	[bx+si], al
+	mov	ax, fs			; add	[bx+si], al
+#todo	mov	ax, st			; add	[bx+si], al
+	mov	ax, cr0			; add	[bx+si], al
+	mov	ax, dr0			; add	[bx+si], al
+	mov	ax, tr0			; add	[bx+si], al
+	mov	ax, mm0			; add	[bx+si], al
+	mov	ax, xmm0		; add	[bx+si], al
+
+	.arch generic32
+	.code32
+	mov	eax, rax
+	mov	eax, axl
+	mov	eax, r8b
+	mov	eax, r8w
+	mov	eax, r8d
+	mov	eax, r8
+#todo	mov	eax, st
+	mov	eax, cr0
+	mov	eax, dr0
+	mov	eax, tr0
+	mov	eax, mm0
+	mov	eax, xmm0
+
+#todo	.arch i387
+	ffree	st
+
+	.arch .mmx
+	pxor	mm0, mm0
+
+	.arch .sse
+	xorps	xmm0, xmm0
+
+	.arch generic64
+	.code64
+	mov	axl, r8b
+	mov	ax, r8w
+	mov	eax, r8d
+	mov	rax, r8



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]