diff --git a/.github/scripts/core_checker.py b/.github/scripts/core_checker.py index 54830a763d..302ed6a938 100755 --- a/.github/scripts/core_checker.py +++ b/.github/scripts/core_checker.py @@ -280,8 +280,8 @@ FREERTOS_IGNORED_FILES = [ 'platform.c', 'platform.h', 'platform_config.h', - 'FreeRTOS_asm_vectors.S' - + 'FreeRTOS_asm_vectors.S', + 'gdbinit' ] FREERTOS_HEADER = [ diff --git a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/Readme.md b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/Readme.md new file mode 100644 index 0000000000..d613ed8dd8 --- /dev/null +++ b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/Readme.md @@ -0,0 +1,70 @@ +# Emulating generic RISC-V 32bit machine on QEMU + +## Requirements + +1. GNU RISC-V toolchains (tested on pre-built Sifive GNU Embedded Toolchain — v2020.12.8) + - https://www.sifive.com/software +1. qemu-riscv32-system (tested on pre-built Sifive QEMU — v2020.08.1) + - https://www.sifive.com/software +1. Linux OS (tested on Ubuntu 20.04.3 LTS) + + +## How to build + +Add path of toolchain that is described above section, such as: + +``` +$ export PATH="/YOUR_PATH/riscv64-unknown-elf/bin:${PATH}" +``` + +For release build: + +``` +$ make -C build/gcc/ +``` + +For debug build: + +``` +$ make -C build/gcc/ DEBUG=1 +``` + +To clean build artifacts: + +``` +$ make -C build/gcc/ clean +``` + +If the build was successful, the RTOSDemo.elf executable will be located in the build/gcc/output directory. + + +## How to run + +``` +$ qemu-system-riscv32 -nographic -machine virt -net none \ + -chardev stdio,id=con,mux=on -serial chardev:con \ + -mon chardev=con,mode=readline -bios none \ + -smp 4 -kernel ./build/gcc/output/RTOSDemo.elf +``` + + +## How to debug with gdb + +Append -s and -S options to the previous qemu command. + +- -s: enable to attach gdb to QEMU at port 1234 +- -S: start and halted CPU (wait for attach from gdb) + +It is recommended to use the 'debug build' so that gdb can automatically map symbols. +Run these commands after starting the QEMU with above options: + +``` +$ riscv64-unknown-elf-gdb -x build/gcc/gdbinit +``` + + +## Description + +This demo just prints Tx/Rx message of queue to serial port, use no +other hardware and use only primary core (currently hart 0). +Other cores are simply going to wfi state and execute nothing else. diff --git a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile index d7ed94b74e..867b674c4d 100644 --- a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile +++ b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile @@ -95,6 +95,7 @@ SOURCE_FILES += (DEMO_PROJECT)/riscv-virt.c SOURCE_FILES += ./printf-stdarg.c ASM_SOURCE_FILES += ./start.S ASM_SOURCE_FILES += ./RegTest.S +ASM_SOURCE_FILES += ./vector.S #Create a list of object files with the desired output directory path. diff --git a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/gdbinit b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/gdbinit new file mode 100644 index 0000000000..b2a47b99ff --- /dev/null +++ b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/gdbinit @@ -0,0 +1,7 @@ +target remote localhost:1234 +set arch riscv:rv32 +set remotetimeout 250 +flushregs +file ./output/RTOSDemo.elf +load +tb main diff --git a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main.c b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main.c index edcb0a956c..04ec3557d0 100644 --- a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main.c +++ b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main.c @@ -67,6 +67,15 @@ demo application will be built. The comprehensive test and demo application is implemented and described in main_full.c. */ #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0 +/* Set to 1 to use direct mode and set to 0 to use vectored mode. +VECTOR MODE=Direct --> all traps into machine mode cause the pc to be set to the +vector base address (BASE) in the mtvec register. +VECTOR MODE=Vectored --> all synchronous exceptions into machine mode cause the +pc to be set to the BASE, whereas interrupts cause the pc to be set to the +address BASE plus four times the interrupt cause number. +*/ +#define mainVECTOR_MODE_DIRECT 0 + /* printf() output uses the UART. These constants define the addresses of the required UART registers. */ #define UART0_ADDRESS ( 0x40004000UL ) @@ -82,6 +91,9 @@ required UART registers. */ #define mainPLIC_ENABLE_0 ( * ( ( volatile uint32_t * ) 0x0C002000UL ) ) #define mainPLIC_ENABLE_1 ( * ( ( volatile uint32_t * ) 0x0C002004UL ) ) +extern void freertos_risc_v_trap_handler( void ); +extern void freertos_vector_table( void ); + /* * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1. * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0. @@ -103,6 +115,16 @@ void main( void ) /* See https://www.freertos.org/freertos-on-qemu-mps2-an385-model.html for instructions. */ + #if( mainVECTOR_MODE_DIRECT == 1 ) + { + __asm__ volatile( "csrw mtvec, %0" :: "r"( freertos_risc_v_trap_handler ) ); + } + #else + { + __asm__ volatile( "csrw mtvec, %0" :: "r"( ( uintptr_t )freertos_vector_table | 0x1 ) ); + } + #endif + /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top of this file. */ #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 ) @@ -299,3 +321,4 @@ void *malloc( size_t size ) } /*-----------------------------------------------------------*/ + diff --git a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main_full.c b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main_full.c index 205826752f..8286c704ea 100644 --- a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main_full.c +++ b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/main_full.c @@ -238,7 +238,7 @@ static void prvRegTestTaskEntry2( void *pvParameters ) /* See the comments at the top of this file. */ static void prvCheckTask( void *pvParameters ) { -static const char * pcMessage = "PASS"; +static const char * pcMessage = "FreeRTOS Demo SUCCESS:"; const TickType_t xTaskPeriod = pdMS_TO_TICKS( 5000UL ); TickType_t xPreviousWakeTime; uint32_t ulLastRegTest1Value = 0, ulLastRegTest2Value = 0; @@ -246,6 +246,9 @@ uint32_t ulLastRegTest1Value = 0, ulLastRegTest2Value = 0; /* Avoid warning about unused parameter. */ ( void ) pvParameters; + /* Demo start marker. */ + printf( "FreeRTOS Demo Start\r\n" ); + xPreviousWakeTime = xTaskGetTickCount(); for( ;; ) @@ -255,95 +258,95 @@ uint32_t ulLastRegTest1Value = 0, ulLastRegTest2Value = 0; /* Has an error been found in any task? */ if( xAreStreamBufferTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreStreamBufferTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreStreamBufferTasksStillRunning() returned false"; } else if( xAreMessageBufferTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreMessageBufferTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreMessageBufferTasksStillRunning() returned false"; } if( xAreGenericQueueTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreGenericQueueTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreGenericQueueTasksStillRunning() returned false"; } else if( xIsCreateTaskStillRunning() != pdTRUE ) { - pcMessage = "xIsCreateTaskStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xIsCreateTaskStillRunning() returned false"; } else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreBlockTimeTestTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreBlockTimeTestTasksStillRunning() returned false"; } else if( xAreSemaphoreTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreSemaphoreTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreSemaphoreTasksStillRunning() returned false"; } else if( xArePollingQueuesStillRunning() != pdTRUE ) { - pcMessage = "xArePollingQueuesStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xArePollingQueuesStillRunning() returned false"; } else if( xAreQueuePeekTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreQueuePeekTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreQueuePeekTasksStillRunning() returned false"; } else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreRecursiveMutexTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreRecursiveMutexTasksStillRunning() returned false"; } else if( xAreQueueSetTasksStillRunning() != pdPASS ) { - pcMessage = "xAreQueueSetTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreQueueSetTasksStillRunning() returned false"; } else if( xAreEventGroupTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreEventGroupTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreEventGroupTasksStillRunning() returned false"; } else if( xAreAbortDelayTestTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreAbortDelayTestTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreAbortDelayTestTasksStillRunning() returned false"; } else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreCountingSemaphoreTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreCountingSemaphoreTasksStillRunning() returned false"; } else if( xAreDynamicPriorityTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreDynamicPriorityTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreDynamicPriorityTasksStillRunning() returned false"; } else if( xAreMessageBufferAMPTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreMessageBufferAMPTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreMessageBufferAMPTasksStillRunning() returned false"; } else if( xIsQueueOverwriteTaskStillRunning() != pdTRUE ) { - pcMessage = "xIsQueueOverwriteTaskStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xIsQueueOverwriteTaskStillRunning() returned false"; } else if( xAreQueueSetPollTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreQueueSetPollTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreQueueSetPollTasksStillRunning() returned false"; } else if( xAreStaticAllocationTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreStaticAllocationTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreStaticAllocationTasksStillRunning() returned false"; } else if( xAreTaskNotificationTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreTaskNotificationTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreTaskNotificationTasksStillRunning() returned false"; } else if( xAreTaskNotificationArrayTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreTaskNotificationArrayTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreTaskNotificationArrayTasksStillRunning() returned false"; } else if( xAreTimerDemoTasksStillRunning( xTaskPeriod ) != pdTRUE ) { - pcMessage = "xAreTimerDemoTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreTimerDemoTasksStillRunning() returned false"; } else if( xIsInterruptStreamBufferDemoStillRunning() != pdTRUE ) { - pcMessage = "xIsInterruptStreamBufferDemoStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xIsInterruptStreamBufferDemoStillRunning() returned false"; } else if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE ) { - pcMessage = "xAreInterruptSemaphoreTasksStillRunning() returned false"; + pcMessage = "FreeRTOS Demo ERROR: xAreInterruptSemaphoreTasksStillRunning() returned false"; } else if( ulLastRegTest1Value == ulRegTest1LoopCounter ) /* Check that the register test 1 task is still running. */ { diff --git a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/vector.S b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/vector.S new file mode 100644 index 0000000000..dd5e656459 --- /dev/null +++ b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/vector.S @@ -0,0 +1,62 @@ +/* + * FreeRTOS V202112.00 + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +.balign 128, 0 +.option norvc +.global freertos_vector_table +freertos_vector_table: +IRQ_0: + j freertos_risc_v_exception_handler +IRQ_1: + j freertos_risc_v_interrupt_handler +IRQ_2: + j freertos_risc_v_interrupt_handler +IRQ_3: + j freertos_risc_v_interrupt_handler +IRQ_4: + j freertos_risc_v_interrupt_handler +IRQ_5: + j freertos_risc_v_interrupt_handler +IRQ_6: + j freertos_risc_v_interrupt_handler +IRQ_7: + j freertos_risc_v_mtimer_interrupt_handler +IRQ_8: + j freertos_risc_v_interrupt_handler +IRQ_9: + j freertos_risc_v_interrupt_handler +IRQ_10: + j freertos_risc_v_interrupt_handler +IRQ_11: + j freertos_risc_v_interrupt_handler +IRQ_12: + j freertos_risc_v_interrupt_handler +IRQ_13: + j freertos_risc_v_interrupt_handler +IRQ_14: + j freertos_risc_v_interrupt_handler +IRQ_15: + j freertos_risc_v_interrupt_handler diff --git a/FreeRTOS/Source b/FreeRTOS/Source index 9efca75d1e..d5a10e4595 160000 --- a/FreeRTOS/Source +++ b/FreeRTOS/Source @@ -1 +1 @@ -Subproject commit 9efca75d1ebfc6c02f9e004c199dffa327267a09 +Subproject commit d5a10e45958148d437ae5096835a118be58e6df9 diff --git a/lexicon.txt b/lexicon.txt index ed93258907..3df1e1402f 100644 --- a/lexicon.txt +++ b/lexicon.txt @@ -1351,6 +1351,7 @@ msr mss mtcoverage mtu +mtvec muc multithreaded multple diff --git a/manifest.yml b/manifest.yml index 9d1dc586ba..0b0e23a0b2 100644 --- a/manifest.yml +++ b/manifest.yml @@ -4,7 +4,7 @@ description: "This is the standard distribution of FreeRTOS." dependencies: - name: "FreeRTOS-Kernel" - version: "9efca75d1" + version: "d5a10e459" repository: type: "git" url: "https://github.com/FreeRTOS/FreeRTOS-Kernel.git"