linux-mips
[Top] [All Lists]

Re: system.h asm fixes

To: Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de>
Subject: Re: system.h asm fixes
From: Justin Carlson <justin@cs.cmu.edu>
Date: 17 Jun 2002 15:57:08 -0700
Cc: linux-mips@oss.sgi.com
In-reply-to: <20020617223650.GD20335@rembrandt.csv.ica.uni-stuttgart.de>
References: <1024338042.1463.21.camel@localhost.localdomain> <20020617224452.C27009@dea.linux-mips.net> <20020617223650.GD20335@rembrandt.csv.ica.uni-stuttgart.de>
Sender: owner-linux-mips@oss.sgi.com
On Mon, 2002-06-17 at 15:36, Thiemo Seufer wrote:
> Ralf Baechle wrote:
> [snip]
> > > Looks to me like we're missing some proper asm clobber markers:
> > 
> > No, as per convention $1 is never used by the compiler per convention,
> > so clobbering not necessary.  I recently removed all "$1" clobbers to
> > make the code a bit easier to read.
> 
> How can this work? A grep shows many instances of $1 usage,
> I don't think all of this code is interrupt safe.
> 

The "$x" clobber markers exist so that the *compiler* won't expect
values in those registers to be preserved across the asm call.  It has
nothing to do with safety across interrupts.  In other words, it's there
to prevent something like this:

        foo = 2;   // Compiler sticks foo a register, say, $2   
        asm (
                "  lw $2, baz\n"
                "  sw $2, (%0)\n"
                ::"r" (sna));   // Assembly code uses $2 as a temp reg
        (*bar) = foo;      // Compiler erroneously does (*bar) = baz;

In terms of interrupt safety, there is no issue with $1; any interrupt
would save the register before mucking with it, and restore it before
returning.  The only registers for which this is not true are k0 and k1.

As others have rightly pointed out, the compiler isn't allowed to muck
with $1 anyways, as it is defined to be a temporary register for the
assembler.  So the clobber notation isn't necessary.

Make sense?

-Justin


<Prev in Thread] Current Thread [Next in Thread>