mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-16 01:05:15 +08:00
* [libcpu][risc-v] Refactor the RISC-V architecture port Introduce an opt-in unified RISC-V common layer for RV32 and RV64 while keeping existing BSPs on the legacy implementation during migration. - use ARCH_RISCV and ARCH_CPU_64BIT for architecture and XLEN selection - unify context, trap, MMU, cache, timer, SBI, SMP and ISA handling - add PLIC, CLIC, ACLINT, APLIC and IMSIC support - map physical hart IDs to contiguous logical CPU IDs - add T-Head vendor overrides while preserving legacy ports - migrate qemu-virt64-riscv with RV32 and RV64 support - update clock_time, MM, LWP, OFW, PCI and Rust integration Existing BSPs continue using legacy_common or common64 unless they select RT_USING_RISCV_NEW_COMMON. Signed-off-by: GuEe-GUI <2991707448@qq.com> * [libcpu][risc-v] skip disabled CPU nodes in early FDT walk Rbb666 noted that rt_hw_fdt_install_early() walked every /cpus child without checking status, so disabled cores still joined hart registration and MMU capability probing. Skip nodes that are not okay/ok via rt_fdt_device_is_available() before reading reg or mmu-type. Signed-off-by: seteiro <chenmoushun@163.com> * [libcpu][risc-v] Fix per-CPU page table mapping - reuse existing non-leaf page table entries when mapping per-CPU areas - reject leaf entry conflicts instead of overwriting mappings Signed-off-by: GuEe-GUI <2991707448@qq.com> --------- Signed-off-by: GuEe-GUI <2991707448@qq.com> Signed-off-by: seteiro <chenmoushun@163.com> Co-authored-by: seteiro <chenmoushun@163.com>
63 lines
1.7 KiB
C
63 lines
1.7 KiB
C
/*
|
|
* Copyright (c) 2006-2025, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2018-10-28 Bernard The unify RISC-V porting code.
|
|
* 2021-02-11 lizhirui add gp support
|
|
* 2021-11-19 JasonHu add fpu support
|
|
* 2025-04-20 GuEe-GUI Port for CPU ID
|
|
*/
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <cpu.h>
|
|
#include <csr.h>
|
|
#include <stack.h>
|
|
#include <cpuport.h>
|
|
#ifdef ARCH_MM_MMU
|
|
#include <mmu.h>
|
|
#endif
|
|
|
|
/**
|
|
* This function will initialize thread stack, we assuming
|
|
* when scheduler restore this new thread, context will restore
|
|
* an entry to user first application
|
|
*
|
|
* s0-s11, ra, sstatus, a0
|
|
* @param tentry the entry of thread
|
|
* @param parameter the parameter of entry
|
|
* @param stack_addr the beginning stack address
|
|
* @param texit the function will be called when thread exit
|
|
*
|
|
* @return stack address
|
|
*/
|
|
rt_uint8_t *rt_hw_stack_init(void *tentry,
|
|
void *parameter,
|
|
rt_uint8_t *stack_addr,
|
|
void *texit)
|
|
{
|
|
rt_ubase_t *sp;
|
|
rt_hw_switch_frame_t frame;
|
|
|
|
/* We use a strict alignment requirement for Q extension */
|
|
sp = (rt_ubase_t *)RT_ALIGN_DOWN((rt_ubase_t)stack_addr, 16);
|
|
|
|
*(--sp) = (rt_ubase_t)tentry;
|
|
*(--sp) = (rt_ubase_t)parameter;
|
|
*(--sp) = (rt_ubase_t)texit;
|
|
/* Alignment */
|
|
--sp;
|
|
|
|
frame = (rt_hw_switch_frame_t)((rt_ubase_t)sp - sizeof(*frame));
|
|
rt_memset(frame, 0, sizeof(*frame));
|
|
|
|
frame->regs[RT_HW_SWITCH_CONTEXT_RA] = (rt_ubase_t)_thread_start;
|
|
frame->regs[RT_HW_SWITCH_CONTEXT_XSTATUS] = K_XSTATUS_DEFAULT;
|
|
/* Bare SMP keeps the current hart's tp across context switches. */
|
|
|
|
return (void *)frame;
|
|
}
|