Date: Wed, 24 Feb 2010 18:31:50 -0800 From: Patrick Mahan <mahan@mahan.org> To: Juli Mallett <jmallett@freebsd.org> Cc: freebsd-mips@freebsd.org Subject: Re: Writing MIPS assembler instructions in C Message-ID: <201002250236.o1P2a2oX024250@ns.mahan.org> In-Reply-To: <eaa228be1002241807q2613ccecy9773155e68ccda62@mail.gmail.com> References: <17060.1267061906@mahan.org> <eaa228be1002241807q2613ccecy9773155e68ccda62@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
See inline ... > Hi Patrick, > > On Wed, Feb 24, 2010 at 17:38, Patrick Mahan <mahan@mahan.org> wrote: > > part of some code built on the linux platform and > > there they are using "%[rt]" which I cannot find > > a description. > > %[foo] can be used to refer to named parameters (input or output, > maybe even clobbered) of inline assembly instructions rather than > using %0, %1, etc., which can be hard to read. Consider: > > %%% > static inline bool > atomic_cmpset64(volatile uint64_t *p, uint64_t o, uint64_t v) > { > uint64_t temp; > int res; > > asm volatile ( > "1:\n\t" > "move %[res], $0\n\t" > "lld %[temp], %[p]\n\t" > "bne %[temp], %[o], 2f\n\t" > "move %[temp], %[v]\n\t" > "li %[res], 1\n\t" > "scd %[temp], %[p]\n\t" > "beqz %[temp], 1b\n\t" > "2:\n\t" > : [res] "=&r"(res), [temp] "=&r"(temp), [p] "+m"(*p) > : [o] "r"(o), [v] "r"(v) > : "memory" > ); > > return (res != 0); > } > %%% > > The brackets with the input and output parameters specify what names > to use to refer to them in the assembly listing (here they happen to > be mostly the same as the variable names, but that's not necessary.) > Ah Sooo <*whack!*>...... I did not even twig on that... I had gotten it in my head that %[rt] was something special to the compiler that caused a certain behavior to occur. Now my problem is I still need to force the value pointed to "addr" into a specific register because there is a jalr to a function else where that I only have binary access too and it expects it's a value in that register. Can I coerce this? Thanks for the education. Patrick
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002250236.o1P2a2oX024250>