www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/13/05:58:53

Message-Id: <199605130945.FAA12824@delorie.com>
Date: Mon, 13 May 96 12:32:31 LIT
From: Martynas Kunigelis <martynas DOT kunigelis AT VM DOT KTU DOT LT>
Subject: Re: Loading Selectors
To: moskewicz AT MEM DOT po DOT com, DJGPP mailing list <djgpp AT delorie DOT com>
In-Reply-To: Your message of Sat, 11 May 1996 19:57:02 -0400

On Sat, 11 May 1996 19:57:02 -0400 you said:
>	I've been using extended asm for a while, and read the info info, as
>well as Brennan's guide (though by the time it was avalible, I'd had to
>piece things together myself). I've noticed that there are no
>constraints for the segment (selector) registers. Is this beacuse they
>must be loaded via another register anyway? If I want to have my
>selector loads done automatically, why can't I use "a" each time? In
>other words, why doesn't this work:
>asm("
>    push  %%ds
>    push  %%es
>    movw %3, %%es
>    movw %4, %%ds
>1:
>    movl %%es:(,%0,1),%%eax
>    add  $0x4, %0
>    movl %%eax,%%ds:(,%1,1)
>    add  $0x4, %1
>    decl %2
>    jnz  1b
>    pop  %%es
>    pop  %%ds
>    "
>    : // no outputs
>    :"D"(gr_offset_offset),"S"(true_gr_offset),"c"(mode.WinSize*256)
>     ,"a"(gr_selector),"a"(true_gr_selector) <-- this gives trouble, GCC
>complains that "asm requires too many reloads"
>    :"%eax"
>    );
>I know it works if I use:
>	,"b"(gr_selector),"a"(true_gr_selector)
>or some varient thereof, but why should I have to?
>BTW: these variables are public data members, and this code sits in a
>member function.
>----
>moskewicz AT mem DOT po DOT com
>
  The major problem here is: you shouldn't push something on the stack and then
use %0-style operands. Why? Because you alter the stack pointer and GCC might
reference the operands through it (e.g. compiling with -fomit-frame-pointer).
I can't think of a perfect way of storing segement registers, but I think the
following would do:

  asm ("
      movw %%es,%w0
      ...
      movw %w0,%%es
      "
      : "=g" (save_es)
      : ...
      : ...
  );

GCC has no constraints for segment registers, because it never uses them. What
the heck are they for in flat memory model from a compiler's point of view?

Martynas

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019