* A question about register constraint of inline assembly
@ 2005-06-02 3:17 Lin Chun-Zhi
2005-06-02 3:24 ` Ian Lance Taylor
0 siblings, 1 reply; 4+ messages in thread
From: Lin Chun-Zhi @ 2005-06-02 3:17 UTC (permalink / raw)
To: gcc-help
Hi there,
I got a question about register constraint in kernel source.
Here is the cut of bios32_service()
597 __asm__("lcall (%%edi); cld"
598 : "=a" (return_code),
599 "=b" (address),
600 "=c" (length),
601 "=d" (entry)
602 : "" (service),
603 "1" (0),
604 "D" (&bios32_indirect));
In line 602, its register constraint is a NULL string. I can't find how
compiler arranges the registers in gcc.info.
Does anyone know the further information?
Kindly regards,
Roach
--
Open WebMail Project (http://openwebmail.org)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A question about register constraint of inline assembly
2005-06-02 3:17 A question about register constraint of inline assembly Lin Chun-Zhi
@ 2005-06-02 3:24 ` Ian Lance Taylor
2005-06-02 5:23 ` Lin Chun-Zhi
[not found] ` <20050602051408.M11066@cs.ccu.edu.tw>
0 siblings, 2 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2005-06-02 3:24 UTC (permalink / raw)
To: Lin Chun-Zhi; +Cc: gcc-help
"Lin Chun-Zhi" <lcz90@cs.ccu.edu.tw> writes:
> I got a question about register constraint in kernel source.
> Here is the cut of bios32_service()
>
> 597 __asm__("lcall (%%edi); cld"
> 598 : "=a" (return_code),
> 599 "=b" (address),
> 600 "=c" (length),
> 601 "=d" (entry)
> 602 : "" (service),
> 603 "1" (0),
> 604 "D" (&bios32_indirect));
>
> In line 602, its register constraint is a NULL string. I can't find how
> compiler arranges the registers in gcc.info.
If there are no constraints, the compiler does not constrain the
operand. It could be anywhere. The statement will use "service",
though; assignments to it will not be deleted.
By the way, in linux-2.6.8.1 that statement looks like this:
__asm__("lcall *(%%edi); cld"
: "=a" (return_code),
"=b" (address),
"=c" (length),
"=d" (entry)
: "0" (service),
"1" (0),
"D" (&bios32_indirect));
Ian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A question about register constraint of inline assembly
2005-06-02 3:24 ` Ian Lance Taylor
@ 2005-06-02 5:23 ` Lin Chun-Zhi
[not found] ` <20050602051408.M11066@cs.ccu.edu.tw>
1 sibling, 0 replies; 4+ messages in thread
From: Lin Chun-Zhi @ 2005-06-02 5:23 UTC (permalink / raw)
To: gcc-help
On 01 Jun 2005 23:23:46 -0400, Ian Lance Taylor wrote
> "Lin Chun-Zhi" <lcz90@cs.ccu.edu.tw> writes:
>
> > I got a question about register constraint in kernel source.
> > Here is the cut of bios32_service()
> >
> > 597 __asm__("lcall (%%edi); cld"
> > 598 : "=a" (return_code),
> > 599 "=b" (address),
> > 600 "=c" (length),
> > 601 "=d" (entry)
> > 602 : "" (service),
> > 603 "1" (0),
> > 604 "D" (&bios32_indirect));
> >
> > In line 602, its register constraint is a NULL string. I can't find how
> > compiler arranges the registers in gcc.info.
>
> If there are no constraints, the compiler does not constrain the
> operand. It could be anywhere. The statement will use "service",
> though; assignments to it will not be deleted.
>
> By the way, in linux-2.6.8.1 that statement looks like this:
>
> __asm__("lcall *(%%edi); cld"
> : "=a" (return_code),
> "=b" (address),
> "=c" (length),
> "=d" (entry)
> : "0" (service),
> "1" (0),
> "D" (&bios32_indirect));
>
> Ian
Thank you, Ian. I got it.
But there is another wield thing. I can't pass the compiling stage use the
code below.
int main(void)
{
int __value, __port;
asm volatile ( "movl %1,%0" : "=a" (__value), "=d" (__port)
: "" (__value), "1" (__port)
);
return 0;
}
The error message is
[root@littleroach tmp]# gcc a.c
a.c: In function `main':
a.c:10: warning: asm operand 2 probably doesn't match constraints
a.c:10: error: impossible constraint in `asm'
But the same code in the kernel works very well.
Do I miss something?
Roach
--
Open WebMail Project (http://openwebmail.org)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A question about register constraint of inline assembly
[not found] ` <m3r7fkyj52.fsf@gossamer.airs.com>
@ 2005-06-03 2:34 ` Lin Chun-Zhi
0 siblings, 0 replies; 4+ messages in thread
From: Lin Chun-Zhi @ 2005-06-03 2:34 UTC (permalink / raw)
To: gcc-help
Thanks for Ian's relpy. It's very helpful for me.
On 02 Jun 2005 09:37:29 -0400, Ian Lance Taylor wrote
> "Lin Chun-Zhi" <lcz90@cs.ccu.edu.tw> writes:
>
> Please reply to the list, not just to me.
>
> > But there is another wield thing. I can't pass the compiling stage use
the
> > code below.
> >
> > int main(void)
> > {
> > int __value, __port;
> >
> > asm volatile ( "movl %1,%0" : "=a" (__value), "=d" (__port)
> > : "" (__value), "1" (__port)
> > );
> >
> > return 0;
> > }
> >
> > The error message is
> > [root@littleroach tmp]# gcc a.c
> > a.c: In function `main':
> > a.c:10: warning: asm operand 2 probably doesn't match constraints
> > a.c:10: error: impossible constraint in `asm'
> >
> > But the same code in the kernel works very well.
> > Do I miss something?
>
> It would probably work when optimizing. Otherwise gcc is complaining
> because it has a memory address and it doesn't know what type of
> register to put it into.
>
> You should specify a constraint, though. It's not a good idea to not
> specify one. If you want to specify that the value is changed by the
> asm (which is not the case in your example) use '+' instead of '='.
>
> Ian
--
Open WebMail Project (http://openwebmail.org)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-06-03 2:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-02 3:17 A question about register constraint of inline assembly Lin Chun-Zhi
2005-06-02 3:24 ` Ian Lance Taylor
2005-06-02 5:23 ` Lin Chun-Zhi
[not found] ` <20050602051408.M11066@cs.ccu.edu.tw>
[not found] ` <m3r7fkyj52.fsf@gossamer.airs.com>
2005-06-03 2:34 ` Lin Chun-Zhi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).