From: David Woodhouse <dwmw2@infradead.org>
To: stas <stas@lvk.cs.msu.su>
Cc: Johnny Hung <johnny.hacking@gmail.com>,
Viral Mehta <viral.mehta@einfochips.com>,
kernelnewbies@nl.linux.org, linux-embedded@vger.kernel.org
Subject: Re: How to move two valuables to x86 CPU register ebx, ecx by using AT&A inline asm.
Date: Fri, 20 Nov 2009 10:43:40 +0000 [thread overview]
Message-ID: <1258713820.10091.487.camel@macbook.infradead.org> (raw)
In-Reply-To: <1258697050.16509.36.camel@sotona>
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
next prev parent reply other threads:[~2009-11-20 10:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1258713820.10091.487.camel@macbook.infradead.org \
--to=dwmw2@infradead.org \
--cc=johnny.hacking@gmail.com \
--cc=kernelnewbies@nl.linux.org \
--cc=linux-embedded@vger.kernel.org \
--cc=stas@lvk.cs.msu.su \
--cc=viral.mehta@einfochips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).