]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/powerpc/lib/code-patching.c
powerpc: Move code patching code into arch/powerpc/lib/code-patching.c
[mv-sheeva.git] / arch / powerpc / lib / code-patching.c
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  */
9
10 #include <linux/kernel.h>
11 #include <asm/code-patching.h>
12
13
14 void create_instruction(unsigned long addr, unsigned int instr)
15 {
16         unsigned int *p;
17         p  = (unsigned int *)addr;
18         *p = instr;
19         asm ("dcbst 0, %0; sync; icbi 0,%0; sync; isync" : : "r" (p));
20 }
21
22 void create_branch(unsigned long addr, unsigned long target, int flags)
23 {
24         unsigned int instruction;
25
26         if (! (flags & BRANCH_ABSOLUTE))
27                 target = target - addr;
28
29         /* Mask out the flags and target, so they don't step on each other. */
30         instruction = 0x48000000 | (flags & 0x3) | (target & 0x03FFFFFC);
31
32         create_instruction(addr, instruction);
33 }