* How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.
@ 2009-11-19 9:50 Johnny Hung
2009-11-19 10:05 ` Viral Mehta
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Johnny Hung @ 2009-11-19 9:50 UTC (permalink / raw)
To: kernelnewbies, linux-kernel, linux-embedded
Hi All:
I want to move two local valuables to x86 arch CPU ebx, ecx
register and do outb cpu instruction by using AT&A inline asm in
kernel driver. The following code was I wrote but gcc report syntax
error:
==
unsigned int val = 10;
unsigned int tmp = 5;
....
__asm__ volatile ("movl %0, %%ebx"
"movl %1, %%ecx"
"outb $0x27, $0xb2"
:
:"r"(val), "r"(tmp)
:"%ebx", "%ecx"
);
Does anyone can point me out. Any reply is appreciated.
BRs, H. Johnny
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-19 9:50 How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm Johnny Hung @ 2009-11-19 10:05 ` Viral Mehta 2009-11-19 10:19 ` Johnny Hung 2009-11-20 6:48 ` Américo Wang 2009-11-20 8:45 ` Jiri Slaby 2 siblings, 1 reply; 11+ messages in thread From: Viral Mehta @ 2009-11-19 10:05 UTC (permalink / raw) To: Johnny Hung; +Cc: kernelnewbies, linux-kernel, linux-embedded How about putting \n at the end ? Just try out, __asm__ volatile ("movl %0, %%ebx\n" "movl %1, %%ecx\n" Thanks, Viral Mehta, Embedded Software Engineer, Tel. No. 91 79 26563705, Ext. 423 www.einfochips.com <http://www.einfochips.com> Prepare and Prevent rather than Repair and Repent Johnny Hung wrote: > Hi All: > I want to move two local valuables to x86 arch CPU ebx, ecx > register and do outb cpu instruction by using AT&A inline asm in > kernel driver. The following code was I wrote but gcc report syntax > error: > == > unsigned int val = 10; > unsigned int tmp = 5; > .... > __asm__ volatile ("movl %0, %%ebx" > "movl %1, %%ecx" > "outb $0x27, $0xb2" > : > :"r"(val), "r"(tmp) > :"%ebx", "%ecx" > ); > > Does anyone can point me out. Any reply is appreciated. > > BRs, H. Johnny > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecartis@nl.linux.org > Please read the FAQ at http://kernelnewbies.org/FAQ > > > > Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com > > > -- _____________________________________________________________________ Disclaimer: This e-mail message and all attachments transmitted with it are intended solely for the use of the addressee and may contain legally privileged and confidential information. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to this message and please delete it from your computer. Any views expressed in this message are those of the individual sender unless otherwise stated.Company has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email. _____________________________________________________________________ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-19 10:05 ` Viral Mehta @ 2009-11-19 10:19 ` Johnny Hung 2009-11-19 10:21 ` Viral Mehta 0 siblings, 1 reply; 11+ messages in thread From: Johnny Hung @ 2009-11-19 10:19 UTC (permalink / raw) To: Viral Mehta; +Cc: kernelnewbies, linux-kernel, linux-embedded It doesn't works. :( 2009/11/19 Viral Mehta <viral.mehta@einfochips.com>: > How about putting \n at the end ? > > Just try out, > > __asm__ volatile ("movl %0, %%ebx\n" > "movl %1, %%ecx\n" > > > > > Thanks, > Viral Mehta, > Embedded Software Engineer, > Tel. No. 91 79 26563705, Ext. 423 > www.einfochips.com <http://www.einfochips.com> > Prepare and Prevent rather than Repair and Repent > > > Johnny Hung wrote: >> >> Hi All: >> I want to move two local valuables to x86 arch CPU ebx, ecx >> register and do outb cpu instruction by using AT&A inline asm in >> kernel driver. The following code was I wrote but gcc report syntax >> error: >> == >> unsigned int val = 10; >> unsigned int tmp = 5; >> .... >> __asm__ volatile ("movl %0, %%ebx" >> "movl %1, %%ecx" >> "outb $0x27, $0xb2" >> : >> :"r"(val), "r"(tmp) >> :"%ebx", "%ecx" >> ); >> >> Does anyone can point me out. Any reply is appreciated. >> >> BRs, H. Johnny >> >> -- >> To unsubscribe from this list: send an email with >> "unsubscribe kernelnewbies" to ecartis@nl.linux.org >> Please read the FAQ at http://kernelnewbies.org/FAQ >> >> >> >> Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com >> >> >> > > -- > _____________________________________________________________________ > Disclaimer: This e-mail message and all attachments transmitted with it > are intended solely for the use of the addressee and may contain legally > privileged and confidential information. If the reader of this message > is not the intended recipient, or an employee or agent responsible for > delivering this message to the intended recipient, you are hereby > notified that any dissemination, distribution, copying, or other use of > this message or its attachments is strictly prohibited. If you have > received this message in error, please notify the sender immediately by > replying to this message and please delete it from your computer. Any > views expressed in this message are those of the individual sender > unless otherwise stated.Company has taken enough precautions to prevent > the spread of viruses. However the company accepts no liability for any > damage caused by any virus transmitted by this email. > _____________________________________________________________________ > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-19 10:19 ` Johnny Hung @ 2009-11-19 10:21 ` Viral Mehta 2009-11-19 11:11 ` Johnny Hung 0 siblings, 1 reply; 11+ messages in thread From: Viral Mehta @ 2009-11-19 10:21 UTC (permalink / raw) To: Johnny Hung; +Cc: kernelnewbies, linux-embedded [root@viral temp_c_files]# gcc foo.c [root@viral temp_c_files]# cat foo.c #include <stdio.h> int main() { unsigned int val = 10; unsigned int tmp = 5; __asm__ volatile ("movl (%0), %%ebx\n" "movl (%1), %%ecx\n" : : "r"(val), "r"(tmp) ); } [root@viral temp_c_files]# Thanks, Viral Mehta, Embedded Software Engineer, Tel. No. 91 79 26563705, Ext. 423 www.einfochips.com <http://www.einfochips.com> Prepare and Prevent rather than Repair and Repent Johnny Hung wrote: > It doesn't works. :( > > 2009/11/19 Viral Mehta <viral.mehta@einfochips.com>: > >> How about putting \n at the end ? >> >> Just try out, >> >> __asm__ volatile ("movl %0, %%ebx\n" >> "movl %1, %%ecx\n" >> >> >> >> >> Thanks, >> Viral Mehta, >> Embedded Software Engineer, >> Tel. No. 91 79 26563705, Ext. 423 >> www.einfochips.com <http://www.einfochips.com> >> Prepare and Prevent rather than Repair and Repent >> >> >> Johnny Hung wrote: >> >>> Hi All: >>> I want to move two local valuables to x86 arch CPU ebx, ecx >>> register and do outb cpu instruction by using AT&A inline asm in >>> kernel driver. The following code was I wrote but gcc report syntax >>> error: >>> == >>> unsigned int val = 10; >>> unsigned int tmp = 5; >>> .... >>> __asm__ volatile ("movl %0, %%ebx" >>> "movl %1, %%ecx" >>> "outb $0x27, $0xb2" >>> : >>> :"r"(val), "r"(tmp) >>> :"%ebx", "%ecx" >>> ); >>> >>> Does anyone can point me out. Any reply is appreciated. >>> >>> BRs, H. Johnny >>> >>> -- >>> To unsubscribe from this list: send an email with >>> "unsubscribe kernelnewbies" to ecartis@nl.linux.org >>> Please read the FAQ at http://kernelnewbies.org/FAQ >>> >>> >>> >>> Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com >>> >>> >>> >>> >> -- >> _____________________________________________________________________ >> Disclaimer: This e-mail message and all attachments transmitted with it >> are intended solely for the use of the addressee and may contain legally >> privileged and confidential information. If the reader of this message >> is not the intended recipient, or an employee or agent responsible for >> delivering this message to the intended recipient, you are hereby >> notified that any dissemination, distribution, copying, or other use of >> this message or its attachments is strictly prohibited. If you have >> received this message in error, please notify the sender immediately by >> replying to this message and please delete it from your computer. Any >> views expressed in this message are those of the individual sender >> unless otherwise stated.Company has taken enough precautions to prevent >> the spread of viruses. However the company accepts no liability for any >> damage caused by any virus transmitted by this email. >> _____________________________________________________________________ >> >> >> > > > Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com > > > -- _____________________________________________________________________ Disclaimer: This e-mail message and all attachments transmitted with it are intended solely for the use of the addressee and may contain legally privileged and confidential information. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to this message and please delete it from your computer. Any views expressed in this message are those of the individual sender unless otherwise stated.Company has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email. _____________________________________________________________________ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-19 10:21 ` Viral Mehta @ 2009-11-19 11:11 ` Johnny Hung 2009-11-20 6:04 ` stas 0 siblings, 1 reply; 11+ messages in thread From: Johnny Hung @ 2009-11-19 11:11 UTC (permalink / raw) To: Viral Mehta; +Cc: kernelnewbies, linux-embedded Thank you. I got error because the valuable I actually pass is a member of structure point. ex. __asm__ volatile ("movl (%0), %%ebx\n" "movl (%1), %%ecx\n" : : "r"(ptr->cnt), "r"(ptr->blk) ); I reassigned ptr->cnt and ptr->blk to local unsigned int valuable and compile successfully. BTW, the first ':' is mean output operands, second ':' is mean input operands but how about third ':'. Does it mean which registers had been changed in inline asm code? So, does gcc do push and pop to retain these registers in the front and end of asm code? I have tried to compile inline asm in user space application and use gcc -S flag to translate c code to asm code. How do I translate kernel driver to asm code without compile to obj file? Thank your help BR, H. Johnny 2009/11/19 Viral Mehta <viral.mehta@einfochips.com>: > [root@viral temp_c_files]# gcc foo.c > [root@viral temp_c_files]# cat foo.c > #include <stdio.h> > int main() > { > unsigned int val = 10; > unsigned int tmp = 5; > > __asm__ volatile ("movl (%0), %%ebx\n" > "movl (%1), %%ecx\n" > : : "r"(val), "r"(tmp) ); > } > > [root@viral temp_c_files]# > Thanks, > Viral Mehta, > Embedded Software Engineer, > Tel. No. 91 79 26563705, Ext. 423 > www.einfochips.com <http://www.einfochips.com> > Prepare and Prevent rather than Repair and Repent > > > Johnny Hung wrote: >> >> It doesn't works. :( >> >> 2009/11/19 Viral Mehta <viral.mehta@einfochips.com>: >> >>> >>> How about putting \n at the end ? >>> >>> Just try out, >>> >>> __asm__ volatile ("movl %0, %%ebx\n" >>> "movl %1, %%ecx\n" >>> >>> >>> >>> >>> Thanks, >>> Viral Mehta, >>> Embedded Software Engineer, >>> Tel. No. 91 79 26563705, Ext. 423 >>> www.einfochips.com <http://www.einfochips.com> >>> Prepare and Prevent rather than Repair and Repent >>> >>> >>> Johnny Hung wrote: >>> >>>> >>>> Hi All: >>>> I want to move two local valuables to x86 arch CPU ebx, ecx >>>> register and do outb cpu instruction by using AT&A inline asm in >>>> kernel driver. The following code was I wrote but gcc report syntax >>>> error: >>>> == >>>> unsigned int val = 10; >>>> unsigned int tmp = 5; >>>> .... >>>> __asm__ volatile ("movl %0, %%ebx" >>>> "movl %1, %%ecx" >>>> "outb $0x27, $0xb2" >>>> : >>>> :"r"(val), "r"(tmp) >>>> :"%ebx", "%ecx" >>>> ); >>>> >>>> Does anyone can point me out. Any reply is appreciated. >>>> >>>> BRs, H. Johnny >>>> >>>> -- >>>> To unsubscribe from this list: send an email with >>>> "unsubscribe kernelnewbies" to ecartis@nl.linux.org >>>> Please read the FAQ at http://kernelnewbies.org/FAQ >>>> >>>> >>>> >>>> Email Scanned for Virus & Dangerous Content by : >>>> www.CleanMailGateway.com >>>> >>>> >>>> >>>> >>> >>> -- >>> _____________________________________________________________________ >>> Disclaimer: This e-mail message and all attachments transmitted with it >>> are intended solely for the use of the addressee and may contain legally >>> privileged and confidential information. If the reader of this message >>> is not the intended recipient, or an employee or agent responsible for >>> delivering this message to the intended recipient, you are hereby >>> notified that any dissemination, distribution, copying, or other use of >>> this message or its attachments is strictly prohibited. If you have >>> received this message in error, please notify the sender immediately by >>> replying to this message and please delete it from your computer. Any >>> views expressed in this message are those of the individual sender >>> unless otherwise stated.Company has taken enough precautions to prevent >>> the spread of viruses. However the company accepts no liability for any >>> damage caused by any virus transmitted by this email. >>> _____________________________________________________________________ >>> >>> >>> >> >> >> Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com >> >> >> > > -- > _____________________________________________________________________ > Disclaimer: This e-mail message and all attachments transmitted with it > are intended solely for the use of the addressee and may contain legally > privileged and confidential information. If the reader of this message > is not the intended recipient, or an employee or agent responsible for > delivering this message to the intended recipient, you are hereby > notified that any dissemination, distribution, copying, or other use of > this message or its attachments is strictly prohibited. If you have > received this message in error, please notify the sender immediately by > replying to this message and please delete it from your computer. Any > views expressed in this message are those of the individual sender > unless otherwise stated.Company has taken enough precautions to prevent > the spread of viruses. However the company accepts no liability for any > damage caused by any virus transmitted by this email. > _____________________________________________________________________ > > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-19 11:11 ` Johnny Hung @ 2009-11-20 6:04 ` stas 2009-11-20 10:43 ` David Woodhouse 0 siblings, 1 reply; 11+ messages in thread From: stas @ 2009-11-20 6:04 UTC (permalink / raw) To: Johnny Hung; +Cc: Viral Mehta, kernelnewbies, linux-embedded It seems to me that this example code is not free of errors. After the third ":" we should list registers "ebx" and "ecx" to let gcc know they could change in asm section. There can be no difference in -O0 but may have large impact on result in -O{2,3} modes. Actually resulting code may not include "push <some reg>"->"asm section"->"pop <some reg>" code. In the compile time gcc would decide when and what should be on registers. So it may look like "movl smth, reg"->"asm section"->"do nothing with reg, because we don't need it any more or directly put some value using movl". __asm__ volatile ( "movl (%0), %%ebx\n\t" "movl (%1), %%ecx\n\t" "outl %%ebx, $0xb2\n\t" "outl %%ecx, $0xb6\n\t" : : "r"(var_a), "r"(var_b) : "ebx", "ecx" ); There is another way. You can select registers should be used to pass arguments into the asm section (you can select registers to get results too). That should look much more pretty. The SAME code: __asm__ volatile ( "outl %%ebx, $0xb2\n\t" "outl %%ecx, $0xb6\n\t" : : "b"(var_a), "c"(var_b) ); And much more pretty way: /* taken from linux-2.6./include/asm-generic/io.h If you want to use it in user-space just replace u8 with unsigned char, u16 with unsigned short. In kernel space just insert #include directive. */ static inline void outb(u8 v, u16 port) { asm volatile("outb %0,%1" : : "a" (v), "dN" (port)); } ... outb(var_a, 0xb2); outb(var_b, 0xb6); > Thank you. I got error because the valuable I actually pass is a > member of structure point. ex. > > __asm__ volatile ("movl (%0), %%ebx\n" > "movl (%1), %%ecx\n" > : : "r"(ptr->cnt), "r"(ptr->blk) ); > > I reassigned ptr->cnt and ptr->blk to local unsigned int valuable and > compile successfully. BTW, the first ':' is mean output operands, > second ':' is mean input operands but how about third ':'. Does it > mean which registers had been changed in inline asm code? So, does gcc > do push and pop to retain these registers in the front and end of asm > code? > I have tried to compile inline asm in user space application and > use gcc -S flag to translate c code to asm code. How do I translate > kernel driver to asm code without compile to obj file? > > Thank your help > BR, H. Johnny > > 2009/11/19 Viral Mehta <viral.mehta@einfochips.com>: > > [root@viral temp_c_files]# gcc foo.c > > [root@viral temp_c_files]# cat foo.c > > #include <stdio.h> > > int main() > > { > > unsigned int val = 10; > > unsigned int tmp = 5; > > > > __asm__ volatile ("movl (%0), %%ebx\n" > > "movl (%1), %%ecx\n" > > : : "r"(val), "r"(tmp) ); > > } > > > > [root@viral temp_c_files]# > > Thanks, > > Viral Mehta, > > Embedded Software Engineer, > > Tel. No. 91 79 26563705, Ext. 423 > > www.einfochips.com <http://www.einfochips.com> > > Prepare and Prevent rather than Repair and Repent > > > > > > Johnny Hung wrote: > >> > >> It doesn't works. :( > >> > >> 2009/11/19 Viral Mehta <viral.mehta@einfochips.com>: > >> > >>> > >>> How about putting \n at the end ? > >>> > >>> Just try out, > >>> > >>> __asm__ volatile ("movl %0, %%ebx\n" > >>> "movl %1, %%ecx\n" > >>> > >>> > >>> > >>> > >>> Thanks, > >>> Viral Mehta, > >>> Embedded Software Engineer, > >>> Tel. No. 91 79 26563705, Ext. 423 > >>> www.einfochips.com <http://www.einfochips.com> > >>> Prepare and Prevent rather than Repair and Repent > >>> > >>> > >>> Johnny Hung wrote: > >>> > >>>> > >>>> Hi All: > >>>> I want to move two local valuables to x86 arch CPU ebx, ecx > >>>> register and do outb cpu instruction by using AT&A inline asm in > >>>> kernel driver. The following code was I wrote but gcc report syntax > >>>> error: > >>>> == > >>>> unsigned int val = 10; > >>>> unsigned int tmp = 5; > >>>> .... > >>>> __asm__ volatile ("movl %0, %%ebx" > >>>> "movl %1, %%ecx" > >>>> "outb $0x27, $0xb2" > >>>> : > >>>> :"r"(val), "r"(tmp) > >>>> :"%ebx", "%ecx" > >>>> ); > >>>> > >>>> Does anyone can point me out. Any reply is appreciated. > >>>> > >>>> BRs, H. Johnny > >>>> > >>>> -- > >>>> To unsubscribe from this list: send an email with > >>>> "unsubscribe kernelnewbies" to ecartis@nl.linux.org > >>>> Please read the FAQ at http://kernelnewbies.org/FAQ > >>>> > >>>> > >>>> > >>>> Email Scanned for Virus & Dangerous Content by : > >>>> www.CleanMailGateway.com > >>>> > >>>> > >>>> > >>>> > >>> > >>> -- > >>> _____________________________________________________________________ > >>> Disclaimer: This e-mail message and all attachments transmitted with it > >>> are intended solely for the use of the addressee and may contain legally > >>> privileged and confidential information. If the reader of this message > >>> is not the intended recipient, or an employee or agent responsible for > >>> delivering this message to the intended recipient, you are hereby > >>> notified that any dissemination, distribution, copying, or other use of > >>> this message or its attachments is strictly prohibited. If you have > >>> received this message in error, please notify the sender immediately by > >>> replying to this message and please delete it from your computer. Any > >>> views expressed in this message are those of the individual sender > >>> unless otherwise stated.Company has taken enough precautions to prevent > >>> the spread of viruses. However the company accepts no liability for any > >>> damage caused by any virus transmitted by this email. > >>> _____________________________________________________________________ > >>> > >>> > >>> > >> > >> > >> Email Scanned for Virus & Dangerous Content by : www.CleanMailGateway.com > >> > >> > >> > > > > -- > > _____________________________________________________________________ > > Disclaimer: This e-mail message and all attachments transmitted with it > > are intended solely for the use of the addressee and may contain legally > > privileged and confidential information. If the reader of this message > > is not the intended recipient, or an employee or agent responsible for > > delivering this message to the intended recipient, you are hereby > > notified that any dissemination, distribution, copying, or other use of > > this message or its attachments is strictly prohibited. If you have > > received this message in error, please notify the sender immediately by > > replying to this message and please delete it from your computer. Any > > views expressed in this message are those of the individual sender > > unless otherwise stated.Company has taken enough precautions to prevent > > the spread of viruses. However the company accepts no liability for any > > damage caused by any virus transmitted by this email. > > _____________________________________________________________________ > > > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-embedded" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-20 6:04 ` stas @ 2009-11-20 10:43 ` David Woodhouse 0 siblings, 0 replies; 11+ messages in thread From: David Woodhouse @ 2009-11-20 10:43 UTC (permalink / raw) To: stas; +Cc: Johnny Hung, Viral Mehta, kernelnewbies, linux-embedded On Fri, 2009-11-20 at 09:04 +0300, stas wrote: > It seems to me that this example code is not free of errors. After the > third ":" we should list registers "ebx" and "ecx" to let gcc know > they could change in asm section. > > __asm__ volatile ( > "movl (%0), %%ebx\n\t" > "movl (%1), %%ecx\n\t" > "outl %%ebx, $0xb2\n\t" > "outl %%ecx, $0xb6\n\t" > > > : > : "r"(var_a), "r"(var_b) > : "ebx", "ecx" That's not good enough. Because the compiler could choose to use %ebx for passing in 'var_b', and then it would get clobbered before you move it to %ecx in the second instruction. You'd need to make it an earlyclobber too. > > The SAME code: > __asm__ volatile ( > "outl %%ebx, $0xb2\n\t" > "outl %%ecx, $0xb6\n\t" > : > : "b"(var_a), "c"(var_b) > ); That's the better approach, although yours didn't do what Johnny's original seemed to. Jiri Slaby posted something which looks correct. > /* taken from linux-2.6./include/asm-generic/io.h > If you want to use it in user-space just replace u8 with unsigned char, > u16 with unsigned short. In kernel space just insert #include directive. > */ > static inline void outb(u8 v, u16 port) And that's just an entirely gratuitous use of our kernel nonsense-types. Just use the proper C types uint16_t and uint8_t instead. Or just 'unsigned char' and 'unsigned short', for that matter -- I believe Linux would blow up horribly if those types ever changed from 8-bit and 16-bit respectively. -- dwmw2 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-19 9:50 How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm Johnny Hung 2009-11-19 10:05 ` Viral Mehta @ 2009-11-20 6:48 ` Américo Wang 2009-11-20 8:45 ` Jiri Slaby 2 siblings, 0 replies; 11+ messages in thread From: Américo Wang @ 2009-11-20 6:48 UTC (permalink / raw) To: Johnny Hung; +Cc: kernelnewbies, linux-kernel, linux-embedded On Thu, Nov 19, 2009 at 5:50 PM, Johnny Hung <johnny.hacking@gmail.com> wrote: > Hi All: > I want to move two local valuables to x86 arch CPU ebx, ecx > register and do outb cpu instruction by using AT&A inline asm in > kernel driver. The following code was I wrote but gcc report syntax > error: You must mean AT&T. > == > unsigned int val = 10; > unsigned int tmp = 5; > .... > __asm__ volatile ("movl %0, %%ebx" You need to put "\n\t" in the end of each asm statement. > "movl %1, %%ecx" > "outb $0x27, $0xb2" This is wrong, 'outb' instruction cann't accept both of its operands as constants, IIRC. > : > :"r"(val), "r"(tmp) > :"%ebx", "%ecx" > ); > > Does anyone can point me out. Any reply is appreciated. Regards. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-19 9:50 How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm Johnny Hung 2009-11-19 10:05 ` Viral Mehta 2009-11-20 6:48 ` Américo Wang @ 2009-11-20 8:45 ` Jiri Slaby 2009-11-23 3:14 ` Johnny Hung 2 siblings, 1 reply; 11+ messages in thread From: Jiri Slaby @ 2009-11-20 8:45 UTC (permalink / raw) To: Johnny Hung; +Cc: kernelnewbies, linux-kernel, linux-embedded On 11/19/2009 10:50 AM, Johnny Hung wrote: > Hi All: > I want to move two local valuables to x86 arch CPU ebx, ecx > register and do outb cpu instruction by using AT&A inline asm in > kernel driver. The following code was I wrote but gcc report syntax > error: > == > unsigned int val = 10; > unsigned int tmp = 5; > .... > __asm__ volatile ("movl %0, %%ebx" > "movl %1, %%ecx" > "outb $0x27, $0xb2" > : > :"r"(val), "r"(tmp) > :"%ebx", "%ecx" > ); > > Does anyone can point me out. Any reply is appreciated. Why not just: ("outb $0x27, %%al" : : "a" (0xb2), "b"(val), "c" (tmp)); -- js Faculty of Informatics, Masaryk University Suse Labs, Novell ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-20 8:45 ` Jiri Slaby @ 2009-11-23 3:14 ` Johnny Hung 2009-11-23 5:43 ` Brian Gerst 0 siblings, 1 reply; 11+ messages in thread From: Johnny Hung @ 2009-11-23 3:14 UTC (permalink / raw) To: Jiri Slaby; +Cc: kernelnewbies, linux-kernel, linux-embedded After testing: # gcc inlineasm.c inlineasm.c: Assembler messages: inlineasm.c:7: Error: suffix or operands invalid for `out' [root@debian-johnny] ~/workspace/test # cat inlineasm.c #include <stdio.h> int main () { unsigned int val = 5, tmp = 10; asm volatile ("outb $0x27, %%al" : : "a" (0xb2), "b"(val), "c" (tmp) ); } It seems the source of outb instruction cannot be a constant. Is there a AT&T instructions document for x86? BRs, H. Johnny > Why not just: > ("outb $0x27, %%al" : : "a" (0xb2), "b"(val), "c" (tmp)); > -- > js > Faculty of Informatics, Masaryk University > Suse Labs, Novell > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm. 2009-11-23 3:14 ` Johnny Hung @ 2009-11-23 5:43 ` Brian Gerst 0 siblings, 0 replies; 11+ messages in thread From: Brian Gerst @ 2009-11-23 5:43 UTC (permalink / raw) To: Johnny Hung; +Cc: Jiri Slaby, kernelnewbies, linux-kernel, linux-embedded On Sun, Nov 22, 2009 at 10:14 PM, Johnny Hung <johnny.hacking@gmail.com> wrote: > After testing: > > # gcc inlineasm.c > inlineasm.c: Assembler messages: > inlineasm.c:7: Error: suffix or operands invalid for `out' > [root@debian-johnny] ~/workspace/test > > # cat inlineasm.c > #include <stdio.h> > > int main () > { > unsigned int val = 5, tmp = 10; > asm volatile ("outb $0x27, %%al" > : > : "a" (0xb2), "b"(val), "c" (tmp) > ); > } > > It seems the source of outb instruction cannot be a constant. Is > there a AT&T instructions document for x86? In AT&T syntax, the source register comes first. So it should be "outb %%al, $0x27", assuming that 0x27 is the port number you are trying to write to. -- Brian Gerst ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2009-11-23 5:43 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-11-19 9:50 How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm Johnny Hung 2009-11-19 10:05 ` Viral Mehta 2009-11-19 10:19 ` Johnny Hung 2009-11-19 10:21 ` Viral Mehta 2009-11-19 11:11 ` Johnny Hung 2009-11-20 6:04 ` stas 2009-11-20 10:43 ` David Woodhouse 2009-11-20 6:48 ` Américo Wang 2009-11-20 8:45 ` Jiri Slaby 2009-11-23 3:14 ` Johnny Hung 2009-11-23 5:43 ` Brian Gerst
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 NNTP newsgroup(s).