Skip to content

Commit 1422604

Browse files
zifeihanRealFYang
authored andcommitted
8297697: RISC-V: Add support for SATP mode detection
8301067: RISC-V: better error message when reporting unsupported satp modes Reviewed-by: fjiang, fyang Backport-of: f49acd52594be3ec1e9682bda3ad69970dfd750d
1 parent 9207935 commit 1422604

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/hotspot/cpu/riscv/vm_version_riscv.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include OS_HEADER_INLINE(os)
3434

3535
const char* VM_Version::_uarch = "";
36+
const char* VM_Version::_vm_mode = "";
3637
uint32_t VM_Version::_initial_vector_length = 0;
3738

3839
void VM_Version::initialize() {
@@ -44,6 +45,13 @@ void VM_Version::initialize() {
4445

4546
get_os_cpu_info();
4647

48+
// check if satp.mode is supported, currently supports up to SV48(RV64)
49+
if (get_satp_mode() > VM_SV48) {
50+
vm_exit_during_initialization(
51+
err_msg("Unsupported satp mode: %s. Only satp modes up to sv48 are supported for now.",
52+
_vm_mode));
53+
}
54+
4755
if (FLAG_IS_DEFAULT(UseFMA)) {
4856
FLAG_SET_DEFAULT(UseFMA, true);
4957
}

src/hotspot/cpu/riscv/vm_version_riscv.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,22 @@ class VM_Version : public Abstract_VM_Version {
3838
static void c2_initialize();
3939
#endif // COMPILER2
4040

41+
// VM modes (satp.mode) privileged ISA 1.10
42+
enum VM_MODE {
43+
VM_MBARE = 0,
44+
VM_SV39 = 8,
45+
VM_SV48 = 9,
46+
VM_SV57 = 10,
47+
VM_SV64 = 11
48+
};
49+
4150
protected:
4251
static const char* _uarch;
52+
static const char* _vm_mode;
4353
static uint32_t _initial_vector_length;
4454
static void get_os_cpu_info();
4555
static uint32_t get_current_vector_length();
56+
static VM_MODE get_satp_mode();
4657

4758
public:
4859
// Initialization

src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ uint32_t VM_Version::get_current_vector_length() {
7575
return (uint32_t)read_csr(CSR_VLENB);
7676
}
7777

78+
VM_Version::VM_MODE VM_Version::get_satp_mode() {
79+
if (!strcmp(_vm_mode, "sv39")) {
80+
return VM_SV39;
81+
} else if (!strcmp(_vm_mode, "sv48")) {
82+
return VM_SV48;
83+
} else if (!strcmp(_vm_mode, "sv57")) {
84+
return VM_SV57;
85+
} else if (!strcmp(_vm_mode, "sv64")) {
86+
return VM_SV64;
87+
} else {
88+
return VM_MBARE;
89+
}
90+
}
91+
7892
void VM_Version::get_os_cpu_info() {
7993

8094
uint64_t auxv = getauxval(AT_HWCAP);
@@ -103,7 +117,14 @@ void VM_Version::get_os_cpu_info() {
103117
char buf[512], *p;
104118
while (fgets(buf, sizeof (buf), f) != NULL) {
105119
if ((p = strchr(buf, ':')) != NULL) {
106-
if (strncmp(buf, "uarch", sizeof "uarch" - 1) == 0) {
120+
if (strncmp(buf, "mmu", sizeof "mmu" - 1) == 0) {
121+
if (_vm_mode[0] != '\0') {
122+
continue;
123+
}
124+
char* vm_mode = os::strdup(p + 2);
125+
vm_mode[strcspn(vm_mode, "\n")] = '\0';
126+
_vm_mode = vm_mode;
127+
} else if (strncmp(buf, "uarch", sizeof "uarch" - 1) == 0) {
107128
char* uarch = os::strdup(p + 2);
108129
uarch[strcspn(uarch, "\n")] = '\0';
109130
_uarch = uarch;

0 commit comments

Comments
 (0)