risc-v support all irq handler

This commit is contained in:
acevest
2019-10-16 18:10:03 +08:00
parent 7983b07386
commit f41e287c2a
15 changed files with 126 additions and 37 deletions

View File

@@ -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_

View File

@@ -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;
}

View File

@@ -15,15 +15,31 @@
* within TencentOS.
*---------------------------------------------------------------------------*/
.global eclic_mtip_handler
.global irq_entry
.global trap_entry
.extern rv32_exception_entry
.extern SysTick_IRQHandler
.align 2
eclic_mtip_handler:
/* normal code */
// add sp, sp, -4
// sw ra, (sp)
// call SysTick_IRQHandler
// lw ra, (sp)
// add sp, sp, 4
// ret
/* the most efficient code */
j SysTick_IRQHandler
// the code will return to caller directly from SysTick_IRQHandler
.align 2
irq_entry:
j rv32_exception_entry
j irq_entry
.align 2
trap_entry:
j rv32_exception_entry
j trap_entry

View File

@@ -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)

View File

@@ -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);

View File

@@ -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_ */

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -137,11 +137,11 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/demo/TOS-CONFIG}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/demo/TencentOS_tiny/arch/risc-v/rv32i}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/demo/TencentOS_tiny/arch/risc-v/spike}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/demo/TencentOS_tiny/kernel/evtdrv/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/demo/TencentOS_tiny/arch/risc-v/rv32i/gcc/}&quot;"/>
</option>

View File

@@ -57,12 +57,12 @@
<link>
<name>TencentOS_tiny/arch/risc-v/common</name>
<type>2</type>
<locationURI>TOP_DIR/arch/risc-v/common</locationURI>
<locationURI>$%7BPARENT-4-PROJECT_LOC%7D/arch/risc-v/common</locationURI>
</link>
<link>
<name>TencentOS_tiny/arch/risc-v/rv32i</name>
<type>2</type>
<locationURI>TOP_DIR/arch/risc-v/rv32i/gcc</locationURI>
<locationURI>$%7BPARENT-4-PROJECT_LOC%7D/arch/risc-v/rv32i</locationURI>
</link>
<link>
<name>TencentOS_tiny/arch/risc-v/spike</name>

View File

@@ -11,7 +11,7 @@
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1303215729854698371" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1292200280605858179" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>

View File

@@ -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();
}
}