From owner-freebsd-mips@FreeBSD.ORG Thu Feb 25 02:31:56 2010 Return-Path: Delivered-To: freebsd-mips@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2BD7B106564A; Thu, 25 Feb 2010 02:31:56 +0000 (UTC) (envelope-from mahan@mahan.org) Received: from ns.mahan.org (ns.mahan.org [67.116.10.138]) by mx1.freebsd.org (Postfix) with ESMTP id 05FED8FC18; Thu, 25 Feb 2010 02:31:55 +0000 (UTC) Received: from mahan.org (crowTrobot [67.116.10.140]) by ns.mahan.org (8.13.6/8.13.6) with ESMTP id o1P2a2oX024250; Wed, 24 Feb 2010 18:36:02 -0800 (PST) (envelope-from mahan@mahan.org) Message-Id: <201002250236.o1P2a2oX024250@ns.mahan.org> To: Juli Mallett In-reply-to: References: <17060.1267061906@mahan.org> Comments: In-reply-to Juli Mallett message dated "Wed, 24 Feb 2010 18:07:23 -0800." Date: Wed, 24 Feb 2010 18:31:50 -0800 From: Patrick Mahan Cc: freebsd-mips@freebsd.org Subject: Re: Writing MIPS assembler instructions in C X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2010 02:31:56 -0000 See inline ... > Hi Patrick, > > On Wed, Feb 24, 2010 at 17:38, Patrick Mahan 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