Skip to content

Commit

Permalink
arch/risc-v: Fix save/load FPU macros
Browse files Browse the repository at this point in the history
The macros destroy t0, t1, t2 when used, make them explicitly restore them
so they are safe to use from where-ever
  • Loading branch information
pussuw authored and xiaoxiang781216 committed Apr 27, 2023
1 parent 4a4386c commit 7184d1f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions arch/risc-v/src/common/riscv_macros.S
Expand Up @@ -105,7 +105,7 @@
li t1, MSTATUS_FS
and t2, t0, t1
li t1, MSTATUS_FS_DIRTY
bne t2, t1, skip_save_fpu
bne t2, t1, 1f
li t1, ~MSTATUS_FS
and t0, t0, t1
li t1, MSTATUS_FS_CLEAN
Expand Down Expand Up @@ -150,7 +150,13 @@
frcsr t0
REGSTORE t0, REG_FCSR(\in)

skip_save_fpu:
1:

/* Restore what we have just destroyed (t0, t1, t2) */

REGLOAD t0, REG_T0(\in)
REGLOAD t1, REG_T1(\in)
REGLOAD t2, REG_T2(\in)

#endif

Expand Down Expand Up @@ -222,7 +228,7 @@ skip_save_fpu:
li t1, MSTATUS_FS
and t2, t0, t1
li t1, MSTATUS_FS_INIT
ble t2, t1, skip_load_fpu
ble t2, t1, 1f

/* Load all floating point registers */

Expand Down Expand Up @@ -264,7 +270,13 @@ skip_save_fpu:
REGLOAD t0, REG_FCSR(\out)
fscsr t0

skip_load_fpu:
1:

/* Restore what we have just destroyed (t0, t1, t2) */

REGLOAD t0, REG_T0(\out)
REGLOAD t1, REG_T1(\out)
REGLOAD t2, REG_T2(\out)

#endif

Expand Down

0 comments on commit 7184d1f

Please sign in to comment.