You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use saved mstatus for FPU/VPU state determination (#1330)
According to the RISC-V Privileged Architecture Specification (20211203),
writing Initial or Clean to the FS field of mstatus may result in the FS
value getting set to Dirty in some implementations. This means we cannot
rely on reading back the same FS value after writing to mstatus.
Previously, the context restore code would:
1. Write an FS value to mstatus
2. Read mstatus again at a later point
3. Use the read FS value to determine FPU status
This change updates the context restore code to use the mstatus value
from the saved context instead of re-reading mstatus after writing to
it. This required chaning the location of the mstatus slot in the
context.
Fixes: #1327
Signed-off-by: Gaurav Aggarwal <[email protected]>
Copy file name to clipboardExpand all lines: portable/GCC/RISC-V/chip_specific_extensions/Pulpino_Vega_RV32M1RM/freertos_risc_v_chip_specific_extensions.h
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -80,22 +80,22 @@ csrr t2, lpcount0
80
80
csrrt3, lpstart1
81
81
csrrt4, lpend1
82
82
csrrt5, lpcount1
83
-
swt0, 2*portWORD_SIZE( sp )
84
-
swt1, 3*portWORD_SIZE( sp )
85
-
swt2, 4*portWORD_SIZE( sp )
86
-
swt3, 5*portWORD_SIZE( sp )
87
-
swt4, 6*portWORD_SIZE( sp )
88
-
swt5, 7*portWORD_SIZE( sp )
83
+
swt0, 1*portWORD_SIZE( sp )
84
+
swt1, 2*portWORD_SIZE( sp )
85
+
swt2, 3*portWORD_SIZE( sp )
86
+
swt3, 4*portWORD_SIZE( sp )
87
+
swt4, 5*portWORD_SIZE( sp )
88
+
swt5, 6*portWORD_SIZE( sp )
89
89
.endm
90
90
91
91
/* Restore the additional registers found on the Pulpino. */
Copy file name to clipboardExpand all lines: portable/GCC/RISC-V/portASM.S
+12-11Lines changed: 12 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -193,8 +193,8 @@ definitions. */
193
193
* portTASK_RETURN_ADDRESS
194
194
* [FPU registers (when enabled/available) go here]
195
195
* [VPU registers (when enabled/available) go here]
196
-
* [chip specific registers go here]
197
196
* mstatus
197
+
* [chip specific registers go here]
198
198
* pxCode
199
199
*/
200
200
pxPortInitialiseStack:
@@ -212,14 +212,6 @@ pxPortInitialiseStack:
212
212
load_x t0, xTaskReturnAddress
213
213
store_x t0, 0(a0) /* Return address onto the stack. */
214
214
215
-
addi t0, x0, portasmADDITIONAL_CONTEXT_SIZE /* The number of chip specific additional registers. */
216
-
chip_specific_stack_frame: /* First add any chip specific registers to the stack frame being created. */
217
-
beq t0, x0, 1f /* No more chip specific registers to save. */
218
-
addi a0, a0, -portWORD_SIZE /* Make space for chip specific register. */
219
-
store_x x0, 0(a0) /* Give the chip specific register an initial value of zero. */
220
-
addi t0, t0, -1 /* Decrement the count of chip specific registers remaining. */
221
-
j chip_specific_stack_frame /* Until no more chip specific registers. */
222
-
1:
223
215
csrr t0, mstatus /* Obtain current mstatus value. */
224
216
andi t0, t0, ~0x8 /* Ensure interrupts are disabled when the stack is restored within an ISR. Required when a task is created after the scheduler has been started, otherwise interrupts would be disabled anyway. */
225
217
addi t1, x0, 0x188 /* Generate the value 0x1880, which are the MPIE=1 and MPP=M_Mode in mstatus. */
@@ -245,6 +237,15 @@ chip_specific_stack_frame: /* First add any chip specific registers
245
237
addi a0, a0, -portWORD_SIZE
246
238
store_x t0, 0(a0) /* mstatus onto the stack. */
247
239
240
+
addi t0, x0, portasmADDITIONAL_CONTEXT_SIZE /* The number of chip specific additional registers. */
241
+
chip_specific_stack_frame: /* First add any chip specific registers to the stack frame being created. */
242
+
beq t0, x0, 1f /* No more chip specific registers to save. */
243
+
addi a0, a0, -portWORD_SIZE /* Make space for chip specific register. */
244
+
store_x x0, 0(a0) /* Give the chip specific register an initial value of zero. */
245
+
addi t0, t0, -1 /* Decrement the count of chip specific registers remaining. */
246
+
j chip_specific_stack_frame /* Until no more chip specific registers. */
247
+
1:
248
+
248
249
addi a0, a0, -portWORD_SIZE
249
250
store_x a1, 0(a0) /* mret value (pxCode parameter) onto the stack. */
250
251
ret
@@ -256,12 +257,12 @@ xPortStartFirstTask:
256
257
257
258
load_x x1, 0( sp ) /* Note for starting the scheduler the exception return address is used as the function return address. */
258
259
260
+
portasmRESTORE_ADDITIONAL_REGISTERS /* Defined in freertos_risc_v_chip_specific_extensions.h to restore any registers unique to the RISC-V implementation. */
addi x5, x5, 0x08 /* Set MIE bit so the first task starts with interrupts enabled - required as returns with ret not eret. */
261
264
csrw mstatus, x5 /* Interrupts enabled from here! */
262
265
263
-
portasmRESTORE_ADDITIONAL_REGISTERS /* Defined in freertos_risc_v_chip_specific_extensions.h to restore any registers unique to the RISC-V implementation. */
0 commit comments