diff --git a/arch/risc-v/bumblebee/gcc/riscv_port.h b/arch/risc-v/bumblebee/gcc/riscv_port.h index 78b2aa44..608ab60e 100644 --- a/arch/risc-v/bumblebee/gcc/riscv_port.h +++ b/arch/risc-v/bumblebee/gcc/riscv_port.h @@ -36,10 +36,4 @@ // EXCCODE 11:0 exception code #define MCAUSE_EXP_CODE_MASK 0x00000FFF -#ifndef __ASSEMBLER__ -void port_cpu_init(); - -void port_systick_priority_set(uint32_t priority); -#endif - #endif // _RISCV_PORT_H_ diff --git a/arch/risc-v/bumblebee/gcc/riscv_port_c.c b/arch/risc-v/bumblebee/gcc/riscv_port_c.c index e19aee3b..a5173726 100644 --- a/arch/risc-v/bumblebee/gcc/riscv_port_c.c +++ b/arch/risc-v/bumblebee/gcc/riscv_port_c.c @@ -108,8 +108,15 @@ static void eclic_set_irq_priority(uint32_t source, uint8_t priority) { eclic_set_intctrl(CLIC_INT_TMR, intctrl_val); } +void rv32_exception_entry(); __PORT__ void port_cpu_init() { + __ASM__ __VOLATILE__("csrw mtvec, %0"::"r"(rv32_exception_entry)); + + // MTVT2: 0x7EC + // use mtvec as entry of irq and other trap + __ASM__ __VOLATILE__("csrc 0x7EC, 0x1"); + eclic_enable_interrupt(CLIC_INT_TMR); eclic_set_irq_level(CLIC_INT_TMR, 0); @@ -119,3 +126,13 @@ __PORT__ void port_cpu_init() { __PORT__ void port_systick_priority_set(uint32_t priority) { eclic_set_irq_priority(CLIC_INT_TMR, priority); } + + +__PORT__ void *port_get_irq_vector_table() { + void *base = 0; + + // MTVT: 0x307 + __ASM__ __VOLATILE__("csrr %0, 0x307":"=r"(base)); + + return base; +} diff --git a/arch/risc-v/bumblebee/gcc/riscv_port_s.S b/arch/risc-v/bumblebee/gcc/riscv_port_s.S index 46324b1c..e1747b09 100644 --- a/arch/risc-v/bumblebee/gcc/riscv_port_s.S +++ b/arch/risc-v/bumblebee/gcc/riscv_port_s.S @@ -15,15 +15,15 @@ * within TencentOS. *---------------------------------------------------------------------------*/ +.global eclic_mtip_handler .global irq_entry .global trap_entry -.extern rv32_exception_entry - .align 2 irq_entry: - j rv32_exception_entry + j irq_entry .align 2 trap_entry: - j rv32_exception_entry + j trap_entry + diff --git a/arch/risc-v/common/tos_cpu.c b/arch/risc-v/common/tos_cpu.c index c46b9414..f8aed581 100644 --- a/arch/risc-v/common/tos_cpu.c +++ b/arch/risc-v/common/tos_cpu.c @@ -126,10 +126,8 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, regs = (cpu_context_t*) sp; - for(int i=1; i<(sizeof(cpu_context_t)/sizeof(cpu_data_t)); i+=2) { - // every task begin with "Tencent" - *(sp + i - 1) = 0x0054656E; - *(sp + i - 0) = 0x63656E74; + for(int i=1; i<(sizeof(cpu_context_t)/sizeof(cpu_data_t)); i++) { + *(sp + i) = 0xACEADD00 | ((i / 10) << 4) | (i % 10); } cpu_data_t gp = 0; @@ -137,7 +135,7 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, regs->gp = (cpu_data_t)gp; // global pointer regs->a0 = (cpu_data_t)arg; // argument - regs->ra = (cpu_data_t)0xACE00ACE; // return address + regs->ra = (cpu_data_t)exit; // return address regs->mstatus = (cpu_data_t)0x00001880; // return to machine mode and enable interrupt regs->mepc = (cpu_data_t)entry; // task entry @@ -151,22 +149,16 @@ void cpu_trap_entry(cpu_data_t cause, cpu_context_t *regs) } } -void SysTick_IRQHandler() { - port_systick_config((uint32_t)k_cpu_cycle_per_tick); - if (tos_knl_is_running()) { - tos_knl_irq_enter(); - tos_tick_handler(); - tos_knl_irq_leave(); - } -} - void cpu_irq_entry(cpu_data_t irq) { - if (irq != 7) { + void (*irq_handler)(); + + irq_handler = *((void (**)())(port_get_irq_vector_table() + irq*sizeof(cpu_addr_t))); + if((*irq_handler) == 0) { return; } - SysTick_IRQHandler(); + (*irq_handler)(); } __API__ uint32_t tos_cpu_clz(uint32_t val) diff --git a/arch/risc-v/rv32i/gcc/port.h b/arch/risc-v/rv32i/gcc/port.h index 66772bd0..933337d8 100644 --- a/arch/risc-v/rv32i/gcc/port.h +++ b/arch/risc-v/rv32i/gcc/port.h @@ -40,6 +40,14 @@ __PORT__ void port_systick_config(uint32_t cycle_per_tick); __PORT__ void port_systick_priority_set(uint32_t prio); + +__PORT__ void port_cpu_init(); + +__PORT__ void port_systick_priority_set(uint32_t priority); + +__PORT__ void* port_get_irq_vector_table(); + + #if TOS_CFG_TICKLESS_EN > 0u __PORT__ void port_systick_resume(void); diff --git a/arch/risc-v/spike/gcc/riscv_port.h b/arch/risc-v/spike/gcc/riscv_port.h index bbbbf3bf..23fbc30a 100644 --- a/arch/risc-v/spike/gcc/riscv_port.h +++ b/arch/risc-v/spike/gcc/riscv_port.h @@ -25,10 +25,4 @@ #define MCAUSE_EXP_CODE_MASK 0x7FFFFFFF -#ifndef __ASSEMBLER__ -void port_cpu_init(); - -void port_systick_priority_set(uint32_t priority); -#endif /* __ASSEMBLER__ */ - #endif /* _RISCV_PORT_H_ */ diff --git a/arch/risc-v/spike/gcc/riscv_port_c.c b/arch/risc-v/spike/gcc/riscv_port_c.c index bcc99c21..c42452cd 100644 --- a/arch/risc-v/spike/gcc/riscv_port_c.c +++ b/arch/risc-v/spike/gcc/riscv_port_c.c @@ -24,3 +24,10 @@ __PORT__ void port_cpu_init() { __PORT__ void port_systick_priority_set(uint32_t priority) { // DO NOTHING } + + +extern cpu_data_t irq_vector_table_base; +__PORT__ void* port_get_irq_vector_table() { + void *base = (void *) &irq_vector_table_base; + return base; +} diff --git a/arch/risc-v/spike/gcc/riscv_port_s.S b/arch/risc-v/spike/gcc/riscv_port_s.S new file mode 100644 index 00000000..01785fc1 --- /dev/null +++ b/arch/risc-v/spike/gcc/riscv_port_s.S @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------- + * Tencent is pleased to support the open source community by making TencentOS + * available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * If you have downloaded a copy of the TencentOS binary from Tencent, please + * note that the TencentOS binary is licensed under the BSD 3-Clause License. + * + * If you have downloaded a copy of the TencentOS source code from Tencent, + * please note that TencentOS source code is licensed under the BSD 3-Clause + * License, except for the third-party components listed below which are + * subject to different license terms. Your integration of TencentOS into your + * own projects may require compliance with the BSD 3-Clause License, as well + * as the other licenses applicable to the third-party components included + * within TencentOS. + *---------------------------------------------------------------------------*/ + +.global irq_vector_table_base + +.extern SysTick_IRQHandler + +.section .text +.align 2 +irq_vector_table_base: + .word 0xACEACEAC + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word SysTick_IRQHandler diff --git a/board/GigaDevice_GD32VF103C_START/BSP/Src/gd32vf103_it.c b/board/GigaDevice_GD32VF103C_START/BSP/Src/gd32vf103_it.c new file mode 100644 index 00000000..aa33583b --- /dev/null +++ b/board/GigaDevice_GD32VF103C_START/BSP/Src/gd32vf103_it.c @@ -0,0 +1,11 @@ +#include "tos.h" + +// systick handler +void eclic_mtip_handler() { + port_systick_config((uint32_t)k_cpu_cycle_per_tick); + if (tos_knl_is_running()) { + tos_knl_irq_enter(); + tos_tick_handler(); + tos_knl_irq_leave(); + } +} diff --git a/board/QEMU_Spike/GCC/demo/Makefile b/board/QEMU_Spike/GCC/demo/Makefile index 6d015d6b..ef9e8ca6 100644 --- a/board/QEMU_Spike/GCC/demo/Makefile +++ b/board/QEMU_Spike/GCC/demo/Makefile @@ -46,7 +46,8 @@ ARCH_SRC = \ C_SOURCES += $(ARCH_SRC) HAL_DRIVER_SRC = \ - $(TOP_DIR)/board/QEMU_Spike/Src/main.c + $(TOP_DIR)/board/QEMU_Spike/Src/main.c \ + $(TOP_DIR)/board/QEMU_Spike/Src/gd32vf103_it.c C_SOURCES += $(HAL_DRIVER_SRC) # ASM sources @@ -54,6 +55,7 @@ ASM_SOURCES = ASM_SOURCES_S = \ $(TOP_DIR)/arch/risc-v/rv32i/gcc/port_s.S \ +$(TOP_DIR)/arch/risc-v/spike/gcc/riscv_port_s.S \ start.S diff --git a/board/QEMU_Spike/Src/gd32vf103_it.c b/board/QEMU_Spike/Src/gd32vf103_it.c new file mode 100644 index 00000000..cf55f885 --- /dev/null +++ b/board/QEMU_Spike/Src/gd32vf103_it.c @@ -0,0 +1,9 @@ +#include "tos.h" +void SysTick_IRQHandler() { + port_systick_config((uint32_t)k_cpu_cycle_per_tick); + if (tos_knl_is_running()) { + tos_knl_irq_enter(); + tos_tick_handler(); + tos_knl_irq_leave(); + } +} diff --git a/board/QEMU_Spike/eclipse/demo/.cproject b/board/QEMU_Spike/eclipse/demo/.cproject index cad83a20..97073eff 100644 --- a/board/QEMU_Spike/eclipse/demo/.cproject +++ b/board/QEMU_Spike/eclipse/demo/.cproject @@ -137,11 +137,11 @@ - - + + diff --git a/board/QEMU_Spike/eclipse/demo/.project b/board/QEMU_Spike/eclipse/demo/.project index 4a407d3f..1b53d2df 100644 --- a/board/QEMU_Spike/eclipse/demo/.project +++ b/board/QEMU_Spike/eclipse/demo/.project @@ -57,12 +57,12 @@ TencentOS_tiny/arch/risc-v/common 2 - TOP_DIR/arch/risc-v/common + $%7BPARENT-4-PROJECT_LOC%7D/arch/risc-v/common TencentOS_tiny/arch/risc-v/rv32i 2 - TOP_DIR/arch/risc-v/rv32i/gcc + $%7BPARENT-4-PROJECT_LOC%7D/arch/risc-v/rv32i TencentOS_tiny/arch/risc-v/spike diff --git a/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml b/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml index 05946d95..5b2c59bc 100644 --- a/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml +++ b/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml @@ -11,7 +11,7 @@ - + diff --git a/board/Sipeed_LonganNano/BSP/Src/gd32vf103_it.c b/board/Sipeed_LonganNano/BSP/Src/gd32vf103_it.c new file mode 100644 index 00000000..aa33583b --- /dev/null +++ b/board/Sipeed_LonganNano/BSP/Src/gd32vf103_it.c @@ -0,0 +1,11 @@ +#include "tos.h" + +// systick handler +void eclic_mtip_handler() { + port_systick_config((uint32_t)k_cpu_cycle_per_tick); + if (tos_knl_is_running()) { + tos_knl_irq_enter(); + tos_tick_handler(); + tos_knl_irq_leave(); + } +}