From bafac8b56056beca4d2521b58204128580f07d1f Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Sat, 12 Jun 2021 07:32:25 +0900 Subject: [PATCH] arch: k210: Fix stack coloring for the idle thread stack Summary: - I noticed that stack coloring for the idle thread stacks does not work due to the recent changes - This commit fixes this issue Impact: - k210 only Testing: - Tested with both maix-bit (dev board) and QEMU Signed-off-by: Masayuki Ishikawa --- arch/risc-v/src/k210/Make.defs | 2 +- arch/risc-v/src/k210/k210_allocateheap.c | 23 +++++++++++++++++++++++ arch/risc-v/src/k210/k210_cpustart.c | 11 +++++++++++ arch/risc-v/src/k210/k210_memorymap.h | 4 ++-- arch/risc-v/src/k210/k210_start.c | 12 +++--------- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/arch/risc-v/src/k210/Make.defs b/arch/risc-v/src/k210/Make.defs index a8bf25e506..56c986d35b 100644 --- a/arch/risc-v/src/k210/Make.defs +++ b/arch/risc-v/src/k210/Make.defs @@ -29,7 +29,7 @@ CMN_ASRCS += riscv_testset.S # Specify C code within the common directory to be included CMN_CSRCS += riscv_initialize.c riscv_swint.c -CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_exit.c riscv_fault.c +CMN_CSRCS += riscv_createstack.c riscv_exit.c riscv_fault.c CMN_CSRCS += riscv_assert.c riscv_blocktask.c riscv_copystate.c riscv_initialstate.c CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c diff --git a/arch/risc-v/src/k210/k210_allocateheap.c b/arch/risc-v/src/k210/k210_allocateheap.c index 49a318235c..a45f4f81db 100644 --- a/arch/risc-v/src/k210/k210_allocateheap.c +++ b/arch/risc-v/src/k210/k210_allocateheap.c @@ -30,6 +30,7 @@ #include #include +#include #include #include "k210.h" @@ -44,6 +45,28 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: up_allocate_heap + * + * Description: + * This function will be called to dynamically set aside the heap region. + * + * For the kernel build (CONFIG_BUILD_PROTECTED=y) with both kernel- and + * user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the + * size of the unprotected, user-space heap. + * + * If a protected kernel-space heap is provided, the kernel heap must be + * allocated (and protected) by an analogous up_allocate_kheap(). + * + ****************************************************************************/ + +void up_allocate_heap(FAR void **heap_start, size_t *heap_size) +{ + board_autoled_on(LED_HEAPALLOCATE); + *heap_start = (FAR void *)K210_HEAP_START; + *heap_size = CONFIG_RAM_END - K210_HEAP_START; +} + /**************************************************************************** * Name: up_allocate_kheap * diff --git a/arch/risc-v/src/k210/k210_cpustart.c b/arch/risc-v/src/k210/k210_cpustart.c index 89a88c7117..c3e47af406 100644 --- a/arch/risc-v/src/k210/k210_cpustart.c +++ b/arch/risc-v/src/k210/k210_cpustart.c @@ -112,6 +112,17 @@ void k210_cpu_boot(int cpu) showprogress('b'); DPRINTF("CPU%d Started\n", this_cpu()); +#ifdef CONFIG_STACK_COLORATION + FAR struct tcb_s *tcb = this_task(); + + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + riscv_stack_color(tcb->stack_alloc_ptr, tcb->adj_stack_size); +#endif + /* TODO: Setup FPU */ /* Clear machine software interrupt for CPU(cpu) */ diff --git a/arch/risc-v/src/k210/k210_memorymap.h b/arch/risc-v/src/k210/k210_memorymap.h index 18365f4832..4b7c3ecfee 100644 --- a/arch/risc-v/src/k210/k210_memorymap.h +++ b/arch/risc-v/src/k210/k210_memorymap.h @@ -51,9 +51,9 @@ extern uintptr_t *_default_stack_limit; #define K210_IDLESTACK1_TOP (K210_IDLESTACK1_BASE + CONFIG_IDLETHREAD_STACKSIZE) #if defined(CONFIG_SMP) && (CONFIG_SMP_NCPUS > 1) -#define K210_IDLESTACK_TOP (K210_IDLESTACK1_TOP) +#define K210_HEAP_START (K210_IDLESTACK1_TOP) #else -#define K210_IDLESTACK_TOP (K210_IDLESTACK0_TOP) +#define K210_HEAP_START (K210_IDLESTACK0_TOP) #endif #endif /* _ARCH_RISCV_SRC_K210_K210_MEMORYMAP_H */ diff --git a/arch/risc-v/src/k210/k210_start.c b/arch/risc-v/src/k210/k210_start.c index 7c1113ae44..427c7143cb 100644 --- a/arch/risc-v/src/k210/k210_start.c +++ b/arch/risc-v/src/k210/k210_start.c @@ -48,17 +48,11 @@ * Public Data ****************************************************************************/ -/* g_idle_topstack: _sbss is the start of the BSS region as defined by the - * linker script. _ebss lies at the end of the BSS region. The idle task - * stack starts at the end of BSS and is of size CONFIG_IDLETHREAD_STACKSIZE. - * The IDLE thread is the thread that the system boots on and, eventually, - * becomes the IDLE, do nothing task that runs only when there is nothing - * else to run. The heap continues from there until the end of memory. - * g_idle_topstack is a read-only variable the provides this computed - * address. +/* NOTE: g_idle_topstack needs to point the top of the idle stack + * for CPU0 and this value is used in up_initial_state() */ -uintptr_t g_idle_topstack = K210_IDLESTACK_TOP; +uintptr_t g_idle_topstack = K210_IDLESTACK0_TOP; volatile bool g_serial_ok = false; extern void k210_cpu_boot(uint32_t);