Merge "sencha: remove unintentional i2s logLevel setting"
diff --git a/shodan_infrastructure/MpactCheriotCPU.cs b/shodan_infrastructure/MpactCheriotCPU.cs
index ecb6a85..ba3ca12 100644
--- a/shodan_infrastructure/MpactCheriotCPU.cs
+++ b/shodan_infrastructure/MpactCheriotCPU.cs
@@ -113,7 +113,6 @@
         config_values.Add("0x" + memorySize.ToString("X"));
         config_values.Add("0x" + revocationMemBase.ToString("X"));
         if (cli_port != 0) {
-            this.Log(LogLevel.Info, "Adding cli port");
             config_names.Add("cliPort");
             config_values.Add("0x" + cli_port.ToString("X"));
             config_names.Add("waitForCLI");
@@ -130,14 +129,24 @@
         }
         // Load executable file or bin file if specified. Otherwise it is
         // handled by the system.
+        this.Log(LogLevel.Info, "symbol_file: '" + symbol_file + "'");
         if (!executable_file.Equals("")) {
-            var entry_point = load_executable(mpact_id, executable_file,
-                                              error_ptr);
+            var entry_point = load_elf(mpact_id, executable_file,
+                                       /*for_symbols_only=*/false,
+                                       error_ptr);
             Int32 result = Marshal.ReadInt32(error_ptr);
             if (result < 0) {
                 LogAndThrowRE("Failed to load executable");
             }
             PC = entry_point;
+        } else if (!symbol_file.Equals("")) {
+            this.Log(LogLevel.Info, "loading symbol_file: '" + symbol_file + "'");
+            load_elf(mpact_id, symbol_file, /*for_symbols_only=*/true,
+                     error_ptr);
+            Int32 result = Marshal.ReadInt32(error_ptr);
+            if (result < 0) {
+                LogAndThrowRE("Failed to load symbols");
+            }
         } else if (!bin_file_info.file_name.Equals("")) {
             Int32 res = load_image(mpact_id, bin_file_info.file_name,
                                    bin_file_info.load_address);
@@ -204,6 +213,11 @@
         set => executable_file = value;
     }
 
+    public string SymbolFile {
+        get => symbol_file;
+        set => symbol_file = value;
+    }
+
     public BinFileLoadInfo BinFileInfo {
         get => bin_file_info;
         set => bin_file_info = value;
@@ -370,10 +384,12 @@
     }
 
     public void OnGPIO(int number, bool value) {
-		if (mpact_id <= 0) {
-			this.Log(LogLevel.Noisy, "OnGPIO: no simulator, discard gpio {0}:{1}", number, value);
-			return;
-		}
+        if (mpact_id < 0) {
+            this.Log(LogLevel.Noisy,
+                     "OnGPIO: no simulator, discard gpio {0}:{1}", number,
+                     value);
+            return;
+        }
         Int32 status = set_irq_value(mpact_id, number, value);
         if (status < 0) {
             Console.Error.WriteLine("Failure in setting irq value");
@@ -591,7 +607,7 @@
     // End of IMpactPeripheral methods.
 
     private ushort cli_port = 0;
-    private bool wait_for_cli = false;
+    private bool wait_for_cli = true;
     private UInt64 base_address = 0;
     private UInt64 size = 0;
     private List<GDBFeatureDescriptor>
@@ -604,6 +620,7 @@
     private Dictionary<string, Int32>
 	        registerNamesMap = new Dictionary<string, Int32>();
     private string executable_file = "";
+    private string symbol_file = "";
     private BinFileLoadInfo
 	        bin_file_info = new BinFileLoadInfo {file_name = "",
 			                             load_address = 0,
@@ -638,6 +655,10 @@
     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
     public delegate Int32 SetIrqValue(Int32 param0, Int32 param1, bool param2);
 
+    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+    public delegate UInt64 LoadElf(Int32 param0, string param1, bool param2,
+                                   IntPtr param3);
+
     // Int32 read_sysmem_delegate(UInt64 address, IntPtr buffer, Int32 size)
     private FuncInt32UInt64IntPtrInt32 read_sysmem_delegate;
     // Int32 write_sysmem_delegate(UInt64 address, IntPtr buffer, Int32 size)
@@ -674,8 +695,9 @@
     private FuncInt32Int32Int32IntPtrIntPtr get_reg_info;
 
     [Import(UseExceptionWrapper = false)]
-    // UInt64 load_executable(Int32 id, String file_name);
-    private FuncUInt64Int32StringIntPtr load_executable;
+    // UInt64 load_elf(Int32 id, String file_name,
+    //                 bool for_symbols_only, Int32* error_ptr);
+    private LoadElf load_elf;
 
     [Import(UseExceptionWrapper = false)]
     // Int32 load_image(Int32 id, String file_name, UInt64 address);