code-patching.c 917 B

123456789101112131415161718192021222324252627282930313233
  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. #include <linux/kernel.h>
  10. #include <asm/code-patching.h>
  11. void create_instruction(unsigned long addr, unsigned int instr)
  12. {
  13. unsigned int *p;
  14. p = (unsigned int *)addr;
  15. *p = instr;
  16. asm ("dcbst 0, %0; sync; icbi 0,%0; sync; isync" : : "r" (p));
  17. }
  18. void create_branch(unsigned long addr, unsigned long target, int flags)
  19. {
  20. unsigned int instruction;
  21. if (! (flags & BRANCH_ABSOLUTE))
  22. target = target - addr;
  23. /* Mask out the flags and target, so they don't step on each other. */
  24. instruction = 0x48000000 | (flags & 0x3) | (target & 0x03FFFFFC);
  25. create_instruction(addr, instruction);
  26. }