1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun * License. See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun * for more details.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (c) 2010 Cavium Networks, Inc.
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun #ifndef _ASM_MIPS_JUMP_LABEL_H
9*4882a593Smuzhiyun #define _ASM_MIPS_JUMP_LABEL_H
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #ifndef __ASSEMBLY__
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/types.h>
14*4882a593Smuzhiyun #include <asm/isa-rev.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #define JUMP_LABEL_NOP_SIZE 4
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #ifdef CONFIG_64BIT
19*4882a593Smuzhiyun #define WORD_INSN ".dword"
20*4882a593Smuzhiyun #else
21*4882a593Smuzhiyun #define WORD_INSN ".word"
22*4882a593Smuzhiyun #endif
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #ifdef CONFIG_CPU_MICROMIPS
25*4882a593Smuzhiyun # define B_INSN "b32"
26*4882a593Smuzhiyun # define J_INSN "j32"
27*4882a593Smuzhiyun #elif MIPS_ISA_REV >= 6
28*4882a593Smuzhiyun # define B_INSN "bc"
29*4882a593Smuzhiyun # define J_INSN "bc"
30*4882a593Smuzhiyun #else
31*4882a593Smuzhiyun # define B_INSN "b"
32*4882a593Smuzhiyun # define J_INSN "j"
33*4882a593Smuzhiyun #endif
34*4882a593Smuzhiyun
arch_static_branch(struct static_key * key,bool branch)35*4882a593Smuzhiyun static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
38*4882a593Smuzhiyun "2:\t.insn\n\t"
39*4882a593Smuzhiyun ".pushsection __jump_table, \"aw\"\n\t"
40*4882a593Smuzhiyun WORD_INSN " 1b, %l[l_yes], %0\n\t"
41*4882a593Smuzhiyun ".popsection\n\t"
42*4882a593Smuzhiyun : : "i" (&((char *)key)[branch]) : : l_yes);
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun return false;
45*4882a593Smuzhiyun l_yes:
46*4882a593Smuzhiyun return true;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun
arch_static_branch_jump(struct static_key * key,bool branch)49*4882a593Smuzhiyun static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun asm_volatile_goto("1:\t" J_INSN " %l[l_yes]\n\t"
52*4882a593Smuzhiyun ".pushsection __jump_table, \"aw\"\n\t"
53*4882a593Smuzhiyun WORD_INSN " 1b, %l[l_yes], %0\n\t"
54*4882a593Smuzhiyun ".popsection\n\t"
55*4882a593Smuzhiyun : : "i" (&((char *)key)[branch]) : : l_yes);
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun return false;
58*4882a593Smuzhiyun l_yes:
59*4882a593Smuzhiyun return true;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun #ifdef CONFIG_64BIT
63*4882a593Smuzhiyun typedef u64 jump_label_t;
64*4882a593Smuzhiyun #else
65*4882a593Smuzhiyun typedef u32 jump_label_t;
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun struct jump_entry {
69*4882a593Smuzhiyun jump_label_t code;
70*4882a593Smuzhiyun jump_label_t target;
71*4882a593Smuzhiyun jump_label_t key;
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #endif /* __ASSEMBLY__ */
75*4882a593Smuzhiyun #endif /* _ASM_MIPS_JUMP_LABEL_H */
76