[PATCH 05/14] powerpc: Add new code patching routines
Kumar Gala
galak at kernel.crashing.org
Tue Jun 24 23:48:14 EST 2008
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.
>
> + unsigned int instruction;
> + long offset;
> +
> + offset = target;
> + if (! (flags & BRANCH_ABSOLUTE))
> + offset = offset - (unsigned long)addr;
> +
> + /* Check we can represent the target in the instruction format */
> + if (offset < -0x8000 || offset > 0x7FFF || offset & 0x3)
> + return 0;
> +
> + /* Mask out the flags and target, so they don't step on each
> other. */
> + instruction = 0x40000000 | (flags & 0x3FF0003) | (offset & 0xFFFC);
> +
> + return instruction;
> +}
[snip]
> +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.
>
> + 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;
> +}
More information about the Linuxppc-dev
mailing list