jump_label.c 1.1 KB

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