]> begriffs open source - freertos/blob - portable/IAR/RISC-V/portASM.s
Add SMP in the License Header (#402)
[freertos] / portable / IAR / RISC-V / portASM.s
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /*
29  * The FreeRTOS kernel's RISC-V port is split between the the code that is
30  * common across all currently supported RISC-V chips (implementations of the
31  * RISC-V ISA), and code which tailors the port to a specific RISC-V chip:
32  *
33  * + The code that is common to all RISC-V chips is implemented in
34  *   FreeRTOS\Source\portable\GCC\RISC-V-RV32\portASM.S.  There is only one
35  *   portASM.S file because the same file is used no matter which RISC-V chip is
36  *   in use.
37  *
38  * + The code that tailors the kernel's RISC-V port to a specific RISC-V
39  *   chip is implemented in freertos_risc_v_chip_specific_extensions.h.  There
40  *   is one freertos_risc_v_chip_specific_extensions.h that can be used with any
41  *   RISC-V chip that both includes a standard CLINT and does not add to the
42  *   base set of RISC-V registers.  There are additional
43  *   freertos_risc_v_chip_specific_extensions.h files for RISC-V implementations
44  *   that do not include a standard CLINT or do add to the base set of RISC-V
45  *   registers.
46  *
47  * CARE MUST BE TAKEN TO INCLDUE THE CORRECT
48  * freertos_risc_v_chip_specific_extensions.h HEADER FILE FOR THE CHIP
49  * IN USE.  To include the correct freertos_risc_v_chip_specific_extensions.h
50  * header file ensure the path to the correct header file is in the assembler's
51  * include path.
52  *
53  * This freertos_risc_v_chip_specific_extensions.h is for use on RISC-V chips
54  * that include a standard CLINT and do not add to the base set of RISC-V
55  * registers.
56  *
57  */
58 #if __riscv_xlen == 64
59         #define portWORD_SIZE 8
60         #define store_x sd
61         #define load_x ld
62 #elif __riscv_xlen == 32
63         #define store_x sw
64         #define load_x lw
65         #define portWORD_SIZE 4
66 #else
67         #error Assembler did not define __riscv_xlen
68 #endif
69
70 #include "freertos_risc_v_chip_specific_extensions.h"
71
72 /* Check the freertos_risc_v_chip_specific_extensions.h and/or command line
73 definitions. */
74 #if defined( portasmHAS_CLINT ) && defined( portasmHAS_MTIME )
75         #error The portasmHAS_CLINT constant has been deprecated.  Please replace it with portasmHAS_MTIME.  portasmHAS_CLINT and portasmHAS_MTIME cannot both be defined at once.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
76 #endif
77
78 #ifdef portasmHAS_CLINT
79         #warning The portasmHAS_CLINT constant has been deprecated.  Please replace it with portasmHAS_MTIME and portasmHAS_SIFIVE_CLINT.  For now portasmHAS_MTIME and portasmHAS_SIFIVE_CLINT are derived from portasmHAS_CLINT.  See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
80         #define portasmHAS_MTIME portasmHAS_CLINT
81         #define portasmHAS_SIFIVE_CLINT portasmHAS_CLINT
82 #endif
83
84 #ifndef portasmHAS_MTIME
85         #error freertos_risc_v_chip_specific_extensions.h must define portasmHAS_MTIME to either 1 (MTIME clock present) or 0 (MTIME clock not present).  See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
86 #endif
87
88 #ifndef portasmHANDLE_INTERRUPT
89         #error portasmHANDLE_INTERRUPT must be defined to the function to be called to handle external/peripheral interrupts.  portasmHANDLE_INTERRUPT can be defined on the assembler command line or in the appropriate freertos_risc_v_chip_specific_extensions.h header file.  https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
90 #endif
91
92
93 #ifndef portasmHAS_SIFIVE_CLINT
94         #define portasmHAS_SIFIVE_CLINT 0
95 #endif
96
97 /* CSR definitions. */
98 #define CSR_MSTATUS             0x300
99 #define CSR_MTVEC                       0x305
100 #define CSR_MEPC            0x341
101 #define CSR_MCAUSE          0x342
102
103
104 /* Only the standard core registers are stored by default.  Any additional
105 registers must be saved by the portasmSAVE_ADDITIONAL_REGISTERS and
106 portasmRESTORE_ADDITIONAL_REGISTERS macros - which can be defined in a chip
107 specific version of freertos_risc_v_chip_specific_extensions.h.  See the notes
108 at the top of this file. */
109 #define portCONTEXT_SIZE ( 30 * portWORD_SIZE )
110
111         PUBLIC xPortStartFirstTask
112         PUBLIC freertos_risc_v_trap_handler
113         PUBLIC pxPortInitialiseStack
114         EXTERN pxCurrentTCB
115         EXTERN ulPortTrapHandler
116         EXTERN vTaskSwitchContext
117         EXTERN xTaskIncrementTick
118         EXTERN Timer_IRQHandler
119         EXTERN pullMachineTimerCompareRegister
120         EXTERN pullNextTime
121         EXTERN uxTimerIncrementsForOneTick /* size_t type so 32-bit on 32-bit core and 64-bits on 64-bit core. */
122         EXTERN xISRStackTop
123         EXTERN portasmHANDLE_INTERRUPT
124
125 /*-----------------------------------------------------------*/
126
127         SECTION `.text`:CODE:NOROOT(2)
128         CODE
129
130 freertos_risc_v_trap_handler:
131         addi sp, sp, -portCONTEXT_SIZE
132         store_x x1, 1 * portWORD_SIZE( sp )
133         store_x x5, 2 * portWORD_SIZE( sp )
134         store_x x6, 3 * portWORD_SIZE( sp )
135         store_x x7, 4 * portWORD_SIZE( sp )
136         store_x x8, 5 * portWORD_SIZE( sp )
137         store_x x9, 6 * portWORD_SIZE( sp )
138         store_x x10, 7 * portWORD_SIZE( sp )
139         store_x x11, 8 * portWORD_SIZE( sp )
140         store_x x12, 9 * portWORD_SIZE( sp )
141         store_x x13, 10 * portWORD_SIZE( sp )
142         store_x x14, 11 * portWORD_SIZE( sp )
143         store_x x15, 12 * portWORD_SIZE( sp )
144         store_x x16, 13 * portWORD_SIZE( sp )
145         store_x x17, 14 * portWORD_SIZE( sp )
146         store_x x18, 15 * portWORD_SIZE( sp )
147         store_x x19, 16 * portWORD_SIZE( sp )
148         store_x x20, 17 * portWORD_SIZE( sp )
149         store_x x21, 18 * portWORD_SIZE( sp )
150         store_x x22, 19 * portWORD_SIZE( sp )
151         store_x x23, 20 * portWORD_SIZE( sp )
152         store_x x24, 21 * portWORD_SIZE( sp )
153         store_x x25, 22 * portWORD_SIZE( sp )
154         store_x x26, 23 * portWORD_SIZE( sp )
155         store_x x27, 24 * portWORD_SIZE( sp )
156         store_x x28, 25 * portWORD_SIZE( sp )
157         store_x x29, 26 * portWORD_SIZE( sp )
158         store_x x30, 27 * portWORD_SIZE( sp )
159         store_x x31, 28 * portWORD_SIZE( sp )
160
161         csrr t0, CSR_MSTATUS                                    /* Required for MPIE bit. */
162         store_x t0, 29 * portWORD_SIZE( sp )
163
164         portasmSAVE_ADDITIONAL_REGISTERS        /* Defined in freertos_risc_v_chip_specific_extensions.h to save any registers unique to the RISC-V implementation. */
165
166         load_x  t0, pxCurrentTCB                        /* Load pxCurrentTCB. */
167         store_x  sp, 0( t0 )                            /* Write sp to first TCB member. */
168
169         csrr a0, CSR_MCAUSE
170         csrr a1, CSR_MEPC
171
172 test_if_asynchronous:
173         srli a2, a0, __riscv_xlen - 1           /* MSB of mcause is 1 if handing an asynchronous interrupt - shift to LSB to clear other bits. */
174         beq a2, x0, handle_synchronous          /* Branch past interrupt handing if not asynchronous. */
175         store_x a1, 0( sp )                                     /* Asynch so save unmodified exception return address. */
176
177 handle_asynchronous:
178
179 #if( portasmHAS_MTIME != 0 )
180
181         test_if_mtimer:                                         /* If there is a CLINT then the mtimer is used to generate the tick interrupt. */
182
183                 addi t0, x0, 1
184
185                 slli t0, t0, __riscv_xlen - 1   /* LSB is already set, shift into MSB.  Shift 31 on 32-bit or 63 on 64-bit cores. */
186                 addi t1, t0, 7                                  /* 0x8000[]0007 == machine timer interrupt. */
187                 bne a0, t1, test_if_external_interrupt
188
189                 load_x t0, pullMachineTimerCompareRegister  /* Load address of compare register into t0. */
190                 load_x t1, pullNextTime                 /* Load the address of ullNextTime into t1. */
191
192                 #if( __riscv_xlen == 32 )
193
194                         /* Update the 64-bit mtimer compare match value in two 32-bit writes. */
195                         li t4, -1
196                         lw t2, 0(t1)                            /* Load the low word of ullNextTime into t2. */
197                         lw t3, 4(t1)                            /* Load the high word of ullNextTime into t3. */
198                         sw t4, 0(t0)                            /* Low word no smaller than old value to start with - will be overwritten below. */
199                         sw t3, 4(t0)                            /* Store high word of ullNextTime into compare register.  No smaller than new value. */
200                         sw t2, 0(t0)                            /* Store low word of ullNextTime into compare register. */
201                         lw t0, uxTimerIncrementsForOneTick      /* Load the value of ullTimerIncrementForOneTick into t0 (could this be optimized by storing in an array next to pullNextTime?). */
202                         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). */
203                         sltu t5, t4, t2                         /* See if the sum of low words overflowed (what about the zero case?). */
204                         add t6, t3, t5                          /* Add overflow to high word of ullNextTime. */
205                         sw t4, 0(t1)                            /* Store new low word of ullNextTime. */
206                         sw t6, 4(t1)                            /* Store new high word of ullNextTime. */
207
208                 #endif /* __riscv_xlen == 32 */
209
210                 #if( __riscv_xlen == 64 )
211
212                         /* Update the 64-bit mtimer compare match value. */
213                         ld t2, 0(t1)                            /* Load ullNextTime into t2. */
214                         sd t2, 0(t0)                            /* Store ullNextTime into compare register. */
215                         ld t0, uxTimerIncrementsForOneTick  /* Load the value of ullTimerIncrementForOneTick into t0 (could this be optimized by storing in an array next to pullNextTime?). */
216                         add t4, t0, t2                          /* Add ullNextTime to the timer increments for one tick. */
217                         sd t4, 0(t1)                            /* Store ullNextTime. */
218
219                 #endif /* __riscv_xlen == 64 */
220
221                 load_x sp, xISRStackTop                 /* Switch to ISR stack before function call. */
222                 jal xTaskIncrementTick
223                 beqz a0, processed_source               /* Don't switch context if incrementing tick didn't unblock a task. */
224                 jal vTaskSwitchContext
225                 j processed_source
226
227         test_if_external_interrupt:                     /* If there is a CLINT and the mtimer interrupt is not pending then check to see if an external interrupt is pending. */
228                 addi t1, t1, 4                                  /* 0x80000007 + 4 = 0x8000000b == Machine external interrupt. */
229                 bne a0, t1, as_yet_unhandled    /* Something as yet unhandled. */
230
231 #endif /* portasmHAS_MTIME */
232
233         load_x sp, xISRStackTop                         /* Switch to ISR stack before function call. */
234         jal portasmHANDLE_INTERRUPT                     /* Jump to the interrupt handler if there is no CLINT or if there is a CLINT and it has been determined that an external interrupt is pending. */
235         j processed_source
236
237 handle_synchronous:
238         addi a1, a1, 4                                          /* Synchronous so updated exception return address to the instruction after the instruction that generated the exeption. */
239         store_x a1, 0( sp )                                     /* Save updated exception return address. */
240
241 test_if_environment_call:
242         li t0, 11                                                       /* 11 == environment call. */
243         bne a0, t0, is_exception                        /* Not an M environment call, so some other exception. */
244         load_x sp, xISRStackTop                         /* Switch to ISR stack before function call. */
245         jal vTaskSwitchContext
246         j processed_source
247
248 is_exception:
249         csrr t0, CSR_MCAUSE                                     /* For viewing in the debugger only. */
250         csrr t1, CSR_MEPC                                       /* For viewing in the debugger only */
251         csrr t2, CSR_MSTATUS
252         j is_exception                                          /* No other exceptions handled yet. */
253
254 as_yet_unhandled:
255         csrr t0, mcause                                         /* For viewing in the debugger only. */
256         j as_yet_unhandled
257
258 processed_source:
259         load_x  t1, pxCurrentTCB                        /* Load pxCurrentTCB. */
260         load_x  sp, 0( t1 )                                     /* Read sp from first TCB member. */
261
262         /* Load mret with the address of the next instruction in the task to run next. */
263         load_x t0, 0( sp )
264         csrw CSR_MEPC, t0
265
266         portasmRESTORE_ADDITIONAL_REGISTERS     /* Defined in freertos_risc_v_chip_specific_extensions.h to restore any registers unique to the RISC-V implementation. */
267
268         /* Load mstatus with the interrupt enable bits used by the task. */
269         load_x  t0, 29 * portWORD_SIZE( sp )
270         csrw CSR_MSTATUS, t0                                            /* Required for MPIE bit. */
271
272         load_x  x1, 1 * portWORD_SIZE( sp )
273         load_x  x5, 2 * portWORD_SIZE( sp )             /* t0 */
274         load_x  x6, 3 * portWORD_SIZE( sp )             /* t1 */
275         load_x  x7, 4 * portWORD_SIZE( sp )             /* t2 */
276         load_x  x8, 5 * portWORD_SIZE( sp )             /* s0/fp */
277         load_x  x9, 6 * portWORD_SIZE( sp )             /* s1 */
278         load_x  x10, 7 * portWORD_SIZE( sp )    /* a0 */
279         load_x  x11, 8 * portWORD_SIZE( sp )    /* a1 */
280         load_x  x12, 9 * portWORD_SIZE( sp )    /* a2 */
281         load_x  x13, 10 * portWORD_SIZE( sp )   /* a3 */
282         load_x  x14, 11 * portWORD_SIZE( sp )   /* a4 */
283         load_x  x15, 12 * portWORD_SIZE( sp )   /* a5 */
284         load_x  x16, 13 * portWORD_SIZE( sp )   /* a6 */
285         load_x  x17, 14 * portWORD_SIZE( sp )   /* a7 */
286         load_x  x18, 15 * portWORD_SIZE( sp )   /* s2 */
287         load_x  x19, 16 * portWORD_SIZE( sp )   /* s3 */
288         load_x  x20, 17 * portWORD_SIZE( sp )   /* s4 */
289         load_x  x21, 18 * portWORD_SIZE( sp )   /* s5 */
290         load_x  x22, 19 * portWORD_SIZE( sp )   /* s6 */
291         load_x  x23, 20 * portWORD_SIZE( sp )   /* s7 */
292         load_x  x24, 21 * portWORD_SIZE( sp )   /* s8 */
293         load_x  x25, 22 * portWORD_SIZE( sp )   /* s9 */
294         load_x  x26, 23 * portWORD_SIZE( sp )   /* s10 */
295         load_x  x27, 24 * portWORD_SIZE( sp )   /* s11 */
296         load_x  x28, 25 * portWORD_SIZE( sp )   /* t3 */
297         load_x  x29, 26 * portWORD_SIZE( sp )   /* t4 */
298         load_x  x30, 27 * portWORD_SIZE( sp )   /* t5 */
299         load_x  x31, 28 * portWORD_SIZE( sp )   /* t6 */
300         addi sp, sp, portCONTEXT_SIZE
301
302         mret
303
304 /*-----------------------------------------------------------*/
305
306 xPortStartFirstTask:
307
308 #if( portasmHAS_SIFIVE_CLINT != 0 )
309         /* If there is a clint then interrupts can branch directly to the FreeRTOS
310         trap handler.  Otherwise the interrupt controller will need to be configured
311         outside of this file. */
312         la t0, freertos_risc_v_trap_handler
313         csrw CSR_MTVEC, t0
314 #endif /* portasmHAS_CLILNT */
315
316         load_x  sp, pxCurrentTCB                        /* Load pxCurrentTCB. */
317         load_x  sp, 0( sp )                                     /* Read sp from first TCB member. */
318
319         load_x  x1, 0( sp ) /* Note for starting the scheduler the exception return address is used as the function return address. */
320
321         portasmRESTORE_ADDITIONAL_REGISTERS     /* Defined in freertos_risc_v_chip_specific_extensions.h to restore any registers unique to the RISC-V implementation. */
322
323         load_x  x6, 3 * portWORD_SIZE( sp )             /* t1 */
324         load_x  x7, 4 * portWORD_SIZE( sp )             /* t2 */
325         load_x  x8, 5 * portWORD_SIZE( sp )             /* s0/fp */
326         load_x  x9, 6 * portWORD_SIZE( sp )             /* s1 */
327         load_x  x10, 7 * portWORD_SIZE( sp )    /* a0 */
328         load_x  x11, 8 * portWORD_SIZE( sp )    /* a1 */
329         load_x  x12, 9 * portWORD_SIZE( sp )    /* a2 */
330         load_x  x13, 10 * portWORD_SIZE( sp )   /* a3 */
331         load_x  x14, 11 * portWORD_SIZE( sp )   /* a4 */
332         load_x  x15, 12 * portWORD_SIZE( sp )   /* a5 */
333         load_x  x16, 13 * portWORD_SIZE( sp )   /* a6 */
334         load_x  x17, 14 * portWORD_SIZE( sp )   /* a7 */
335         load_x  x18, 15 * portWORD_SIZE( sp )   /* s2 */
336         load_x  x19, 16 * portWORD_SIZE( sp )   /* s3 */
337         load_x  x20, 17 * portWORD_SIZE( sp )   /* s4 */
338         load_x  x21, 18 * portWORD_SIZE( sp )   /* s5 */
339         load_x  x22, 19 * portWORD_SIZE( sp )   /* s6 */
340         load_x  x23, 20 * portWORD_SIZE( sp )   /* s7 */
341         load_x  x24, 21 * portWORD_SIZE( sp )   /* s8 */
342         load_x  x25, 22 * portWORD_SIZE( sp )   /* s9 */
343         load_x  x26, 23 * portWORD_SIZE( sp )   /* s10 */
344         load_x  x27, 24 * portWORD_SIZE( sp )   /* s11 */
345         load_x  x28, 25 * portWORD_SIZE( sp )   /* t3 */
346         load_x  x29, 26 * portWORD_SIZE( sp )   /* t4 */
347         load_x  x30, 27 * portWORD_SIZE( sp )   /* t5 */
348         load_x  x31, 28 * portWORD_SIZE( sp )   /* t6 */
349
350         load_x  x5, 29 * portWORD_SIZE( sp )    /* Initial mstatus into x5 (t0) */
351         addi x5, x5, 0x08                                               /* Set MIE bit so the first task starts with interrupts enabled - required as returns with ret not eret. */
352         csrrw  x0, CSR_MSTATUS, x5                                      /* Interrupts enabled from here! */
353         load_x  x5, 2 * portWORD_SIZE( sp )             /* Initial x5 (t0) value. */
354         addi    sp, sp, portCONTEXT_SIZE
355         ret
356
357 /*-----------------------------------------------------------*/
358
359 /*
360  * Unlike other ports pxPortInitialiseStack() is written in assembly code as it
361  * needs access to the portasmADDITIONAL_CONTEXT_SIZE constant.  The prototype
362  * for the function is as per the other ports:
363  * StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters );
364  *
365  * As per the standard RISC-V ABI pxTopcOfStack is passed in in a0, pxCode in
366  * a1, and pvParameters in a2.  The new top of stack is passed out in a0.
367  *
368  * RISC-V maps registers to ABI names as follows (X1 to X31 integer registers
369  * for the 'I' profile, X1 to X15 for the 'E' profile, currently I assumed).
370  *
371  * Register             ABI Name        Description                                             Saver
372  * x0                   zero            Hard-wired zero                                 -
373  * x1                   ra                      Return address                                  Caller
374  * x2                   sp                      Stack pointer                                   Callee
375  * x3                   gp                      Global pointer                                  -
376  * x4                   tp                      Thread pointer                                  -
377  * x5-7                 t0-2            Temporaries                                             Caller
378  * x8                   s0/fp           Saved register/Frame pointer    Callee
379  * x9                   s1                      Saved register                                  Callee
380  * x10-11               a0-1            Function Arguments/return values Caller
381  * x12-17               a2-7            Function arguments                              Caller
382  * x18-27               s2-11           Saved registers                                 Callee
383  * x28-31               t3-6            Temporaries                                             Caller
384  *
385  * The RISC-V context is saved t FreeRTOS tasks in the following stack frame,
386  * where the global and thread pointers are currently assumed to be constant so
387  * are not saved:
388  *
389  * mstatus
390  * x31
391  * x30
392  * x29
393  * x28
394  * x27
395  * x26
396  * x25
397  * x24
398  * x23
399  * x22
400  * x21
401  * x20
402  * x19
403  * x18
404  * x17
405  * x16
406  * x15
407  * x14
408  * x13
409  * x12
410  * x11
411  * pvParameters
412  * x9
413  * x8
414  * x7
415  * x6
416  * x5
417  * portTASK_RETURN_ADDRESS
418  * [chip specific registers go here]
419  * pxCode
420  */
421 pxPortInitialiseStack:
422
423         csrr t0, CSR_MSTATUS                                    /* Obtain current mstatus value. */
424         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. */
425         addi t1, x0, 0x188                                      /* Generate the value 0x1880, which are the MPIE and MPP bits to set in mstatus. */
426         slli t1, t1, 4
427         or t0, t0, t1                                           /* Set MPIE and MPP bits in mstatus value. */
428
429         addi a0, a0, -portWORD_SIZE
430         store_x t0, 0(a0)                                       /* mstatus onto the stack. */
431         addi a0, a0, -(22 * portWORD_SIZE)      /* Space for registers x11-x31. */
432         store_x a2, 0(a0)                                       /* Task parameters (pvParameters parameter) goes into register X10/a0 on the stack. */
433         addi a0, a0, -(6 * portWORD_SIZE)       /* Space for registers x5-x9. */
434         store_x x0, 0(a0)                                       /* Return address onto the stack, could be portTASK_RETURN_ADDRESS */
435         addi t0, x0, portasmADDITIONAL_CONTEXT_SIZE /* The number of chip specific additional registers. */
436 chip_specific_stack_frame:                              /* First add any chip specific registers to the stack frame being created. */
437         beq t0, x0, no_more_regs                        /* No more chip specific registers to save. */
438         addi a0, a0, -portWORD_SIZE                     /* Make space for chip specific register. */
439         store_x x0, 0(a0)                                       /* Give the chip specific register an initial value of zero. */
440         addi t0, t0, -1                                         /* Decrement the count of chip specific registers remaining. */
441         j chip_specific_stack_frame                     /* Until no more chip specific registers. */
442 no_more_regs:
443         addi a0, a0, -portWORD_SIZE
444         store_x a1, 0(a0)                                       /* mret value (pxCode parameter) onto the stack. */
445         ret
446
447 /*-----------------------------------------------------------*/