i386 - GAS problem (fwd)

H.J. Lu hjl@lucon.org
Sat Mar 21 22:55:00 GMT 1998


> 
> 
> 
> 
> On Fri, 20 Mar 1998 18:02:00 -0500 H.J. Lu wrote:
> 
> > From: H.J. Lu <hjl@lucon.org>
> > Date: Fri, 20 Mar 1998 18:02:00 -0500
> > Subject: Re: i386 - GAS problem (fwd)
> > To: Joel Sherrill <joel@OARcorp.com>
> > Cc: erik.ivanenko@utoronto.ca, gas2@cygnus.com
> > 
> > > Date: Fri, 20 Mar 1998 15:38:16 -0500
> > > From: "erik.ivanenko" <erik.ivanenko@utoronto.ca>
> > > To: Joel Sherrill <joel@OARcorp.com>
> > > Subject: Re: i386 - GAS  problem
> > > 
> > > Joel Sherrill wrote:
> > > 
> > > > Could you put together a small compilable file 
> with this in it?  binutils
> > > > 2.9 is getting closer and we don't want problems 
> like this in there.
> > > 
> > > The following file shows that the ds register is 
> ignored by the lidt and
> > > lgdt instructions.This is also a problem with the 
> GAS I have ( shipped with
> > > gcc-2.7.2.1 , Linux Universe version ).
> > > I suspect this has been there for a while. 
> > > 
> > >  .section .text
> > >  .code16
> > >    movw $0x1000, %ax
> > >  movw    %ax, %ds
> > > 
> > >  lidt    %ds:0x1000
> > >  lidt    0x1000
> > > 
> > >  lgdt    %ds:0x1000
> > >  lgdt    0x1000
> > > 
> > >  .code32
> > > 
> > >  lidt    %ds:0x1000
> > >  lidt    0x1000
> > > 
> > >  lgdt    %ds:0x1000
> > >  lgdt    0x1000
> > > 
> > 
> > They look ok to me. Please tell me if you run into any 
> real problems
> > with your programs.
> > 
> > Correct me if I am wrong. I believe %ds is the default 
> segment
> > register for lidt/lgdt. gas just optimizes it out.
> > 
> > 
> > H.J.
> 
> I don't think that ds is used as a default for these 
> instructions:
> 
> The code that used these instructions loaded ds with 
> 0x100, and used a 0x0 offset.  The lidt failed; a logica 
> analyzer showed memory writes starting at address 0.
> 
> It was re-written into an equivalent form: ds contained 
> 0x0 with offset 0x1000.  That code worked; the logic 
> analyzer showed memory writes starting at address 
> 0x1000.
> 
> The 386sx programmers manual states that the lidt and 
> lgdt instructions take either m16:24 or m16:32 
> arguments.  The manual claims that the address follows 
> the opcode directly.
> 
> I don't have it in front of me,but I will try to remind 
> myself to send you the exact wording on Monday.
> 

Ian, I think lidt/lgdt are only 2 special cases which use
the linear address only. Here is a patch which seems to
work for me.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
---
Sat Mar 21 22:47:13 1998  H.J. Lu  (hjl@gnu.org)

	* config/tc-i386.c (md_assemble): Don't update "default_seg"
	if the instruction uses linear address only.

	* config/tc-i386.h (LinearAddress): New to indicate the
	instruction using linear address only.

Index: gas/config/tc-i386.c
===================================================================
RCS file: /home/work/cvs/gnu/binutils/gas/config/tc-i386.c,v
retrieving revision 1.30
diff -u -p -r1.30 tc-i386.c
--- gas/config/tc-i386.c	1998/03/21 02:02:54	1.30
+++ gas/config/tc-i386.c	1998/03/22 06:33:14
@@ -1563,7 +1563,7 @@ md_assemble (line)
 
 		    /* Find the default segment for the memory operand.
 		       Used to optimize out explicit segment specifications.  */
-		    if (i.seg)
+		    if (i.seg && !(t->opcode_modifier & LinearAddress))
 		      {
 			unsigned int seg_index;
 
Index: gas/config/tc-i386.h
===================================================================
RCS file: /home/work/cvs/gnu/binutils/gas/config/tc-i386.h,v
retrieving revision 1.17
diff -u -p -r1.17 tc-i386.h
--- gas/config/tc-i386.h	1997/11/01 03:09:10	1.17
+++ gas/config/tc-i386.h	1998/03/22 06:24:59
@@ -297,6 +297,8 @@ typedef struct
 #define Data16 0x20000		/* needs data prefix if in 32-bit mode */
 #define Data32 0x40000		/* needs data prefix if in 16-bit mode */
 #define iclrKludge 0x80000	/* used to convert clr to xor */
+/* Indicate the instruction using linear address only */
+#define LinearAddress 0x100000
 
   /* (opcode_modifier & COMES_IN_ALL_SIZES) is true if the
      instuction comes in byte, word, and dword sizes and is encoded into
Sat Mar 21 22:47:13 1998  H.J. Lu  (hjl@gnu.org)

	* opcode/i386.h (i386_optab): Set "lgdt" and "lidt" to use
	linear address only with LinearAddress in the "opcode_modifier"
	bit.

Index: include/opcode/i386.h
===================================================================
RCS file: /home/work/cvs/gnu/binutils/include/opcode/i386.h,v
retrieving revision 1.20
diff -u -p -r1.20 i386.h
--- include/opcode/i386.h	1997/11/01 03:09:27	1.20
+++ include/opcode/i386.h	1998/03/22 06:25:45
@@ -464,8 +464,8 @@ static const template i386_optab[] = {
 /* protection control */
 {"arpl", 2, 0x63, _, Modrm, { Reg16, Reg16|Mem, 0} },
 {"lar", 2, 0x0f02, _, Modrm|ReverseRegRegmem, { WordReg|Mem, WordReg, 0} },
-{"lgdt", 1, 0x0f01, 2, Modrm, { Mem, 0, 0} },
-{"lidt", 1, 0x0f01, 3, Modrm, { Mem, 0, 0} },
+{"lgdt", 1, 0x0f01, 2, Modrm|LinearAddress, { Mem, 0, 0} },
+{"lidt", 1, 0x0f01, 3, Modrm|LinearAddress, { Mem, 0, 0} },
 {"lldt", 1, 0x0f00, 2, Modrm, { WordReg|Mem, 0, 0} },
 {"lmsw", 1, 0x0f01, 6, Modrm, { WordReg|Mem, 0, 0} },
 {"lsl", 2, 0x0f03, _, Modrm|ReverseRegRegmem, { WordReg|Mem, WordReg, 0} },



More information about the Gas2 mailing list