portASM.S 19 KB

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