jump_label.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2025 Chen Miao
  4. *
  5. * Based on arch/arm/include/asm/jump_label.h
  6. */
  7. #ifndef __ASM_OPENRISC_JUMP_LABEL_H
  8. #define __ASM_OPENRISC_JUMP_LABEL_H
  9. #ifndef __ASSEMBLER__
  10. #include <linux/types.h>
  11. #include <asm/insn-def.h>
  12. #define HAVE_JUMP_LABEL_BATCH
  13. #define JUMP_LABEL_NOP_SIZE OPENRISC_INSN_SIZE
  14. /**
  15. * JUMP_TABLE_ENTRY - Create a jump table entry
  16. * @key: Jump key identifier (typically a symbol address)
  17. * @label: Target label address
  18. *
  19. * This macro creates a jump table entry in the dedicated kernel section (__jump_table).
  20. * Each entry contains the following information:
  21. * Offset from current instruction to jump instruction (1b - .)
  22. * Offset from current instruction to target label (label - .)
  23. * Offset from current instruction to key identifier (key - .)
  24. */
  25. #define JUMP_TABLE_ENTRY(key, label) \
  26. ".pushsection __jump_table, \"aw\" \n\t" \
  27. ".align 4 \n\t" \
  28. ".long 1b - ., " label " - . \n\t" \
  29. ".long " key " - . \n\t" \
  30. ".popsection \n\t"
  31. #define ARCH_STATIC_BRANCH_ASM(key, label) \
  32. ".align 4 \n\t" \
  33. "1: l.nop \n\t" \
  34. " l.nop \n\t" \
  35. JUMP_TABLE_ENTRY(key, label)
  36. static __always_inline bool arch_static_branch(struct static_key *const key,
  37. const bool branch)
  38. {
  39. asm goto (ARCH_STATIC_BRANCH_ASM("%0", "%l[l_yes]")
  40. ::"i"(&((char *)key)[branch])::l_yes);
  41. return false;
  42. l_yes:
  43. return true;
  44. }
  45. #define ARCH_STATIC_BRANCH_JUMP_ASM(key, label) \
  46. ".align 4 \n\t" \
  47. "1: l.j " label " \n\t" \
  48. " l.nop \n\t" \
  49. JUMP_TABLE_ENTRY(key, label)
  50. static __always_inline bool
  51. arch_static_branch_jump(struct static_key *const key, const bool branch)
  52. {
  53. asm goto (ARCH_STATIC_BRANCH_JUMP_ASM("%0", "%l[l_yes]")
  54. ::"i"(&((char *)key)[branch])::l_yes);
  55. return false;
  56. l_yes:
  57. return true;
  58. }
  59. #endif /* __ASSEMBLER__ */
  60. #endif /* __ASM_OPENRISC_JUMP_LABEL_H */