2009-11-19 09:50:26

by Johnny Hung

[permalink] [raw]
Subject: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

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


2009-11-19 10:07:24

by Viral Mehta

[permalink] [raw]
Subject: Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

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
http://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 [email protected]
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>
>
> Email Scanned for Virus & Dangerous Content by : http://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.
_____________________________________________________________________

2009-11-19 10:19:51

by Johnny Hung

[permalink] [raw]
Subject: Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

It doesn't works. :(

2009/11/19 Viral Mehta <[email protected]>:
> 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
> http://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 [email protected]
>> Please read the FAQ at http://kernelnewbies.org/FAQ
>>
>>
>>
>> Email Scanned for Virus & Dangerous Content by : http://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.
> _____________________________________________________________________
>
>

2009-11-20 06:48:28

by Cong Wang

[permalink] [raw]
Subject: Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

On Thu, Nov 19, 2009 at 5:50 PM, Johnny Hung <[email protected]> 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.

2009-11-20 08:45:07

by Jiri Slaby

[permalink] [raw]
Subject: Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

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

2009-11-23 03:14:37

by Johnny Hung

[permalink] [raw]
Subject: Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

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
>

2009-11-23 05:43:44

by Brian Gerst

[permalink] [raw]
Subject: Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.

On Sun, Nov 22, 2009 at 10:14 PM, Johnny Hung <[email protected]> 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