]> git.sur5r.net Git - freertos/commitdiff
Add trap handler to RISC-V port so there is no dependency on third party code.
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 23 Sep 2018 03:52:23 +0000 (03:52 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 23 Sep 2018 03:52:23 +0000 (03:52 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2584 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/portable/GCC/RISC-V-RV32/port.c
FreeRTOS/Source/portable/GCC/RISC-V-RV32/portASM.S [new file with mode: 0644]

index 17dbb0d8075a9b12f6efc1680483f97752dc83d3..5e66d08c4f7262b2b5a380943cf6c6f1b03928f0 100644 (file)
@@ -94,67 +94,67 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
        */\r
 \r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) pxCode; /* X1 */\r
-       pxTopOfStack--;\r
-//     *pxTopOfStack = ( StackType_t ) 2; /* Stack pointer is handled separately. */\r
-//     pxTopOfStack--;\r
-//     *pxTopOfStack = ( StackType_t ) 3; /* Global pointer is not manipulated. */\r
-//     pxTopOfStack--;\r
-//     *pxTopOfStack = ( StackType_t ) 4; /* Thread pointer is not manipulated. */\r
-//     pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 5;\r
+       *pxTopOfStack = ( StackType_t ) 31;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 6;\r
+       *pxTopOfStack = ( StackType_t ) 30;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 7;\r
+       *pxTopOfStack = ( StackType_t ) 29;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 8;\r
+       *pxTopOfStack = ( StackType_t ) 28;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 9;\r
+       *pxTopOfStack = ( StackType_t ) 27;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) pvParameters;\r
+       *pxTopOfStack = ( StackType_t ) 26;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 11;\r
+       *pxTopOfStack = ( StackType_t ) 25;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 12;\r
+       *pxTopOfStack = ( StackType_t ) 24;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 13;\r
+       *pxTopOfStack = ( StackType_t ) 23;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 14;\r
+       *pxTopOfStack = ( StackType_t ) 22;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 15;\r
+       *pxTopOfStack = ( StackType_t ) 21;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 16;\r
+       *pxTopOfStack = ( StackType_t ) 20;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 17;\r
+       *pxTopOfStack = ( StackType_t ) 19;\r
        pxTopOfStack--;\r
        *pxTopOfStack = ( StackType_t ) 18;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 19;\r
+       *pxTopOfStack = ( StackType_t ) 17;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 20;\r
+       *pxTopOfStack = ( StackType_t ) 16;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 21;\r
+       *pxTopOfStack = ( StackType_t ) 15;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 22;\r
+       *pxTopOfStack = ( StackType_t ) 14;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 23;\r
+       *pxTopOfStack = ( StackType_t ) 13;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 24;\r
+       *pxTopOfStack = ( StackType_t ) 12;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 25;\r
+       *pxTopOfStack = ( StackType_t ) 11;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 26;\r
+       *pxTopOfStack = ( StackType_t ) pvParameters;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 27;\r
+       *pxTopOfStack = ( StackType_t ) 9;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 28;\r
+       *pxTopOfStack = ( StackType_t ) 8;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 29;\r
+       *pxTopOfStack = ( StackType_t ) 7;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 30;\r
+       *pxTopOfStack = ( StackType_t ) 6;\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( StackType_t ) 31;\r
+       *pxTopOfStack = ( StackType_t ) 5;\r
+       pxTopOfStack--;\r
+//     *pxTopOfStack = ( StackType_t ) 4;  /* Thread pointer. */\r
+//     pxTopOfStack--;\r
+//     *pxTopOfStack = ( StackType_t ) 3;  /* Global pointer. */\r
+//     pxTopOfStack--;\r
+//     *pxTopOfStack = ( StackType_t ) 2;  /* Stack pointer. */\r
+//     pxTopOfStack--;\r
+       *pxTopOfStack = ( StackType_t ) pxCode;\r
 \r
        return pxTopOfStack;\r
 }\r
@@ -183,50 +183,11 @@ volatile uint32_t * const pulTimeLow = ( volatile uint32_t * const ) 0x200BFFc;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t xPortStartScheduler( void )\r
+void Software_IRQHandler( void )\r
 {\r
-       __asm volatile\r
-       (\r
-               ".extern pxCurrentTCB                   \r\n"\r
-               "lw             sp, pxCurrentTCB                \r\n" /* Load pxCurrentTCB. */\r
-               "lw             sp, 0x00( sp )                  \r\n" /* Read sp from first TCB member. */\r
-               "lw             x31, 0( sp )                    \r\n" /* X31 */\r
-               "lw             x30, 4( sp )                    \r\n" /* X30 */\r
-               "lw             x29, 8( sp )                    \r\n" /* X29 */\r
-               "lw             x28, 12( sp )                   \r\n" /* X28 */\r
-               "lw             x27, 16( sp )                   \r\n" /* X27 */\r
-               "lw             x26, 20( sp )                   \r\n" /* X26 */\r
-               "lw             x25, 24( sp )                   \r\n" /* X25 */\r
-               "lw             x24, 28( sp )                   \r\n" /* X24 */\r
-               "lw             x23, 32( sp )                   \r\n" /* X23 */\r
-               "lw             x22, 36( sp )                   \r\n" /* X22 */\r
-               "lw             x21, 40( sp )                   \r\n" /* X21 */\r
-               "lw             x20, 44( sp )                   \r\n" /* X20 */\r
-               "lw             x19, 48( sp )                   \r\n" /* X19 */\r
-               "lw             x18, 52( sp )                   \r\n" /* X18 */\r
-               "lw             x17, 56( sp )                   \r\n" /* X17 */\r
-               "lw             x16, 60( sp )                   \r\n" /* X16 */\r
-               "lw             x15, 64( sp )                   \r\n" /* X15 */\r
-               "lw             x14, 68( sp )                   \r\n" /* X14 */\r
-               "lw             x13, 72( sp )                   \r\n" /* X13 */\r
-               "lw             x12, 76( sp )                   \r\n" /* X12 */\r
-               "lw             x11, 80( sp )                   \r\n" /* X11 */\r
-               "lw             x10, 84( sp )                   \r\n" /* X10 */\r
-               "lw             x9, 88( sp )                    \r\n" /* X9 */\r
-               "lw             x8, 92( sp )                    \r\n" /* X8 */\r
-               "lw             x7, 96( sp )                    \r\n" /* X7 */\r
-               "lw             x6, 100( sp )                   \r\n" /* X6 */\r
-               "lw             x5, 104( sp )                   \r\n" /* X5 */\r
-               "lw             x1, 108( sp )                   \r\n" /* X1 */\r
-               "csrs   mie, 8                                  \r\n" /* Enable soft interrupt. */\r
-               "csrs   mstatus, 8                              \r\n" /* Enable interrupts. */\r
-               "ret                                                            "\r
-       );\r
-\r
-       /*Should not get here*/\r
-       return pdFALSE;\r
+       vTaskSwitchContext();\r
 }\r
-/*-----------------------------------------------------------*/\r
+\r
 \r
 \r
 \r
diff --git a/FreeRTOS/Source/portable/GCC/RISC-V-RV32/portASM.S b/FreeRTOS/Source/portable/GCC/RISC-V-RV32/portASM.S
new file mode 100644 (file)
index 0000000..d86757e
--- /dev/null
@@ -0,0 +1,167 @@
+/*\r
+ * FreeRTOS Kernel V10.1.1\r
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and t\r
+\r
+ o permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
+\r
+#if __riscv_xlen == 64\r
+    #error Not implemented yet - change lw to ld, and sw to sd.\r
+    #define WORD_SIZE 8\r
+#elif __riscv_xlen == 32\r
+    #define WORD_SIZE 4\r
+#else\r
+    #error Assembler has not defined __riscv_xlen\r
+#endif\r
+\r
+#define CONTEXT_SIZE ( 28 * WORD_SIZE )\r
+\r
+.global xPortStartScheduler\r
+.global vPortTrapHandler\r
+.extern pxCurrentTCB\r
+.extern handle_trap\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+.align 8\r
+xPortStartScheduler:\r
+       lw      sp, pxCurrentTCB                        /* Load pxCurrentTCB. */\r
+       lw      sp, 0( sp )                                     /* Read sp from first TCB member. */\r
+       lw      x1, 0( sp )\r
+       lw      x5, 1 * WORD_SIZE( sp )         /* t0 */\r
+       lw      x6, 2 * WORD_SIZE( sp )         /* t1 */\r
+       lw      x7, 3 * WORD_SIZE( sp )         /* t2 */\r
+       lw      x8, 4 * WORD_SIZE( sp )         /* s0/fp */\r
+       lw      x9, 5 * WORD_SIZE( sp )         /* s1 */\r
+       lw      x10, 6 * WORD_SIZE( sp )        /* a0 */\r
+       lw      x11, 7 * WORD_SIZE( sp )        /* a1 */\r
+       lw      x12, 8 * WORD_SIZE( sp )        /* a2 */\r
+       lw      x13, 9 * WORD_SIZE( sp )        /* a3 */\r
+       lw      x14, 10 * WORD_SIZE( sp )       /* a4 */\r
+       lw      x15, 11 * WORD_SIZE( sp )       /* a5 */\r
+       lw      x16, 12 * WORD_SIZE( sp )       /* a6 */\r
+       lw      x17, 13 * WORD_SIZE( sp )       /* a7 */\r
+       lw      x18, 14 * WORD_SIZE( sp )       /* s2 */\r
+       lw      x19, 15 * WORD_SIZE( sp )       /* s3 */\r
+       lw      x20, 16 * WORD_SIZE( sp )       /* s4 */\r
+       lw      x21, 17 * WORD_SIZE( sp )       /* s5 */\r
+       lw      x22, 18 * WORD_SIZE( sp )       /* s6 */\r
+       lw      x23, 19 * WORD_SIZE( sp )       /* s7 */\r
+       lw      x24, 20 * WORD_SIZE( sp )       /* s8 */\r
+       lw      x25, 21 * WORD_SIZE( sp )       /* s9 */\r
+       lw      x26, 22 * WORD_SIZE( sp )       /* s10 */\r
+       lw      x27, 23 * WORD_SIZE( sp )       /* s11 */\r
+       lw      x28, 24 * WORD_SIZE( sp )       /* t3 */\r
+       lw      x29, 25 * WORD_SIZE( sp )       /* t4 */\r
+       lw      x30, 26 * WORD_SIZE( sp )       /* t5 */\r
+       lw      x31, 27 * WORD_SIZE( sp )       /* t6 */\r
+       addi    sp, sp, CONTEXT_SIZE\r
+       csrs    mie, 8                                  /* Enable soft interrupt. */\r
+       csrs    mstatus, 8                              /* Enable interrupts. */\r
+       ret\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+.align 8\r
+vPortTrapHandler:\r
+       addi sp, sp, -CONTEXT_SIZE\r
+       sw x1, 0( sp )\r
+       sw x5, 1 * WORD_SIZE( sp )\r
+       sw x6, 2 * WORD_SIZE( sp )\r
+       sw x7, 3 * WORD_SIZE( sp )\r
+       sw x8, 4 * WORD_SIZE( sp )\r
+       sw x9, 5 * WORD_SIZE( sp )\r
+       sw x10, 6 * WORD_SIZE( sp )\r
+       sw x11, 7 * WORD_SIZE( sp )\r
+       sw x12, 8 * WORD_SIZE( sp )\r
+       sw x13, 9 * WORD_SIZE( sp )\r
+       sw x14, 10 * WORD_SIZE( sp )\r
+       sw x15, 11 * WORD_SIZE( sp )\r
+       sw x16, 12 * WORD_SIZE( sp )\r
+       sw x17, 13 * WORD_SIZE( sp )\r
+       sw x18, 14 * WORD_SIZE( sp )\r
+       sw x19, 15 * WORD_SIZE( sp )\r
+       sw x20, 16 * WORD_SIZE( sp )\r
+       sw x21, 17 * WORD_SIZE( sp )\r
+       sw x22, 18 * WORD_SIZE( sp )\r
+       sw x23, 19 * WORD_SIZE( sp )\r
+       sw x24, 20 * WORD_SIZE( sp )\r
+       sw x25, 21 * WORD_SIZE( sp )\r
+       sw x26, 22 * WORD_SIZE( sp )\r
+       sw x27, 23 * WORD_SIZE( sp )\r
+       sw x28, 24 * WORD_SIZE( sp )\r
+       sw x29, 25 * WORD_SIZE( sp )\r
+       sw x30, 26 * WORD_SIZE( sp )\r
+       sw x31, 27 * WORD_SIZE( sp )\r
+    lw  t0, pxCurrentTCB            /* Load pxCurrentTCB. */\r
+    sw  sp, 0( t0 )                 /* Write sp from first TCB member. */\r
+\r
+       csrr t0, mepc\r
+       sw t0, 31 * WORD_SIZE( sp )\r
+\r
+       csrr a0, mcause\r
+       csrr a1, mepc\r
+       mv a2, sp\r
+       jal handle_trap\r
+       csrw mepc, a0\r
+\r
+       # Remain in M-mode after mret\r
+       li t0, 0x00001800 /* MSTATUS MPP */\r
+       csrs mstatus, t0\r
+\r
+       /* Cut and past restore code from xPortStartScheduler - can be made a macro\r
+       but that makes debugging harder. */\r
+       lw      sp, pxCurrentTCB                        /* Load pxCurrentTCB. */\r
+       lw      sp, 0( sp )                                     /* Read sp from first TCB member. */\r
+       lw      x1, 0( sp )\r
+       lw      x5, 1 * WORD_SIZE( sp )         /* t0 */\r
+       lw      x6, 2 * WORD_SIZE( sp )         /* t1 */\r
+       lw      x7, 3 * WORD_SIZE( sp )         /* t2 */\r
+       lw      x8, 4 * WORD_SIZE( sp )         /* s0/fp */\r
+       lw      x9, 5 * WORD_SIZE( sp )         /* s1 */\r
+       lw      x10, 6 * WORD_SIZE( sp )        /* a0 */\r
+       lw      x11, 7 * WORD_SIZE( sp )        /* a1 */\r
+       lw      x12, 8 * WORD_SIZE( sp )        /* a2 */\r
+       lw      x13, 9 * WORD_SIZE( sp )        /* a3 */\r
+       lw      x14, 10 * WORD_SIZE( sp )       /* a4 */\r
+       lw      x15, 11 * WORD_SIZE( sp )       /* a5 */\r
+       lw      x16, 12 * WORD_SIZE( sp )       /* a6 */\r
+       lw      x17, 13 * WORD_SIZE( sp )       /* a7 */\r
+       lw      x18, 14 * WORD_SIZE( sp )       /* s2 */\r
+       lw      x19, 15 * WORD_SIZE( sp )       /* s3 */\r
+       lw      x20, 16 * WORD_SIZE( sp )       /* s4 */\r
+       lw      x21, 17 * WORD_SIZE( sp )       /* s5 */\r
+       lw      x22, 18 * WORD_SIZE( sp )       /* s6 */\r
+       lw      x23, 19 * WORD_SIZE( sp )       /* s7 */\r
+       lw      x24, 20 * WORD_SIZE( sp )       /* s8 */\r
+       lw      x25, 21 * WORD_SIZE( sp )       /* s9 */\r
+       lw      x26, 22 * WORD_SIZE( sp )       /* s10 */\r
+       lw      x27, 23 * WORD_SIZE( sp )       /* s11 */\r
+       lw      x28, 24 * WORD_SIZE( sp )       /* t3 */\r
+       lw      x29, 25 * WORD_SIZE( sp )       /* t4 */\r
+       lw      x30, 26 * WORD_SIZE( sp )       /* t5 */\r
+       lw      x31, 27 * WORD_SIZE( sp )       /* t6 */\r
+       addi sp, sp, CONTEXT_SIZE\r
+       mret\r