From 49b8dd56503a42f6092269c8a87569ae32d10bd4 Mon Sep 17 00:00:00 2001 From: Michael Ellerman Date: Tue, 24 Jun 2008 11:32:24 +1000 Subject: [PATCH] --- yaml --- r: 101715 b: refs/heads/master c: 053a858efa46c9ab86363b271374ec02ad2af753 h: refs/heads/master i: 101713: 13dd31d9c0b637ba20df984b51b308b6c2846d7d 101711: c6b96708478ad0d49ec52f002c3c19f99874d3e5 v: v3 --- [refs] | 2 +- trunk/arch/powerpc/lib/code-patching.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/[refs] b/[refs] index 48a389198095..aafe68a426d8 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: e7a57273c6407bb6903fbaddec8c2119bf318617 +refs/heads/master: 053a858efa46c9ab86363b271374ec02ad2af753 diff --git a/trunk/arch/powerpc/lib/code-patching.c b/trunk/arch/powerpc/lib/code-patching.c index 638dde313cbc..430f4c15d786 100644 --- a/trunk/arch/powerpc/lib/code-patching.c +++ b/trunk/arch/powerpc/lib/code-patching.c @@ -26,12 +26,18 @@ unsigned int create_branch(const unsigned int *addr, unsigned long target, int flags) { unsigned int instruction; + long offset; + offset = target; if (! (flags & BRANCH_ABSOLUTE)) - target = target - (unsigned long)addr; + offset = offset - (unsigned long)addr; + + /* Check we can represent the target in the instruction format */ + if (offset < -0x2000000 || offset > 0x1fffffc || offset & 0x3) + return 0; /* Mask out the flags and target, so they don't step on each other. */ - instruction = 0x48000000 | (flags & 0x3) | (target & 0x03FFFFFC); + instruction = 0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC); return instruction; }