mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-17 07:05:31 +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>
106 lines
2.6 KiB
C
106 lines
2.6 KiB
C
/*
|
|
* Copyright (c) 2006-2025 RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2023-03-12 WangXiaoyao the first version
|
|
* 2025-04-20 GuEe-GUI Merge 64 and 32 mode
|
|
*/
|
|
|
|
#ifndef __ASM_GENERIC_H__
|
|
#define __ASM_GENERIC_H__
|
|
|
|
#if defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
|
|
/* For XuanTie GCC */
|
|
#define __ASSEMBLY__
|
|
#endif
|
|
|
|
#include <rtconfig.h>
|
|
|
|
#ifdef __ASSEMBLY__
|
|
/* use to mark a start point where every task start from */
|
|
#define START_POINT(funcname) \
|
|
.global funcname; \
|
|
.type funcname, %function; \
|
|
funcname: \
|
|
.cfi_sections .debug_frame, .eh_frame; \
|
|
.cfi_startproc; \
|
|
.cfi_undefined ra
|
|
|
|
#define START_POINT_END(name) \
|
|
.cfi_endproc; \
|
|
.size name, .-name;
|
|
|
|
#define _AC(X,Y) X
|
|
#define _AT(T,X) X
|
|
#define __ASM_STR(x) x
|
|
#else
|
|
#define _AC(X,Y) (X##Y)
|
|
#define _AT(T,X) ((T)(X))
|
|
#define __ASM_STR(x) #x
|
|
#endif
|
|
|
|
#define _UL(x) (_AC(x, UL))
|
|
#define _ULL(x) (_AC(x, ULL))
|
|
|
|
#if __riscv_xlen == 64
|
|
#define BITS_PER_LONG 64
|
|
#define __REG_SEL(a, b) __ASM_STR(a)
|
|
#elif __riscv_xlen == 32
|
|
#define BITS_PER_LONG 32
|
|
#define __REG_SEL(a, b) __ASM_STR(b)
|
|
#else
|
|
#error "Unexpected __riscv_xlen"
|
|
#endif
|
|
|
|
#ifndef RT_BITS_PER_LONG
|
|
#define RT_BITS_PER_LONG BITS_PER_LONG
|
|
#endif
|
|
|
|
#ifndef BIT
|
|
#define BIT(x) (_UL(1) << (x))
|
|
#endif
|
|
|
|
#ifndef GENMASK
|
|
#define GENMASK(h, l) (((_UL(~0)) << (l)) & (_UL(~0) >> (BITS_PER_LONG - 1 - (h))))
|
|
#endif
|
|
|
|
#define REG_WIDTH __REG_SEL(d, w)
|
|
#define REG_L __REG_SEL(ld, lw)
|
|
#define REG_S __REG_SEL(sd, sw)
|
|
#define REG_SC __REG_SEL(sc.d, sc.w)
|
|
#define REG_AMOSWAP_AQ __REG_SEL(amoswap.d.aq, amoswap.w.aq)
|
|
#define REG_ASM __REG_SEL(.dword, .word)
|
|
#define SZREG __REG_SEL(8, 4)
|
|
#define LGREG __REG_SEL(3, 2)
|
|
#define FREG_L __REG_SEL(fld, flw)
|
|
#define FREG_S __REG_SEL(fsd, fsw)
|
|
|
|
#if __riscv_xlen == 64
|
|
#ifdef __ASSEMBLY__
|
|
#define RISCV_PTR .dword
|
|
#define RISCV_SZPTR 8
|
|
#define RISCV_LGPTR 3
|
|
#else
|
|
#define RISCV_PTR ".dword"
|
|
#define RISCV_SZPTR "8"
|
|
#define RISCV_LGPTR "3"
|
|
#endif
|
|
#elif __riscv_xlen == 32
|
|
#ifdef __ASSEMBLY__
|
|
#define RISCV_PTR .word
|
|
#define RISCV_SZPTR 4
|
|
#define RISCV_LGPTR 2
|
|
#else
|
|
#define RISCV_PTR ".word"
|
|
#define RISCV_SZPTR "4"
|
|
#define RISCV_LGPTR "2"
|
|
#endif
|
|
#else
|
|
#error "Unexpected __riscv_xlen"
|
|
#endif
|
|
|
|
#endif /* __ASM_GENERIC_H__ */
|