jump_label.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <linux/kernel.h>
  2. #include <linux/types.h>
  3. #include <linux/mutex.h>
  4. #include <linux/cpu.h>
  5. #include <linux/jump_label.h>
  6. #include <linux/memory.h>
  7. #include <asm/cacheflush.h>
  8. #ifdef HAVE_JUMP_LABEL
  9. void arch_jump_label_transform(struct jump_entry *entry,
  10. enum jump_label_type type)
  11. {
  12. u32 *insn = (u32 *) (unsigned long) entry->code;
  13. u32 val;
  14. if (type == JUMP_LABEL_JMP) {
  15. s32 off = (s32)entry->target - (s32)entry->code;
  16. bool use_v9_branch = false;
  17. BUG_ON(off & 3);
  18. #ifdef CONFIG_SPARC64
  19. if (off <= 0xfffff && off >= -0x100000)
  20. use_v9_branch = true;
  21. #endif
  22. if (use_v9_branch) {
  23. /* WDISP19 - target is . + immed << 2 */
  24. /* ba,pt %xcc, . + off */
  25. val = 0x10680000 | (((u32) off >> 2) & 0x7ffff);
  26. } else {
  27. /* WDISP22 - target is . + immed << 2 */
  28. BUG_ON(off > 0x7fffff);
  29. BUG_ON(off < -0x800000);
  30. /* ba . + off */
  31. val = 0x10800000 | (((u32) off >> 2) & 0x3fffff);
  32. }
  33. } else {
  34. val = 0x01000000;
  35. }
  36. get_online_cpus();
  37. mutex_lock(&text_mutex);
  38. *insn = val;
  39. flushi(insn);
  40. mutex_unlock(&text_mutex);
  41. put_online_cpus();
  42. }
  43. #endif