From: Daniel Egger <egger@suse.de>
To: Raghava Raju <vraghava_raju@yahoo.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: __asm__ usage ????
Date: 11 Aug 2001 19:32:53 +0200 [thread overview]
Message-ID: <997551186.791.68.camel@sonja> (raw)
In-Reply-To: <20010810195004.18859.qmail@web20008.mail.yahoo.com>
In-Reply-To: <20010810195004.18859.qmail@web20008.mail.yahoo.com>
Am 10 Aug 2001 12:50:04 -0700 schrieb Raghava Raju:
> I want some basic insights into assembly level code
> emmbedded in C language. Following is the code of
> PowerPc ambedded in C languagge:
It's not really kernel related but nevertheless...
> unsigned long old,mask, *p;
>
> __asm__ __volatile__(SMP_WMB "\
> 1: lwarx %0,0,%3
> andc %0,%0,%2
> stwcx %0,0,%3
> bne 1b"
> SMP_MB
> : "=&r" (old), "=m" (*p)
> : "r" (mask), "r" (p), "m" (*p)
> : "cc")"
> 1) what does these things denote: __volatile__,
It means the compiler should by no means touch the code.
> SMP_WMB, SMP_MB,
I suspect those are defined to some memory barriing code
and only in SMP kernels.
> "r","=&r","=m",
r means register, = means output and & is early clobber.
=m means address that is written to and in ppc assembler
this means a different notation in the final assembly
in the form 4(%r1) for example.
> "cc" and 1: .
cc is the condition code register and 1: a local label
which can be used for a look like "bne 1b" (branch if not
equal to label 1 backwards).
> 2) Is it that %0,%2,%3 denote addresses of old,mask,p
> respectively.
No, they are just labels which are replaced by the compiler
with whatever is defined after the colons.
> 4) I think in power PC we can't access
> directly the contents of memory, but we should
> give addresses of memory in registers then use
> registers in instructions to access memory. But in
> above example he is using %3 in lwarx command
> accessing that memory directly. Is my interpretation
> of above instructions wrong.
Yes, you're wrong. By issuing an "r" (p) the p (which is a
pointer in this case) is assigned to a register which is then
used in the load command as the absolute address.
> 5) Some people use "memory" in place of "cc" ,
> like I want to know what are these things.
Those are other clobbers. memory means that memory has been modified
by the command sequence and cc means that the condition register
is modify and thus has to be saved by the compiler if in doubt.
> 6) Finally I want to write a simple programme
> to write the contents of a local variable "xyz" into
> register r33, then store the contents of r33 into
> local variable "abc". Kindly would u give me a sample
> code of doing it.
Negative for two reasons: There is no register 33 (at least)
on 32bit PPC CPUs, and second, you normally don't want to
hardcode registers in inline assembly. If you really want to
then use normal assembly.
But for your example:
long xyz, abc;
__asm__ __volatile__ ("mr %0,%1\n\t": "r" (abc) : "r" (xyz));
However this is a really dumb example.
Servus,
Daniel
next prev parent reply other threads:[~2001-08-11 17:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-10 19:50 __asm__ usage ???? Raghava Raju
2001-08-10 22:25 ` george anzinger
2001-08-10 23:24 ` Erik Mouw
2001-08-11 17:32 ` Daniel Egger [this message]
2001-08-11 21:03 ` Raghava Raju
2001-08-13 5:02 ` Albert D. Cahalan
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=997551186.791.68.camel@sonja \
--to=egger@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=vraghava_raju@yahoo.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