-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add VDSO functionality under the riscv64 architecture. #10219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f0131c
52c7674
a451d47
f0e716d
ca901cd
6e6e481
badcd88
22d801d
98b3c68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,19 +10,19 @@ | |
|
|
||
| typedef struct | ||
| { | ||
| Elf64_Word st_name; | ||
| Elf64_Addr st_value; | ||
| Elf64_Word st_size; | ||
| Elf64_Word st_name; | ||
| Elf64_Addr st_value; | ||
| Elf64_Word st_size; | ||
| unsigned char st_info; | ||
| unsigned char st_other; | ||
| Elf64_Half st_shndx; | ||
| Elf64_Half st_shndx; | ||
| } Elf64_sym; | ||
|
|
||
| #ifdef ARCH_MM_MMU | ||
| void arch_elf_reloc(rt_aspace_t aspace, void *text_start, void *rel_dyn_start, size_t rel_dyn_size, void *got_start, size_t got_size, Elf64_sym *dynsym) | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. arch_elf_reloc 这个函数在哪里被调用的,没发现调用的地方?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个reloc.c文件是原本就有的,这个pr里面只修改了这个文件的位置,这个函数arch_elf_reloc 具体的调用我也不太清楚。
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议研究一下,即使不在这个 pr 里改,或许是个另外的问题,可以提 issue,在另外的 pr 里改。
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的 |
||
| size_t rel_off; | ||
| void* addr; | ||
| void *addr; | ||
|
|
||
| if (rel_dyn_size && !dynsym) | ||
| { | ||
|
|
@@ -40,26 +40,26 @@ void arch_elf_reloc(rt_aspace_t aspace, void *text_start, void *rel_dyn_start, s | |
| addr = rt_hw_mmu_v2p(aspace, (void *)((rt_size_t)text_start + v1)); | ||
| if ((v2 & 0xff) == R_ARM_RELATIVE) | ||
| { | ||
| *(rt_size_t*)addr += (rt_size_t)text_start; | ||
| *(rt_size_t *)addr += (rt_size_t)text_start; | ||
| } | ||
| else if ((v2 & 0xff) == R_ARM_ABS32) | ||
| { | ||
| uint32_t t; | ||
| t = (v2 >> 8); | ||
| if (t) /* 0 is UDF */ | ||
| { | ||
| *(rt_size_t*)addr = (((rt_size_t)text_start) + dynsym[t].st_value); | ||
| *(rt_size_t *)addr = (((rt_size_t)text_start) + dynsym[t].st_value); | ||
| } | ||
| } | ||
| } | ||
| /* modify got */ | ||
| if (got_size) | ||
| { | ||
| uint32_t *got_item = (uint32_t*)got_start; | ||
| uint32_t *got_item = (uint32_t *)got_start; | ||
|
|
||
| for (rel_off = 0; rel_off < got_size; rel_off += 4, got_item++) | ||
| { | ||
| addr = rt_hw_mmu_v2p(aspace, got_item); | ||
| addr = rt_hw_mmu_v2p(aspace, got_item); | ||
| *(rt_size_t *)addr += (rt_size_t)text_start; | ||
| } | ||
| } | ||
|
|
@@ -83,22 +83,22 @@ void arch_elf_reloc(void *text_start, void *rel_dyn_start, size_t rel_dyn_size, | |
|
|
||
| if ((v2 & 0xff) == R_ARM_RELATIVE) | ||
| { | ||
| *(uint32_t*)(((rt_size_t)text_start) + v1) += (uint32_t)text_start; | ||
| *(uint32_t *)(((rt_size_t)text_start) + v1) += (uint32_t)text_start; | ||
| } | ||
| else if ((v2 & 0xff) == R_ARM_ABS32) | ||
| { | ||
| uint32_t t; | ||
| t = (v2 >> 8); | ||
| if (t) /* 0 is UDF */ | ||
| { | ||
| *(uint32_t*)(((rt_size_t)text_start) + v1) = (uint32_t)(((rt_size_t)text_start) + dynsym[t].st_value); | ||
| *(uint32_t *)(((rt_size_t)text_start) + v1) = (uint32_t)(((rt_size_t)text_start) + dynsym[t].st_value); | ||
| } | ||
| } | ||
| } | ||
| /* modify got */ | ||
| if (got_size) | ||
| { | ||
| uint32_t *got_item = (uint32_t*)got_start; | ||
| uint32_t *got_item = (uint32_t *)got_start; | ||
|
|
||
| for (rel_off = 0; rel_off < got_size; rel_off += 4, got_item++) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2006-2025 RT-Thread Development Team | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Change Logs: | ||
| * Date Author Notes | ||
| * 2025-04-22 ScuDays Add VDSO functionality under the riscv64 architecture. | ||
| */ | ||
|
|
||
| #include <rtthread.h> | ||
| #include <ktime.h> | ||
| #include <time.h> | ||
| #include <vdso_datapage.h> | ||
| #include <vdso_data.h> | ||
| #include <encoding.h> | ||
|
|
||
| void rt_vdso_update_glob_time(void) | ||
| { | ||
| struct vdso_data *vdata = get_k_vdso_data(); | ||
| struct timespec *vdso_ts; | ||
| uint64_t initdata = vdata->realtime_initdata; | ||
| rt_vdso_write_begin(vdata); | ||
|
|
||
| vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_REALTIME]; | ||
| rt_ktime_boottime_get_ns(vdso_ts); | ||
| vdso_ts->tv_sec = initdata + vdso_ts->tv_sec; | ||
|
|
||
| vdso_ts = &vdata[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC]; | ||
| rt_ktime_boottime_get_ns(vdso_ts); | ||
|
|
||
| vdata->cycle_last = rdtime(); | ||
| rt_vdso_write_end(vdata); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| menuconfig RT_USING_VDSO | ||
| bool "vDSO" | ||
| default y | ||
| depends on RT_USING_SMART && ARCH_ARMV8 | ||
| depends on RT_USING_SMART && (ARCH_ARMV8 || ARCH_RISCV) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ import subprocess | |
|
|
||
| arguments = sys.argv[2] | ||
| vdso_usr = os.path.dirname(arguments) | ||
| vdso_root = os.path.dirname(vdso_usr) | ||
| user_path = os.path.dirname(vdso_usr) | ||
| user_path = os.path.dirname(user_path) | ||
| user_path = os.path.dirname(user_path) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么需要三个连续赋值?不一样的吗
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已经修改,需要找到特定那一级目录。 |
||
|
|
||
|
|
||
| EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/usr/bin' | ||
|
|
@@ -22,8 +24,7 @@ CXXFLAGS = DEVICE + ' -Wall -fdiagnostics-color=always' | |
| AFLAGS = ' -x assembler-with-cpp' | ||
| CFLAGS = DEVICE + ' -Wall -Wno-cpp -std=gnu99 -fdiagnostics-color=always -fPIC -O2' | ||
| LFLAGS = DEVICE + ' -Bsymbolic -Wl,--gc-sections,-u,system_vectors -T {path}/vdso.lds'.format(path=vdso_usr) | ||
| CFLAGS += " -I {path} -I{path}/user".format(path=vdso_root) | ||
|
|
||
| CFLAGS += " -I {path} -I {upath} ".format(path=vdso_usr ,upath=user_path) | ||
| env = Environment(tools=['gcc', 'link'], | ||
| AS = AS, ASFLAGS = AFLAGS, | ||
| CC = CC, CFLAGS = CFLAGS, | ||
|
|
@@ -34,6 +35,6 @@ env.PrependENVPath('PATH', EXEC_PATH) | |
|
|
||
| src = os.path.join(vdso_usr,'vdso_sys.c') | ||
| target_name = 'librtos_vdso.so' | ||
| target = os.path.join(vdso_usr, "build", target_name) | ||
| target = os.path.join(user_path + "/user", "build", target_name) | ||
| shared_lib = env.SharedLibrary(target=target, source=src) | ||
| env.Default(shared_lib) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里挺奇怪的,为什么要改,而不是增加。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改