From b99fd2e38f0710d11f09e42ab35b7f0745c6912e Mon Sep 17 00:00:00 2001 From: Dino Li Date: Mon, 23 Dec 2019 10:17:32 +0800 Subject: core/nds32: remove unnecessary condition In the previous implementation, we added conditions to prevent stack overflow panic or memory get overwritten at first context switch. Actually, we won't hit these two situation if scratchpad size is correct. Let's remove them. BUG=none BRANCH=none TEST=EC boots, and the "runtime" is saved in scratchpad at first context switch. Change-Id: I647e1ebb01dbb8fe24adc9f22b6581bb8f8f97fb Signed-off-by: Dino Li Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1980097 Reviewed-by: Jett Rink --- core/nds32/cpu.h | 12 +++++++++++- core/nds32/ec.lds.S | 3 ++- core/nds32/switch.S | 3 ++- core/nds32/task.c | 13 +++++-------- 4 files changed, 20 insertions(+), 11 deletions(-) (limited to 'core/nds32') diff --git a/core/nds32/cpu.h b/core/nds32/cpu.h index eeacaf4c07..3bd5a93efc 100644 --- a/core/nds32/cpu.h +++ b/core/nds32/cpu.h @@ -8,13 +8,21 @@ #ifndef __CROS_EC_CPU_H #define __CROS_EC_CPU_H -#include +/* + * This is the space required by both irq_x_ and __switch_task to store all + * of the caller and callee registers for each task context before switching. + */ +#define TASK_SCRATCHPAD_SIZE (18) /* Process Status Word bits */ #define PSW_GIE BIT(0) /* Global Interrupt Enable */ #define PSW_INTL_SHIFT 1 /* Interrupt Stack Level */ #define PSW_INTL_MASK (0x3 << PSW_INTL_SHIFT) +#ifndef __ASSEMBLER__ + +#include + /* write Process Status Word privileged register */ static inline void set_psw(uint32_t val) { @@ -57,4 +65,6 @@ void cpu_init(void); extern uint32_t ilp; extern uint32_t ec_reset_lp; +#endif /* !__ASSEMBLER__ */ + #endif /* __CROS_EC_CPU_H */ diff --git a/core/nds32/ec.lds.S b/core/nds32/ec.lds.S index ae26e58f7b..98edb36c3f 100644 --- a/core/nds32/ec.lds.S +++ b/core/nds32/ec.lds.S @@ -238,9 +238,10 @@ SECTIONS . = ALIGN(8); __bss_start = .; *(.bss.tasks) - *(.bss.task_scratchpad) . = ALIGN(8); *(.bss.system_stack) + . = ALIGN(8); + *(.bss.task_scratchpad) /* Rest of .bss takes care of its own alignment */ *(.bss) *(.bss.slow) diff --git a/core/nds32/switch.S b/core/nds32/switch.S index 11fc0d76cd..8696ef5f00 100644 --- a/core/nds32/switch.S +++ b/core/nds32/switch.S @@ -6,6 +6,7 @@ */ #include "config.h" +#include "cpu.h" .text @@ -89,7 +90,7 @@ __task_start: movi55 $r0, 0 /* syscall 1st parameter : de-schedule nothing */ /* put the stack pointer at the top of the stack in scratchpad */ - addi $sp, $r3, 4 * 18 + addi $sp, $r3, 4 * TASK_SCRATCHPAD_SIZE /* we are ready to re-schedule */ swi.gp $r4, [ + need_resched] swi.gp $r4, [ + start_called] diff --git a/core/nds32/task.c b/core/nds32/task.c index 74b7501acc..f034c53f48 100644 --- a/core/nds32/task.c +++ b/core/nds32/task.c @@ -134,7 +134,8 @@ uint8_t task_stacks[0 #undef TASK /* Reserve space to discard context on first context switch. */ -uint32_t scratchpad[19]; +uint32_t scratchpad[TASK_SCRATCHPAD_SIZE] __attribute__ + ((section(".bss.task_scratchpad"))); task_ *current_task = (task_ *)scratchpad; @@ -294,10 +295,8 @@ task_ *next_sched_task(void) #ifdef CONFIG_TASK_PROFILING if (current_task != new_task) { - if ((current_task - tasks) < TASK_ID_COUNT) { - current_task->runtime += + current_task->runtime += (exc_start_time - exc_end_time - exc_sub_time); - } task_will_switch = 1; } #endif @@ -305,13 +304,11 @@ task_ *next_sched_task(void) #ifdef CONFIG_DEBUG_STACK_OVERFLOW if (*current_task->stack != STACK_UNUSED_VALUE) { int i = task_get_current(); - if (i < TASK_ID_COUNT) { - panic_printf("\n\nStack overflow in %s task!\n", - task_names[i]); + + panic_printf("\n\nStack overflow in %s task!\n", task_names[i]); #ifdef CONFIG_SOFTWARE_PANIC software_panic(PANIC_SW_STACK_OVERFLOW, i); #endif - } } #endif -- cgit v1.2.1