8297697: RISC-V: Add support for SATP mode detection

Reviewed-by: fyang, luhenry
This commit is contained in:
Feilong Jiang 2022-12-01 04:01:25 +00:00 committed by Fei Yang
parent 3b513a4f5c
commit f49acd5259
3 changed files with 39 additions and 1 deletions

View File

@ -31,11 +31,17 @@
#include "utilities/macros.hpp" #include "utilities/macros.hpp"
const char* VM_Version::_uarch = ""; const char* VM_Version::_uarch = "";
const char* VM_Version::_vm_mode = "";
uint32_t VM_Version::_initial_vector_length = 0; uint32_t VM_Version::_initial_vector_length = 0;
void VM_Version::initialize() { void VM_Version::initialize() {
get_os_cpu_info(); 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 // https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#rva20-profiles
if (UseRVA20U64) { if (UseRVA20U64) {
if (FLAG_IS_DEFAULT(UseRVC)) { if (FLAG_IS_DEFAULT(UseRVC)) {

View File

@ -38,11 +38,22 @@ private:
static void c2_initialize(); static void c2_initialize();
#endif // COMPILER2 #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: protected:
static const char* _uarch; static const char* _uarch;
static const char* _vm_mode;
static uint32_t _initial_vector_length; static uint32_t _initial_vector_length;
static void get_os_cpu_info(); static void get_os_cpu_info();
static uint32_t get_current_vector_length(); static uint32_t get_current_vector_length();
static VM_MODE get_satp_mode();
public: public:
// Initialization // Initialization

View File

@ -75,6 +75,20 @@ uint32_t VM_Version::get_current_vector_length() {
return (uint32_t)read_csr(CSR_VLENB); 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() { void VM_Version::get_os_cpu_info() {
uint64_t auxv = getauxval(AT_HWCAP); uint64_t auxv = getauxval(AT_HWCAP);
@ -103,7 +117,14 @@ void VM_Version::get_os_cpu_info() {
char buf[512], *p; char buf[512], *p;
while (fgets(buf, sizeof (buf), f) != NULL) { while (fgets(buf, sizeof (buf), f) != NULL) {
if ((p = strchr(buf, ':')) != 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); char* uarch = os::strdup(p + 2);
uarch[strcspn(uarch, "\n")] = '\0'; uarch[strcspn(uarch, "\n")] = '\0';
_uarch = uarch; _uarch = uarch;