adds hooks in bootup do move smp booting into the smp port lib
This commit is contained in:
1 parent
d97e71ca83
commit
ba39d23a18
6 files changed
+143
-156
No files matched your search
@@ -0,0 +1,113 @@
|
||||
|
||||
#include "aclint.h"
|
||||
#include "aclint_ipi.h"
|
||||
#include "board.h"
|
||||
#include "csr.h"
|
||||
#include "hwtimer.h"
|
||||
#include "riscv-csr.h"
|
||||
#include "riscv-traps.h"
|
||||
#include "tx_port.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern CHAR __heap_start;
|
||||
extern void trap_entry(void);
|
||||
extern void _tx_timer_interrupt(void);
|
||||
|
||||
extern ULONG* _tx_thread_system_stack_ptr;
|
||||
extern ULONG* _tx_initialize_unused_memory;
|
||||
extern void _tx_thread_smp_initialize_wait(void) __attribute__((noreturn));
|
||||
|
||||
void handle_RISCV_INT_MTI(void)
|
||||
{
|
||||
hwtimer_handler();
|
||||
_tx_timer_interrupt();
|
||||
}
|
||||
|
||||
void handle_RISCV_INT_MEI()
|
||||
{
|
||||
puts("[INTERRUPT]: handler ext irq error!\n");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
#ifdef TX_THREAD_SMP_INTER_CORE_INTERRUPT
|
||||
void handle_RISCV_INT_MSI()
|
||||
{
|
||||
set_aclint_msip(aclint, csr_read_mhartid(), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void __attribute__((used)) bootup_ipi_clear_handler(void)
|
||||
{
|
||||
set_aclint_msip(aclint, csr_read_mhartid(), 0);
|
||||
}
|
||||
|
||||
void _secondary_ipi_trap(void) __attribute__((naked, noreturn, section(".text.boot")));
|
||||
void _secondary_initialize(void) __attribute__((noreturn, section(".text.boot")));
|
||||
void bootup_wake_secondary_cores(void);
|
||||
|
||||
void _secondary_initialize(void)
|
||||
{
|
||||
csr_write_mtvec((uint_xlen_t)_secondary_ipi_trap);
|
||||
csr_set_bits_mie(MIE_MSI_BIT_MASK);
|
||||
csr_set_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||
|
||||
__asm__ volatile("wfi");
|
||||
|
||||
csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||
|
||||
_tx_thread_smp_initialize_wait();
|
||||
}
|
||||
|
||||
void _secondary_ipi_trap(void)
|
||||
{
|
||||
#if __riscv_xlen == 64
|
||||
__asm__ volatile("addi sp, sp, -16;"
|
||||
"sd ra, 8(sp);"
|
||||
"call bootup_ipi_clear_handler;"
|
||||
"ld ra, 8(sp);"
|
||||
"addi sp, sp, 16;"
|
||||
"mret");
|
||||
#else
|
||||
__asm__ volatile("addi sp, sp, -8;"
|
||||
"sw ra, 4(sp);"
|
||||
"call bootup_ipi_clear_handler;"
|
||||
"lw ra, 4(sp);"
|
||||
"addi sp, sp, 8;"
|
||||
"mret");
|
||||
#endif
|
||||
}
|
||||
|
||||
void bootup_wake_secondary_cores(void)
|
||||
{
|
||||
for (UINT core = 1; core < TX_THREAD_SMP_MAX_CORES; ++core) {
|
||||
send_ipi(core);
|
||||
}
|
||||
}
|
||||
|
||||
VOID _tx_initialize_low_level(VOID)
|
||||
{
|
||||
_tx_thread_system_stack_ptr = (VOID*)(ULONG)riscv_get_sp();
|
||||
_tx_initialize_unused_memory = (VOID*)&__heap_start;
|
||||
|
||||
// disable interrupts
|
||||
asm volatile("csrrc zero, mstatus, %0" : : "r"(MSTATUS_MIE));
|
||||
// set previous interrupt enable and previous priv mode to be set when executing "mret"
|
||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_MPP_M | MSTATUS_MPIE));
|
||||
// enable timer, software and external interrupts
|
||||
asm volatile("csrrs zero, mie, %0" : : "r"(MIE_MTIE | MIE_MSIE | MIE_MEIE));
|
||||
|
||||
#ifdef __riscv_flen
|
||||
// enable f extension and reset state
|
||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_FS));
|
||||
asm volatile("fscsr x0");
|
||||
#endif
|
||||
|
||||
board_init();
|
||||
register_irq_handler(RISCV_INT_MTI, handle_RISCV_INT_MTI);
|
||||
register_irq_handler(RISCV_INT_MEI, handle_RISCV_INT_MEI);
|
||||
#ifdef TX_THREAD_SMP_INTER_CORE_INTERRUPT
|
||||
register_irq_handler(RISCV_INT_MSI, handle_RISCV_INT_MSI);
|
||||
#endif
|
||||
asm volatile("csrw mtvec, %0" : : "r"((uintptr_t)trap_entry));
|
||||
}
|
||||
Reference in new issue
Block a user