Files
x653 62810c1a83 Update os.c
Hey there,
I implemented risc-v in fpga and try to port your mini-os to my fpga.
02_ContextSwitch did not work correctly, because the stackpointer is not word alligned after context switch.
Changing uint8_t to word size (32 bit) solved the problem, because &task0_stack[STACK_SIZE-1] should be the last word of the stack, instead of the last byte of the stack.
Some hardware may ignore the two least significant bits of address when accessing a 32 bit word.
So uint8_t might work also.
2022-02-19 13:36:44 +01:00

25 lines
429 B
C

#include "os.h"
#define STACK_SIZE 1024
reg_t task0_stack[STACK_SIZE];
struct context ctx_os;
struct context ctx_task;
extern void sys_switch();
void user_task0(void)
{
lib_puts("Task0: Context Switch Success !\n");
while (1) {} // stop here.
}
int os_main(void)
{
lib_puts("OS start\n");
ctx_task.ra = (reg_t) user_task0;
ctx_task.sp = (reg_t) &task0_stack[STACK_SIZE-1];
sys_switch(&ctx_os, &ctx_task);
return 0;
}