Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions ports/risc-v64/gnu/src/tx_thread_context_restore.S
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,11 @@ _tx_thread_context_restore:
Set MPIE and restore MPP to Machine, preserve other fields. */

csrr t1, mstatus
li t2, 0x1880 // Set MPP(0x1800) | MPIE(0x80)
li t3, ~0x8 // Preserve all bits except MIE

/* Clear MPP/MPIE/MIE bits in t1 then set desired values. */

li t2, 0x1888 // MPP(0x1800) | MPIE(0x80) | MIE(0x08)
li t3, 0x1800 // Set MPP to Machine mode (bits 12:11)

/* Construct new mstatus in t1: clear mask bits, set MPP/MPIE and optionally FP bit,
preserve everything except the bits we will modify. */

li t4, ~0x1888 // Clear mask for MPP/MPIE/MIE
and t1, t1, t4
or t1, t1, t3
or t1, t1, t2 // MPP and MPIE are now set
and t1, t1, t2 // Clear MIE, Hardware will restore it from MPIE

#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
li t0, 0x2000 // Set FS bits (bits 14:13 to 01) for FP state
Expand Down Expand Up @@ -352,14 +345,16 @@ _tx_thread_no_preempt_restore:
ld t0, 30*8(sp) // Recover mepc
csrw mepc, t0 // Setup mepc

/* Compose mstatus via read/modify/write to avoid clobbering unrelated bits. */

/* Compose mstatus via read/modify/write to avoid clobbering unrelated bits.
Set MPIE and restore MPP to Machine, preserve other fields. */

csrr t1, mstatus
li t2, 0x1888 // MPP(0x1800) | MPIE(0x80) | MIE(0x08)
li t3, 0x1800 // Set MPP to Machine mode
li t4, ~0x1888 // Clear mask for MPP/MPIE/MIE
and t1, t1, t4
or t1, t1, t3
li t2, 0x1880 // Set MPP(0x1800) | MPIE(0x80)
li t3, ~0x8 // Preserve all bits except MIE

or t1, t1, t2 // MPP and MPIE are now set
and t1, t1, t2 // Clear MIE, Hardware will restore it from MPIE

#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
li t0, 0x2000 // Set FS bits for FP state
Expand Down