gcc inline asm - short question

gcc inline asm - short question

Post by Carl Spallett » Wed, 20 Mar 2002 08:40:05



  In studying the kernel I find many gcc inline 'asm' statements,
like so.

        asm ( assembler template
            : output operands                           (optional)
            : input operands                            (optional)
            : list of clobbered registers               (optional)
            );  

  I have read all the docs and I still can't clearly understand when it
is required to specify a clobberlist - a register or memory that will
be modified and must be preserved by gcc.

  In searching the kernel source there were very few clobbers given
and most of those were for memory.

  For example in arch/i386/lib/delay.c:

71         __asm__("mull %0"
72         :"=d" (xloops), "=&a" (d0)
73         :"1" (xloops),"" (current_cpu_data.loops_per_jiffy));
74         __delay(xloops * HZ);

  It's pretty obvious that eax gets clobbered, as I know clobber.  Why is
it not listed as such? Does the answer to this question apply in all cases?
What about memory clobbers - how do they happen?

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

gcc inline asm - short question

Post by Keith Owen » Wed, 20 Mar 2002 09:00:12


On Mon, 18 Mar 2002 15:27:40 -0800 (PST),


>        asm ( assembler template
>        : output operands                           (optional)
>        : input operands                            (optional)
>        : list of clobbered registers               (optional)
>        );  

>  I have read all the docs and I still can't clearly understand when it
>is required to specify a clobberlist - a register or memory that will
>be modified and must be preserved by gcc.

The clobber list is _extra_ clobbers, registers or memory that gcc
cannot deduce from the other parameters.  =d" (xloops), "=&a" (d0)
already tells gcc that edx and eax are used, you do not need to
explicitly specify them as clobbers.  OTOH, asm ("mov 1, %eax")
requires a clobber because the operands do not mention eax.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

gcc inline asm - short question

Post by H. Peter Anvi » Wed, 20 Mar 2002 14:30:10




In newsgroup: linux.dev.kernel

Quote:

>   I have read all the docs and I still can't clearly understand when it
> is required to specify a clobberlist - a register or memory that will
> be modified and must be preserved by gcc.

>   In searching the kernel source there were very few clobbers given
> and most of those were for memory.

>   For example in arch/i386/lib/delay.c:

> 71         __asm__("mull %0"
> 72         :"=d" (xloops), "=&a" (d0)
> 73         :"1" (xloops),"" (current_cpu_data.loops_per_jiffy));
> 74         __delay(xloops * HZ);

>   It's pretty obvious that eax gets clobbered, as I know clobber.  Why is
> it not listed as such? Does the answer to this question apply in all cases?
> What about memory clobbers - how do they happen?

It's not listed as such because it's an output (the second output),
not a clobber.  This is particularly common on x86 where registers are
so specialized that they all have their own constraint letters.

Incidentally, the above asm statement is technically incorrect, "=&a"
(d0) means eax is an "early clobber", however, the instruction doesn't
require it to be early clobbered.

        -hpa
--

"Unix gives you enough rope to shoot yourself in the foot."

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. inline asm errors when compiling linux-1.2.13 with gcc-2.7.1

Hello,

I've run into problems compiling the linux-1.2.13 kernel, which
always worked fine for me. I suspect the problem is not the
kernel, but gcc. I recently upgraded my gcc to version 2.7.1
(homebuilt from GNU sources, linux-aout configuration). When I
try to build the kernel, I get:

ZOO-station:/usr/src/linux# make zlilo
gcc -D__KERNEL__ -I/usr/src/linux/include -Wall
-Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -m486  -c -o
init/main.o init/main.c
/usr/src/linux/include/asm/io.h: In function `copro_timeout':
/usr/src/linux/include/asm/io.h:82: inconsistent operand
constraints in an `asm'
/usr/src/linux/include/asm/io.h:82: inconsistent operand
constraints in an `asm'
/usr/src/linux/include/asm/io.h:82: inconsistent operand
constraints in an `asm'
/usr/src/linux/include/asm/io.h:82: inconsistent operand
constraints in an `asm'
/usr/src/linux/include/asm/io.h: In function `check_fpu':
/usr/src/linux/include/asm/io.h:78: inconsistent operand
constraints in an `asm'
/usr/src/linux/include/asm/io.h:82: inconsistent operand
constraints in an `asm'
/usr/src/linux/include/asm/io.h:78: inconsistent operand
constraints in an `asm'
/usr/src/linux/include/asm/io.h:82: inconsistent operand
constraints in an `asm'
make: *** [init/main.o] Error 1
ZOO-station:/usr/src/linux#

So, did gcc-2.7.1 chenge the syntax for inline asm?
Does anybody have the same problems, or know how to fix this?

The offending part from linux/include/asm/io.h:

73: #define __OUTS(s) \
74: extern inline void outs##s(unsigned short port, const void *
addr, unsigned long count) \
75: { __asm__ __volatile__ ("cld ; rep ; outs" #s \
76: : "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1"
(count)); }
77:
78: __IN(b,"b","0" (0))
79: __IN(w,"w","0" (0))
80: __IN(l,"")
81:
82: __OUT(b,"b",char)
83: __OUT(w,"w",short)
84: __OUT(l,,int)
85:
86: __INS(b)
87: __INS(w)
88: __INS(l)
89:
90: __OUTS(b)
91: __OUTS(w)
92: __OUTS(l)

BTW: The ftape module, which also never gave me troubles, gives
about the
same errors.

Happy hacking,
          JanJaap

2. cdrecord and smart and friendly mach 12

3. PIII-instruction SHUFPS with gcc-inline-asm

4. simple tar question

5. Singapore LUG: April Meeting and Talk

6. Help with gcc inline floating point asm

7. gmake

8. inline Asm syntax question.

9. GCC gas x86 asm -> Intel X86 asm ?

10. inline asm

11. Linux-1.0-inline-asm uploaded

12. C inline ASM IN/OUT operation