Skip to content

Commit 7fbd88b

Browse files
committed
[Arch/RISC-V] Next RISC-V
1. ISA manager interface. 2. Merge 32E/32I/64I. 3. Cache by CBOM ISA. 4. MMU support Sv32/Sv39/Sv48/Sv57/Sv64, SVPBMT ISA. 5. Merge M-mode, S-mode CSR ops. 6. Support SMP. 7. Support APLIC & IMSIC (AIA), CLIC, ACLINT/CLINT, INTC, PLIC. 8. Support DM (only by OFW) or not DM. 9. Merge T-HEAD vendor. Signed-off-by: GuEe-GUI <[email protected]>
1 parent 3ebad06 commit 7fbd88b

File tree

144 files changed

+10600
-10667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+10600
-10667
lines changed

components/drivers/cputime/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
config RT_USING_CPUTIME
1+
menuconfig RT_USING_CPUTIME
22
bool "Enable CPU time for high resolution clock counter"
33
default n
44
help
@@ -25,9 +25,9 @@ if RT_USING_CPUTIME
2525
config RT_USING_CPUTIME_RISCV
2626
bool "Use rdtime instructions for CPU time"
2727
default y
28-
depends on ARCH_RISCV64
28+
depends on ARCH_RISCV
2929
help
30-
Some RISCV64 MCU Use rdtime instructions read CPU time.
30+
Some RISC-V MCU Use rdtime instructions read CPU time.
3131
config CPUTIME_TIMER_FREQ
3232
int "CPUTIME timer freq"
3333
default 0

components/drivers/cputime/cputime_riscv.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
#include <rtthread.h>
44

55
#include <board.h>
6+
#include <riscv_timer.h>
67

78
/* Use Cycle counter of Data Watchpoint and Trace Register for CPU time */
89

910
static uint64_t riscv_cputime_getres(void)
1011
{
1112
uint64_t ret = 1000UL * 1000 * 1000;
1213

13-
ret = (ret * (1000UL * 1000)) / CPUTIME_TIMER_FREQ;
14+
ret = (ret * (1000UL * 1000)) / riscv_timer_get_frequency();
1415
return ret;
1516
}
1617

1718
static uint64_t riscv_cputime_gettime(void)
1819
{
19-
uint64_t time_elapsed;
20-
__asm__ __volatile__(
21-
"rdtime %0"
22-
: "=r"(time_elapsed));
23-
return time_elapsed;
20+
return riscv_timer_rdtime();
2421
}
2522

2623
const static struct rt_clock_cputime_ops _riscv_ops =
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
/*
2-
* Copyright (c) 2006-2023, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2023-07-10 xqyjlj The first version.
9+
* 2025-04-20 GuEe-GUI Port to the DM
910
*/
1011

1112
#include "ktime.h"
13+
#include "riscv_timer.h"
1214

1315
static volatile unsigned long _init_cnt = 0;
1416

1517
rt_uint64_t rt_ktime_cputimer_getres(void)
1618
{
17-
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / CPUTIME_TIMER_FREQ;
19+
return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / riscv_timer_get_frequency();
1820
}
1921

2022
unsigned long rt_ktime_cputimer_getfrq(void)
2123
{
22-
return CPUTIME_TIMER_FREQ;
24+
return riscv_timer_get_frequency();
2325
}
2426

2527
unsigned long rt_ktime_cputimer_getcnt(void)
2628
{
27-
unsigned long time_elapsed;
28-
__asm__ __volatile__("rdtime %0" : "=r"(time_elapsed));
29-
return time_elapsed - _init_cnt;
29+
return riscv_timer_rdtime() - _init_cnt;
3030
}
3131

3232
unsigned long rt_ktime_cputimer_getstep(void)
@@ -36,5 +36,5 @@ unsigned long rt_ktime_cputimer_getstep(void)
3636

3737
void rt_ktime_cputimer_init(void)
3838
{
39-
__asm__ __volatile__("rdtime %0" : "=r"(_init_cnt));
39+
_init_cnt = riscv_timer_rdtime();
4040
}

libcpu/Kconfig

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ if ARCH_ARMV8 && ARCH_CPU_64BIT
22
orsource "./aarch64/Kconfig"
33
endif
44

5+
if ARCH_RISCV
6+
orsource "./risc-v/Kconfig"
7+
endif
8+
59
config ARCH_CPU_64BIT
610
bool
711

@@ -195,7 +199,7 @@ config ARCH_ARMV8
195199
select ARCH_ARM
196200
select ARCH_ARM_MMU
197201
select RT_USING_CPU_FFS
198-
select ARCH_USING_ASID
202+
select ARCH_USING_ASID if RT_USING_SMART
199203
select ARCH_USING_IRQ_CTX_LIST
200204

201205
config ARCH_MIPS
@@ -220,55 +224,8 @@ config ARCH_POWERPC
220224

221225
config ARCH_RISCV
222226
bool
223-
224-
config ARCH_RISCV_FPU
225-
bool
226-
227-
config ARCH_RISCV_VECTOR
228-
bool
229-
230-
if ARCH_RISCV_VECTOR
231-
choice
232-
prompt "RISCV Vector Vlen"
233-
default ARCH_VECTOR_VLEN_128
234-
235-
config ARCH_VECTOR_VLEN_128
236-
bool "128"
237-
config ARCH_VECTOR_VLEN_256
238-
bool "256"
239-
endchoice
240-
endif
241-
242-
config ARCH_RISCV_FPU_S
243-
select ARCH_RISCV_FPU
244-
bool
245-
246-
config ARCH_RISCV_FPU_D
247-
select ARCH_RISCV_FPU
248-
bool
249-
250-
config ARCH_RISCV32
251-
select ARCH_RISCV
252-
bool
253-
254-
config ARCH_RISCV64
255-
select ARCH_RISCV
256-
select ARCH_CPU_64BIT
257-
bool
258-
259-
if ARCH_RISCV64
260-
config ARCH_USING_NEW_CTX_SWITCH
261-
bool
262-
default y
263-
264-
config ARCH_USING_RISCV_COMMON64
265-
bool
266-
depends on ARCH_RISCV64
267-
select RT_USING_CPUTIME
268-
select ARCH_USING_NEW_CTX_SWITCH
269-
help
270-
Using the common64 implementation under ./libcpu/risc-v
271-
endif
227+
select RT_USING_CPU_FFS
228+
select RT_PAGE_MPR_SIZE_DYNAMIC if ARCH_MM_MMU
272229

273230
config ARCH_REMAP_KERNEL
274231
bool

libcpu/risc-v/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
link.lds

libcpu/risc-v/Kconfig

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
menu "RISC-V Architecture Configuration"
2+
config ARCH_TEXT_OFFSET
3+
hex "Text offset"
4+
default 0x200000
5+
help
6+
We use the area as the DM ioremap address space in 32 bits RT-Thread:
7+
[ARCH_TEXT_OFFSET - IOREMAP_SIZE, ARCH_TEXT_OFFSET)
8+
So you SHOULD config the value bigger than this area.
9+
The `IOREMAP_SIZE` is defined a default value in common/setup.c.
10+
11+
config ARCH_RAM_OFFSET
12+
hex "RAM offset"
13+
default 0
14+
15+
config ARCH_SECONDARY_CPU_STACK_SIZE
16+
int "Secondary CPU stack size"
17+
default 4096
18+
19+
config ARCH_HAVE_EFFICIENT_UNALIGNED_ACCESS
20+
bool
21+
default y
22+
23+
config ARCH_HEAP_SIZE
24+
hex "Size of system heap"
25+
default 0x4000000
26+
27+
config ARCH_INIT_PAGE_SIZE
28+
hex "Size of init page region"
29+
default 0x200000
30+
31+
config ARCH_RISCV_DISABLE_FENCE_I
32+
bool
33+
default n
34+
35+
config ARCH_RISCV_DISABLE_SFENCE_VMA_ASID
36+
bool
37+
default n
38+
39+
config ARCH_RISCV_M_MODE
40+
bool
41+
depends on !ARCH_MM_MMU
42+
default n
43+
44+
config ARCH_RISCV_32E
45+
bool
46+
depends on !ARCH_CPU_64BIT
47+
depends on !ARCH_MM_MMU
48+
depends on !RT_USING_DM
49+
50+
config ARCH_RISCV_FPU
51+
bool "Enable FPU"
52+
default y
53+
54+
config ARCH_RISCV_VECTOR
55+
bool "Using RISC-V Vector Extension"
56+
depends on !ARCH_RISCV_32E
57+
58+
choice
59+
prompt "Vector Registers Length in Bits"
60+
depends on ARCH_RISCV_VECTOR
61+
default ARCH_VECTOR_VLEN_128
62+
63+
config ARCH_VECTOR_VLEN_128
64+
bool "128"
65+
config ARCH_VECTOR_VLEN_256
66+
bool "256"
67+
endchoice
68+
69+
config ARCH_RISCV_FPU_S
70+
select ARCH_RISCV_FPU
71+
bool
72+
73+
config ARCH_RISCV_FPU_D
74+
select ARCH_RISCV_FPU
75+
bool
76+
77+
config ARCH_USING_NEW_CTX_SWITCH
78+
bool
79+
depends on ARCH_CPU_64BIT
80+
default y
81+
82+
config ARCH_USING_RISCV_COMMON64
83+
bool
84+
depends on ARCH_CPU_64BIT
85+
select RT_USING_CPUTIME
86+
select ARCH_USING_NEW_CTX_SWITCH
87+
88+
config RT_USING_USERSPACE_32BIT_LIMIT
89+
bool "Enable userspace 32bit limit"
90+
default n
91+
endmenu

libcpu/risc-v/SConscript

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,38 @@ from building import *
55

66
Import('rtconfig')
77

8-
common64_arch = ['virt64', 'c906', 'c908']
98
cwd = GetCurrentDir()
109
group = []
1110
list = os.listdir(cwd)
11+
bsp_path = Dir('#').abspath
12+
vender_path = cwd
1213

13-
# add common code files
14-
if rtconfig.CPU in common64_arch :
15-
group += SConscript(os.path.join('common64', 'SConscript'))
16-
else :
17-
group += SConscript(os.path.join('common', 'SConscript'))
14+
if not os.path.exists(bsp_path + "/link.lds"):
15+
Env['LINKFLAGS'] = Env['LINKFLAGS'].replace('link.lds', cwd + "/link.lds")
16+
Preprocessing("link.lds.S", ".lds", CPPPATH=[bsp_path, cwd + '/common/include'])
17+
18+
# fix the linker with crtx.o
19+
Env['LINKFLAGS'] += ' -nostartfiles'
1820

19-
group += SConscript(os.path.join('vector', 'SConscript'))
21+
# add common code files
22+
group += SConscript(os.path.join('common', 'SConscript'))
2023

2124
# cpu porting code files
22-
if 'VENDOR' in vars(rtconfig) and rtconfig.VENDOR != '':
23-
group = group + SConscript(os.path.join(rtconfig.VENDOR, rtconfig.CPU, 'SConscript'))
24-
elif rtconfig.CPU in list:
25+
if 'VENDER' in vars(rtconfig) and rtconfig.VENDER != '':
26+
group = group + SConscript(os.path.join(rtconfig.VENDER, rtconfig.CPU, 'SConscript'))
27+
vender_path += rtconfig.VENDER + "/" + rtconfig.CPU
28+
elif rtconfig.CPU != '':
2529
group = group + SConscript(os.path.join(rtconfig.CPU, 'SConscript'))
30+
vender_path += rtconfig.CPU
31+
32+
if os.path.exists(vender_path + "/mmu_vendor.h"):
33+
Env['ASFLAGS'] += '-D__HAS_MMU_VENDOR__'
34+
Env['CFLAGS'] += '-D__HAS_MMU_VENDOR__'
35+
Env['CXXFLAGS'] += '-D__HAS_MMU_VENDOR__'
36+
37+
if os.path.exists(vender_path + "/opcode_vendor.h"):
38+
Env['ASFLAGS'] += '-D__HAS_OPCODE_VENDOR__'
39+
Env['CFLAGS'] += '-D__HAS_OPCODE_VENDOR__'
40+
Env['CXXFLAGS'] += '-D__HAS_OPCODE_VENDOR__'
2641

2742
Return('group')

0 commit comments

Comments
 (0)