11/*
2- * Copyright (c) 2006-2024 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
8- * 2024-07-04 rcitach init ver .
8+ * 2025-04-22 ScuDays Add VDSO functionality under the riscv64 architecture .
99 */
1010
1111#include <rtthread.h>
1212#include <mmu.h>
13- #include <gtimer.h>
1413#include <lwp_user_mm.h>
1514
1615#include "vdso.h"
1716#include "vdso_datapage.h"
18- #define DBG_TAG "vdso"
19- #define DBG_LVL DBG_INFO
17+ #define DBG_TAG "vdso"
18+ #define DBG_LVL DBG_INFO
2019#include <rtdbg.h>
2120
22- enum vdso_abi {
23- VDSO_ABI_AA64 ,
21+ enum vdso_abi
22+ {
23+ VDSO_ABI_COMMON ,
2424};
25- enum vvar_pages {
25+
26+ enum vvar_pages
27+ {
2628 VVAR_DATA_PAGE_OFFSET ,
2729 VVAR_TIMENS_PAGE_OFFSET ,
2830 VVAR_NR_PAGES ,
2931};
30- struct vdso_abi_info {
31- const char * name ;
32- const char * vdso_code_start ;
33- const char * vdso_code_end ;
34- unsigned long vdso_pages ;
3532
33+
34+ struct vdso_abi_info
35+ {
36+ const char * name ;
37+ const char * vdso_code_start ;
38+ const char * vdso_code_end ;
39+ unsigned long vdso_pages ;
3640};
3741
3842static struct vdso_abi_info vdso_info [] = {
39- [VDSO_ABI_AA64 ] = {
40- .name = "vdso_aarch64 " ,
41- .vdso_code_start = __vdso_text_start ,
42- .vdso_code_end = __vdso_text_end ,
43- },
43+ [VDSO_ABI_COMMON ] = {
44+ .name = "vdso_common " ,
45+ .vdso_code_start = __vdso_text_start ,
46+ .vdso_code_end = __vdso_text_end ,
47+ },
4448};
4549
4650static union {
47- struct vdso_data data [CS_BASES ];
48- uint8_t page [ARCH_PAGE_SIZE ];
51+ struct vdso_data data [CS_BASES ];
52+ uint8_t page [ARCH_PAGE_SIZE ];
4953} vdso_data_store __page_aligned_data ;
50- struct vdso_data * vdso_data = vdso_data_store .data ;
51- int init_ret_flag = RT_EOK ;
54+ struct vdso_data * vdso_data = vdso_data_store .data ;
55+ int init_ret_flag = RT_EOK ;
5256
5357static int __setup_additional_pages (enum vdso_abi abi , struct rt_lwp * lwp )
5458{
5559 RT_ASSERT (lwp != RT_NULL );
5660
57- int ret ;
58- void * vdso_base = RT_NULL ;
61+ int ret ;
62+ void * vdso_base = RT_NULL ;
5963 unsigned long vdso_data_len , vdso_text_len ;
6064
6165 vdso_data_len = VVAR_NR_PAGES * ARCH_PAGE_SIZE ;
6266 vdso_text_len = vdso_info [abi ].vdso_pages << ARCH_PAGE_SHIFT ;
6367
6468 vdso_base = lwp_map_user_phy (lwp , RT_NULL , rt_kmem_v2p ((void * )vdso_data ), vdso_data_len , 0 );
65- if (vdso_base != RT_NULL )
69+ if (vdso_base != RT_NULL )
6670 {
6771 ret = RT_EOK ;
6872 }
6973 else
7074 {
7175 ret = RT_ERROR ;
7276 }
77+
7378 vdso_base += vdso_data_len ;
74- vdso_base = lwp_map_user_phy (lwp , vdso_base , rt_kmem_v2p ((void * )vdso_info [abi ].vdso_code_start ), vdso_text_len , 0 );
79+ vdso_base = lwp_map_user_phy (lwp , vdso_base , rt_kmem_v2p ((void * )vdso_info [abi ].vdso_code_start ), vdso_text_len , 0 );
7580
7681 lwp -> vdso_vbase = vdso_base ;
7782 return ret ;
@@ -81,28 +86,28 @@ int arch_setup_additional_pages(struct rt_lwp *lwp)
8186{
8287 int ret ;
8388 if (init_ret_flag != RT_EOK ) return - RT_ERROR ;
84- ret = __setup_additional_pages (VDSO_ABI_AA64 , lwp );
89+ ret = __setup_additional_pages (VDSO_ABI_COMMON , lwp );
8590
8691 return ret ;
8792}
8893
94+
8995static void __initdata (void )
9096{
91- struct tm time_vdso = SOFT_RTC_VDSOTIME_DEFAULT ;
97+ struct tm time_vdso = SOFT_RTC_VDSOTIME_DEFAULT ;
9298 vdso_data -> realtime_initdata = timegm (& time_vdso );
9399}
94100
101+
95102static int validate_vdso_elf (void )
96103{
97- if (rt_memcmp (vdso_info [VDSO_ABI_AA64 ].vdso_code_start , ELF_HEAD , ELF_HEAD_LEN )) {
104+ if (rt_memcmp (vdso_info [VDSO_ABI_COMMON ].vdso_code_start , ELF_HEAD , ELF_HEAD_LEN ))
105+ {
98106 LOG_E ("vDSO is not a valid ELF object!" );
99107 init_ret_flag = - RT_ERROR ;
100108 return - RT_ERROR ;
101109 }
102- vdso_info [VDSO_ABI_AA64 ].vdso_pages = (
103- vdso_info [VDSO_ABI_AA64 ].vdso_code_end -
104- vdso_info [VDSO_ABI_AA64 ].vdso_code_start ) >>
105- ARCH_PAGE_SHIFT ;
110+ vdso_info [VDSO_ABI_COMMON ].vdso_pages = (vdso_info [VDSO_ABI_COMMON ].vdso_code_end - vdso_info [VDSO_ABI_COMMON ].vdso_code_start ) >> ARCH_PAGE_SHIFT ;
106111
107112 __initdata ();
108113 return RT_EOK ;
0 commit comments