Re: clobbered registers



On 27.04.2006 5:18, luke wrote:

Hi everybody,
I'm trying to develop a little operating system,
but I can't resolve the following issue.
I have defined a macro which purpose is to set the base address of a
segment:

#define set_base(addr,base) \
__asm__("movw %%dx,%0\n\t" \
"rorl $16,%%edx\n\t" \
"movb %%dl,%1\n\t" \
"movb %%dh,%2" \
::"m" (*((addr)+2)), \
"m" (*((addr)+4)), \
"m" (*((addr)+7)), \
"d" (base) \
)

Here, gcc doesn't know that you've clobbered %edx in your code. In fact, this statement explicitly tells GCC that you DON'T clobber %edx. You either need to specify %edx both as input and output, or try to list it as a clobbered register, e.g.

....
"d"(base) : "%edx" \
....

However, I'm not sure that GCC is going to like that, since %edx is also listed as an input.

The problem is that when I use it in the following way:

set_base(ldt[1], code_base);
set_base(ldt[2], data_base);

the gcc compiler doesn't reload the edx register so I get a wrong
result.

Even with your code, if gcc doesn't think that code_base and data_base are the same for some reason, it should reload %edx. How are code_base and data_base declared?

--
Cyril

.



Relevant Pages

  • Re: clobbered registers
    ... gcc doesn't know that you've clobbered %edx in your code. ... this statement explicitly tells GCC that you DON'T clobber %edx. ... are the same for some reason, it should reload %edx. ...
    (comp.lang.asm.x86)
  • Re: VMI broken on tip/master...
    ... edx was just loaded with the address for the paravirt call. ... Is there is a way to get GCC to not do such fancy tricks, ... freely converted back into a structure offset. ... These macros are intended to wrap calls through one of the paravirt ...
    (Linux-Kernel)
  • Re: clobbered registers
    ... On 02.05.2006 5:00, luke wrote: ... gcc doesn't know that you've clobbered %edx in your code. ... this statement explicitly tells GCC that you DON'T clobber %edx. ...
    (comp.lang.asm.x86)
  • Re: understanding clobber list in GNU inline ASM
    ... why gcc complains if I put this ... (I am trying to tell gcc: eax and edx are input, but I modify eax, ... and ecx) saying that could'nt find a register in DREG class while ...
    (comp.lang.asm.x86)
  • Re: [Xen-devel] Re: [PATCH] xen: Disable stack protector for irq helper
    ... and in general both eax and edx are marked clobbered. ... Then it will be also wrong for functions returning void. ... clobber eax but never set it to something correct. ... Try to use edx. ...
    (Linux-Kernel)