Skip to content

Commit cfa1c9f

Browse files
committed
Add address alignment checks for F ext load/store
Current F extnesion implementation did not properly handle address alignment concerns. A check for address misalignment has been introduced, and the corresponding exception handler is invoked to ensure correct behavior. Reported-by: Shi-Sheng Yang <[email protected]>
1 parent 821155f commit cfa1c9f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/rv32_template.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,9 @@ RVOP(
13831383
flw,
13841384
{
13851385
/* copy into the float register */
1386-
const uint32_t data = rv->io.mem_read_w(rv->X[ir->rs1] + ir->imm);
1387-
rv->F[ir->rd].v = data;
1386+
const uint32_t addr = rv->X[ir->rs1] + ir->imm;
1387+
RV_EXC_MISALIGN_HANDLER(3, load, false, 1);
1388+
rv->F[ir->rd].v = rv->io.mem_read_w(addr);
13881389
},
13891390
GEN({
13901391
assert; /* FIXME: Implement */
@@ -1395,8 +1396,9 @@ RVOP(
13951396
fsw,
13961397
{
13971398
/* copy from float registers */
1398-
uint32_t data = rv->F[ir->rs2].v;
1399-
rv->io.mem_write_w(rv->X[ir->rs1] + ir->imm, data);
1399+
const uint32_t addr = rv->X[ir->rs1] + ir->imm;
1400+
RV_EXC_MISALIGN_HANDLER(3, store, false, 1);
1401+
rv->io.mem_write_w(addr, rv->F[ir->rs2].v);
14001402
},
14011403
GEN({
14021404
assert; /* FIXME: Implement */

0 commit comments

Comments
 (0)