Skip to content

Commit

Permalink
fixup! feat: implement hypervisor extension
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmikhalevich committed Oct 15, 2023
1 parent c287764 commit 799e5ce
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/clua-machine-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ CM_PROC_CSR clua_check_cm_proc_csr(lua_State *L, int idx) try {
{"hie", CM_PROC_HIE},
{"hvip", CM_PROC_HVIP},
{"hgatp", CM_PROC_HGATP},
{"henvcfg", CM_PROC_HENVCFG},
{"htimedelta", CM_PROC_HTIMEDELTA},
{"htval", CM_PROC_HTVAL},
{"vsepc", CM_PROC_VSEPC},
Expand Down
1 change: 1 addition & 0 deletions src/machine-c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ typedef enum { // NOLINT(modernize-use-using)
CM_PROC_HIP,
CM_PROC_HVIP,
CM_PROC_HGATP,
CM_PROC_HENVCFG,
CM_PROC_HTIMEDELTA,
CM_PROC_HTVAL,
CM_PROC_VSEPC,
Expand Down
2 changes: 1 addition & 1 deletion src/riscv-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ enum CARTESI_init : uint64_t {
MCAUSE_INIT = UINT64_C(0), ///< Initial value for mcause
MTVAL_INIT = UINT64_C(0), ///< Initial value for mtval
MISA_INIT = (MISA_MXL_VALUE << MISA_MXL_SHIFT) | MISA_EXT_S_MASK | MISA_EXT_U_MASK | MISA_EXT_I_MASK |
MISA_EXT_M_MASK | MISA_EXT_A_MASK | MISA_EXT_F_MASK | MISA_EXT_D_MASK |
MISA_EXT_M_MASK | MISA_EXT_A_MASK | MISA_EXT_F_MASK | MISA_EXT_D_MASK | MISA_EXT_H_MASK |
MISA_EXT_C_MASK, ///< Initial value for misa
MIE_INIT = UINT64_C(0), ///< Initial value for mie
MIP_INIT = UINT64_C(0), ///< Initial value for mip
Expand Down
48 changes: 35 additions & 13 deletions src/tests/machine-bind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,33 @@ local cpu_csr_addr = {
satp = 712,
scounteren = 720,
senvcfg = 728,
ilrsc = 736,
iflags = 744,
clint_mtimecmp = 752,
htif_tohost = 760,
htif_fromhost = 768,
htif_ihalt = 776,
htif_iconsole = 784,
htif_iyield = 792,
hstatus = 736,
hideleg = 744,
hedeleg = 752,
hie = 760,
hip = 768,
hvip = 776,
hgatp = 784,
henvcfg = 792,
htimedelta = 800,
htval = 808,
vsepc = 816,
vsstatus = 824,
vscause = 832,
vstval = 840,
vstvec = 848,
vsscratch = 856,
vsatp = 864,
vsie = 872,
vsip = 880,
ilrsc = 888,
iflags = 896,
clint_mtimecmp = 904,
htif_tohost = 912,
htif_fromhost = 920,
htif_ihalt = 928,
htif_iconsole = 936,
htif_iyield = 944,
}

local function get_cpu_csr_test_values()
Expand Down Expand Up @@ -242,7 +261,7 @@ local function get_cpu_csr_test_values()
hip = 0x2f8,
hvip = 0x300,
hgatp = 0x308,
henvcfg = 0x310,
henvcfg = -1,
htimedelta = 0x318,
htval = 0x320,
vsepc = 0x328,
Expand All @@ -255,7 +274,7 @@ local function get_cpu_csr_test_values()
vsie = 0x360,
vsip = 0x368,
fcsr = 0x61,
ilrsc = 0x370,
ilrsc = 0x378,
}
end

Expand Down Expand Up @@ -362,6 +381,7 @@ do_test("machine should have default config shadow register values", function(ma
initial_csr_values.mvendorid = nil
initial_csr_values.marchid = nil
initial_csr_values.mimpid = nil
initial_csr_values.henvcfg = nil
-- Check initialization and shadow reads
for k, v in pairs(initial_csr_values) do
local r = machine:read_word(cpu_csr_addr[k])
Expand Down Expand Up @@ -427,7 +447,7 @@ end)

print("\n\ntesting get_x_uarch_address function binding")
do_test("should return address value for uarch x registers", function()
local SHADOW_UARCH_XBASE = 0x340
local SHADOW_UARCH_XBASE = 0x3d8
local module = cartesi
if machine_type == "grpc" then
if not remote then remote = connect() end
Expand Down Expand Up @@ -522,9 +542,10 @@ do_test("should have expected values", function(machine)
-- Check initial config
local initial_config = machine:get_initial_config()
test_config(initial_config)
print(initial_config.processor.mstatus)
assert(initial_config.processor.pc == 0x200, "wrong pc reg initial config value")
assert(initial_config.processor.ilrsc == 0x2e0, "wrong ilrsc reg initial config value")
assert(initial_config.processor.mstatus == 0x368, "wrong mstatus reg initial config value")
assert(initial_config.processor.ilrsc == 0x378, "wrong ilrsc reg initial config value")
assert(initial_config.processor.mstatus == 0x230, "wrong mstatus reg initial config value")
assert(initial_config.clint.mtimecmp == 0, "wrong clint mtimecmp initial config value")
assert(initial_config.htif.fromhost == 0, "wrong htif fromhost initial config value")
assert(initial_config.htif.tohost == 0, "wrong htif tohost initial config value")
Expand All @@ -538,6 +559,7 @@ do_test("should return expected values", function(machine)
initial_csr_values.mvendorid = cartesi.MVENDORID
initial_csr_values.marchid = cartesi.MARCHID
initial_csr_values.mimpid = cartesi.MIMPID
initial_csr_values.henvcfg = 0x0
initial_csr_values.htif_tohost = 0x0
initial_csr_values.htif_fromhost = 0x0
initial_csr_values.htif_ihalt = 0x0
Expand Down

0 comments on commit 799e5ce

Please sign in to comment.