summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/nds32/cpu.h12
-rw-r--r--core/nds32/ec.lds.S3
-rw-r--r--core/nds32/switch.S3
-rw-r--r--core/nds32/task.c13
4 files changed, 20 insertions, 11 deletions
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 <stdint.h>
+/*
+ * 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 <stdint.h>
+
/* 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