stack pointer aligment

Following the standard RISC-V calling convention, make sure
the stack pointer sp is always 16-byte aligned.

Fixed an issue, make sure the sp of task point to the bottom
of the stack, while originally we waste one byte (forgive my
stupid ~~~).

Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
This commit is contained in:
Wang Chen
2023-06-17 21:46:13 +08:00
parent 6d2c046c67
commit a94fb0cd58
21 changed files with 90 additions and 18 deletions

View File

@@ -4,7 +4,11 @@
extern void switch_to(struct context *next);
#define STACK_SIZE 1024
uint8_t task_stack[STACK_SIZE];
/*
* In the standard RISC-V calling convention, the stack pointer sp
* is always 16-byte aligned.
*/
uint8_t __attribute__((aligned(16))) task_stack[STACK_SIZE];
struct context ctx_task;
static void w_mscratch(reg_t x)
@@ -17,7 +21,7 @@ void sched_init()
{
w_mscratch(0);
ctx_task.sp = (reg_t) &task_stack[STACK_SIZE - 1];
ctx_task.sp = (reg_t) &task_stack[STACK_SIZE];
ctx_task.ra = (reg_t) user_task0;
}

View File

@@ -36,6 +36,9 @@ park:
wfi
j park
# In the standard RISC-V calling convention, the stack pointer sp
# is always 16-byte aligned.
.align 16
stacks:
.skip STACK_SIZE * MAXNUM_CPU # allocate space for all the harts stacks