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

@@ -5,7 +5,11 @@ extern void switch_to(struct context *next);
#define MAX_TASKS 10
#define STACK_SIZE 1024
uint8_t task_stack[MAX_TASKS][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[MAX_TASKS][STACK_SIZE];
struct context ctx_tasks[MAX_TASKS];
/*
@@ -46,7 +50,7 @@ void schedule()
int task_create(void (*start_routin)(void))
{
if (_top < MAX_TASKS) {
ctx_tasks[_top].sp = (reg_t) &task_stack[_top][STACK_SIZE - 1];
ctx_tasks[_top].sp = (reg_t) &task_stack[_top][STACK_SIZE];
ctx_tasks[_top].ra = (reg_t) start_routin;
_top++;
return 0;