[PATCH 05/14] powerpc: Add new code patching routines

Michael Ellerman michael at ellerman.id.au
Thu Jun 26 13:54:39 EST 2008


On Tue, 2008-06-24 at 08:48 -0500, Kumar Gala wrote:
> On Jun 23, 2008, at 8:32 PM, Michael Ellerman wrote:
> 
> > This commit adds some new routines for patching code, they will be  
> > used
> > in a following commit.
> >
> > Signed-off-by: Michael Ellerman <michael at ellerman.id.au>
> > ---
> > arch/powerpc/lib/code-patching.c    |  107 ++++++++++++++++++++++++++ 
> > +++++++++
> > include/asm-powerpc/code-patching.h |    8 +++
> > 2 files changed, 115 insertions(+), 0 deletions(-)
> >
> > diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/ 
> > code-patching.c
> > index 430f4c1..27957c4 100644
> > --- a/arch/powerpc/lib/code-patching.c
> > +++ b/arch/powerpc/lib/code-patching.c
> > @@ -41,3 +41,110 @@ unsigned int create_branch(const unsigned int  
> > *addr,
> >
> > 	return instruction;
> > }
> > +
> > +unsigned int create_cond_branch(const unsigned int *addr,
> > +				unsigned long target, int flags)
> > +{
> 
> it would be nice to have some idea what flags is suppose to be.

Yeah this routine is a bit of kludge, it's really only written for
translate_branch(). As it is, flags just takes any of the bits in a
conditional branch that aren't the opcode or target.

To fully synthesise a conditional branch by hand you'd probably want
another routine which constructs the BO & BI fields for you.

> > +unsigned int translate_branch(const unsigned int *dest, const  
> > unsigned int *src)
> > +{
> 
> I'm not sure I get what this function is trying to do.

It takes a relative branch at src and returns a new branch of the same
type that could be placed at dest, and would jump to the same target as
the original instruction. I guess I should add some doco :)

> > +	unsigned long target;
> > +
> > +	target = branch_target(src);
> > +
> > +	if (instr_is_branch_iform(*src))
> > +		return create_branch(dest, target, *src);
> > +	else if (instr_is_branch_bform(*src))
> > +		return create_cond_branch(dest, target, *src);
> > +
> > +	return 0;
> > +}

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20080626/55ddcef7/attachment.pgp>


More information about the Linuxppc-dev mailing list