Mail Archives: djgpp/1998/10/25/12:34:22
Michael Beck wrote:
>
> Ignacio García Pérez wrote in message <36237ef5 DOT 671209 AT crispin>...
> [..]
> >I've traced down the problem to the following function:
> At least with 2.7.2 it works for me in all combinations, however the problem
> are the asm instructions.
> asm did NOT work like inline assembly in typical x86 compilers. GCC did not
> recognize any instruction
> in the asm statement, it simply add the string you have specified into the
> assembly it generates. That's why
> you have to tell gcc which registers/memory your inline asm uses/changes.
> The way you have specified your
> instructions means: Neither changes registers NOR memory. So, the optimizer
> is free to remove your code!
> The right way is the following:
>
> __asm __volatile__("pushf"
> "cli");
>
> The __volatile__ here tells the compiler, that this code cannot be removed
> and further that it cannot be moved to another
> place. If you specify two asm and both change no register, gcc is free to
> change the execution order of it!
Actually, I think GCC now assumes `volatile' for an asm with no outputs,
which is probably the Right Thing. But it's certainly safer to use it.
Another thing: Manipulating the stack without the compiler's knowledge
is not such a good thing, especially if you use `-fomit-frame-pointer'.
Also, there's no good way to tell the compiler that the stack pointer is
not where it thinks. I would use code more like this (though it's
somewhat less efficient):
unsigned long flags;
asm("pushfl; popl %0" : "=r" (flags)); /* "g" or "m" will also be bad
*/
/* Now disable interrupts or whatever */
asm("pushl %0; popfl" : : "r" (flags) : "cc");
This way the stack is correct everywhere GCC wants to access it.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -