~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/kernel/insn.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/bug.h>
  3 #include <linux/kernel.h>
  4 #include <asm/opcodes.h>
  5 
  6 static 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 
 37 static 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 
 57 unsigned 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 }
 65 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php