-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rabin Vincent
authored and
Russell King
committed
Mar 24, 2012
1 parent
db3e433
commit 395d58c
Showing
5 changed files
with
88 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 4394e2824c8d97d81a336edb469b13c8806604e4 | ||
refs/heads/master: d82227cf8f0b42ff42c21ed47025fdf54cb1698d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <linux/kernel.h> | ||
#include <asm/opcodes.h> | ||
|
||
static unsigned long | ||
__arm_gen_branch_thumb2(unsigned long pc, unsigned long addr, bool link) | ||
{ | ||
unsigned long s, j1, j2, i1, i2, imm10, imm11; | ||
unsigned long first, second; | ||
long offset; | ||
|
||
offset = (long)addr - (long)(pc + 4); | ||
if (offset < -16777216 || offset > 16777214) { | ||
WARN_ON_ONCE(1); | ||
return 0; | ||
} | ||
|
||
s = (offset >> 24) & 0x1; | ||
i1 = (offset >> 23) & 0x1; | ||
i2 = (offset >> 22) & 0x1; | ||
imm10 = (offset >> 12) & 0x3ff; | ||
imm11 = (offset >> 1) & 0x7ff; | ||
|
||
j1 = (!i1) ^ s; | ||
j2 = (!i2) ^ s; | ||
|
||
first = 0xf000 | (s << 10) | imm10; | ||
second = 0x9000 | (j1 << 13) | (j2 << 11) | imm11; | ||
if (link) | ||
second |= 1 << 14; | ||
|
||
return __opcode_thumb32_compose(first, second); | ||
} | ||
|
||
static unsigned long | ||
__arm_gen_branch_arm(unsigned long pc, unsigned long addr, bool link) | ||
{ | ||
unsigned long opcode = 0xea000000; | ||
long offset; | ||
|
||
if (link) | ||
opcode |= 1 << 24; | ||
|
||
offset = (long)addr - (long)(pc + 8); | ||
if (unlikely(offset < -33554432 || offset > 33554428)) { | ||
WARN_ON_ONCE(1); | ||
return 0; | ||
} | ||
|
||
offset = (offset >> 2) & 0x00ffffff; | ||
|
||
return opcode | offset; | ||
} | ||
|
||
unsigned long | ||
__arm_gen_branch(unsigned long pc, unsigned long addr, bool link) | ||
{ | ||
if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) | ||
return __arm_gen_branch_thumb2(pc, addr, link); | ||
else | ||
return __arm_gen_branch_arm(pc, addr, link); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef __ASM_ARM_INSN_H | ||
#define __ASM_ARM_INSN_H | ||
|
||
unsigned long | ||
__arm_gen_branch(unsigned long pc, unsigned long addr, bool link); | ||
|
||
static inline unsigned long | ||
arm_gen_branch(unsigned long pc, unsigned long addr) | ||
{ | ||
return __arm_gen_branch(pc, addr, false); | ||
} | ||
|
||
static inline unsigned long | ||
arm_gen_branch_link(unsigned long pc, unsigned long addr) | ||
{ | ||
return __arm_gen_branch(pc, addr, true); | ||
} | ||
|
||
#endif |