Skip to content

Commit af807e5

Browse files
nylon7gregkh
authored andcommitted
riscv: misaligned: Add handling for ZCB instructions
[ Upstream commit eb16b37 ] Add support for the Zcb extension's compressed half-word instructions (C.LHU, C.LH, and C.SH) in the RISC-V misaligned access trap handler. Signed-off-by: Zong Li <zong.li@sifive.com> Signed-off-by: Nylon Chen <nylon.chen@sifive.com> Fixes: 956d705 ("riscv: Unaligned load/store handling for M_MODE") Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20250411073850.3699180-2-nylon.chen@sifive.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b196812 commit af807e5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

arch/riscv/kernel/traps_misaligned.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@
8888
#define INSN_MATCH_C_FSWSP 0xe002
8989
#define INSN_MASK_C_FSWSP 0xe003
9090

91+
#define INSN_MATCH_C_LHU 0x8400
92+
#define INSN_MASK_C_LHU 0xfc43
93+
#define INSN_MATCH_C_LH 0x8440
94+
#define INSN_MASK_C_LH 0xfc43
95+
#define INSN_MATCH_C_SH 0x8c00
96+
#define INSN_MASK_C_SH 0xfc43
97+
9198
#define INSN_LEN(insn) ((((insn) & 0x3) < 0x3) ? 2 : 4)
9299

93100
#if defined(CONFIG_64BIT)
@@ -431,6 +438,13 @@ static int handle_scalar_misaligned_load(struct pt_regs *regs)
431438
fp = 1;
432439
len = 4;
433440
#endif
441+
} else if ((insn & INSN_MASK_C_LHU) == INSN_MATCH_C_LHU) {
442+
len = 2;
443+
insn = RVC_RS2S(insn) << SH_RD;
444+
} else if ((insn & INSN_MASK_C_LH) == INSN_MATCH_C_LH) {
445+
len = 2;
446+
shift = 8 * (sizeof(ulong) - len);
447+
insn = RVC_RS2S(insn) << SH_RD;
434448
} else {
435449
regs->epc = epc;
436450
return -1;
@@ -530,6 +544,9 @@ static int handle_scalar_misaligned_store(struct pt_regs *regs)
530544
len = 4;
531545
val.data_ulong = GET_F32_RS2C(insn, regs);
532546
#endif
547+
} else if ((insn & INSN_MASK_C_SH) == INSN_MATCH_C_SH) {
548+
len = 2;
549+
val.data_ulong = GET_RS2S(insn, regs);
533550
} else {
534551
regs->epc = epc;
535552
return -1;

0 commit comments

Comments
 (0)