adds hooks in bootup do move smp booting into the smp port lib

This commit is contained in:
2026-04-10 14:40:21 +02:00
parent d97e71ca83
commit ba39d23a18
6 changed files with 143 additions and 156 deletions

View File

@@ -6,20 +6,15 @@
*/
#include <stddef.h>
#include <stdint.h>
#include <string.h>
//#include <picotls.h>
#include <aclint_ipi.h>
//#include <tx_port.h>
#include <riscv-csr.h>
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C extern
#endif
#if defined(TX_THREAD_SMP_MAX_CORES) && (TX_THREAD_SMP_MAX_CORES > 1)
#define BOOTUP_SMP_ENABLED
#endif
// Generic C function pointer.
typedef void(*function_t)(void) ;
@@ -49,8 +44,9 @@ EXTERN_C void _start(void) __attribute__ ((naked,section(".text.boot")));
// Entry and exit points as C functions.
EXTERN_C void _initialize(void) __attribute__ ((noreturn,section(".text.boot")));
EXTERN_C void _secondary_sleep_forever(void) __attribute__ ((noreturn,section(".text.boot")));
EXTERN_C void _secondary_initialize(void) __attribute__ ((noreturn,section(".text.boot"),weak));
EXTERN_C void _exit(int exit_code) __attribute__ ((noreturn,noinline,weak));
EXTERN_C void bootup_wake_secondary_cores(void) __attribute__ ((weak));
// Standard entry point, no arguments.
extern int main(void);
@@ -59,52 +55,6 @@ extern int main(void);
EXTERN_C void _set_tls(uint8_t*) __attribute__ ((noreturn,section(".text.boot")));
#endif
#if defined BOOTUP_SMP_ENABLED
EXTERN_C void _secondary_initialize(void) __attribute__ ((noreturn,section(".text.boot")));
EXTERN_C void _secondary_ipi_trap(void) __attribute__ ((naked,noreturn,section(".text.boot")));
EXTERN_C void _tx_thread_smp_initialize_wait(void) __attribute__ ((noreturn));
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
}
static void bootup_wake_secondary_cores(void) {
for (UINT core = 1; core < TX_THREAD_SMP_MAX_CORES; ++core) {
send_ipi(core);
}
}
__attribute__((used)) void bootup_ipi_clear_handler(void) {
set_aclint_msip(aclint, csr_read_mhartid(), 0);
}
#endif
// The linker script will place this in the reset entry point.
// It will be 'called' with no stack or C runtime configuration.
// tp will not be initialized
@@ -137,11 +87,7 @@ void _start(void) {
"j 1b;"
"2:;"
"beqz t0, 3f;"
#ifdef BOOTUP_SMP_ENABLED
"jal zero, _secondary_initialize;"
#else
"jal zero, _secondary_sleep_forever;"
#endif
"3:;"
"jal zero, _initialize;"
: /* output: none %0 */
@@ -167,9 +113,7 @@ void _initialize(void) {
++entry) {
(*entry)();
}
#ifdef BOOTUP_SMP_ENABLED
bootup_wake_secondary_cores();
#endif
#ifdef __THREAD_LOCAL_STORAGE
_set_tls(__tls_base)
#endif
@@ -183,7 +127,8 @@ void _initialize(void) {
_exit(rc);
}
void _secondary_sleep_forever(void) {
void _secondary_initialize(void) {
// sleep forever
csr_clr_bits_mie(MIE_MTI_BIT_MASK);
csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK);
while (1) {
@@ -191,6 +136,9 @@ void _secondary_sleep_forever(void) {
}
}
void bootup_wake_secondary_cores(void) {
}
// This should never be called. Report the exit code through HTIF and idle the CPU.
void _exit(int exit_code) {
uintptr_t htif_exit_code = (((uintptr_t)(unsigned int)exit_code) << 1) | 1u;
@@ -201,4 +149,4 @@ void _exit(int exit_code) {
while (1) {
__asm__ volatile ("wfi");
}
}
}

View File

@@ -30,13 +30,6 @@ void trap_handler(uintptr_t mcause, uintptr_t mepc, uintptr_t mtval) {
if(OS_IS_INTERRUPT(mcause)) {
unsigned irq_id = mcause&(__riscv_xlen-1);
switch(irq_id){
/*
#ifdef TX_THREAD_SMP_INTER_CORE_INTERRUPT
case RISCV_INT_MSI:
set_aclint_msip(aclint, csr_read_mhartid(), 0);
break;
#endif
*/
default:
if(irq_handler[irq_id])
irq_handler[irq_id]();