code-patching.c (e7a57273c6407bb6903fbaddec8c2119bf318617) code-patching.c (053a858efa46c9ab86363b271374ec02ad2af753)
1/*
2 * Copyright 2008 Michael Ellerman, IBM Corporation.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */

--- 12 unchanged lines hidden (view full) ---

21{
22 patch_instruction(addr, create_branch(addr, target, flags));
23}
24
25unsigned int create_branch(const unsigned int *addr,
26 unsigned long target, int flags)
27{
28 unsigned int instruction;
1/*
2 * Copyright 2008 Michael Ellerman, IBM Corporation.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */

--- 12 unchanged lines hidden (view full) ---

21{
22 patch_instruction(addr, create_branch(addr, target, flags));
23}
24
25unsigned int create_branch(const unsigned int *addr,
26 unsigned long target, int flags)
27{
28 unsigned int instruction;
29 long offset;
29
30
31 offset = target;
30 if (! (flags & BRANCH_ABSOLUTE))
32 if (! (flags & BRANCH_ABSOLUTE))
31 target = target - (unsigned long)addr;
33 offset = offset - (unsigned long)addr;
32
34
35 /* Check we can represent the target in the instruction format */
36 if (offset < -0x2000000 || offset > 0x1fffffc || offset & 0x3)
37 return 0;
38
33 /* Mask out the flags and target, so they don't step on each other. */
39 /* Mask out the flags and target, so they don't step on each other. */
34 instruction = 0x48000000 | (flags & 0x3) | (target & 0x03FFFFFC);
40 instruction = 0x48000000 | (flags & 0x3) | (offset & 0x03FFFFFC);
35
36 return instruction;
37}
41
42 return instruction;
43}