mirror of
https://github.com/plctlab/riscv-operating-system-mooc.git
synced 2025-12-16 04:19:11 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user