1 #include <linux/kernel.h>
2 #include <asm/opcodes.h>
5 __arm_gen_branch_thumb2(unsigned long pc, unsigned long addr, bool link)
7 unsigned long s, j1, j2, i1, i2, imm10, imm11;
8 unsigned long first, second;
11 offset = (long)addr - (long)(pc + 4);
12 if (offset < -16777216 || offset > 16777214) {
17 s = (offset >> 24) & 0x1;
18 i1 = (offset >> 23) & 0x1;
19 i2 = (offset >> 22) & 0x1;
20 imm10 = (offset >> 12) & 0x3ff;
21 imm11 = (offset >> 1) & 0x7ff;
26 first = 0xf000 | (s << 10) | imm10;
27 second = 0x9000 | (j1 << 13) | (j2 << 11) | imm11;
31 return __opcode_thumb32_compose(first, second);
35 __arm_gen_branch_arm(unsigned long pc, unsigned long addr, bool link)
37 unsigned long opcode = 0xea000000;
43 offset = (long)addr - (long)(pc + 8);
44 if (unlikely(offset < -33554432 || offset > 33554428)) {
49 offset = (offset >> 2) & 0x00ffffff;
51 return opcode | offset;
55 __arm_gen_branch(unsigned long pc, unsigned long addr, bool link)
57 if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
58 return __arm_gen_branch_thumb2(pc, addr, link);
60 return __arm_gen_branch_arm(pc, addr, link);