Linux Audio

Check our new training course

Loading...
v4.6
 
 1#include <linux/bug.h>
 2#include <linux/kernel.h>
 3#include <asm/opcodes.h>
 4
 5static unsigned long
 6__arm_gen_branch_thumb2(unsigned long pc, unsigned long addr, bool link)
 
 7{
 8	unsigned long s, j1, j2, i1, i2, imm10, imm11;
 9	unsigned long first, second;
10	long offset;
11
12	offset = (long)addr - (long)(pc + 4);
13	if (offset < -16777216 || offset > 16777214) {
14		WARN_ON_ONCE(1);
15		return 0;
16	}
17
18	s	= (offset >> 24) & 0x1;
19	i1	= (offset >> 23) & 0x1;
20	i2	= (offset >> 22) & 0x1;
21	imm10	= (offset >> 12) & 0x3ff;
22	imm11	= (offset >>  1) & 0x7ff;
23
24	j1 = (!i1) ^ s;
25	j2 = (!i2) ^ s;
26
27	first = 0xf000 | (s << 10) | imm10;
28	second = 0x9000 | (j1 << 13) | (j2 << 11) | imm11;
29	if (link)
30		second |= 1 << 14;
31
32	return __opcode_thumb32_compose(first, second);
33}
34
35static unsigned long
36__arm_gen_branch_arm(unsigned long pc, unsigned long addr, bool link)
37{
38	unsigned long opcode = 0xea000000;
39	long offset;
40
41	if (link)
42		opcode |= 1 << 24;
43
44	offset = (long)addr - (long)(pc + 8);
45	if (unlikely(offset < -33554432 || offset > 33554428)) {
46		WARN_ON_ONCE(1);
47		return 0;
48	}
49
50	offset = (offset >> 2) & 0x00ffffff;
51
52	return opcode | offset;
53}
54
55unsigned long
56__arm_gen_branch(unsigned long pc, unsigned long addr, bool link)
57{
58	if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
59		return __arm_gen_branch_thumb2(pc, addr, link);
60	else
61		return __arm_gen_branch_arm(pc, addr, link);
62}
v6.2
 1// SPDX-License-Identifier: GPL-2.0
 2#include <linux/bug.h>
 3#include <linux/kernel.h>
 4#include <asm/opcodes.h>
 5
 6static unsigned long __arm_gen_branch_thumb2(unsigned long pc,
 7					     unsigned long addr, bool link,
 8					     bool warn)
 9{
10	unsigned long s, j1, j2, i1, i2, imm10, imm11;
11	unsigned long first, second;
12	long offset;
13
14	offset = (long)addr - (long)(pc + 4);
15	if (offset < -16777216 || offset > 16777214) {
16		WARN_ON_ONCE(warn);
17		return 0;
18	}
19
20	s	= (offset >> 24) & 0x1;
21	i1	= (offset >> 23) & 0x1;
22	i2	= (offset >> 22) & 0x1;
23	imm10	= (offset >> 12) & 0x3ff;
24	imm11	= (offset >>  1) & 0x7ff;
25
26	j1 = (!i1) ^ s;
27	j2 = (!i2) ^ s;
28
29	first = 0xf000 | (s << 10) | imm10;
30	second = 0x9000 | (j1 << 13) | (j2 << 11) | imm11;
31	if (link)
32		second |= 1 << 14;
33
34	return __opcode_thumb32_compose(first, second);
35}
36
37static unsigned long __arm_gen_branch_arm(unsigned long pc, unsigned long addr,
38					  bool link, bool warn)
39{
40	unsigned long opcode = 0xea000000;
41	long offset;
42
43	if (link)
44		opcode |= 1 << 24;
45
46	offset = (long)addr - (long)(pc + 8);
47	if (unlikely(offset < -33554432 || offset > 33554428)) {
48		WARN_ON_ONCE(warn);
49		return 0;
50	}
51
52	offset = (offset >> 2) & 0x00ffffff;
53
54	return opcode | offset;
55}
56
57unsigned long
58__arm_gen_branch(unsigned long pc, unsigned long addr, bool link, bool warn)
59{
60	if (IS_ENABLED(CONFIG_THUMB2_KERNEL))
61		return __arm_gen_branch_thumb2(pc, addr, link, warn);
62	else
63		return __arm_gen_branch_arm(pc, addr, link, warn);
64}