Skip to content

Commit b190bef

Browse files
committed
Support emulation of misaligned FLH/FSH
1 parent fb9d13a commit b190bef

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

machine/misaligned_ldst.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
union byte_array {
1111
uint8_t bytes[8];
1212
uintptr_t intx;
13+
uint16_t int16;
1314
uint32_t int32;
1415
uint64_t int64;
1516
};
@@ -36,6 +37,8 @@ void misaligned_load_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
3637
fp = 1, len = 8;
3738
else if ((insn & MASK_FLW) == MATCH_FLW)
3839
fp = 1, len = 4;
40+
else if ((insn & MASK_FLH) == MATCH_FLH)
41+
fp = 1, len = 2;
3942
#endif
4043
else if ((insn & MASK_LH) == MATCH_LH)
4144
len = 2, shift = 8*(sizeof(uintptr_t) - len);
@@ -83,8 +86,10 @@ void misaligned_load_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
8386
#endif
8487
else if (len == 8)
8588
SET_F64_RD(insn, regs, val.int64);
86-
else
89+
else if (len == 4)
8790
SET_F32_RD(insn, regs, val.int32);
91+
else
92+
SET_F32_RD(insn, regs, val.int16 | 0xffff0000U);
8893

8994
write_csr(mepc, npc);
9095
}
@@ -109,6 +114,8 @@ void misaligned_store_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
109114
len = 8, val.int64 = GET_F64_RS2(insn, regs);
110115
else if ((insn & MASK_FSW) == MATCH_FSW)
111116
len = 4, val.intx = GET_F32_RS2(insn, regs);
117+
else if ((insn & MASK_FSH) == MATCH_FSH)
118+
len = 2, val.intx = GET_F32_RS2(insn, regs);
112119
#endif
113120
else if ((insn & MASK_SH) == MATCH_SH)
114121
len = 2;

0 commit comments

Comments
 (0)