Skip to content
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

Add 39-bit virtual memory scheme support for riscv64. #49

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -78,6 +78,8 @@ if cc.symbols_have_underscore_prefix()
mangling = 'leading-underscore'
endif

memory_addr_bits = 'undefined'

if arch == 'x86'
bitness = 32
elif arch == 'x86_64'
@@ -88,6 +90,9 @@ elif arch == 'aarch64'
bitness = 64
elif arch == 'riscv64'
bitness = 64
# 39 bit virtual address scheme(sv39) is widely used in riscv64 in 2023
# still need to find a stable method to detect address scheme in user mode
memory_addr_bits = '39'
else
error('Architecture "@0@" is not supported.'.format(arch))
endif
@@ -121,6 +126,10 @@ config.set('BXF_ARCH_@0@'.format(arch.to_upper()), 1)
config.set('BXF_MANGLING', mangling)
config.set('BXF_BITS', bitness)

if memory_addr_bits != 'undefined'
config.set('BXF_MEM_ADDR_BITS', memory_addr_bits)
endif

checks = [
{'fn': 'clock_gettime'},
{'fn': 'gettimeofday'},
8 changes: 8 additions & 0 deletions src/arena.c
Original file line number Diff line number Diff line change
@@ -54,11 +54,19 @@ static void *mmap_max = (void *) 0x80000000;
static intptr_t mmap_off = (intptr_t) 1 << 16;
static intptr_t mmap_off_mask = 0x3fff;
#elif BXF_BITS == 64
# ifndef BXF_MEM_ADDR_BITS
/* On Linux it seems that you cannot map > 48-bit addresses */
static void *mmap_base = (void *) 0x200000000000;
static void *mmap_max = (void *) 0x7f0000000000;
static intptr_t mmap_off = (intptr_t) 1 << 24;
static intptr_t mmap_off_mask = 0x3fffff;
# elif BXF_MEM_ADDR_BITS == 39
/* 39-bit virtual memory scheme is used in some riscv64 or amd64 machines */
static void *mmap_base = (void *) 0x1000000000;
static void *mmap_max = (void *) 0x3f00000000;
static intptr_t mmap_off = (intptr_t) 1 << 20;
static intptr_t mmap_off_mask = 0x1ffff;
# endif
#else
# error Platform not supported
#endif
2 changes: 2 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@
#mesondefine BXF_MANGLING
#mesondefine BXF_OS_FAMILY

#mesondefine BXF_MEM_ADDR_BITS

# ifdef BXF_OS_FAMILY
# define BXF_OS_FAMILY_STR #BXF_OS_FAMILY
# endif