Skip to content

Commit 9396e37

Browse files
committed
Merge branch 'merge-main-3' into smp-dev-complete-merge-candidate-history
2 parents 2d90cf8 + 1d59f65 commit 9396e37

File tree

4 files changed

+53
-31
lines changed

4 files changed

+53
-31
lines changed

portable/GCC/RISC-V/portASM.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ pxPortInitialiseStack:
208208
store_x x0, 0(a0) /* Critical nesting count starts at 0 for every task. */
209209

210210
#ifdef __riscv_32e
211-
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x11-x15. */
211+
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x10-x15. */
212212
#else
213-
addi a0, a0, -(22 * portWORD_SIZE) /* Space for registers x11-x31. */
213+
addi a0, a0, -(22 * portWORD_SIZE) /* Space for registers x10-x31. */
214214
#endif
215215
store_x a2, 0(a0) /* Task parameters (pvParameters parameter) goes into register X10/a0 on the stack. */
216-
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x5-x9. */
216+
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x5-x9 + taskReturnAddress. */
217217
load_x t0, xTaskReturnAddress
218218
store_x t0, 0(a0) /* Return address onto the stack. */
219219
addi t0, x0, portasmADDITIONAL_CONTEXT_SIZE /* The number of chip specific additional registers. */

portable/IAR/RISC-V/portASM.s

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,35 @@ definitions. */
107107
CODE
108108

109109
portUPDATE_MTIMER_COMPARE_REGISTER MACRO
110-
load_x t0, pullMachineTimerCompareRegister /* Load address of compare register into t0. */
111-
load_x t1, pullNextTime /* Load the address of ullNextTime into t1. */
110+
load_x a0, pullMachineTimerCompareRegister /* Load address of compare register into a0. */
111+
load_x a1, pullNextTime /* Load the address of ullNextTime into a1. */
112112

113113
#if( __riscv_xlen == 32 )
114114

115115
/* Update the 64-bit mtimer compare match value in two 32-bit writes. */
116-
li t4, -1
117-
lw t2, 0(t1) /* Load the low word of ullNextTime into t2. */
118-
lw t3, 4(t1) /* Load the high word of ullNextTime into t3. */
119-
sw t4, 0(t0) /* Low word no smaller than old value to start with - will be overwritten below. */
120-
sw t3, 4(t0) /* Store high word of ullNextTime into compare register. No smaller than new value. */
121-
sw t2, 0(t0) /* Store low word of ullNextTime into compare register. */
116+
li a4, -1
117+
lw a2, 0(a1) /* Load the low word of ullNextTime into a2. */
118+
lw a3, 4(a1) /* Load the high word of ullNextTime into a3. */
119+
sw a4, 0(a0) /* Low word no smaller than old value to start with - will be overwritten below. */
120+
sw a3, 4(a0) /* Store high word of ullNextTime into compare register. No smaller than new value. */
121+
sw a2, 0(a0) /* Store low word of ullNextTime into compare register. */
122122
lw t0, uxTimerIncrementsForOneTick /* Load the value of ullTimerIncrementForOneTick into t0 (could this be optimized by storing in an array next to pullNextTime?). */
123-
add t4, t0, t2 /* Add the low word of ullNextTime to the timer increments for one tick (assumes timer increment for one tick fits in 32-bits). */
124-
sltu t5, t4, t2 /* See if the sum of low words overflowed (what about the zero case?). */
125-
add t6, t3, t5 /* Add overflow to high word of ullNextTime. */
126-
sw t4, 0(t1) /* Store new low word of ullNextTime. */
127-
sw t6, 4(t1) /* Store new high word of ullNextTime. */
123+
add a4, t0, a2 /* Add the low word of ullNextTime to the timer increments for one tick (assumes timer increment for one tick fits in 32-bits). */
124+
sltu t1, a4, a2 /* See if the sum of low words overflowed (what about the zero case?). */
125+
add t2, a3, t1 /* Add overflow to high word of ullNextTime. */
126+
sw a4, 0(a1) /* Store new low word of ullNextTime. */
127+
sw t2, 4(a1) /* Store new high word of ullNextTime. */
128128

129129
#endif /* __riscv_xlen == 32 */
130130

131131
#if( __riscv_xlen == 64 )
132132

133133
/* Update the 64-bit mtimer compare match value. */
134-
ld t2, 0(t1) /* Load ullNextTime into t2. */
135-
sd t2, 0(t0) /* Store ullNextTime into compare register. */
134+
ld t2, 0(a1) /* Load ullNextTime into t2. */
135+
sd t2, 0(a0) /* Store ullNextTime into compare register. */
136136
ld t0, uxTimerIncrementsForOneTick /* Load the value of ullTimerIncrementForOneTick into t0 (could this be optimized by storing in an array next to pullNextTime?). */
137137
add t4, t0, t2 /* Add ullNextTime to the timer increments for one tick. */
138-
sd t4, 0(t1) /* Store ullNextTime. */
138+
sd t4, 0(a1) /* Store ullNextTime. */
139139

140140
#endif /* __riscv_xlen == 64 */
141141
ENDM
@@ -205,7 +205,7 @@ portUPDATE_MTIMER_COMPARE_REGISTER MACRO
205205
* pxCode
206206
*/
207207
pxPortInitialiseStack:
208-
csrr t0, CSR_MSTATUS /* Obtain current mstatus value. */
208+
csrr t0, CSR_MSTATUS /* Obtain current mstatus value. */
209209
andi t0, t0, ~0x8 /* Ensure interrupts are disabled when the stack is restored within an ISR. Required when a task is created after the schedulre has been started, otherwise interrupts would be disabled anyway. */
210210
addi t1, x0, 0x188 /* Generate the value 0x1880, which are the MPIE and MPP bits to set in mstatus. */
211211
slli t1, t1, 4
@@ -215,9 +215,13 @@ pxPortInitialiseStack:
215215
store_x t0, 0(a0) /* mstatus onto the stack. */
216216
addi a0, a0, -portWORD_SIZE /* Space for critical nesting count. */
217217
store_x x0, 0(a0) /* Critical nesting count starts at 0 for every task. */
218-
addi a0, a0, -(22 * portWORD_SIZE) /* Space for registers x11-x31. */
218+
#ifdef __riscv_32e
219+
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x10-15. */
220+
#else
221+
addi a0, a0, -(22 * portWORD_SIZE) /* Space for registers x10-x31. */
222+
#endif
219223
store_x a2, 0(a0) /* Task parameters (pvParameters parameter) goes into register X10/a0 on the stack. */
220-
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x5-x9. */
224+
addi a0, a0, -(6 * portWORD_SIZE) /* Space for registers x5-x9 + taskReturnAddress. */
221225
load_x t0, xTaskReturnAddress
222226
store_x t0, 0(a0) /* Return address onto the stack. */
223227
addi t0, x0, portasmADDITIONAL_CONTEXT_SIZE /* The number of chip specific additional registers. */
@@ -250,6 +254,7 @@ xPortStartFirstTask:
250254
load_x x13, 10 * portWORD_SIZE( sp ) /* a3 */
251255
load_x x14, 11 * portWORD_SIZE( sp ) /* a4 */
252256
load_x x15, 12 * portWORD_SIZE( sp ) /* a5 */
257+
#ifndef __riscv_32e
253258
load_x x16, 13 * portWORD_SIZE( sp ) /* a6 */
254259
load_x x17, 14 * portWORD_SIZE( sp ) /* a7 */
255260
load_x x18, 15 * portWORD_SIZE( sp ) /* s2 */
@@ -266,12 +271,13 @@ xPortStartFirstTask:
266271
load_x x29, 26 * portWORD_SIZE( sp ) /* t4 */
267272
load_x x30, 27 * portWORD_SIZE( sp ) /* t5 */
268273
load_x x31, 28 * portWORD_SIZE( sp ) /* t6 */
274+
#endif
269275

270-
load_x x5, 29 * portWORD_SIZE( sp ) /* Obtain xCriticalNesting value for this task from task's stack. */
276+
load_x x5, portCRITICAL_NESTING_OFFSET * portWORD_SIZE( sp ) /* Obtain xCriticalNesting value for this task from task's stack. */
271277
load_x x6, pxCriticalNesting /* Load the address of xCriticalNesting into x6. */
272278
store_x x5, 0( x6 ) /* Restore the critical nesting value for this task. */
273279

274-
load_x x5, 30 * portWORD_SIZE( sp ) /* Initial mstatus into x5 (t0). */
280+
load_x x5, portMSTATUS_OFFSET * portWORD_SIZE( sp ) /* Initial mstatus into x5 (t0). */
275281
addi x5, x5, 0x08 /* Set MIE bit so the first task starts with interrupts enabled - required as returns with ret not eret. */
276282
csrrw x0, CSR_MSTATUS, x5 /* Interrupts enabled from here! */
277283

portable/IAR/RISC-V/portContext.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@
4848
* portasmRESTORE_ADDITIONAL_REGISTERS macros - which can be defined in a chip
4949
* specific version of freertos_risc_v_chip_specific_extensions.h. See the
5050
* notes at the top of portASM.S file. */
51-
#define portCONTEXT_SIZE ( 31 * portWORD_SIZE )
51+
#ifdef __riscv_32e
52+
#define portCONTEXT_SIZE ( 15 * portWORD_SIZE )
53+
#define portCRITICAL_NESTING_OFFSET 13
54+
#define portMSTATUS_OFFSET 14
55+
#else
56+
#define portCONTEXT_SIZE ( 31 * portWORD_SIZE )
57+
#define portCRITICAL_NESTING_OFFSET 29
58+
#define portMSTATUS_OFFSET 30
59+
#endif
5260

5361
EXTERN pxCurrentTCB
5462
EXTERN xISRStackTop
@@ -71,6 +79,7 @@ portcontextSAVE_CONTEXT_INTERNAL MACRO
7179
store_x x13, 10 * portWORD_SIZE( sp )
7280
store_x x14, 11 * portWORD_SIZE( sp )
7381
store_x x15, 12 * portWORD_SIZE( sp )
82+
#ifndef __riscv_32e
7483
store_x x16, 13 * portWORD_SIZE( sp )
7584
store_x x17, 14 * portWORD_SIZE( sp )
7685
store_x x18, 15 * portWORD_SIZE( sp )
@@ -87,12 +96,13 @@ portcontextSAVE_CONTEXT_INTERNAL MACRO
8796
store_x x29, 26 * portWORD_SIZE( sp )
8897
store_x x30, 27 * portWORD_SIZE( sp )
8998
store_x x31, 28 * portWORD_SIZE( sp )
99+
#endif
90100

91101
load_x t0, xCriticalNesting /* Load the value of xCriticalNesting into t0. */
92-
store_x t0, 29 * portWORD_SIZE( sp ) /* Store the critical nesting value to the stack. */
102+
store_x t0, portCRITICAL_NESTING_OFFSET * portWORD_SIZE( sp ) /* Store the critical nesting value to the stack. */
93103

94104
csrr t0, mstatus /* Required for MPIE bit. */
95-
store_x t0, 30 * portWORD_SIZE( sp )
105+
store_x t0, portMSTATUS_OFFSET * portWORD_SIZE( sp )
96106

97107
portasmSAVE_ADDITIONAL_REGISTERS /* Defined in freertos_risc_v_chip_specific_extensions.h to save any registers unique to the RISC-V implementation. */
98108

@@ -123,7 +133,7 @@ portcontextSAVE_INTERRUPT_CONTEXT MACRO
123133

124134
portcontextRESTORE_CONTEXT MACRO
125135
load_x t1, pxCurrentTCB /* Load pxCurrentTCB. */
126-
load_x sp, 0( t1 ) /* Read sp from first TCB member. */
136+
load_x sp, 0( t1 ) /* Read sp from first TCB member. */
127137

128138
/* Load mepc with the address of the instruction in the task to run next. */
129139
load_x t0, 0( sp )
@@ -133,10 +143,10 @@ portcontextRESTORE_CONTEXT MACRO
133143
portasmRESTORE_ADDITIONAL_REGISTERS
134144

135145
/* Load mstatus with the interrupt enable bits used by the task. */
136-
load_x t0, 30 * portWORD_SIZE( sp )
146+
load_x t0, portMSTATUS_OFFSET * portWORD_SIZE( sp )
137147
csrw mstatus, t0 /* Required for MPIE bit. */
138148

139-
load_x t0, 29 * portWORD_SIZE( sp ) /* Obtain xCriticalNesting value for this task from task's stack. */
149+
load_x t0, portCRITICAL_NESTING_OFFSET * portWORD_SIZE( sp ) /* Obtain xCriticalNesting value for this task from task's stack. */
140150
load_x t1, pxCriticalNesting /* Load the address of xCriticalNesting into t1. */
141151
store_x t0, 0( t1 ) /* Restore the critical nesting value for this task. */
142152

@@ -152,6 +162,7 @@ portcontextRESTORE_CONTEXT MACRO
152162
load_x x13, 10 * portWORD_SIZE( sp )
153163
load_x x14, 11 * portWORD_SIZE( sp )
154164
load_x x15, 12 * portWORD_SIZE( sp )
165+
#ifndef __riscv_32e
155166
load_x x16, 13 * portWORD_SIZE( sp )
156167
load_x x17, 14 * portWORD_SIZE( sp )
157168
load_x x18, 15 * portWORD_SIZE( sp )
@@ -168,6 +179,7 @@ portcontextRESTORE_CONTEXT MACRO
168179
load_x x29, 26 * portWORD_SIZE( sp )
169180
load_x x30, 27 * portWORD_SIZE( sp )
170181
load_x x31, 28 * portWORD_SIZE( sp )
182+
#endif
171183
addi sp, sp, portCONTEXT_SIZE
172184

173185
mret

portable/IAR/RISC-V/portmacro.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ typedef portUBASE_TYPE TickType_t;
8282
/* Architecture specifics. */
8383
#define portSTACK_GROWTH ( -1 )
8484
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
85-
#define portBYTE_ALIGNMENT 16
85+
#ifdef __riscv_32e
86+
#define portBYTE_ALIGNMENT 8 /* RV32E uses RISC-V EABI with reduced stack alignment requirements. */
87+
#else
88+
#define portBYTE_ALIGNMENT 16
89+
#endif
8690
/*-----------------------------------------------------------*/
8791

8892
/* Scheduler utilities. */

0 commit comments

Comments
 (0)