[dv, cosim] Enable ELF loading in MPACT co-simulation model

Bug: 439909603

Change-Id: I695fc2232424e66344f72b5468e73228ec194272
diff --git a/tests/uvm/common/cosim/kelvin_cosim_checker_pkg.sv b/tests/uvm/common/cosim/kelvin_cosim_checker_pkg.sv
index 167847a..517d342 100644
--- a/tests/uvm/common/cosim/kelvin_cosim_checker_pkg.sv
+++ b/tests/uvm/common/cosim/kelvin_cosim_checker_pkg.sv
@@ -51,6 +51,7 @@
 
     // Event to wait on, which will be triggered by the RVVI monitor
     uvm_event instruction_retired_event;
+    string test_elf;
 
     // Constructor
     function new(string name = "kelvin_cosim_checker",
@@ -69,6 +70,11 @@
          `uvm_fatal(get_type_name(), "RVVI virtual interface not found!")
       end
 
+      // Get the ELF file path
+      if (!uvm_config_db#(string)::get(this, "", "elf_file_for_iss", test_elf)) begin
+        `uvm_fatal(get_type_name(), "TEST_ELF file path not found!")
+      end
+
       // Create the event that this component will wait on.
       instruction_retired_event = new("instruction_retired_event");
       // Pass the event to the monitor using an absolute path
@@ -86,6 +92,8 @@
 
       if (mpact_init() != 0)
         `uvm_fatal(get_type_name(), "MPACT simulator DPI init failed.")
+      if (mpact_load_program(test_elf) != 0)
+        `uvm_fatal(get_type_name(), "MPACT simulator DPI init failed.")
 
       // Main co-simulation loop
       forever begin
diff --git a/tests/uvm/common/cosim/kelvin_cosim_dpi_if.sv b/tests/uvm/common/cosim/kelvin_cosim_dpi_if.sv
index ce111f4..5e6d216 100644
--- a/tests/uvm/common/cosim/kelvin_cosim_dpi_if.sv
+++ b/tests/uvm/common/cosim/kelvin_cosim_dpi_if.sv
@@ -23,6 +23,10 @@
   // Returns 0 on success.
   import "DPI-C" context function int mpact_init();
 
+  // Function to load an ELF program.
+  // Returns 0 on success.
+  import "DPI-C" context function int mpact_load_program(input string elf_file);
+
   // Function to reset the MPACT simulator.
   // Returns 0 on success.
   import "DPI-C" context function int mpact_reset();
diff --git a/tests/uvm/tests/kelvin_test_pkg.sv b/tests/uvm/tests/kelvin_test_pkg.sv
index cff058e..6c73a4b 100644
--- a/tests/uvm/tests/kelvin_test_pkg.sv
+++ b/tests/uvm/tests/kelvin_test_pkg.sv
@@ -124,12 +124,16 @@
     endfunction
 
     virtual function void build_phase(uvm_phase phase);
+      string test_elf;
       string timeout_str;
       int timeout_int;
       uvm_cmdline_processor clp = uvm_cmdline_processor::get_inst();
 
       super.build_phase(phase);
       `uvm_info(get_type_name(), "Build phase starting", UVM_MEDIUM)
+      if (!clp.get_arg_value("+TEST_ELF=", test_elf)) begin
+        `uvm_fatal(get_type_name(), "+TEST_ELF plusarg not specified.")
+      end
 
       if (clp.get_arg_value("+TEST_TIMEOUT=", timeout_str)) begin
         if ($sscanf(timeout_str, "%d", timeout_int) == 1 && timeout_int > 0)
@@ -144,6 +148,9 @@
 
       env = kelvin_env::type_id::create("env", this);
 
+      uvm_config_db#(string)::set(this, "*.m_cosim_checker",
+                                  "elf_file_for_iss", test_elf);
+
       // Get the event handle that was created and set by tb_top
       if (!uvm_config_db#(uvm_event)::get(this, "",
           "tohost_written_event", tohost_written_event)) begin