Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/hotspot/cpu/riscv/vm_version_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@
#include "utilities/macros.hpp"

const char* VM_Version::_uarch = "";
const char* VM_Version::_vm_mode = "";
uint32_t VM_Version::_initial_vector_length = 0;

void VM_Version::initialize() {
get_os_cpu_info();

// check if satp.mode is supported, currently supports up to SV48(RV64)
if (get_satp_mode() > VM_SV48) {
vm_exit_during_initialization(err_msg("Unsupported satp mode: %s", _vm_mode));
}

// https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#rva20-profiles
if (UseRVA20U64) {
if (FLAG_IS_DEFAULT(UseRVC)) {
Expand Down
11 changes: 11 additions & 0 deletions src/hotspot/cpu/riscv/vm_version_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ class VM_Version : public Abstract_VM_Version {
static void c2_initialize();
#endif // COMPILER2

// VM modes (satp.mode) privileged ISA 1.10
enum VM_MODE {
VM_MBARE = 0,
VM_SV39 = 8,
VM_SV48 = 9,
VM_SV57 = 10,
VM_SV64 = 11
};

protected:
static const char* _uarch;
static const char* _vm_mode;
static uint32_t _initial_vector_length;
static void get_os_cpu_info();
static uint32_t get_current_vector_length();
static VM_MODE get_satp_mode();

public:
// Initialization
Expand Down
23 changes: 22 additions & 1 deletion src/hotspot/os_cpu/linux_riscv/vm_version_linux_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ uint32_t VM_Version::get_current_vector_length() {
return (uint32_t)read_csr(CSR_VLENB);
}

VM_Version::VM_MODE VM_Version::get_satp_mode() {
if (!strcmp(_vm_mode, "sv39")) {
return VM_SV39;
} else if (!strcmp(_vm_mode, "sv48")) {
return VM_SV48;
} else if (!strcmp(_vm_mode, "sv57")) {
return VM_SV57;
} else if (!strcmp(_vm_mode, "sv64")) {
return VM_SV64;
} else {
return VM_MBARE;
}
}

void VM_Version::get_os_cpu_info() {

uint64_t auxv = getauxval(AT_HWCAP);
Expand Down Expand Up @@ -103,7 +117,14 @@ void VM_Version::get_os_cpu_info() {
char buf[512], *p;
while (fgets(buf, sizeof (buf), f) != NULL) {
if ((p = strchr(buf, ':')) != NULL) {
if (strncmp(buf, "uarch", sizeof "uarch" - 1) == 0) {
if (strncmp(buf, "mmu", sizeof "mmu" - 1) == 0) {
if (_vm_mode[0] != '\0') {
continue;
}
char* vm_mode = os::strdup(p + 2);
vm_mode[strcspn(vm_mode, "\n")] = '\0';
_vm_mode = vm_mode;
} else if (strncmp(buf, "uarch", sizeof "uarch" - 1) == 0) {
char* uarch = os::strdup(p + 2);
uarch[strcspn(uarch, "\n")] = '\0';
_uarch = uarch;
Expand Down