aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZi Shen Lim <zlim.lnx@gmail.com>2014-08-27 00:15:22 -0400
committerWill Deacon <will.deacon@arm.com>2014-09-08 09:39:20 -0400
commit9951a157fa678db0ec92e5fc4c6320c038ffb67e (patch)
treeee66008edd5ba09f12a418d9562e6d929236664e
parent1bba567d0f3050e33b4dd1404fdcbceaf5a73034 (diff)
arm64: introduce aarch64_insn_gen_add_sub_imm()
Introduce function to generate add/subtract (immediate) instructions. Signed-off-by: Zi Shen Lim <zlim.lnx@gmail.com> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--arch/arm64/include/asm/insn.h16
-rw-r--r--arch/arm64/kernel/insn.c44
2 files changed, 60 insertions, 0 deletions
diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index eef8f1ef6736..29386aaf2e85 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -75,6 +75,7 @@ enum aarch64_insn_register_type {
75 AARCH64_INSN_REGTYPE_RN, 75 AARCH64_INSN_REGTYPE_RN,
76 AARCH64_INSN_REGTYPE_RT2, 76 AARCH64_INSN_REGTYPE_RT2,
77 AARCH64_INSN_REGTYPE_RM, 77 AARCH64_INSN_REGTYPE_RM,
78 AARCH64_INSN_REGTYPE_RD,
78}; 79};
79 80
80enum aarch64_insn_register { 81enum aarch64_insn_register {
@@ -162,6 +163,13 @@ enum aarch64_insn_ldst_type {
162 AARCH64_INSN_LDST_STORE_PAIR_POST_INDEX, 163 AARCH64_INSN_LDST_STORE_PAIR_POST_INDEX,
163}; 164};
164 165
166enum aarch64_insn_adsb_type {
167 AARCH64_INSN_ADSB_ADD,
168 AARCH64_INSN_ADSB_SUB,
169 AARCH64_INSN_ADSB_ADD_SETFLAGS,
170 AARCH64_INSN_ADSB_SUB_SETFLAGS
171};
172
165#define __AARCH64_INSN_FUNCS(abbr, mask, val) \ 173#define __AARCH64_INSN_FUNCS(abbr, mask, val) \
166static __always_inline bool aarch64_insn_is_##abbr(u32 code) \ 174static __always_inline bool aarch64_insn_is_##abbr(u32 code) \
167{ return (code & (mask)) == (val); } \ 175{ return (code & (mask)) == (val); } \
@@ -174,6 +182,10 @@ __AARCH64_INSN_FUNCS(stp_post, 0x7FC00000, 0x28800000)
174__AARCH64_INSN_FUNCS(ldp_post, 0x7FC00000, 0x28C00000) 182__AARCH64_INSN_FUNCS(ldp_post, 0x7FC00000, 0x28C00000)
175__AARCH64_INSN_FUNCS(stp_pre, 0x7FC00000, 0x29800000) 183__AARCH64_INSN_FUNCS(stp_pre, 0x7FC00000, 0x29800000)
176__AARCH64_INSN_FUNCS(ldp_pre, 0x7FC00000, 0x29C00000) 184__AARCH64_INSN_FUNCS(ldp_pre, 0x7FC00000, 0x29C00000)
185__AARCH64_INSN_FUNCS(add_imm, 0x7F000000, 0x11000000)
186__AARCH64_INSN_FUNCS(adds_imm, 0x7F000000, 0x31000000)
187__AARCH64_INSN_FUNCS(sub_imm, 0x7F000000, 0x51000000)
188__AARCH64_INSN_FUNCS(subs_imm, 0x7F000000, 0x71000000)
177__AARCH64_INSN_FUNCS(b, 0xFC000000, 0x14000000) 189__AARCH64_INSN_FUNCS(b, 0xFC000000, 0x14000000)
178__AARCH64_INSN_FUNCS(bl, 0xFC000000, 0x94000000) 190__AARCH64_INSN_FUNCS(bl, 0xFC000000, 0x94000000)
179__AARCH64_INSN_FUNCS(cbz, 0xFE000000, 0x34000000) 191__AARCH64_INSN_FUNCS(cbz, 0xFE000000, 0x34000000)
@@ -220,6 +232,10 @@ u32 aarch64_insn_gen_load_store_pair(enum aarch64_insn_register reg1,
220 int offset, 232 int offset,
221 enum aarch64_insn_variant variant, 233 enum aarch64_insn_variant variant,
222 enum aarch64_insn_ldst_type type); 234 enum aarch64_insn_ldst_type type);
235u32 aarch64_insn_gen_add_sub_imm(enum aarch64_insn_register dst,
236 enum aarch64_insn_register src,
237 int imm, enum aarch64_insn_variant variant,
238 enum aarch64_insn_adsb_type type);
223 239
224bool aarch64_insn_hotpatch_safe(u32 old_insn, u32 new_insn); 240bool aarch64_insn_hotpatch_safe(u32 old_insn, u32 new_insn);
225 241
diff --git a/arch/arm64/kernel/insn.c b/arch/arm64/kernel/insn.c
index 7880c060f684..ec3a90256ff9 100644
--- a/arch/arm64/kernel/insn.c
+++ b/arch/arm64/kernel/insn.c
@@ -285,6 +285,7 @@ static u32 aarch64_insn_encode_register(enum aarch64_insn_register_type type,
285 285
286 switch (type) { 286 switch (type) {
287 case AARCH64_INSN_REGTYPE_RT: 287 case AARCH64_INSN_REGTYPE_RT:
288 case AARCH64_INSN_REGTYPE_RD:
288 shift = 0; 289 shift = 0;
289 break; 290 break;
290 case AARCH64_INSN_REGTYPE_RN: 291 case AARCH64_INSN_REGTYPE_RN:
@@ -555,3 +556,46 @@ u32 aarch64_insn_gen_load_store_pair(enum aarch64_insn_register reg1,
555 return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_7, insn, 556 return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_7, insn,
556 offset >> shift); 557 offset >> shift);
557} 558}
559
560u32 aarch64_insn_gen_add_sub_imm(enum aarch64_insn_register dst,
561 enum aarch64_insn_register src,
562 int imm, enum aarch64_insn_variant variant,
563 enum aarch64_insn_adsb_type type)
564{
565 u32 insn;
566
567 switch (type) {
568 case AARCH64_INSN_ADSB_ADD:
569 insn = aarch64_insn_get_add_imm_value();
570 break;
571 case AARCH64_INSN_ADSB_SUB:
572 insn = aarch64_insn_get_sub_imm_value();
573 break;
574 case AARCH64_INSN_ADSB_ADD_SETFLAGS:
575 insn = aarch64_insn_get_adds_imm_value();
576 break;
577 case AARCH64_INSN_ADSB_SUB_SETFLAGS:
578 insn = aarch64_insn_get_subs_imm_value();
579 break;
580 default:
581 BUG_ON(1);
582 }
583
584 switch (variant) {
585 case AARCH64_INSN_VARIANT_32BIT:
586 break;
587 case AARCH64_INSN_VARIANT_64BIT:
588 insn |= AARCH64_INSN_SF_BIT;
589 break;
590 default:
591 BUG_ON(1);
592 }
593
594 BUG_ON(imm & ~(SZ_4K - 1));
595
596 insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RD, insn, dst);
597
598 insn = aarch64_insn_encode_register(AARCH64_INSN_REGTYPE_RN, insn, src);
599
600 return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_12, insn, imm);
601}