From 8ef8fed56e1b8a9c0d5068c3c42bc5036aecf9cb Mon Sep 17 00:00:00 2001 From: acevest Date: Tue, 24 Sep 2019 10:19:57 +0800 Subject: [PATCH] fix risc-v gp(global pointer register) problem --- arch/risc-v/common/tos_cpu.c | 4 ++++ board/GD32VF103C_START/eclipse/hello_world/.cproject | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/risc-v/common/tos_cpu.c b/arch/risc-v/common/tos_cpu.c index 6edd6079..311396f2 100644 --- a/arch/risc-v/common/tos_cpu.c +++ b/arch/risc-v/common/tos_cpu.c @@ -99,6 +99,10 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, #undef _V } + cpu_data_t gp; + asm("mv %0, gp"::"r"(gp)); + + regs->gp = (cpu_data_t)gp; // gp: global pointer regs->a0 = (cpu_data_t)arg; // a0: argument regs->ra = (cpu_data_t)0xACE00ACE; // ra: return address regs->mstatus = (cpu_data_t)(MSTATUS_MPP | MSTATUS_MPIE); // return to machine mode and enable interrupt diff --git a/board/GD32VF103C_START/eclipse/hello_world/.cproject b/board/GD32VF103C_START/eclipse/hello_world/.cproject index 10165b10..c4535ca2 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.cproject +++ b/board/GD32VF103C_START/eclipse/hello_world/.cproject @@ -175,7 +175,7 @@