This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new bafac8b arch: k210: Fix stack coloring for the idle thread stack
bafac8b is described below
commit bafac8b56056beca4d2521b58204128580f07d1f
Author: Masayuki Ishikawa <[email protected]>
AuthorDate: Sat Jun 12 07:32:25 2021 +0900
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 <[email protected]>
---
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 a8bf25e..56c986d 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 49a3182..a45f4f8 100644
--- a/arch/risc-v/src/k210/k210_allocateheap.c
+++ b/arch/risc-v/src/k210/k210_allocateheap.c
@@ -30,6 +30,7 @@
#include <nuttx/userspace.h>
#include <nuttx/arch.h>
+#include <nuttx/board.h>
#include <arch/board/board.h>
#include "k210.h"
@@ -45,6 +46,28 @@
****************************************************************************/
/****************************************************************************
+ * 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
*
* Description:
diff --git a/arch/risc-v/src/k210/k210_cpustart.c
b/arch/risc-v/src/k210/k210_cpustart.c
index 89a88c7..c3e47af 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 18365f4..4b7c3ec 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 7c1113a..427c714 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);