]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/RISC-V-RV32/chip_specific_extensions/Pulpino_Vega_RV32M1RM/freertos_risc_v_chip_specific_extensions.h
da213e92fe6003e35e9e7bc9a550ef5729608eb1
[freertos] / FreeRTOS / Source / portable / GCC / RISC-V-RV32 / chip_specific_extensions / Pulpino_Vega_RV32M1RM / freertos_risc_v_chip_specific_extensions.h
1 /*\r
2  * FreeRTOS Kernel V10.1.1\r
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and t\r
10 \r
11  o permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * http://www.FreeRTOS.org\r
25  * http://aws.amazon.com/freertos\r
26  *\r
27  * 1 tab == 4 spaces!\r
28  */\r
29 \r
30 /*\r
31  * The FreeRTOS kernel's RISC-V port is split between the the code that is\r
32  * common across all currently supported RISC-V chips (implementations of the\r
33  * RISC-V ISA), and code which tailors the port to a specific RISC-V chip:\r
34  *\r
35  * + FreeRTOS\Source\portable\GCC\RISC-V-RV32\portASM.S contains the code that\r
36  *   is common to all currently supported RISC-V chips.  There is only one\r
37  *   portASM.S file because the same file is built for all RISC-V target chips.\r
38  *\r
39  * + Header files called freertos_risc_v_chip_specific_extensions.h contain the\r
40  *   code that tailors the FreeRTOS kernel's RISC-V port to a specific RISC-V\r
41  *   chip.  There are multiple freertos_risc_v_chip_specific_extensions.h files\r
42  *   as there are multiple RISC-V chip implementations.\r
43  *\r
44  * !!!NOTE!!!\r
45  * CARE MUST BE TAKEN TO INCLUDE THE CORRECT\r
46  * freertos_risc_v_chip_specific_extensions.h HEADER FILE FOR THE CHIP IN USE.\r
47  * If the chip in use includes a core local interrupter (CLINT) and does not\r
48  * include any chip specific register extensions then set the GNU assembler's\r
49  * include path such that the header file contained in the\r
50  * FreeRTOS\Source\portable\GCC\RISC-V-RV32 directory is the header file that is\r
51  * actually inlcuded.  Otherwise set the assembler's include patch to the\r
52  * sub-directory off of the\r
53  * FreeRTOS\Source\portable\GCC\RISC-V-RV32\chip_specific_extensions directory\r
54  * that contains the freertos_risc_v_chip_specific_extensions.h specific to the\r
55  * target chip.\r
56  *\r
57  */\r
58 \r
59 /*\r
60  * This freertos_risc_v_chip_specific_extensions.h is for use with Pulpino Ri5cy\r
61  * devices, developed and tested using the Vega board RV32M1RM.\r
62  */\r
63 \r
64 #ifndef __FREERTOS_RISC_V_EXTENSIONS_H__\r
65 #define __FREERTOS_RISC_V_EXTENSIONS_H__\r
66 \r
67 #define portasmHAS_CLINT 0\r
68 \r
69 /* Constants to define the additional registers found on the Pulpino RI5KY. */\r
70 #define lpstart0        0x7b0\r
71 #define lpend0          0x7b1\r
72 #define lpcount0        0x7b2\r
73 #define lpstart1        0x7b4\r
74 #define lpend1          0x7b5\r
75 #define lpcount1        0x7b6\r
76 \r
77 /* Six additional registers to save and restore, as per the #defines above. */\r
78 #define portasmADDITIONAL_CONTEXT_SIZE 6 /* Must be even number on 32-bit cores. */\r
79 \r
80 /* Save additional registers found on the Pulpino. */\r
81 .macro portasmSAVE_ADDITIONAL_REGISTERS\r
82         addi sp, sp, -(portasmADDITIONAL_CONTEXT_SIZE * portWORD_SIZE) /* Make room for the additional registers. */\r
83         csrr t0, lpstart0                                                        /* Load additional registers into accessable temporary registers. */\r
84         csrr t1, lpend0\r
85         csrr t2, lpcount0\r
86         csrr t3, lpstart1\r
87         csrr t4, lpend1\r
88         csrr t5, lpcount1\r
89         sw t0, 1 * portWORD_SIZE( sp )\r
90         sw t1, 2 * portWORD_SIZE( sp )\r
91         sw t2, 3 * portWORD_SIZE( sp )\r
92         sw t3, 4 * portWORD_SIZE( sp )\r
93         sw t4, 5 * portWORD_SIZE( sp )\r
94         sw t5, 6 * portWORD_SIZE( sp )\r
95         .endm\r
96 \r
97 /* Restore the additional registers found on the Pulpino. */\r
98 .macro portasmRESTORE_ADDITIONAL_REGISTERS\r
99         lw t0, 1 * portWORD_SIZE( sp )                  /* Load additional registers into accessable temporary registers. */\r
100         lw t1, 2 * portWORD_SIZE( sp )\r
101         lw t2, 3 * portWORD_SIZE( sp )\r
102         lw t3, 4 * portWORD_SIZE( sp )\r
103         lw t4, 5 * portWORD_SIZE( sp )\r
104         lw t5, 6 * portWORD_SIZE( sp )\r
105         csrw lpstart0, t0\r
106         csrw lpend0, t1\r
107         csrw lpcount0, t2\r
108         csrw lpstart1, t3\r
109         csrw lpend1, t4\r
110         csrw lpcount1, t5\r
111         addi sp, sp, (portasmADDITIONAL_CONTEXT_SIZE * portWORD_SIZE )/* Remove space added for additional registers. */\r
112         .endm\r
113 \r
114 #endif /* __FREERTOS_RISC_V_EXTENSIONS_H__ */\r