Jiang Liu | 9732caf | 2014-01-07 22:17:13 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Huawei Ltd. |
| 3 | * Author: Jiang Liu <liuj97@gmail.com> |
| 4 | * |
| 5 | * Based on arch/arm/kernel/jump_label.c |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/jump_label.h> |
| 21 | #include <asm/insn.h> |
| 22 | |
| 23 | #ifdef HAVE_JUMP_LABEL |
| 24 | |
Mark Rutland | 6ddae41 | 2014-11-25 15:44:18 +0000 | [diff] [blame] | 25 | void arch_jump_label_transform(struct jump_entry *entry, |
| 26 | enum jump_label_type type) |
Jiang Liu | 9732caf | 2014-01-07 22:17:13 +0800 | [diff] [blame] | 27 | { |
| 28 | void *addr = (void *)entry->code; |
| 29 | u32 insn; |
| 30 | |
Peter Zijlstra | 76b235c | 2015-07-24 14:45:44 +0200 | [diff] [blame] | 31 | if (type == JUMP_LABEL_JMP) { |
Jiang Liu | 9732caf | 2014-01-07 22:17:13 +0800 | [diff] [blame] | 32 | insn = aarch64_insn_gen_branch_imm(entry->code, |
| 33 | entry->target, |
| 34 | AARCH64_INSN_BRANCH_NOLINK); |
| 35 | } else { |
| 36 | insn = aarch64_insn_gen_nop(); |
| 37 | } |
| 38 | |
Mark Rutland | 6ddae41 | 2014-11-25 15:44:18 +0000 | [diff] [blame] | 39 | aarch64_insn_patch_text(&addr, &insn, 1); |
Jiang Liu | 9732caf | 2014-01-07 22:17:13 +0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void arch_jump_label_transform_static(struct jump_entry *entry, |
| 43 | enum jump_label_type type) |
| 44 | { |
Mark Rutland | 6ddae41 | 2014-11-25 15:44:18 +0000 | [diff] [blame] | 45 | /* |
| 46 | * We use the architected A64 NOP in arch_static_branch, so there's no |
| 47 | * need to patch an identical A64 NOP over the top of it here. The core |
| 48 | * will call arch_jump_label_transform from a module notifier if the |
| 49 | * NOP needs to be replaced by a branch. |
| 50 | */ |
Jiang Liu | 9732caf | 2014-01-07 22:17:13 +0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | #endif /* HAVE_JUMP_LABEL */ |